From: Amery Hung <ameryhung@gmail.com>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, alexei.starovoitov@gmail.com,
andrii@kernel.org, daniel@iogearbox.net, eddyz87@gmail.com,
memxor@gmail.com, martin.lau@kernel.org,
mykyta.yatsenko5@gmail.com, ameryhung@gmail.com,
kernel-team@meta.com
Subject: [PATCH bpf-next v3 2/5] bpf: Check acquire_reference() error for "__ref" struct_ops arguments
Date: Fri, 5 Jun 2026 13:20:53 -0700 [thread overview]
Message-ID: <20260605202056.1780352-3-ameryhung@gmail.com> (raw)
In-Reply-To: <20260605202056.1780352-1-ameryhung@gmail.com>
When acquiring references for struct_ops program arguments tagged with
"__ref", the return value of acquire_reference() was stored directly
into u32 ctx_arg_info[i].ref_id without checking for failure.
acquire_reference() returns -ENOMEM when acquire_reference_state() fails
to allocate, so the error was silently stored as a ref_id instead of
aborting verification. Fix it by checking the return.
Fixes: a687df2008f6 ("bpf: Support getting referenced kptr from struct_ops argument")
Signed-off-by: Amery Hung <ameryhung@gmail.com>
---
kernel/bpf/verifier.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 6446db9628ae..80a72402463d 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -18362,9 +18362,13 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog)
/* Acquire references for struct_ops program arguments tagged with "__ref" */
if (!subprog && env->prog->type == BPF_PROG_TYPE_STRUCT_OPS) {
- for (i = 0; i < aux->ctx_arg_info_size; i++)
- aux->ctx_arg_info[i].ref_id = aux->ctx_arg_info[i].refcounted ?
- acquire_reference(env, 0, 0) : 0;
+ for (i = 0; i < aux->ctx_arg_info_size; i++) {
+ ret = aux->ctx_arg_info[i].refcounted ? acquire_reference(env, 0, 0) : 0;
+ if (ret < 0)
+ goto out;
+
+ aux->ctx_arg_info[i].ref_id = ret;
+ }
}
ret = do_check(env);
--
2.53.0-Meta
next prev parent reply other threads:[~2026-06-05 20:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 20:20 [PATCH bpf-next v3 0/5] Object relationship tracking refactor followup Amery Hung
2026-06-05 20:20 ` [PATCH bpf-next v3 1/5] bpf: Fix dead error check on acquire_reference() in check_kfunc_call Amery Hung
2026-06-05 20:20 ` Amery Hung [this message]
2026-06-05 20:20 ` [PATCH bpf-next v3 3/5] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR Amery Hung
2026-06-05 20:50 ` bot+bpf-ci
2026-06-05 20:20 ` [PATCH bpf-next v3 4/5] bpf: Remove WARN_ON_ONCE in check_ids() Amery Hung
2026-06-05 20:50 ` bot+bpf-ci
2026-06-05 20:20 ` [PATCH bpf-next v3 5/5] selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test Amery Hung
2026-06-05 21:20 ` [PATCH bpf-next v3 0/5] Object relationship tracking refactor followup 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=20260605202056.1780352-3-ameryhung@gmail.com \
--to=ameryhung@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=netdev@vger.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