public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf v3 0/2] bpf: reject negative CO-RE accessor indices
@ 2026-04-04 16:12 Weiming Shi
  2026-04-04 16:12 ` [PATCH bpf v3 1/2] bpf: reject negative CO-RE accessor indices in bpf_core_parse_spec() Weiming Shi
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Weiming Shi @ 2026-04-04 16:12 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa, bpf,
	Xiang Mei, Weiming Shi

bpf_core_parse_spec() parses CO-RE accessor strings with sscanf("%d"),
which accepts negative values.  The downstream bounds checks only test
the upper bound, so a negative index like -1 slips through, gets cast
to u32 0xffffffff in btf_member_bit_offset(), and crashes the kernel.

To clarify the kernel-side concern from v2 review:
tools/lib/bpf/relo_core.c is shared code -- the kernel compiles it
directly via kernel/bpf/relo_core.c (#include).  So the fix does
apply in the kernel's BPF_PROG_LOAD -> check_core_relo() ->
bpf_core_apply() -> bpf_core_parse_spec() path.

v3: added selftest (patch 2/2)
v2: fix typo Signed-off-by tag (missing leading 'S')

Weiming Shi (2):
  bpf: reject negative CO-RE accessor indices in bpf_core_parse_spec()
  selftests/bpf: add test for negative CO-RE accessor index rejection

 tools/lib/bpf/relo_core.c                     |  2 +
 .../selftests/bpf/prog_tests/core_reloc_raw.c | 94 +++++++++++++++++++
 2 files changed, 96 insertions(+)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-04-07 15:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-04 16:12 [PATCH bpf v3 0/2] bpf: reject negative CO-RE accessor indices Weiming Shi
2026-04-04 16:12 ` [PATCH bpf v3 1/2] bpf: reject negative CO-RE accessor indices in bpf_core_parse_spec() Weiming Shi
2026-04-04 18:07   ` Emil Tsalapatis
2026-04-06 15:01   ` Paul Chaignon
2026-04-04 16:12 ` [PATCH bpf v3 2/2] selftests/bpf: add test for negative CO-RE accessor index rejection Weiming Shi
2026-04-04 18:12   ` Emil Tsalapatis
2026-04-06 15:03   ` Paul Chaignon
2026-04-04 18:06 ` [PATCH bpf v3 0/2] bpf: reject negative CO-RE accessor indices Emil Tsalapatis
2026-04-07 15:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox