From: Jan-Gerd Tenberge <janten@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, yonghong.song@linux.dev
Subject: [PATCH bpf] bpf: Propagate precision for outgoing stack arguments
Date: Fri, 9 Oct 2026 09:27:52 +0200 [thread overview]
Message-ID: <20261009072752.21037-1-janten@gmail.com> (raw)
BPF subprogram arguments beyond r1-r5 are kept separately in
bpf_func_state::stack_arg_regs. State comparison and precision
backtracking account for these arguments, but propagate_precision() does
not seed backtracking from precise stack argument entries in an
equivalent state.
Consequently, when state pruning requires precision to be propagated,
the producer of an outgoing scalar stack argument can remain imprecise.
A later state can then be pruned despite a different argument value.
This can cause the verifier to miss value-dependent safety checks and
accept an unsafe program.
The conservative fallback in bpf_mark_all_scalars_precise() has the same
gap: it marks scalar registers and ordinary scalar spills, but not scalar
stack arguments.
Include precise outgoing stack arguments in the backtracking seed used
by propagate_precision(), and mark them precise in the fallback path as
well.
Reaching the affected calling convention requires permission to load a
BPF-to-BPF program and a JIT with stack-argument support. This is not an
ordinary unprivileged-BPF path, but it is reachable through an
appropriately delegated BPF token.
An isolated x86-64 QEMU reproducer confirmed native kernel stack
corruption, including a complete overwrite of a JIT return address. The
reproducer is available privately on request.
Fixes: 0f6bd5e7a804 ("bpf: Support stack arguments for bpf functions")
Assisted-by: LLM
Signed-off-by: Jan-Gerd Tenberge <janten@gmail.com>
---
A source reproducer and benign load-only regression tests are available
privately on request. They are intentionally not included publicly in
accordance with Documentation/process/security-bugs.rst guidance for
AI-assisted findings.
Please queue this fix for stable kernels containing commit 0f6bd5e7a804
("bpf: Support stack arguments for bpf functions").
kernel/bpf/backtrack.c | 10 ++++++++++
kernel/bpf/states.c | 14 ++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/kernel/bpf/backtrack.c b/kernel/bpf/backtrack.c
index 47282ffeeaf9..707cf12d5e91 100644
--- a/kernel/bpf/backtrack.c
+++ b/kernel/bpf/backtrack.c
@@ -705,6 +705,16 @@ void bpf_mark_all_scalars_precise(struct bpf_verifier_env *env,
i, -(j + 1) * 8);
}
}
+ bpf_for_each_spilled_stack_arg(j, func, reg) {
+ if (!reg || reg->type != SCALAR_VALUE || reg->precise)
+ continue;
+ reg->precise = true;
+ if (env->log.level & BPF_LOG_LEVEL2) {
+ verbose(env,
+ "force_precise: frame%d: forcing sa%d to be precise\n",
+ i, j);
+ }
+ }
}
}
}
diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
index 012b82513a3b..7f995521baaf 100644
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -1062,6 +1062,20 @@ static int propagate_precision(struct bpf_verifier_env *env,
bpf_bt_set_frame_slot(&env->bt, fr, i);
first = false;
}
+
+ bpf_for_each_spilled_stack_arg(i, state, state_reg) {
+ if (!state_reg || state_reg->type != SCALAR_VALUE ||
+ !state_reg->precise)
+ continue;
+ if (env->log.level & BPF_LOG_LEVEL2) {
+ if (first)
+ verbose(env, "frame %d: propagating sa%d", fr, i);
+ else
+ verbose(env, ",sa%d", i);
+ }
+ bt_set_frame_stack_arg_slot(&env->bt, fr, i);
+ first = false;
+ }
if (!first && (env->log.level & BPF_LOG_LEVEL2))
verbose(env, "\n");
}
--
2.54.0 (Apple Git-157)
next reply other threads:[~2026-10-09 7:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 7:27 Jan-Gerd Tenberge [this message]
2026-10-09 7:39 ` [PATCH bpf] bpf: Propagate precision for outgoing stack arguments sashiko-bot
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=20261009072752.21037-1-janten@gmail.com \
--to=janten@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=memxor@gmail.com \
--cc=yonghong.song@linux.dev \
/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.