From patchwork Tue Jun 25 14:57:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13711455 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 3C0A0C30658 for ; Tue, 25 Jun 2024 15:04:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DDF28D0005; Tue, 25 Jun 2024 11:04:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88D7E8D0002; Tue, 25 Jun 2024 11:04:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72DA08D0005; Tue, 25 Jun 2024 11:04:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 51B608D0002 for ; Tue, 25 Jun 2024 11:04:25 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F3ED540154 for ; Tue, 25 Jun 2024 15:04:24 +0000 (UTC) X-FDA: 82269732048.22.27639B4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 3A42440101 for ; Tue, 25 Jun 2024 15:04:02 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="L/22fLgn"; spf=pass (imf07.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=1719327836; 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=d5lwspFvI5I2ieiR1OOj3Toqfdj2H13XDYafhczsY99yVHCF8Ab9r0kgqubPEL1dQhvwvB p6cy9sJfwDYtBCzmso7bu8rF3/wQcw3HN1b/znbAUKXv4vImGYrvHBbWZfzahwe5XWIeBy z5wmgNUPNpzfOmQvp3BvWMIrfgb6wps= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="L/22fLgn"; spf=pass (imf07.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=1719327836; a=rsa-sha256; cv=none; b=OuRkZRz1e3RrxsciSevoV7fk/0ExQLURunsKgRto5+52typLR5LJQBJQBanIL6Qm321cBv M6Np8LPgEIk4RrWszdU5F0ON+fD48aYf5bfEABOMtQGX9azyGDE/vTta9s5tkt4EFWnf9Q Wm7P2LpGhcAMgGhSepCKPtj3E96EGPk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id DAF0C614A2; Tue, 25 Jun 2024 15:04:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 952C8C32786; Tue, 25 Jun 2024 15:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719327841; bh=18sWPiMz/2PRxXCIvtfcK7spgh5pr5ZrfaiB3z+47E4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=L/22fLgnVrCDuOa9AvI6QdbD1mU2fPLWMyOny0LJICnsPQ+OE/mai2HAC7OkLXWrJ pcjmdvOHUArp132IpQ/J7Z21Sv/jOjoC6HDAqdUKWzSDHPvfBs0pcnv8FRQWxrb3Sr FraOwe39xbpr7uXa7BJ61D/F5eof33J8kY9ZTgInPA47/sgIlBPg/f8C2pZayWI2YR nrWC+5A2Hs6TAQQZSCany+TRS3b/filwuFp/OmO63FLC5Pow0ctynPP+i3tlzxgMWn ycNQHDCO02rxEI6Wbb971VZMdfryYPFOk1DSQOosLTixKz+ahicdLElvrOaKYhN9HJ TYvGOxzLrD3vA== From: Mark Brown Date: Tue, 25 Jun 2024 15:57:56 +0100 Subject: [PATCH v9 28/39] kselftest: Provide shadow stack enable helpers for arm64 MIME-Version: 1.0 Message-Id: <20240625-arm64-gcs-v9-28-0f634469b8f0@kernel.org> References: <20240625-arm64-gcs-v9-0-0f634469b8f0@kernel.org> In-Reply-To: <20240625-arm64-gcs-v9-0-0f634469b8f0@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.14-dev-d4707 X-Developer-Signature: v=1; a=openpgp-sha256; l=2438; i=broonie@kernel.org; h=from:subject:message-id; bh=18sWPiMz/2PRxXCIvtfcK7spgh5pr5ZrfaiB3z+47E4=; b=owGbwMvMwMWocq27KDak/QLjabUkhrSq2x0KqV3vs2a/V1Pb7Be8+t4u7WmabwqCORe9/xTgHr+8 zNa2k9GYhYGRi0FWTJFl7bOMVenhElvnP5r/CmYQKxPIFAYuTgGYiHcj+292TZ+CQLdbi9mYW8zEN2 X1LjihftFL8fvMrGl2EZzskwXMdeZ+eBMrWuqa2borvMb24hZlk386KTFbd8ltvyeVsXVOUuDr1asv 5ZQFu/QfNL7cmbnl1obSPh5WI7muxXX+i5PSXV4x/kwPf7jnbGuQWhhDb1TwV5+nwho3/2t21fw80T +/J3pniDibQTHbr237989ZsoBNX6Ly+1zl60weQQfadrmbdbHmndF47pjSx75Xe2qA22mzq809x4pu SvLH7TaZ1mPz6YWxRt70D7HrehQD3Njlrr2cmpYzdT2bxNJMr5m6ejY8x25oC3rm7/86pfBzBmdA0f namwlBHDZhJpa9tqHSxU6cK8oB X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 3A42440101 X-Stat-Signature: a8y5nrqdo5tp5apo7poni753m9nnnnyn X-HE-Tag: 1719327842-18169 X-HE-Meta: U2FsdGVkX1/p2pwyiIDsJ9ZtChCAZScJlUmIKDIEv096Au4xrVPZPVZwrYslbtU31AqNl0pMVD3AuvfMA3nhOBqJSN1CbXdAKl+87sL83Z+5rlTSmgQvB4AWzUoVkJFB4mwkZP5ow/n7QEI1ov4QsClfmS53JzrHbPKFxIDZV7yV5cQvXywqgYiEpHBcId8PLLX1Muin+tvSd+QfdI3F7quolgoa8wjT1fo2qaLuUpdhbeQ0EJNNQtto74VCenOqQaMY+uLxxoJ9WB/NTaMll9eC5n1mqYxFMrf9BHw/51xONzN6UObupjfl6tRpPZ248VxaV7rh+N+xOuE5MO6tnlpUm7TbCLNDzzvoyoaHuH/jt3aq47uCQa2FQJcEe7P2KEQzn47s7h7yOjLFXIxMotqBsxNJpcsYg6L+GswEQp6to/A/tZaCfsvGiSD4T/NRJOcmUtfgU/i38hqnD7iNnONtLhMZbJV3Z3oSs52dnfynUOkWcQOhlXZkYoLxG29Ann83/Euylq3QySUXNSih3pig2ovnK7eeRBCgtI/EgFrJxMBqPtoGd68TgXJuJtp0aoFcNlifNMO7x8j5sQU7xFYPD0NyhNcWR/TgmWH81kCE+RbqygDPkRBQ6jns74Bj6zzXpD/iOxlrb+jETP4zItrE985NsCmbCbeqnYaJql62P1EuUBU18UP6HMgIhtHtYXauSP6MF9PUfOwUrI0wpAKBbqglU41Niy2V+m2DyEvnAboa3tZ31v/Rd77AIo4T2jeqUFmjspoilXCzkrkT/gbHS490WC7lfyowZTEwYnCJ8OrwDzRwATaOMHR1VonyuUMclXIfEH2KMz2Om17d2f7uYMIRCaud8ByM6CT4zztpC6F2V+Y3DWg6hvb1KhjSxT+aSSKELx5nrhk5rRSq8c0YwH2eIumQXQDKfTRl3/jC6UwG8JnMMWFOUvpQ9tpMMyvwaWsdY8Bh49tINy4 zEmuQtw0 lTB+MR2Sx0HxJ4+56QcX14UuQvICppcQGw8J2OvDOyBJRXepTM6t/gbitrFjeYqitRYC/TS/kmN26aTZqgikAcg4K/6HWTZ3PD8Z5TuNiqk3Q3GA28/k3tQjlGR3dDM5r4KvbC3vKtHyixC5yeZAQi1mhMAU8jIDIdVcyJyMyVS+/yfUNBuM03ByCWzuHXZJlB/SFgS8KKhelo+6jC6TLsyJ+HLT00NRD+KSjAfj8a2BdJxOIujb6dmH+redJE/0BPZ1/oDnSCS+cVkWnzdAY9UEdElA5X1ndQi69ymyTYJ6heGDjT4Lav2OFYcQM3ogsaCjwGnGHX3nToVMu5azH7BHpcBvavGwrtVjRvUMTlzEfMErIoFbf0Bo4uVgS4qFg9KZn 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