BPF List
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] libbpf: Reject private struct_ops bitfields before data access
@ 2026-09-10 17:23 Mingpei CAO
  2026-09-10 17:23 ` [PATCH bpf 1/2] libbpf: Reject struct_ops bitfields before accessing data Mingpei CAO
  2026-09-10 17:23 ` [PATCH bpf 2/2] selftests/bpf: Test private struct_ops bitfield rejection Mingpei CAO
  0 siblings, 2 replies; 6+ messages in thread
From: Mingpei CAO @ 2026-09-10 17:23 UTC (permalink / raw)
  To: bpf; +Cc: andrii, eddyz87, Mingpei CAO

This series fixes a bug in bpf_map__init_kern_struct_ops() that can
cause a userspace crash when loading a BPF object containing an all-zero
private bitfield in a local struct_ops mirror.

For structures with kind_flag set, member->offset also encodes the
bitfield width. bpf_map__init_kern_struct_ops() currently uses that raw
value to calculate the member data pointer before rejecting bitfields.
The absent-member compatibility path can consequently pass a pointer
far outside the struct_ops data to libbpf_is_mem_zeroed().

Patch 1 rejects local bitfields before calculating the data pointer.
Patch 2 adds a regression test for the all-zero private bitfield while
retaining the existing ordinary all-zero field compatibility control.

The issue was reproduced with a Clang generated object. Before the fix,
AddressSanitizer reported a SEGV caused by a read. After the fix, the
same object was rejected with -ENOTSUP and the expected bitfield
diagnostic. The ordinary all-zero field control continued to load
successfully.

AI assistance was used in preparing this series. I independently
reviewed the changes and reproduced the results.

Mingpei CAO (2):
  libbpf: Reject struct_ops bitfields before accessing data
  selftests/bpf: Test private struct_ops bitfield rejection

 tools/lib/bpf/libbpf.c                        |  9 ++++--
 .../bpf/prog_tests/test_struct_ops_module.c   | 31 +++++++++++++++++++
 .../selftests/bpf/progs/struct_ops_module.c   |  7 +++++
 3 files changed, 45 insertions(+), 2 deletions(-)


base-commit: e4a62833adff6ef0fe7c0b90393204fe3c26b5c5
-- 
2.43.0

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

end of thread, other threads:[~2026-09-10 21:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10 17:23 [PATCH bpf 0/2] libbpf: Reject private struct_ops bitfields before data access Mingpei CAO
2026-09-10 17:23 ` [PATCH bpf 1/2] libbpf: Reject struct_ops bitfields before accessing data Mingpei CAO
2026-09-10 18:26   ` bot+bpf-ci
2026-09-10 21:32   ` Amery Hung
2026-09-10 17:23 ` [PATCH bpf 2/2] selftests/bpf: Test private struct_ops bitfield rejection Mingpei CAO
2026-09-10 18:26   ` bot+bpf-ci

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