BPF List
 help / color / mirror / Atom feed
From: Mingpei CAO <caomingpei@gmail.com>
To: bpf@vger.kernel.org
Cc: Mingpei CAO <caomingpei@gmail.com>,
	andrii@kernel.org, eddyz87@gmail.com, ameryhung@gmail.com
Subject: [PATCH bpf v3 0/2] libbpf: Reject local struct_ops bitfields before data access
Date: Tue, 15 Sep 2026 16:22:35 +0000	[thread overview]
Message-ID: <20260915162252.473044-1-caomingpei@gmail.com> (raw)

A local struct_ops type can contain a bitfield absent from the
corresponding kernel BTF type. libbpf calculated the member data pointer
from the encoded BTF member offset before rejecting the bitfield. The
absent member zero check could then read outside the local struct_ops data
and crash libbpf.

Patch 1 rejects local bitfields before calculating the member data pointer.
Patch 2 adds a negative test for a local bitfield absent from the kernel
BTF type.

AI assistance was used to prepare the messages. I independently reviewed the code and test results.

Changes since v2:
- Restore the local bitfield check from v1.
- Drop general offset validation and the bpftool changes, which covered
  malformed BTF outside.
- Describe the local struct_ops type and absent kernel member.
- Keep the negative test and check the load result before the diagnostic.

v2: https://lore.kernel.org/bpf/20260913145233.1446643-1-caomingpei@gmail.com/
v1: https://lore.kernel.org/bpf/20260910172340.1467764-1-caomingpei@gmail.com/

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

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


base-commit: ee363e055895364039bf28348ff13c615afad4ba
-- 
2.43.0

             reply	other threads:[~2026-09-15 16:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 16:22 Mingpei CAO [this message]
2026-09-15 16:22 ` [PATCH bpf v3 1/2] libbpf: Reject local struct_ops bitfields before data access Mingpei CAO
2026-09-15 17:40   ` Amery Hung
2026-09-15 16:22 ` [PATCH bpf v3 2/2] selftests/bpf: Test local struct_ops bitfield rejection Mingpei CAO
2026-09-15 17:30   ` bot+bpf-ci
2026-09-17 22:30 ` [PATCH bpf v3 0/2] libbpf: Reject local struct_ops bitfields before data access patchwork-bot+netdevbpf

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=20260915162252.473044-1-caomingpei@gmail.com \
    --to=caomingpei@gmail.com \
    --cc=ameryhung@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