BPF List
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
	<martin.lau@kernel.org>
Cc: <andrii@kernel.org>, <kernel-team@meta.com>
Subject: [PATCH v2 bpf-next 05/10] selftests/bpf: validate STACK_ZERO is preserved on subreg spill
Date: Mon, 20 Nov 2023 16:22:16 -0800	[thread overview]
Message-ID: <20231121002221.3687787-6-andrii@kernel.org> (raw)
In-Reply-To: <20231121002221.3687787-1-andrii@kernel.org>

Add tests validating that STACK_ZERO slots are preserved when slot is
partially overwritten with subregister spill.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 .../selftests/bpf/progs/verifier_spill_fill.c | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/verifier_spill_fill.c b/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
index 6115520154e3..899a74ac9093 100644
--- a/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
+++ b/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
@@ -450,4 +450,40 @@ l0_%=:	r1 >>= 16;					\
 	: __clobber_all);
 }
 
+SEC("raw_tp")
+__log_level(2)
+__success
+__msg("fp-8=0m??mmmm")
+__msg("fp-16=00mm??mm")
+__msg("fp-24=00mm???m")
+__naked void spill_subregs_preserve_stack_zero(void)
+{
+	asm volatile (
+		"call %[bpf_get_prandom_u32];"
+
+		/* 32-bit subreg spill with ZERO, MISC, and INVALID */
+		"*(u8 *)(r10 -1) = 0;"  /* ZERO */
+		"*(u8 *)(r10 -2) = r0;" /* MISC */
+		/* fp-3 and fp-4 stay INVALID */
+		"*(u32 *)(r10 -8) = r0;"
+
+		/* 16-bit subreg spill with ZERO, MISC, and INVALID */
+		"*(u16 *)(r10 -10) = 0;"  /* ZERO */
+		"*(u16 *)(r10 -12) = r0;" /* MISC */
+		/* fp-13 and fp-14 stay INVALID */
+		"*(u16 *)(r10 -16) = r0;"
+
+		/* 8-bit subreg spill with ZERO, MISC, and INVALID */
+		"*(u16 *)(r10 -18) = 0;"  /* ZERO */
+		"*(u16 *)(r10 -20) = r0;" /* MISC */
+		/* fp-21, fp-22, and fp-23 stay INVALID */
+		"*(u8 *)(r10 -24) = r0;"
+
+		"r0 = 0;"
+		"exit;"
+	:
+	: __imm(bpf_get_prandom_u32)
+	: __clobber_all);
+}
+
 char _license[] SEC("license") = "GPL";
-- 
2.34.1


  parent reply	other threads:[~2023-11-21  0:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21  0:22 [PATCH v2 bpf-next 00/10] Complete BPF verifier precision tracking support for register spills Andrii Nakryiko
2023-11-21  0:22 ` [PATCH v2 bpf-next 01/10] bpf: support non-r10 register spill/fill to/from stack in precision tracking Andrii Nakryiko
2023-11-21  0:22 ` [PATCH v2 bpf-next 02/10] selftests/bpf: add stack access precision test Andrii Nakryiko
2023-11-21  0:42   ` Eduard Zingerman
2023-11-21  0:22 ` [PATCH v2 bpf-next 03/10] bpf: fix check for attempt to corrupt spilled pointer Andrii Nakryiko
2023-11-21  0:22 ` [PATCH v2 bpf-next 04/10] bpf: preserve STACK_ZERO slots on partial reg spills Andrii Nakryiko
2023-11-21  0:22 ` Andrii Nakryiko [this message]
2023-11-21  0:55   ` [PATCH v2 bpf-next 05/10] selftests/bpf: validate STACK_ZERO is preserved on subreg spill Eduard Zingerman
2023-11-21  0:22 ` [PATCH v2 bpf-next 06/10] bpf: preserve constant zero when doing partial register restore Andrii Nakryiko
2023-11-21 16:20   ` Eduard Zingerman
2023-11-21 18:14     ` Andrii Nakryiko
2023-11-21 20:22       ` Eduard Zingerman
2023-11-21  0:22 ` [PATCH v2 bpf-next 07/10] selftests/bpf: validate zero preservation for sub-slot loads Andrii Nakryiko
2023-11-21 16:20   ` Eduard Zingerman
2023-11-21 18:15     ` Andrii Nakryiko
2023-11-21  0:22 ` [PATCH v2 bpf-next 08/10] bpf: track aligned STACK_ZERO cases as imprecise spilled registers Andrii Nakryiko
2023-11-21 20:38   ` Alexei Starovoitov
2023-11-21 22:01     ` Andrii Nakryiko
2023-11-21  0:22 ` [PATCH v2 bpf-next 09/10] selftests/bpf: validate precision logic in partial_stack_load_preserves_zeros Andrii Nakryiko
2023-11-21 16:20   ` Eduard Zingerman
2023-11-21  0:22 ` [PATCH v2 bpf-next 10/10] bpf: use common instruction history across all states Andrii Nakryiko
2023-11-21 16:20   ` Eduard Zingerman

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=20231121002221.3687787-6-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox