libbpf: Fix program log buffer size validation
PATCH v2 1/1 libbpf: Fix program log buffer size validation
bpf_program__set_log_buf() checks the existing prog->log_size instead of the incoming log_size argument when enforcing the UINT_MAX limit. As a result, an oversized value can be accepted.
The setter also accepts a non-NULL log_buf with a zero log_size, while bpf_prog_load() rejects mismatched log buffer and size values.
Validate the log buffer and size pair consistently with bpf_prog_load(), and check the supplied log_size against UINT_MAX.
---
Changes in v2:
- Target bpf-next instead of bpf and drop the Fixes tag.
- Drop the regression selftest.
- Validate log_buf and log_size consistently with bpf_prog_load().
- Link to v1: https://patch.msgid.link/[email protected]
To: Andrii Nakryiko <[email protected]>
To: Eduard Zingerman <[email protected]>
To: Ihor Solodrai <[email protected]>
To: Alexei Starovoitov <[email protected]>
To: Daniel Borkmann <[email protected]>
To: Kumar Kartikeya Dwivedi <[email protected]>
To: Martin KaFai Lau <[email protected]>
To: Song Liu <[email protected]>
To: Yonghong Song <[email protected]>
To: Jiri Olsa <[email protected]>
To: Emil Tsalapatis <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- tools/lib/bpf/libbpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
@@ -9966,9 +9966,9 @@ const char *bpf_program__log_buf(const struct bpf_program *prog, size_t *log_sizint bpf_program__set_log_buf (struct bpf_program *prog,char *log_buf,size_t log_size) { -if (log_size && !log_buf) +if (!!log_buf != !!log_size)return libbpf_err (-EINVAL ); -if (prog->log_size >UINT_MAX ) +if (log_size >UINT_MAX )return libbpf_err (-EINVAL );if (prog->obj->state >=OBJ_LOADED )return libbpf_err (-EBUSY );
---
base-commit: 5ef40d69b38a93bc9951dadb1a15c85c597e1a40
change-id: 20260913-libbpf-log-buf-fix-49f5038caa5d
Best regards,
Signature · 1 line
Luis Vieira <[email protected]>
[email protected]
AI reviewThis looks like a bug fix. Should this include:
Quoted 6 lines
libbpf: Fix program log buffer size validation
bpf_program__set_log_buf()checks the existingprog->log_sizeinstead of the incominglog_sizeargument when enforcing theUINT_MAXlimit. As a result, an oversized value can be accepted.
Quoted 7 lines
The setter also accepts a non-NULL
log_bufwith a zerolog_size, whilebpf_prog_load()rejects mismatched log buffer and size values.Validate the log buffer and size pair consistently with
bpf_prog_load(), and check the suppliedlog_sizeagainstUINT_MAX.Signed-off-by Luis Vieira <[email protected]>
This looks like a bug fix. Should this include:
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/35007077686
Quoted 18 lines · Luis Vieira
bpf_program__set_log_buf()checks the existingprog->log_sizeinstead of the incominglog_sizeargument when enforcing theUINT_MAXlimit. As a result, an oversized value can be accepted.The setter also accepts a non-NULL
log_bufwith a zerolog_size, whilebpf_prog_load()rejects mismatched log buffer and size values.Validate the log buffer and size pair consistently with
bpf_prog_load(), and check the suppliedlog_sizeagainstUINT_MAX.Signed-off-by Luis Vieira <[email protected]>---
Changes in v2:
- Target bpf-next instead of bpf and drop the Fixes tag.
- Drop the regression selftest.
- Validatelog_bufandlog_sizeconsistently withbpf_prog_load().
- Link to v1: https://patch.msgid.link/[email protected]
Quoted 14 lines
To: Andrii Nakryiko <[email protected]>
To: Eduard Zingerman <[email protected]>
To: Ihor Solodrai <[email protected]>
To: Alexei Starovoitov <[email protected]>
To: Daniel Borkmann <[email protected]>
To: Kumar Kartikeya Dwivedi <[email protected]>
To: Martin KaFai Lau <[email protected]>
To: Song Liu <[email protected]>
To: Yonghong Song <[email protected]>
To: Jiri Olsa <[email protected]>
To: Emil Tsalapatis <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
Quoted 28 lines
tools/lib/bpf/libbpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/lib/bpf/libbpf.c +2
-3@@ -9966,9 +9966,9 @@ const char *bpf_program__log_buf(const struct bpf_program *prog, size_t *log_sizint bpf_program__set_log_buf (struct bpf_program *prog,char *log_buf,size_t log_size) { -if (log_size && !log_buf) +if (!!log_buf != !!log_size)return libbpf_err (-EINVAL ); -if (prog->log_size >UINT_MAX ) +if (log_size >UINT_MAX )return libbpf_err (-EINVAL );if (prog->obj->state >=OBJ_LOADED )return libbpf_err (-EBUSY ); ---base-commit:
5ef40d69b38a93bc9951dadb1a15c85c597e1a40
change-id: 20260913-libbpf-log-buf-fix-49f5038caa5dBest regards,
Signature · 1 line
Luis Vieira <[email protected]>
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 8 lines · On Tue, 15 Sep 2026 15:13:35 -0300 you wrote:
bpf_program__set_log_buf()checks the existingprog->log_sizeinstead of the incominglog_sizeargument when enforcing theUINT_MAXlimit. As a result, an oversized value can be accepted.The setter also accepts a non-NULL
log_bufwith a zerolog_size, whilebpf_prog_load()rejects mismatched log buffer and size values.[...]
Here is the summary with links:
- [bpf-next,v2] libbpf: Fix program log buffer size validation
https://git.kernel.org/bpf/bpf-next/c/8cca9a6bb681
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html