linux-yocto/kernel/bpf
Paul Chaignon 97303e541e bpf: Reject %p% format string in bprintf-like helpers
[ Upstream commit f824274587 ]

static const char fmt[] = "%p%";
    bpf_trace_printk(fmt, sizeof(fmt));

The above BPF program isn't rejected and causes a kernel warning at
runtime:

    Please remove unsupported %\x00 in format string
    WARNING: CPU: 1 PID: 7244 at lib/vsprintf.c:2680 format_decode+0x49c/0x5d0

This happens because bpf_bprintf_prepare skips over the second %,
detected as punctuation, while processing %p. This patch fixes it by
not skipping over punctuation. %\x00 is then processed in the next
iteration and rejected.

Reported-by: syzbot+e2c932aec5c8a6e1d31c@syzkaller.appspotmail.com
Fixes: 48cac3f4a9 ("bpf: Implement formatted output helpers with bstr_printf")
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Link: https://lore.kernel.org/r/a0e06cc479faec9e802ae51ba5d66420523251ee.1751395489.git.paul.chaignon@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-08-28 16:24:01 +02:00
..
preload
arraymap.c bpf: Check percpu map value size first 2024-10-17 15:11:49 +02:00
bpf_inode_storage.c
bpf_iter.c
bpf_local_storage.c
bpf_lru_list.c bpf: Address KCSAN report on bpf_lru_list 2024-03-01 13:21:55 +01:00
bpf_lru_list.h bpf: Address KCSAN report on bpf_lru_list 2024-03-01 13:21:55 +01:00
bpf_lsm.c
bpf_struct_ops_types.h
bpf_struct_ops.c
bpf_task_storage.c
btf.c bpf: Eliminate remaining "make W=1" warnings in kernel/bpf/btf.o 2024-08-19 05:44:59 +02:00
cgroup.c
core.c bpf: Avoid __bpf_prog_ret0_warn when jit fails 2025-06-27 11:05:14 +01:00
cpumap.c xdp: Move conversion to xdp_frame out of map functions 2024-05-17 11:50:47 +02:00
devmap.c bpf: fix OOB devmap writes when deleting elements 2024-12-14 19:51:33 +01:00
disasm.c
disasm.h
dispatcher.c
hashtab.c bpf: fix possible endless loop in BPF map iteration 2025-06-04 14:37:54 +02:00
helpers.c bpf: Reject %p% format string in bprintf-like helpers 2025-08-28 16:24:01 +02:00
inode.c
Kconfig
local_storage.c
lpm_trie.c bpf: Fix exact match conditions in trie_get_next_key() 2024-12-14 19:51:31 +01:00
Makefile
map_in_map.c bpf: Defer the free of inner map when necessary 2024-03-26 18:21:12 -04:00
map_in_map.h bpf: Add map and need_defer parameters to .map_fd_put_ptr() 2024-02-23 08:54:42 +01:00
map_iter.c
net_namespace.c
offload.c
percpu_freelist.c
percpu_freelist.h
prog_iter.c
queue_stack_maps.c
reuseport_array.c
ringbuf.c bpf: Fix overrunning reservations in ringbuf 2024-07-27 10:46:06 +02:00
stackmap.c bpf: Fix stackmap overflow check on 32-bit arches 2024-03-26 18:21:22 -04:00
syscall.c bpf: avoid holding freeze_mutex during mmap operation 2025-05-02 07:44:21 +02:00
sysfs_btf.c
task_iter.c
tnum.c
trampoline.c x86/ibt,ftrace: Search for __fentry__ location 2024-07-05 09:14:12 +02:00
verifier.c bpf: fix precision backtracking instruction iteration 2025-07-17 18:30:48 +02:00