From: Eduard Zingerman <eddyz87@gmail.com>
To: Puranjay Mohan <puranjay@kernel.org>, bpf@vger.kernel.org
Cc: Puranjay Mohan <puranjay12@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
kernel-team@meta.com
Subject: Re: [PATCH bpf-next 1/7] bpf: Make KF_TRUSTED_ARGS the default for all kfuncs
Date: Tue, 30 Dec 2025 15:49:23 -0800 [thread overview]
Message-ID: <4cb72b4808c333156552374c5f3912260097af43.camel@gmail.com> (raw)
In-Reply-To: <20251224192448.3176531-2-puranjay@kernel.org>
On Wed, 2025-12-24 at 11:24 -0800, Puranjay Mohan wrote:
> Change the verifier to make trusted args the default requirement for
> all kfuncs by removing is_kfunc_trusted_args() assuming it be to always
> return true.
>
> This works because:
> 1. Context pointers (xdp_md, __sk_buff, etc.) are handled through their
> own KF_ARG_PTR_TO_CTX case label and bypass the trusted check
> 2. Struct_ops callback arguments are already marked as PTR_TRUSTED during
> initialization and pass is_trusted_reg()
> 3. KF_RCU kfuncs are handled separately via is_kfunc_rcu() checks at
> call sites (always checked with || alongside is_kfunc_trusted_args)
>
> This simple change makes all kfuncs require trusted args by default
> while maintaining correct behavior for all existing special cases.
While I like the idea behind this patch, I don't think this is 100%
backwards compatible change. Not unless you check definition of every
kfunc in the kernel and add appropriate __nullable annotations,
like you do for some in patch #2.
For example, consider the following kfunc from drivers/hid/bpf/hid_bpf_dispatch.c:
__bpf_kfunc int
hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
enum hid_report_type rtype, enum hid_class_request reqtype)
... __hid_bpf_hw_check_params(ctx, buf, &size, rtype); ...
static int
__hid_bpf_hw_check_params(struct hid_bpf_ctx *ctx, __u8 *buf, size_t *buf__sz,
enum hid_report_type rtype)
...
if (... !buf)
return -EINVAL;
BTF_ID_FLAGS(func, hid_bpf_hw_request, KF_SLEEPABLE)
Currently, it is possible to pass 'buf' parameter as NULL.
In this particular case it would lead to an error code returned from
the function, but is it the case for all kfuncs in the kernel?
For some kfuncs NULL parameter might be expected as a part of a
non-error scenario.
Also, there is a question about kfuncs declared in out of tree modules.
So, I think there are two questions to be answered:
- a review of all kfuncs in the kernel checking if there are
sufficient __nullable annotations;
- are we ready to potentially break BPF programs working with kfuncs
defined in out-of-tree modules?
Wdyt?
[...]
next prev parent reply other threads:[~2025-12-30 23:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-24 19:24 [PATCH bpf-next 0/7] bpf: Make KF_TRUSTED_ARGS default Puranjay Mohan
2025-12-24 19:24 ` [PATCH bpf-next 1/7] bpf: Make KF_TRUSTED_ARGS the default for all kfuncs Puranjay Mohan
2025-12-30 23:49 ` Eduard Zingerman [this message]
2025-12-30 23:56 ` Alexei Starovoitov
2025-12-31 0:08 ` Puranjay Mohan
2025-12-31 0:29 ` Eduard Zingerman
2025-12-31 12:34 ` Puranjay Mohan
2025-12-31 16:45 ` Alexei Starovoitov
2025-12-24 19:24 ` [PATCH bpf-next 2/7] bpf: net: netfilter: Mark kfuncs accurately Puranjay Mohan
2025-12-24 19:24 ` [PATCH bpf-next 3/7] bpf: Remove redundant KF_TRUSTED_ARGS flag from all kfuncs Puranjay Mohan
2025-12-24 19:24 ` [PATCH bpf-next 4/7] selftests: bpf: Update kfunc_param_nullable test for new error message Puranjay Mohan
2025-12-24 19:24 ` [PATCH bpf-next 5/7] selftests: bpf: Update failure message for rbtree_fail Puranjay Mohan
2025-12-24 19:24 ` [PATCH bpf-next 6/7] selftests: bpf: fix test_kfunc_dynptr_param Puranjay Mohan
2025-12-31 2:04 ` Alexei Starovoitov
2025-12-24 19:24 ` [PATCH bpf-next 7/7] selftests: bpf: fix cgroup_hierarchical_stats Puranjay Mohan
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=4cb72b4808c333156552374c5f3912260097af43.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=puranjay12@gmail.com \
--cc=puranjay@kernel.org \
/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