BPF Streams - Fixes
Kumar Kartikeya Dwivedi
maintainercover BPF Streams - Fixes
This set contains some fixes for recently reported issues for BPF streams. Please check individual patches for details.
Kumar Kartikeya Dwivedi (2):
bpf: Fix bounds for bpf_prog_get_file_line linfo loop
bpf: Fix improper int-to-ptr cast in dump_stack_cb
kernel/bpf/core.c | 4 +++- kernel/bpf/stream.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)
base-commit: 03fe01ddd1d8be7799419ea5e5f228a0186ae8c2
Signature · 1 line
2.47.1
Kumar Kartikeya Dwivedi
maintainerPATCH 1/2 bpf: Fix bounds for bpf_prog_get_file_line linfo loop
We may overrun the bounds because linfo and jited_linfo are already advanced to prog->aux->linfo_idx, hence we must only iterate the remaining elements until we reach prog->aux->nr_linfo. Adjust the nr_linfo calculation to fix this. Reported in [0].
[0]: https://lore.kernel.org/bpf/[email protected]
--- kernel/bpf/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/bpf/core.c +3 -1
@@ -3244,6 +3244,7 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char *struct bpf_line_info *linfo;void **jited_linfo;struct btf *btf; +int nr_linfo; btf = prog->aux->btf; linfo = prog->aux->linfo;
@@ -3258,8 +3259,9 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char * insn_start = linfo[0 ].insn_off; insn_end = insn_start + len; + nr_linfo = prog->aux->nr_linfo - prog->aux->linfo_idx; -for (int i =0 ; i < prog->aux->nr_linfo && +for (int i =0 ; i < nr_linfo && linfo[i].insn_off >= insn_start && linfo[i].insn_off < insn_end; i++) {if (jited_linfo[i] >= (void *)ip)break ;
Signature · 1 line
2.47.1
Re: [PATCH bpf-next v1 1/2] bpf: Fix bounds for bpf_prog_get_file_line linfo loop
Quoted 11 lines · Kumar Kartikeya Dwivedi
We may overrun the bounds because linfo and
jited_linfoare already advanced toprog->aux->linfo_idx, hence we must only iterate the remaining elements until we reachprog->aux->nr_linfo. Adjust thenr_linfocalculation to fix this. Reported in [0].[0]: https://lore.kernel.org/bpf/[email protected]
Reported-by Eduard Zingerman <[email protected]>Fixes 0e521efaf363 ("bpf: Add function to extract program source info")Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>---
Nit: It would be nice to extend progs/stream.c, so that e.g.
cond_break exhaustion is reported from a subprogram. I checked it locally and everything works as expected.
Kumar Kartikeya Dwivedi
maintainerPATCH 2/2 bpf: Fix improper int-to-ptr cast in dump_stack_cb
In reply to Kumar Kartikeya DwivediOn 32-bit platforms, we'll try to convert a u64 directly to a pointer type which is 32-bit, which causes the compiler to complain about cast from an integer of a different size to a pointer type. Cast to long before casting to the pointer type to match the pointer width.
--- kernel/bpf/stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/stream.c +2 -2
@@ -498,11 +498,11 @@ static bool dump_stack_cb(void *cookie, u64 ip, u64 sp, u64 bp)if (ret <0 ) goto end; ctxp->err =bpf_stream_stage_printk (ctxp->ss,"%pS\n %s @ %s:%d\n" , - (void *)ip, line, file, num); + (void *)(long )ip, line, file, num);return !ctxp->err; } end: - ctxp->err =bpf_stream_stage_printk (ctxp->ss,"%pS\n" , (void *)ip); + ctxp->err =bpf_stream_stage_printk (ctxp->ss,"%pS\n" , (void *)(long )ip);return !ctxp->err; }
Signature · 1 line
2.47.1
Re: [PATCH bpf-next v1 2/2] bpf: Fix improper int-to-ptr cast in dump_stack_cb
Quoted 9 lines · Kumar Kartikeya Dwivedi
On 32-bit platforms, we'll try to convert a u64 directly to a pointer type which is 32-bit, which causes the compiler to complain about cast from an integer of a different size to a pointer type. Cast to long before casting to the pointer type to match the pointer width.
Reported-by kernelci.org bot <[email protected]>Reported-by Randy Dunlap <[email protected]>Fixes d7c431cafcb4 ("bpf: Add dump_stack() analogue to print to BPF stderr")Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>
Thanks.
Quoted 22 lines
--- kernel/bpf/stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/bpf/stream.c +2
-2@@ -498,11 +498,11 @@ static bool dump_stack_cb(void *cookie, u64 ip, u64 sp, u64 bp)if (ret <0 ) goto end; ctxp->err =bpf_stream_stage_printk (ctxp->ss,"%pS\n %s @ %s:%d\n" , - (void *)ip, line, file, num); + (void *)(long )ip, line, file, num);return !ctxp->err; } end: - ctxp->err =bpf_stream_stage_printk (ctxp->ss,"%pS\n" , (void *)ip); + ctxp->err =bpf_stream_stage_printk (ctxp->ss,"%pS\n" , (void *)(long )ip);return !ctxp->err; }
Signature · 1 line
~Randy
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 Fri, 4 Jul 2025 22:30:33 -0700 you wrote:
This set contains some fixes for recently reported issues for BPF streams. Please check individual patches for details.
Kumar Kartikeya Dwivedi (2):
bpf: Fix bounds forbpf_prog_get_file_linelinfo loop
bpf: Fix improper int-to-ptr cast indump_stack_cb[...]
Here is the summary with links:
- [bpf-next,v1,1/2] bpf: Fix bounds for bpf_prog_get_file_line linfo loop
https://git.kernel.org/bpf/bpf-next/c/116c8f474722 - [bpf-next,v1,2/2] bpf: Fix improper int-to-ptr cast in dump_stack_cb https://git.kernel.org/bpf/bpf-next/c/bfa2bb9abd99
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html