BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 1/2] libbpf: use strlcpy() in path resolution fallback logic
@ 2022-04-07 23:04 Andrii Nakryiko
  2022-04-07 23:04 ` [PATCH bpf-next 2/2] libbpf: allow WEAK and GLOBAL bindings during BTF fixup Andrii Nakryiko
  2022-04-08 16:20 ` [PATCH bpf-next 1/2] libbpf: use strlcpy() in path resolution fallback logic patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2022-04-07 23:04 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Coverity static analyzer complains that strcpy() can cause buffer
overflow. Use libbpf_strlcpy() instead to be 100% sure this doesn't
happen.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/usdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
index b699e720136a..5d7ba171ad39 100644
--- a/tools/lib/bpf/usdt.c
+++ b/tools/lib/bpf/usdt.c
@@ -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:
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH bpf-next 2/2] libbpf: allow WEAK and GLOBAL bindings during BTF fixup
  2022-04-07 23:04 [PATCH bpf-next 1/2] libbpf: use strlcpy() in path resolution fallback logic Andrii Nakryiko
@ 2022-04-07 23:04 ` Andrii Nakryiko
  2022-04-08 16:20 ` [PATCH bpf-next 1/2] libbpf: use strlcpy() in path resolution fallback logic patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2022-04-07 23:04 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team, Hengqi Chen

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.

Reported-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 016ecdd1c3e1..9deb1fc67f19 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -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);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next 1/2] libbpf: use strlcpy() in path resolution fallback logic
  2022-04-07 23:04 [PATCH bpf-next 1/2] libbpf: use strlcpy() in path resolution fallback logic Andrii Nakryiko
  2022-04-07 23:04 ` [PATCH bpf-next 2/2] libbpf: allow WEAK and GLOBAL bindings during BTF fixup Andrii Nakryiko
@ 2022-04-08 16:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-08 16:20 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, kernel-team

Hello:

This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Thu, 7 Apr 2022 16:04:45 -0700 you wrote:
> Coverity static analyzer complains that strcpy() can cause buffer
> overflow. Use libbpf_strlcpy() instead to be 100% sure this doesn't
> happen.
> 
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>  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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-08 16:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-07 23:04 [PATCH bpf-next 1/2] libbpf: use strlcpy() in path resolution fallback logic Andrii Nakryiko
2022-04-07 23:04 ` [PATCH bpf-next 2/2] libbpf: allow WEAK and GLOBAL bindings during BTF fixup Andrii Nakryiko
2022-04-08 16:20 ` [PATCH bpf-next 1/2] libbpf: use strlcpy() in path resolution fallback logic patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox