From: Yuyang Huang <yuyanghuang@google.com>
To: Yuyang Huang <yuyanghuang@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Alexei Starovoitov <ast@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Nikolay Aleksandrov <razor@blackwall.org>,
Paolo Abeni <pabeni@redhat.com>, Shuah Khan <shuah@kernel.org>,
Simon Horman <horms@kernel.org>, Song Liu <song@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>,
Yonghong Song <yonghong.song@linux.dev>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH bpf-next 0/2] bpf: Align syscall writeback behavior with user-declared size
Date: Fri, 15 May 2026 16:15:02 +0900 [thread overview]
Message-ID: <20260515071504.2054786-1-yuyanghuang@google.com> (raw)
The bpf(cmd, attr, size) syscall copies up to 'size' bytes on input, but
several commands write outputs back to userspace unconditionally. If the
caller passes a short buffer, this can lead to out-of-bounds writes,
potentially overwriting adjacent userspace memory.
This series addresses this by introducing size-gating based on field type:
1) Mandatory fields (original ABI): Return -EINVAL in __sys_bpf() if the
user-provided buffer size is smaller than the minimum size required to
cover these fields. This hardens the syscall entry point for several
commands.
2) Optional fields (later revisions): Skip writeback if the user-provided
buffer size is too small to cover them. This is applied to
'query.revision' in BPF_PROG_QUERY.
The first patch implements the plumbing and enforcement in the kernel.
The second patch adds a selftest to verify the behavior.
Yuyang Huang (2):
bpf: align syscall writeback behavior with caller-declared size
selftests/bpf: Add verification for BPF_PROG_QUERY attr size
boundaries
drivers/net/netkit.c | 5 +-
include/linux/bpf-cgroup.h | 5 +-
include/linux/bpf_mprog.h | 4 +-
include/net/netkit.h | 6 +-
include/net/tcx.h | 5 +-
kernel/bpf/cgroup.c | 13 +--
kernel/bpf/mprog.c | 5 +-
kernel/bpf/syscall.c | 34 ++++++--
kernel/bpf/tcx.c | 5 +-
.../selftests/bpf/prog_tests/bpf_attr_size.c | 84 +++++++++++++++++++
10 files changed, 141 insertions(+), 25 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_attr_size.c
--
2.54.0.563.g4f69b47b94-goog
next reply other threads:[~2026-05-15 7:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 7:15 Yuyang Huang [this message]
2026-05-15 7:15 ` [PATCH bpf-next 1/2] bpf: align syscall writeback behavior with caller-declared size Yuyang Huang
2026-05-15 8:14 ` bot+bpf-ci
2026-05-15 7:15 ` [PATCH bpf-next 2/2] selftests/bpf: Add verification for BPF_PROG_QUERY attr size boundaries Yuyang Huang
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=20260515071504.2054786-1-yuyanghuang@google.com \
--to=yuyanghuang@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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