From: "Ömer Mete Kaya" <omermetekaya0@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net
Cc: john.fastabend@gmail.com, andrii@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
ihor.solodrai@linux.dev, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Ömer Mete Kaya" <omermetekaya0@gmail.com>
Subject: [PATCH bpf] bpf: Fix wrong frame passed to check_fastcall_stack_contract() in check_stack_read_fixed_off()
Date: Mon, 28 Sep 2026 01:23:44 +0300 [thread overview]
Message-ID: <20260927222718.414674-1-omermetekaya0@gmail.com> (raw)
check_stack_read_fixed_off() calls check_fastcall_stack_contract() with
'state' (the current frame, i.e. the callee) instead of 'reg_state'
(the frame that owns the stack being read, i.e. the caller).
In a bpf2bpf call where a callee reads from a PTR_TO_STACK pointing
into the caller's frame, 'reg_state' and 'state' are different:
'reg_state' is the caller's frame, while 'state' is the callee's.
Passing 'state' causes the fastcall contract to be checked against the
callee's subprog instead of the caller's, leaving the caller's fastcall
region unprotected and potentially can cause an incorrect fastcall
rewrite.
The three sibling functions are all correct:
check_stack_write_fixed_off -> passes 'state' (writes to curframe)
check_stack_write_var_off -> passes 'state' (writes to curframe)
check_stack_read_var_off -> passes 'ptr_state' (reads from ptr's frame)
Fix check_stack_read_fixed_off() to match the read pattern and pass
'reg_state' instead of 'state'.
Fixes: 5b5f51bff1b6 ("bpf: no_caller_saved_registers attribute for helper calls")
Signed-off-by: Ömer Mete Kaya <omermetekaya0@gmail.com>
---
kernel/bpf/verifier.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1cd92336309b..5c523a9bde6b 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -4020,7 +4020,7 @@ static int check_stack_read_fixed_off(struct bpf_verifier_env *env,
reg = ®_state->stack[spi].spilled_ptr;
mark_stack_slot_scratched(env, spi);
- check_fastcall_stack_contract(env, state, env->insn_idx, off);
+ check_fastcall_stack_contract(env, reg_state, env->insn_idx, off);
/*
* Refine the in-progress load record's origin to the source stack slot.
--
2.55.0
next reply other threads:[~2026-09-27 22:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-27 22:23 Ömer Mete Kaya [this message]
2026-09-27 23:08 ` bot+bpf-ci
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=20260927222718.414674-1-omermetekaya0@gmail.com \
--to=omermetekaya0@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®