]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Fix improper int-to-ptr cast in dump_stack_cb
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Sat, 5 Jul 2025 05:30:35 +0000 (22:30 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 7 Jul 2025 15:30:15 +0000 (08:30 -0700)
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: d7c431cafcb4 ("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>
kernel/bpf/stream.c

index 8c842f845245ac07fb834bc0555f431423cc2395..ab592db4a4bf6140a9c82bb14abf3bafbe9689c9 100644 (file)
@@ -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;
 }