From patchwork Thu Aug 1 12:06:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750408 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 E9EF8C3DA64 for ; Thu, 1 Aug 2024 13:00:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E57C6B00C4; Thu, 1 Aug 2024 09:00:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76D356B00C5; Thu, 1 Aug 2024 09:00:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BFED6B00C6; Thu, 1 Aug 2024 09:00:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3DE366B00C4 for ; Thu, 1 Aug 2024 09:00:40 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E4ADAA77A1 for ; Thu, 1 Aug 2024 13:00:39 +0000 (UTC) X-FDA: 82403685798.23.BAFA102 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id DA76620024 for ; Thu, 1 Aug 2024 13:00:37 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LLg1OHA3; spf=pass (imf03.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722517232; 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=4i9CKDG7ncScjip5i0iO/FjjJ91XpqkXTPTkLZDpV8M=; b=ZSUaBFbJqqRsgXnsnilw8dr5OZAsg5crdtdUUl08vWIkDcz/aDcfdjpCDkmwjFKU3ys/jv 9jqwU1e8LpnIFYx5YNElpJe9nNY89E0gYNTQwN9ibL2Ba5QMLl3QqcPYLcbB7jlsjMZyv4 +3SKOpGQAbf1d0RsmAqUWGxLhzL5sDA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LLg1OHA3; spf=pass (imf03.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517232; a=rsa-sha256; cv=none; b=yQvi3UFBV57DALYvdcm7l7vak3D9dBZcAcQaTvI1uRuFJEygve9GJBQlsJQ54Ufbetf3aw tyvWlpcvKKcGKLNargXowTXN248wBIohagtzqzIHULVVYXxzOC0Ffy+D80BFtbPS27F8YL dwmeyOBDCUfKFG3Re+L2kN8WoZt/Xys= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 082DA62850; Thu, 1 Aug 2024 13:00:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56ABDC4AF09; Thu, 1 Aug 2024 13:00:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517236; bh=18sWPiMz/2PRxXCIvtfcK7spgh5pr5ZrfaiB3z+47E4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LLg1OHA31BGAOp+FcPmnJJOjzfR45mz7vsAtPMUFCrp3V7jiNukUbotugAHXE9tfV aIcA8L9FYxshLmS4g00Xcx4OAeSAXMA7Cx6hpLIH3QZnSQCt8YXedBHO8JI/yttRb9 JpkHjxdKoSHdhI9vBqBIdnPygpaZJ95EUystul9JiKsQD6DkVqldmjSesjTbLv0sqm NikT1hoabasrT4HukGBspGC81nPLvOcQeycfSnyUlng10ZobRMGQEKzhITf55ljibS VtYKfgXcpzqVAaAmo+gfDKDoKfc1vsoY8HVPiXk+19EWEoJEiduwxjrgaCrru96J69 z1MECEs5pWqoQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:55 +0100 Subject: [PATCH v10 28/40] kselftest: Provide shadow stack enable helpers for arm64 MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-28-699e2bd2190b@kernel.org> References: <20240801-arm64-gcs-v10-0-699e2bd2190b@kernel.org> In-Reply-To: <20240801-arm64-gcs-v10-0-699e2bd2190b@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 , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , Kees Cook Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , Thiago Jung Bauermann , Ross Burton , 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.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2438; i=broonie@kernel.org; h=from:subject:message-id; bh=18sWPiMz/2PRxXCIvtfcK7spgh5pr5ZrfaiB3z+47E4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YbFMDh5Ckm74QVwECa6WtHKMFE+UgmODNhyXqy jR+iB0mJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGGwAKCRAk1otyXVSH0P71B/ 9V7hV3CQrkTFd7jDYY3vyp6DGdl60ANtDN9HiUq6OdnYyjo74919F2XR8dM7OFco4J0gWHLqcHOJMQ mCqdEM4vB9PQSvpXx2GH03cxvxIqdqfE55+qgXzqgNbizwwLZUpwdgD5RHVNHSFRB9W/bjx+JZXJqE PKyTwIymZZopYRk+Y7ejaWLDSbbzDu0NF6S8j6E5VbD9oU0rsQLaLyqdWH6OjAzZA3A/kzW6XVepic IbfLQ4Lre1T22ts5jLylYp9CPZR3M4w4IURa3eyhuBgX98WzddCT/kBy8n9tPazpRw0cDNsaEqUins yEg+6uGOgaqj7quxk0iWHDXsMAOH09 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Stat-Signature: 47ordtnxrmoj76c1dj8ki89by6eqxuxg X-Rspamd-Queue-Id: DA76620024 X-Rspamd-Server: rspam11 X-HE-Tag: 1722517237-981091 X-HE-Meta: U2FsdGVkX1/nepNl3QTezrYEYXl3DY9kZgk+O4JH7I78i9gtizf6hm+F+J6dchdcZ3Z8wKtf5xQD0pHuespyfGwciJmPApmNi0CtOJIoyb2DGeahHClYo6DCKWFmi1TtKkRQegfHst66wEUrz0uNVwaVMoc34kzC/PmrBS2NiMczRvTMiN0xCLI5FLm2B3kGYMH6RmvCdL62vMkSMAtf0aXZrPB0FmuQST9ktJFQ9t9669Sn0pCp8s5LJFNVANB+Az6LvYd0kax0aOMyPu4CsJSz466aBGPO4cphPR7/U+YNEBdnxjehAbxRySzXsnosDK09tMNXeFlMcGPHAXbpTtHyKU2Mq9YSEohhDNu40mJN6V6pLtSIDfyQ6y4d9UQjvbS178xd/gkFJM60LGJG/CxD6yHcZIUAXh8K+H9MKu8YTCD5E68qroLN2kwkP7EzCfIisEDgpb5U1edTjSeEvLMwzmgVspO8jSF7PYlet/QvJMp6PdLT4lCu6fyMcuAEylRaa6q+I3JNB36mrUsHYFN+Teo7elQB+9U8ulZctCXQuZRafa9rMsrRyVryO48YmMi0JLESiswfcMZcaUoVMSyyz3EYpap5A50EuQfnS3R91nCIRaR4b5zYAqWOeJr9KVoUKdDfh82oQ8XmAtolND7vzrtIHNCfqGa02yXYtBlNXummJ43iA3ZHuegFdNT3IXWTY1NSC8SbAIUxq+wbq93mQwTGcnGP+2MBNpZ0avRfaNX4XraApXYqLTLAe/VbW+IIEQuimkkZjyBoEit6JJvdczyuRy9BZOQkOm6T+D95BUdNqgs0HE53AMP86ky/c3iyeHb4KeRPLHBcdhiB5Dp2PVYXTeeASBy3lRPqOqY2rVBMUU/jm14G0JyFpVjGwxwjJQtKGRwjCBx00z/KT2M07G8kfEvelP8Xzvvfqiu5KtHDbnhbEM+cs7rxjRxKGgC0VJpwx0lYgxOj/J+ pfPuL8Ic aayeCBL6YZSMl3wf2dGluowiZn9POBy0wS6vZEEQmEcmH6XotDfNoLIw19DHNF5+X55Odz9Z1r03JPhWCRGYbNZPsCHAHFWXMPKKlGbh3dbl5BMaiMwmdVoKCUayCExnGi68mvtbuLyE6+ybv+IAt2CEeTbzTt95ooF4jJWHGUm3CwrXw8GktXay288EwoASQPH7Qpz6TcrT+u3XcYjoepAX8J/ZgCylUWgMR0HTwsr2bsEnc8DeJGzC6ByroiMsSKikRpouwO+aelrG4PSRV40A29Vj7nRKkOQ14G3jqaz/rsGNKlyr1YwYVZcyznTlKZI+T4lKS5KqD2U63vwM/h4h0ZMjuRo5crYuInUEPij9sM5WHluNUPOIy0vNRyahx0tqv 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. Reviewed-by: Thiago Jung Bauermann 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..302957a0bbd5 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 75 +# 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