Skip to content

bpf: reject negative CO-RE accessor indices

Weiming Shi bpf 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 5 repliesIn review 1 of 2 applied
  2. v21 patch 0 repliesSuperseded
  3. v11 patch 1 replySuperseded

Patches in v3 1 of 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: reject negative CO-RE accessor indices in bpf_core_parse_spec()tools/lib/bpf/relo_core.c+2 -02 repliesApplied
2/2selftests/bpf: add test for negative CO-RE accessor index rejectiontools/testing/selftests/bpf/prog_tests/core_reloc_raw.c+94 -02 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchEmil TsalapatisPaul Chaignon
1/2R-b A-b
2/2R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH bpf v3 0/2] bpf: reject negative CO-RE accessor indices

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(+)
Signature · 1 line
2.43.0