From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Eduard Zingerman <eddyz87@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Sasha Levin <sashal@kernel.org>,
ast@kernel.org, shuah@kernel.org, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH AUTOSEL 6.6 03/23] selftests/bpf: Verify that sync_linked_regs preserves subreg_def
Date: Wed, 23 Oct 2024 10:30:47 -0400 [thread overview]
Message-ID: <20241023143116.2981369-3-sashal@kernel.org> (raw)
In-Reply-To: <20241023143116.2981369-1-sashal@kernel.org>
From: Eduard Zingerman <eddyz87@gmail.com>
[ Upstream commit a41b3828ec056a631ad22413d4560017fed5c3bd ]
This test was added because of a bug in verifier.c:sync_linked_regs(),
upon range propagation it destroyed subreg_def marks for registers.
The test is written in a way to return an upper half of a register
that is affected by range propagation and must have it's subreg_def
preserved. This gives a return value of 0 and leads to undefined
return value if subreg_def mark is not preserved.
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20240924210844.1758441-2-eddyz87@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
.../selftests/bpf/progs/verifier_scalar_ids.c | 67 +++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_scalar_ids.c b/tools/testing/selftests/bpf/progs/verifier_scalar_ids.c
index 13b29a7faa71a..d24d3a36ec144 100644
--- a/tools/testing/selftests/bpf/progs/verifier_scalar_ids.c
+++ b/tools/testing/selftests/bpf/progs/verifier_scalar_ids.c
@@ -656,4 +656,71 @@ __naked void two_old_ids_one_cur_id(void)
: __clobber_all);
}
+SEC("socket")
+/* Note the flag, see verifier.c:opt_subreg_zext_lo32_rnd_hi32() */
+__flag(BPF_F_TEST_RND_HI32)
+__success
+/* This test was added because of a bug in verifier.c:sync_linked_regs(),
+ * upon range propagation it destroyed subreg_def marks for registers.
+ * The subreg_def mark is used to decide whether zero extension instructions
+ * are needed when register is read. When BPF_F_TEST_RND_HI32 is set it
+ * also causes generation of statements to randomize upper halves of
+ * read registers.
+ *
+ * The test is written in a way to return an upper half of a register
+ * that is affected by range propagation and must have it's subreg_def
+ * preserved. This gives a return value of 0 and leads to undefined
+ * return value if subreg_def mark is not preserved.
+ */
+__retval(0)
+/* Check that verifier believes r1/r0 are zero at exit */
+__log_level(2)
+__msg("4: (77) r1 >>= 32 ; R1_w=0")
+__msg("5: (bf) r0 = r1 ; R0_w=0 R1_w=0")
+__msg("6: (95) exit")
+__msg("from 3 to 4")
+__msg("4: (77) r1 >>= 32 ; R1_w=0")
+__msg("5: (bf) r0 = r1 ; R0_w=0 R1_w=0")
+__msg("6: (95) exit")
+/* Verify that statements to randomize upper half of r1 had not been
+ * generated.
+ */
+__xlated("call unknown")
+__xlated("r0 &= 2147483647")
+__xlated("w1 = w0")
+/* This is how disasm.c prints BPF_ZEXT_REG at the moment, x86 and arm
+ * are the only CI archs that do not need zero extension for subregs.
+ */
+#if !defined(__TARGET_ARCH_x86) && !defined(__TARGET_ARCH_arm64)
+__xlated("w1 = w1")
+#endif
+__xlated("if w0 < 0xa goto pc+0")
+__xlated("r1 >>= 32")
+__xlated("r0 = r1")
+__xlated("exit")
+__naked void linked_regs_and_subreg_def(void)
+{
+ asm volatile (
+ "call %[bpf_ktime_get_ns];"
+ /* make sure r0 is in 32-bit range, otherwise w1 = w0 won't
+ * assign same IDs to registers.
+ */
+ "r0 &= 0x7fffffff;"
+ /* link w1 and w0 via ID */
+ "w1 = w0;"
+ /* 'if' statement propagates range info from w0 to w1,
+ * but should not affect w1->subreg_def property.
+ */
+ "if w0 < 10 goto +0;"
+ /* r1 is read here, on archs that require subreg zero
+ * extension this would cause zext patch generation.
+ */
+ "r1 >>= 32;"
+ "r0 = r1;"
+ "exit;"
+ :
+ : __imm(bpf_ktime_get_ns)
+ : __clobber_all);
+}
+
char _license[] SEC("license") = "GPL";
--
2.43.0
next prev parent reply other threads:[~2024-10-23 14:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 14:30 [PATCH AUTOSEL 6.6 01/23] 9p: v9fs_fid_find: also lookup by inode if not found dentry Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 02/23] 9p: Avoid creating multiple slab caches with the same name Sasha Levin
2024-10-23 14:30 ` Sasha Levin [this message]
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 04/23] irqchip/ocelot: Fix trigger register address Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 05/23] nvme: tcp: avoid race between queue_lock lock and destroy Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 06/23] block: Fix elevator_get_default() checking for NULL q->tag_set Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 07/23] HID: multitouch: Add support for B2402FVA track point Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 08/23] HID: multitouch: Add quirk for HONOR MagicBook Art 14 touchpad Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 09/23] iommu/arm-smmu: Clarify MMU-500 CPRE workaround Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 10/23] nvme: disable CC.CRIME (NVME_CC_CRIME) Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 11/23] bpf: use kvzmalloc to allocate BPF verifier environment Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 12/23] crypto: api - Fix liveliness check in crypto_alg_tested Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 13/23] crypto: marvell/cesa - Disable hash algorithms Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 14/23] sound: Make CONFIG_SND depend on INDIRECT_IOMEM instead of UML Sasha Levin
2024-10-23 14:30 ` [PATCH AUTOSEL 6.6 15/23] drm/vmwgfx: Limit display layout ioctl array size to VMWGFX_NUM_DISPLAY_UNITS Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.6 16/23] RDMA/siw: Add sendpage_ok() check to disable MSG_SPLICE_PAGES Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.6 17/23] kasan: Disable Software Tag-Based KASAN with GCC Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.6 18/23] nvme-multipath: defer partition scanning Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.6 19/23] drm/amdkfd: Accounting pdd vram_usage for svm Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.6 20/23] powerpc/powernv: Free name on error in opal_event_init() Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.6 21/23] net: phy: mdio-bcm-unimac: Add BCM6846 support Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.6 22/23] nvme-loop: flush off pending I/O while shutting down loop controller Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.6 23/23] nvme: make keep-alive synchronous operation Sasha Levin
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=20241023143116.2981369-3-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=stable@vger.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.