All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libbpf: fix an snprintf() overflow check
@ 2022-07-19  9:51 Dan Carpenter
  2022-07-19 17:19 ` Martin KaFai Lau
  2022-07-19 17:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-07-19  9:51 UTC (permalink / raw)
  To: Andrii Nakryiko, Alexei Starovoitov
  Cc: Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, bpf, kernel-janitors

The snprintf() function returns the number of bytes it *would* have
copied if there were enough space.  So it can return > the
sizeof(gen->attach_target).

Fixes: 67234743736a ("libbpf: Generate loader program out of BPF ELF file.")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 tools/lib/bpf/gen_loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
index 927745b08014..23f5c46708f8 100644
--- a/tools/lib/bpf/gen_loader.c
+++ b/tools/lib/bpf/gen_loader.c
@@ -533,7 +533,7 @@ void bpf_gen__record_attach_target(struct bpf_gen *gen, const char *attach_name,
 	gen->attach_kind = kind;
 	ret = snprintf(gen->attach_target, sizeof(gen->attach_target), "%s%s",
 		       prefix, attach_name);
-	if (ret == sizeof(gen->attach_target))
+	if (ret >= sizeof(gen->attach_target))
 		gen->error = -ENOSPC;
 }
 
-- 
2.35.1


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

* Re: [PATCH] libbpf: fix an snprintf() overflow check
  2022-07-19  9:51 [PATCH] libbpf: fix an snprintf() overflow check Dan Carpenter
@ 2022-07-19 17:19 ` Martin KaFai Lau
  2022-07-19 17:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Martin KaFai Lau @ 2022-07-19 17:19 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
	kernel-janitors

On Tue, Jul 19, 2022 at 12:51:28PM +0300, Dan Carpenter wrote:
> The snprintf() function returns the number of bytes it *would* have
> copied if there were enough space.  So it can return > the
> sizeof(gen->attach_target).
Acked-by: Martin KaFai Lau <kafai@fb.com>

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

* Re: [PATCH] libbpf: fix an snprintf() overflow check
  2022-07-19  9:51 [PATCH] libbpf: fix an snprintf() overflow check Dan Carpenter
  2022-07-19 17:19 ` Martin KaFai Lau
@ 2022-07-19 17:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-19 17:50 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: andrii, ast, daniel, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, bpf, kernel-janitors

Hello:

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

On Tue, 19 Jul 2022 12:51:28 +0300 you wrote:
> The snprintf() function returns the number of bytes it *would* have
> copied if there were enough space.  So it can return > the
> sizeof(gen->attach_target).
> 
> Fixes: 67234743736a ("libbpf: Generate loader program out of BPF ELF file.")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> [...]

Here is the summary with links:
  - libbpf: fix an snprintf() overflow check
    https://git.kernel.org/bpf/bpf-next/c/b77ffb30cfc5

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-07-19 17:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19  9:51 [PATCH] libbpf: fix an snprintf() overflow check Dan Carpenter
2022-07-19 17:19 ` Martin KaFai Lau
2022-07-19 17:50 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.