BPF List
 help / color / mirror / Atom feed
From: Amery Hung <ameryhung@gmail.com>
To: bpf@vger.kernel.org
Cc: alexei.starovoitov@gmail.com, andrii@kernel.org,
	daniel@iogearbox.net, eddyz87@gmail.com, memxor@gmail.com,
	ameryhung@gmail.com, kernel-team@meta.com
Subject: [PATCH bpf-next v3 05/11] bpf: Check global subprog untrusted arguments in the common path
Date: Mon, 28 Sep 2026 11:53:28 -0700	[thread overview]
Message-ID: <20260928185334.1004200-6-ameryhung@gmail.com> (raw)
In-Reply-To: <20260928185334.1004200-1-ameryhung@gmail.com>

Global subprogram arguments tagged __arg_untrusted deliberately
accept any caller value. The callee is verified separately with a
read-only untrusted pointer, whose accesses use protected probe-read
instructions.

Keep the untrusted type in the canonical bpf_subprog_info used to
prepare the callee state. Represent it as ARG_IGNORE only in the
temporary bpf_func_proto used for call-site checking, then extend the
guarded check_func_arg() path to cover it.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
---
 kernel/bpf/verifier.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index e3c7c1aa0573..79b9e7242fee 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -10806,9 +10806,18 @@ static void gen_subprog_arg_proto(const struct bpf_subprog_info *sub, const stru
 
 	memset(proto, 0, sizeof(*proto));
 	for (arg = 0; arg < btf_type_vlen(func_proto); arg++) {
+		enum bpf_arg_type arg_type = sub->args[slot].arg_type;
 		const struct btf_type *t;
 
-		proto->arg_type[arg] = sub->args[slot].arg_type;
+		if (arg_type & PTR_UNTRUSTED) {
+			/*
+			 * An __arg_untrusted argument accepts any caller value. The
+			 * callee treats it as read-only and uses probe-read instructions
+			 * to protect against invalid memory access.
+			 */
+			arg_type = ARG_IGNORE;
+		}
+		proto->arg_type[arg] = arg_type;
 		t = btf_type_skip_modifiers(btf, args[arg].type, NULL);
 		slot += btf_arg_slots(t);
 	}
@@ -10871,16 +10880,10 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
 		t = btf_type_skip_modifiers(btf, args[arg].type, NULL);
 		nslots = btf_arg_slots(t);
 
-		if (arg_type == ARG_SCALAR) {
+		if (arg_type == ARG_SCALAR || arg_type == ARG_IGNORE) {
 			ret = check_func_arg(env, arg, slot, 0, &meta, env->insn_idx);
 			if (ret)
 				return ret;
-		} else if (arg_type & PTR_UNTRUSTED) {
-			/*
-			 * Anything is allowed for untrusted arguments, as these are
-			 * read-only and probe read instructions would protect against
-			 * invalid memory access.
-			 */
 		} else if (arg_type == ARG_PTR_TO_CTX) {
 			ret = check_func_arg_reg_off(env, reg, argno, ARG_PTR_TO_CTX);
 			if (ret < 0)
-- 
2.52.0


  parent reply	other threads:[~2026-09-28 18:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 18:53 [PATCH bpf-next v3 00/11] Unify subprog argument checks Amery Hung
2026-09-28 18:53 ` [PATCH bpf-next v3 01/11] bpf: Fix kfunc BTF parameter lookups after wide arguments Amery Hung
2026-09-28 18:53 ` [PATCH bpf-next v3 02/11] bpf: Identify subprog calls in argument metadata Amery Hung
2026-09-28 18:53 ` [PATCH bpf-next v3 03/11] bpf: Build argument prototypes for subprog calls Amery Hung
2026-09-28 18:53 ` [PATCH bpf-next v3 04/11] bpf: Check subprog scalar arguments in the common path Amery Hung
2026-09-28 18:53 ` Amery Hung [this message]
2026-09-28 18:53 ` [PATCH bpf-next v3 06/11] bpf: Check subprog context " Amery Hung
2026-09-28 18:53 ` [PATCH bpf-next v3 07/11] bpf: Check subprog arena " Amery Hung
2026-09-28 18:53 ` [PATCH bpf-next v3 08/11] bpf: Check subprog dynptr " Amery Hung
2026-09-28 18:53 ` [PATCH bpf-next v3 09/11] bpf: Check global subprog BTF-ID " Amery Hung
2026-09-28 18:53 ` [PATCH bpf-next v3 10/11] bpf: Check global subprog memory " Amery Hung
2026-09-28 19:53   ` bot+bpf-ci
2026-09-28 18:53 ` [PATCH bpf-next v3 11/11] bpf: Check all subprog " Amery Hung
2026-09-29 10:40 ` [PATCH bpf-next v3 00/11] Unify subprog argument checks 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=20260928185334.1004200-6-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=memxor@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