Skip to content

bpf: fix null pointer access for malformed BPF_CORE_TYPE_ID_LOCAL relos

Eduard Zingerman bpf 2 versions Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 0 repliesApplied 2/2
  2. v22 patches 7 repliesSuperseded

Changes in v3 from the cover letter

- selftest update suggested by Andrii:
avoid memset(0) for log buffer and do memset(0) for bpf_attr.

Patches in v3 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: correctly handle malformed BPF_CORE_TYPE_ID_LOCAL reloskernel/bpf/btf.c+8 -00 repliesApplied
2/2selftests/bpf: test for malformed BPF_CORE_TYPE_ID_LOCAL relocationtools/testing/selftests/bpf/prog_tests/core_reloc_raw.c+125 -00 repliesApplied

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchAndrii Nakryiko
1/2A-b
2/2

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-next v3 0/2] bpf: fix null pointer access for malformed BPF_CORE_TYPE_ID_LOCAL relos

Liu RuiTong reported an in-kernel null pointer derefence when processing BPF_CORE_TYPE_ID_LOCAL relocations referencing non-existing BTF types. Fix this by adding proper id checks.

Changes v2->v3:
- selftest update suggested by Andrii:
avoid memset(0) for log buffer and do memset(0) for bpf_attr.

Changes v1->v2:
- moved check from bpf_core_calc_relo_insn() to bpf_core_apply() now both in kernel and in libbpf relocation type id is guaranteed to exist when bpf_core_calc_relo_insn() is called;
- added a test case.

v1: https://lore.kernel.org/bpf/[email protected]/
v2: https://lore.kernel.org/bpf/[email protected]/

Eduard Zingerman (2):
bpf: correctly handle malformed BPF_CORE_TYPE_ID_LOCAL relos selftests/bpf: test for malformed BPF_CORE_TYPE_ID_LOCAL relocation

 kernel/bpf/btf.c                              |   8 ++
 .../selftests/bpf/prog_tests/core_reloc_raw.c | 125 ++++++++++++++++++
 2 files changed, 133 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
Signature · 1 line
2.45.2