From patchwork Sat Feb 3 12:26:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13544164 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 188D9C4828D for ; Sat, 3 Feb 2024 12:34:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A09D36B00CE; Sat, 3 Feb 2024 07:34:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B76A6B00CF; Sat, 3 Feb 2024 07:34:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87FF36B00D0; Sat, 3 Feb 2024 07:34:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6F6A06B00CE for ; Sat, 3 Feb 2024 07:34:04 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4118780841 for ; Sat, 3 Feb 2024 12:34:04 +0000 (UTC) X-FDA: 81750434808.14.FEB97B1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 7D2A540013 for ; Sat, 3 Feb 2024 12:34:02 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=F78PhGGK; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706963642; a=rsa-sha256; cv=none; b=RYc81cP4FYN9MY060femYUA+8jdUwArr1ZFAt6zYJ+92zK8a6xRv2eBY7SsffUyx40tbQ1 jggtfw6gboEL0wI84Uet+4gJVb9KNWgFiEZnzaydYr2hpomF/ALB7iQvJAsNOBlF2Z92Fe ebmPMIEX2zxFsfnQHpdyl4vso6dG+YM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=F78PhGGK; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706963642; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=l2wMPb0I/C+AdwW1G0Uit64xGryvNSm5ssmsYVRi/4c=; b=WmV+MiChZwlLQNAJFB4m5VYXRS98RG2U4PZGX5pi5XFPxtjemCItm0gLbOMNWM6gWAqJ+7 vZel1o24vp9t43Hv6nzlaY26xDtMHLSUJZpei1tCCvOA8+Ec62XE2mEDOzZjyd26JiXGm4 9csWERpiAKpnJPb9o3U9T76nA93ZUqo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C073060A67; Sat, 3 Feb 2024 12:34:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35D85C43394; Sat, 3 Feb 2024 12:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706963641; bh=WXqbYsgYYOXFEeMs+roJ3AXRYBhuL60ozPF+o7O4bAk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=F78PhGGK2tKTlc1p2op6t75h6sAseztGvobKzgGSABUqePNhCLv6h7b0MXYZozVvf TMoM8VKK0ZO5F2e6/66jeGgtskS0UMHEiCAZUXqg+6vxYh1xgH6tpBdIJiNPgo7YpK EnaGYjMB/A//4+Sjcv0gbyN2txDslqcYGoLlVah+34dTkNIBFZPTZDpK5wR3pQL70I Dzxx0jU1Bjxx/D0JoI4d/HNBk5LzI9/lGYtAoE48s/fM91juriLFdFQwpik4auJ+g4 1D/HN4P1oVK7bX97yoTav7bFx3jIr53qvhASYz8zdLRC/yDEo0s7d2QHFhc9ilv97S gLO6O0zcUVi6Q== From: Mark Brown Date: Sat, 03 Feb 2024 12:26:04 +0000 Subject: [PATCH v8 38/38] kselftest: Provide shadow stack enable helpers for arm64 MIME-Version: 1.0 Message-Id: <20240203-arm64-gcs-v8-38-c9fec77673ef@kernel.org> References: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> In-Reply-To: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> To: Catalin Marinas , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , Thiago Jung Bauermann , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Brown X-Mailer: b4 0.13-dev-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=2372; i=broonie@kernel.org; h=from:subject:message-id; bh=WXqbYsgYYOXFEeMs+roJ3AXRYBhuL60ozPF+o7O4bAk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlvjDvM7ObtGoCDxxiAl89DYa6RzxdLnWQy+FkForz aUSU5kiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZb4w7wAKCRAk1otyXVSH0NEICA CCvybEtXLigY0Lceu5RSwEZ8U+9W6svq5+knPV3mZQY4TSxy9Yy4lyeVk8Pv21v/12qFvp6uqzLp0g k6+WV9GRZ/Pqfacx9BQ00Oc/rfhKVczK0MsQz3mDGVuLKbJ4qSNpb8/dqtFqZr2ObsOcGe2ZV7T/CG ALJt/tNjptHMxvEWIyQI3z/Smo1ZEdn4C7yaVXufiGkwDmFEB8wquT7O7Dh3npGDpxL78q4rAtfJy+ 8dPSdobFohDZMcnrMhjgw8Klf2bbVp8Sut5M7DVJ/t3nRkqxRoYhyVFTjjG6NdjDWhhL+IKQdltpt4 8U4+ItNFhfAZrHX27/JjU9V30WRy/h X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7D2A540013 X-Stat-Signature: jqekou7tw9rxcapowd871ae6jxucmgtk X-HE-Tag: 1706963642-892071 X-HE-Meta: U2FsdGVkX1+OIUDu8bq7Xpvn0gqOfhldumB3sRG23cf4iemC8aysRYDJa4S4FnJyE7V6MkYH3V8IrMUc47nSPkGlkBpe5COBfqaNYBzFo+KADe3pMl13+NkzAUTsC8ZiBY6mpBhCIyR7hjCsae20LtejdFAnHPqIkpUEIxFKmrqmHyhKpR0YfVEbu7bz2ClBw1QCnQJMlqWRq2PwuaeYv52fbmxCAYc0rDnYTj5fpNmNsw8fmBtBAzqWOw92CO8NmqlOYAginks11LBx+ntVGWL5MHBg4reZwYwOPseQYF82ADOLuBYb43Yfy9sGbyVWoafuJVnJi1EKzzhX/KtRUpruILDoLUQoobxuSkzt/78XMssivS0Yvb9PA/tVyHNuVSaRiezErpPMvuULFoKn+b6JnhLBdxRweD1wzqtMS0mcnJynZScV+p0ZRavxPT7tjRrGdn0mco8+vQtWb9wvOYSGqJTjLL+fbR04HTWjBjsPmhreAUqwCrxJOH9QWnvZAYbGxVEw3RAEkI36vPJLPjGKmc4slXRSXQ6p3T9Mqp4/0QuAa8IDsCqaRomoflmEGvi03xJjbG/Kh46Cdw8PVr8yNfIbk+gujYevY+uVQdemJJ9OocD/30G6rU6sPZwaMSPL2SP2jDoZ445e5MwoikHGdTobfH50IOreoth5FKW6wkKPRgpOEd8wP5icauQ9KFLeJpb8oyH15G9ZGD18o4WNdIm697d5fKThm7izVcAqOShukKl2Cv+rQFZPVSE8cZBj/1JSUqVspGVHwqZldyGI/pOjzVfDgZ4VJaFWoSIalu/CDlMJzAgzJNDg+YrSKao1qgmZBPgBZ/ViB9oKgNv6O6wUDfUnsbGZpGaGhphL148h43Ht1r/EukzDCZx+9h3yJRKUIL3nXlkfKsnaRbOpdJrb1uCiYYstJHyi2ten4ErPmFP1DF+s+2e1lnoZmbFWtbMuZopQY5qftJQ Gn7H0luk YgsM4KHIwrZrkMVcOdXb9NLpdv07vccxG4KyQnLeTnyunm77W9OoAmZvtYa98rGzyHGNvZ4+soQmqDjuhHp8sl1J/ADL8XItBD+S2HaZTY5GY4Freorqwl8B7oX21F7QIn72EpDIzUFBpV+E6s7SVTDLtMGTrrk3JTzXMM+4xl7G0Nshu34K1lrjentLx17M7oHqB8p/jLKzNUt97KER6oDS0kClpLTY0/Xq93eizlzC7jO9eyUTtbOBbb/HJFEDZk7Yrira3tJZXtwA2Oqr1aGO40Ah97UNkxo5cqSS582u4u/muf9wqARbDksOYbVHK73ro X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Allow test programs to use the shadow stack helpers on arm64. Signed-off-by: Mark Brown --- tools/testing/selftests/ksft_shstk.h | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/testing/selftests/ksft_shstk.h b/tools/testing/selftests/ksft_shstk.h index 85d0747c1802..223e24b4eb80 100644 --- a/tools/testing/selftests/ksft_shstk.h +++ b/tools/testing/selftests/ksft_shstk.h @@ -50,6 +50,43 @@ static inline __attribute__((always_inline)) void enable_shadow_stack(void) #endif +#ifdef __aarch64__ +#define PR_SET_SHADOW_STACK_STATUS 72 +# define PR_SHADOW_STACK_ENABLE (1UL << 0) + +#define my_syscall2(num, arg1, arg2) \ +({ \ + register long _num __asm__ ("x8") = (num); \ + register long _arg1 __asm__ ("x0") = (long)(arg1); \ + register long _arg2 __asm__ ("x1") = (long)(arg2); \ + register long _arg3 __asm__ ("x2") = 0; \ + register long _arg4 __asm__ ("x3") = 0; \ + register long _arg5 __asm__ ("x4") = 0; \ + \ + __asm__ volatile ( \ + "svc #0\n" \ + : "=r"(_arg1) \ + : "r"(_arg1), "r"(_arg2), \ + "r"(_arg3), "r"(_arg4), \ + "r"(_arg5), "r"(_num) \ + : "memory", "cc" \ + ); \ + _arg1; \ +}) + +#define ENABLE_SHADOW_STACK +static inline __attribute__((always_inline)) void enable_shadow_stack(void) +{ + int ret; + + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + PR_SHADOW_STACK_ENABLE); + if (ret == 0) + shadow_stack_enabled = true; +} + +#endif + #ifndef __NR_map_shadow_stack #define __NR_map_shadow_stack 453 #endif