From: "Emil Tsalapatis" <emil@etsalapatis.com>
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>, <bpf@vger.kernel.org>
Cc: "Alexei Starovoitov" <ast@kernel.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Martin KaFai Lau" <martin.lau@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Tejun Heo" <tj@kernel.org>,
"Dan Schatzberg" <dschatzberg@meta.com>, <kkd@meta.com>,
<kernel-team@meta.com>
Subject: Re: [PATCH bpf-next v1 3/4] bpf: Reject modified syscall PTR_TO_CTX for global subprogs
Date: Tue, 17 Mar 2026 12:50:29 -0400 [thread overview]
Message-ID: <DH57NGRHX9CO.2K2NWI7CJNN1S@etsalapatis.com> (raw)
In-Reply-To: <20260317111850.2107846-4-memxor@gmail.com>
On Tue Mar 17, 2026 at 7:18 AM EDT, Kumar Kartikeya Dwivedi wrote:
> Now that syscall programs allow modified offsets to be passed as a
> context argument, we must make sure that they are passed unmodified to
> global subprogs. The reasoning is that we can have inconsistent and
> potentially unsafe max_ctx_offset based checks if the global subprog is
> used to access the ctx, or when it is replaced by an extension prog.
> We'll need a post-processing pass to correctly identify the
> max_ctx_offset across the call graph, but it's extra work for little
> functional gain, hence just reject this case.
>
> We have to make this change now, since we opened up the checks made in
> check_func_arg_reg_off for BPF_PROG_TYPE_SYSCALL's PTR_TO_CTX in past
> commits.
>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Whether we end up merging it into patch #1 or not, the logic is correct.
> ---
> kernel/bpf/verifier.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 50639bb69d91..3f34510ec183 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -10778,6 +10778,17 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
> bpf_log(log, "arg#%d expects pointer to ctx\n", i);
> return -EINVAL;
> }
> + /*
> + * We should not allow modified offset ctx to be passed
> + * into global subprogs, to avoid messing up the math of
> + * max_ctx_offset for the whole program. Supporting this
> + * will require a post-verification pass, not worth it.
> + */
> + if (resolve_prog_type(env->prog) == BPF_PROG_TYPE_SYSCALL &&
> + (!tnum_is_const(reg->var_off) || reg->var_off.value)) {
> + bpf_log(log, "arg#%d of syscall prog must have zero offset\n", i);
> + return -EINVAL;
> + }
> } else if (base_type(arg->arg_type) == ARG_PTR_TO_MEM) {
> ret = check_func_arg_reg_off(env, reg, regno, ARG_DONTCARE);
> if (ret < 0)
next prev parent reply other threads:[~2026-03-17 16:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 11:18 [PATCH bpf-next v1 0/4] Allow variable offsets for syscall PTR_TO_CTX Kumar Kartikeya Dwivedi
2026-03-17 11:18 ` [PATCH bpf-next v1 1/4] bpf: Support " Kumar Kartikeya Dwivedi
2026-03-17 12:09 ` bot+bpf-ci
2026-03-17 16:45 ` Emil Tsalapatis
2026-03-17 11:18 ` [PATCH bpf-next v1 2/4] selftests/bpf: Adjust syscall ctx variable offset tests Kumar Kartikeya Dwivedi
2026-03-17 18:24 ` Emil Tsalapatis
2026-03-17 11:18 ` [PATCH bpf-next v1 3/4] bpf: Reject modified syscall PTR_TO_CTX for global subprogs Kumar Kartikeya Dwivedi
2026-03-17 16:50 ` Emil Tsalapatis [this message]
2026-03-17 18:46 ` Kumar Kartikeya Dwivedi
2026-03-17 11:18 ` [PATCH bpf-next v1 4/4] selftests/bpf: Test modified syscall ctx for global subprog Kumar Kartikeya Dwivedi
2026-03-17 16:13 ` Emil Tsalapatis
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=DH57NGRHX9CO.2K2NWI7CJNN1S@etsalapatis.com \
--to=emil@etsalapatis.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dschatzberg@meta.com \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.