diff options
| author | Amery Hung <ameryhung@gmail.com> | 2026-09-11 15:04:03 -0700 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2026-09-11 20:16:03 -0700 |
| commit | 2b2b08c277cb2ba2596e88d6a2efdb9df3117b75 (patch) | |
| tree | 8d3710af7aec94d346cb6a3c3b38f987f56077b0 /kernel | |
| parent | 78811eac7ae6e4510827f320d780b3c417601142 (diff) | |
bpf: Set MEM_RCU when generating kfunc argument types
The BTF ID argument of a kfunc has to be referenced or trusted unless
the kfunc is KF_RCU, in which case an RCU-protected pointer is accepted
too. check_kfunc_args() reads that off meta->kfunc_flags on every
verification of the call, which is the last thing keeping the argument
policy of ARG_PTR_TO_BTF_ID out of the generated prototype.
Set MEM_RCU in get_kfunc_arg_type() for ARG_PTR_TO_BTF_ID arguments of
KF_RCU kfuncs, the way it already sets OBJ_RELEASE for release
arguments, and test the generated flag instead. MEM_RCU represents the
KF_RCU relaxation applied by the ARG_PTR_TO_BTF_ID trust check; other
argument kinds have their own provenance requirements.
No functional change intended.
Signed-off-by: Amery Hung <ameryhung@gmail.com>
Link: https://lore.kernel.org/r/20260911220415.1396439-12-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/bpf/verifier.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index c602007bf583..39f7f633b4d6 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -12336,6 +12336,14 @@ get_kfunc_arg_type(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta, if (is_kfunc_release(meta) && arg == 0) arg_type |= OBJ_RELEASE; + /* + * A KF_RCU kfunc accepts an RCU-protected pointer where it would + * otherwise demand a referenced or trusted one. Other argument kinds + * have their own provenance requirements and must not inherit MEM_RCU. + */ + if (base_type(arg_type) == ARG_PTR_TO_BTF_ID && is_kfunc_rcu(meta)) + arg_type |= MEM_RCU; + return arg_type; } @@ -13275,7 +13283,7 @@ check_ok: reg2btf_ids[base_type(reg->type)]) { if (!is_trusted_reg(env, reg) || bpf_type_has_unsafe_modifiers(reg->type)) { - if (!is_kfunc_rcu(meta)) { + if (!(arg_type & MEM_RCU)) { const char *expected_type; expected_type = bpf_diag_fmt_btf_type(env, btf, ref_id); |
