From: Mingpei CAO <caomingpei@gmail.com>
To: bpf@vger.kernel.org
Cc: andrii@kernel.org, eddyz87@gmail.com, Mingpei CAO <caomingpei@gmail.com>
Subject: [PATCH bpf 0/2] libbpf: Reject private struct_ops bitfields before data access
Date: Thu, 10 Sep 2026 17:23:38 +0000 [thread overview]
Message-ID: <20260910172340.1467764-1-caomingpei@gmail.com> (raw)
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
next reply other threads:[~2026-09-10 17:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 17:23 Mingpei CAO [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260910172340.1467764-1-caomingpei@gmail.com \
--to=caomingpei@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox