bpf: Fix improper int-to-ptr cast in dump_stack_cb

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 <bot@kernelci.org>
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Fixes: d7c431cafc ("bpf: Add dump_stack() analogue to print to BPF stderr")
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Link: https://lore.kernel.org/r/20250705053035.3020320-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
pull/1309/head
Kumar Kartikeya Dwivedi 2025-07-04 22:30:35 -07:00 committed by Alexei Starovoitov
parent 116c8f4747
commit bfa2bb9abd
1 changed files with 2 additions and 2 deletions

View File

@ -498,11 +498,11 @@ static bool dump_stack_cb(void *cookie, u64 ip, u64 sp, u64 bp)
if (ret < 0) if (ret < 0)
goto end; goto end;
ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n %s @ %s:%d\n", 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; return !ctxp->err;
} }
end: 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; return !ctxp->err;
} }