linux/tools/lib/bpf
Andrii Nakryiko 9fc205b413 libbpf: Add sane strncpy alternative and use it internally
strncpy() has a notoriously error-prone semantics which makes GCC
complain about it a lot (and quite often completely completely falsely
at that). Instead of pleasing GCC all the time (-Wno-stringop-truncation
is unfortunately only supported by GCC, so it's a bit too messy to just
enable it in Makefile), add libbpf-internal libbpf_strlcpy() helper
which follows what FreeBSD's strlcpy() does and what most people would
expect from strncpy(): copies up to N-1 first bytes from source string
into destination string and ensures zero-termination afterwards.

Replace all the relevant uses of strncpy/strncat/memcpy in libbpf with
libbpf_strlcpy().

This also fixes the issue reported by Emmanuel Deloget in xsk.c where
memcpy() could access source string beyond its end.

Fixes: 2f6324a393 (libbpf: Support shared umems between queues and devices)
Reported-by: Emmanuel Deloget <emmanuel.deloget@eho.link>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20211211004043.2374068-1-andrii@kernel.org
2021-12-14 15:47:56 +01:00
..
.gitignore libbpf: Make libbpf_version.h non-auto-generated 2021-09-13 15:36:47 -07:00
bpf_core_read.h libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() 2021-10-25 20:39:41 -07:00
bpf_endian.h libbpf: Make bpf_endian co-exist with vmlinux.h 2020-07-01 09:06:12 +02:00
bpf_gen_internal.h Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2021-12-10 15:56:13 -08:00
bpf_helpers.h libbpf: Use static const fmt string in __bpf_printk 2021-09-17 14:02:05 -07:00
bpf_prog_linfo.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
bpf_tracing.h riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h 2021-11-01 17:08:21 +01:00
bpf.c libbpf: Add sane strncpy alternative and use it internally 2021-12-14 15:47:56 +01:00
bpf.h libbpf: Allow passing user log setting through bpf_object_open_opts 2021-12-10 15:29:17 -08:00
btf_dump.c libbpf: Add sane strncpy alternative and use it internally 2021-12-14 15:47:56 +01:00
btf.c libbpf: Fix typo in btf__dedup@LIBBPF_0.0.2 definition 2021-12-10 15:35:29 -08:00
btf.h libbpf: Fix potential misaligned memory access in btf_ext__new() 2021-11-26 00:14:06 +01:00
Build libbpf: Split CO-RE logic into relo_core.c. 2021-07-26 12:29:14 -07:00
gen_loader.c libbpf: Add sane strncpy alternative and use it internally 2021-12-14 15:47:56 +01:00
hashmap.c libbpf: Centralize poisoning and poison reallocarray() 2020-08-18 18:38:25 -07:00
hashmap.h libbpf, hashmap: Fix undefined behavior in hash_bits 2020-11-02 23:33:51 +01:00
libbpf_common.h libbpf: Deprecate bpf_prog_load_xattr() API 2021-12-02 15:23:41 -08:00
libbpf_errno.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
libbpf_internal.h libbpf: Add sane strncpy alternative and use it internally 2021-12-14 15:47:56 +01:00
libbpf_legacy.h libbpf: Rename DECLARE_LIBBPF_OPTS into LIBBPF_OPTS 2021-11-07 08:34:22 -08:00
libbpf_probes.c libbpf: Add OPTS-based bpf_btf_load() API 2021-12-10 15:29:17 -08:00
libbpf_version.h libbpf: Add API to get/set log_level at per-program level 2021-12-02 15:23:40 -08:00
libbpf.c libbpf: Add sane strncpy alternative and use it internally 2021-12-14 15:47:56 +01:00
libbpf.h libbpf: Add doc comments for bpf_program__(un)pin() 2021-12-13 13:55:53 -08:00
libbpf.map libbpf: Add per-program log buffer setter and getter 2021-12-10 15:29:18 -08:00
libbpf.pc.template libbpf: Add zlib as a dependency in pkg-config template 2019-12-16 14:55:29 -08:00
linker.c libbpf: Fix using invalidated memory in bpf_linker 2021-11-26 00:15:03 +01:00
Makefile libbpf: Compile using -std=gnu89 2021-11-09 13:27:52 -08:00
netlink.c libbpf: Switch to void * casting in netlink helpers 2021-06-22 17:04:02 +02:00
nlattr.c libbpf: Switch to void * casting in netlink helpers 2021-06-22 17:04:02 +02:00
nlattr.h libbpf: Switch to void * casting in netlink helpers 2021-06-22 17:04:02 +02:00
relo_core.c libbpf: Fix potential uninit memory read 2021-12-14 15:37:58 +01:00
relo_core.h libbpf: Reduce bpf_core_apply_relo_insn() stack usage. 2021-12-03 13:21:59 -08:00
ringbuf.c libbpf: Streamline error reporting for high-level APIs 2021-05-25 17:32:35 -07:00
skel_internal.h bpf, mips: Fix build errors about __NR_bpf undeclared 2021-11-26 22:11:25 +01:00
str_error.c libbpf: Poison kernel-only integer types 2020-01-10 10:38:00 -08:00
str_error.h
strset.c libbpf: Fix memory leak in strset 2021-10-01 22:54:38 +02:00
strset.h libbpf: Extract internal set-of-strings datastructure APIs 2021-03-18 16:14:22 -07:00
xsk.c libbpf: Add sane strncpy alternative and use it internally 2021-12-14 15:47:56 +01:00
xsk.h libbpf: Deprecate AF_XDP support 2021-11-01 18:12:44 -07:00