diff mbox series

libbpf: fix an snprintf() overflow check

Message ID YtZ+oAySqIhFl6/J@kili (mailing list archive)
State Accepted
Commit b77ffb30cfc5f58e957571d8541c6a7e3da19221
Delegated to: BPF
Headers show
Series libbpf: fix an snprintf() overflow check | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Kernel LATEST on z15 with gcc
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15

Commit Message

Dan Carpenter July 19, 2022, 9:51 a.m. UTC
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(-)

Comments

Martin KaFai Lau July 19, 2022, 5:19 p.m. UTC | #1
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>
patchwork-bot+netdevbpf@kernel.org July 19, 2022, 5:50 p.m. UTC | #2
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!
diff mbox series

Patch

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;
 }