From: Hao Sun <sunhao.th@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, john.fastabend@gmail.com, memxor@gmail.com,
martin.lau@linux.dev, linux-kernel@vger.kernel.org,
sunhao.th@gmail.com
Subject: [PATCH 2/2] selftests/bpf: Test non-fetch atomic on a narrow stack spill
Date: Thu, 24 Sep 2026 15:13:42 +0200 [thread overview]
Message-ID: <20260924131342.934290-2-sunhao.th@gmail.com> (raw)
In-Reply-To: <20260924131342.934290-1-sunhao.th@gmail.com>
Spill a 32-bit scalar into an 8-byte stack slot, leaving the other half
of the slot uninitialized, and apply a non-fetch 64-bit atomic add to the
slot. With CAP_BPF but without CAP_PERFMON the verifier rejects it.
Signed-off-by: Hao Sun <sunhao.th@gmail.com>
---
.../selftests/bpf/progs/verifier_spill_fill.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_spill_fill.c b/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
index 39a1766dae3f..d9a4164b6685 100644
--- a/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
+++ b/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
@@ -1344,6 +1344,23 @@ __naked void old_imprecise_scalar32_vs_cur_stack_misc(void)
: __clobber_all);
}
+SEC("socket")
+__description("stack_noperfmon: reject non-fetch atomic on narrow spill")
+__success
+__caps_unpriv(CAP_BPF)
+__failure_unpriv __msg_unpriv("invalid read from stack off -8+4 size 8")
+__naked void stack_noperfmon_reject_atomic_on_narrow_spill(void)
+{
+ asm volatile (
+ "r1 = 1;"
+ "*(u32 *)(r10 - 8) = r1;"
+ /* A non-fetch atomic reads all 8 bytes of the slot. */
+ "lock *(u64 *)(r10 - 8) += r1;"
+ "r0 = 0;"
+ "exit;"
+ ::: __clobber_all);
+}
+
SEC("raw_tp")
__success
__naked void var_off_write_over_scalar_spill(void)
--
2.34.1
prev parent reply other threads:[~2026-09-24 13:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 13:13 [PATCH 1/2] bpf: Fix uninit read for non-fetch atomics on partially spilled slots Hao Sun
2026-09-24 13:13 ` Hao Sun [this message]
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=20260924131342.934290-2-sunhao.th@gmail.com \
--to=sunhao.th@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--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
all inboxes | Powered by JetHome®