libbpf: use strlcpy() in path resolution fallback logic
Andrii Nakryiko
maintainerPATCH 1/2 libbpf: use strlcpy() in path resolution fallback logic
Coverity static analyzer complains that strcpy() can cause buffer overflow. Use libbpf_strlcpy() instead to be 100% sure this doesn't happen.
--- tools/lib/bpf/usdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/usdt.c +1 -1
@@ -456,7 +456,7 @@ static int parse_lib_segs(int pid, const char *lib_path, struct elf_seg **segs,if (!realpath (lib_path, path)) {pr_warn ("usdt: failed to get absolute path of '%s' (err %d), using path as is...\n" , lib_path, -errno); -strcpy (path, lib_path); +libbpf_strlcpy (path, lib_path,sizeof (path)); } proceed:
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 2/2 libbpf: allow WEAK and GLOBAL bindings during BTF fixup
During BTF fix up for global variables, global variable can be global weak and will have STB_WEAK binding in ELF. Support such global variables in addition to non-weak ones.
This is not the problem when using BPF static linking, as BPF static linker "fixes up" BTF during generation so that libbpf doesn't have to do it anymore during bpf_object__open(), which led to this not being noticed for a while, along with a pretty rare (currently) use of __weak variables and maps.
--- tools/lib/bpf/libbpf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +5 -2
@@ -1401,8 +1401,11 @@ static int find_elf_var_offset(const struct bpf_object *obj, const char *name, _for (si =0 ; si < symbols->d_size /sizeof (Elf64_Sym); si++) {Elf64_Sym *sym =elf_sym_by_idx (obj, si); -if (ELF64_ST_BIND (sym->st_info) !=STB_GLOBAL || -ELF64_ST_TYPE (sym->st_info) !=STT_OBJECT ) +if (ELF64_ST_TYPE (sym->st_info) !=STT_OBJECT ) +continue ; + +if (ELF64_ST_BIND (sym->st_info) !=STB_GLOBAL && +ELF64_ST_BIND (sym->st_info) !=STB_WEAK )continue ; sname =elf_sym_str (obj, sym->st_name);
Signature · 1 line
2.30.2
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Thu, 7 Apr 2022 16:04:45 -0700 you wrote:
Coverity static analyzer complains that
strcpy()can cause buffer overflow. Uselibbpf_strlcpy()instead to be 100% sure this doesn't happen.Signed-off-by Andrii Nakryiko <[email protected]>--- tools/lib/bpf/usdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Here is the summary with links:
- [bpf-next,1/2] libbpf: use strlcpy() in path resolution fallback logic
https://git.kernel.org/bpf/bpf-next/c/3c0dfe6e4c43 - [bpf-next,2/2] libbpf: allow WEAK and GLOBAL bindings during BTF fixup https://git.kernel.org/bpf/bpf-next/c/3a06ec0a996d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html