From patchwork Thu Aug 1 12:06:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750380 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 DB349C3DA64 for ; Thu, 1 Aug 2024 12:57:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76B0D6B0096; Thu, 1 Aug 2024 08:57:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71B456B0098; Thu, 1 Aug 2024 08:57:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60A926B0099; Thu, 1 Aug 2024 08:57:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 439816B0096 for ; Thu, 1 Aug 2024 08:57:33 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E17471C3E5C for ; Thu, 1 Aug 2024 12:57:32 +0000 (UTC) X-FDA: 82403677944.13.B95DF09 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 24FA04002F for ; Thu, 1 Aug 2024 12:57:30 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BZbXzFPN; spf=pass (imf27.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=1722517022; a=rsa-sha256; cv=none; b=nc6xbEy/qqrIoHspCvi8/7hS4EiHzPDchFYRl77VIo2FqifjX/IukHXlpSmGhlwNj7u74A zLqO4xYdlsO3pvMEgeKQGgMWoTrroI81tjl2BpDShcTnPGSkG2bpkD7XA6T88iT2WJIh80 UsUlNUFvQXyP3MOvHjtDExjdGBoTzaI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BZbXzFPN; spf=pass (imf27.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=1722517022; 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=pqqAahuGOgVzBd2V2rC3cp6LsHNItpORh1WCuQkluUA=; b=VUDjJewKwH992u2TCdWodzsiD02oDQ66MJfZSFenSGiBXMhi9yQqLY6Urg+aa1tfJ5z0cc GNfPcN1oGkFPDD6i1oW9PtMmVaALlzKMsZruXqbMAd6/6m9Gkom2Z6u0A9TjWyFSaa9r8X y7kXLGLT9x/BkkHjlhRZOY2zF8l19SY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A87916285D; Thu, 1 Aug 2024 12:57:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB0C0C4AF09; Thu, 1 Aug 2024 12:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517046; bh=bsiMqAlOgEwP0cbRhsqWxUT30GAWtj7CcR/m2yEY+EM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BZbXzFPNzPvbVSEL1HQGb9vwgWBSp98cTAPSVjgtfvJw92HXoTlzukkF3KirLERxc bqNPNcakZeZ/4Csghs6sC/XpdJCwoczXybGu7jfJiioe7ljfYE4qxdv6Q0hGT5BMXt eIqPOfLqmTZwbfvoVmaVqmAFunVsB0EF3q98WvvHeu9kip39NlikjgyNpwevVVHoeq H5Ci97Hqtb2MoP/46USTpEYDzAs4bjD5CG6Opz6g2V+D7Ss3x4ldV4Do03mZti3btS r8pN2FEjEAryz6qhJyFeD7V9FRQ7eboOa9BOTKFurPui97bxufWmSq7NQ2pj0rkkLZ vS/O9RPKAAgmg== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:28 +0100 Subject: [PATCH v10 01/40] arm64/mm: Restructure arch_validate_flags() for extensibility MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-1-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=1369; i=broonie@kernel.org; h=from:subject:message-id; bh=bsiMqAlOgEwP0cbRhsqWxUT30GAWtj7CcR/m2yEY+EM=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YGqNne7baHl23QOwDNZcKGE/jpNiGj7M5xDaR7 lIob1RyJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGBgAKCRAk1otyXVSH0P6kB/ wIOf1cMolmdce2aUsq0S+hmD8dGJDuLlSKxaFli9jY4UBL8wsQJFyiNa/OYFI8nDKrC5byoMT1dO0M TqsVdiKMI+P8FfRaguIINosdMj2HarIZXN1a5vv2E26G44gzwk+9wjKUMgc26wRPvP+R9Oa9FgWaKM jR+dEdnMkFQja9XnvYvrIpSN7VCp0GZ9n3Hf5G+tMTC/pVQibgBVYGV6j38kDUitFDpMiYJvHjFRpw vWH8ACdZCETPX9eigVl2ElUysqkSWWtpY+fLh856UWEVGsXYY0P/Aqm5NoC5EBRo9DP9EU2Qxcpjo5 j0naxVNyc9NsDOrN3vlTlgohZmbE/F X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: kkafacbhzcneh1m3jzp66s97u46fx6ph X-Rspamd-Queue-Id: 24FA04002F X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722517050-695116 X-HE-Meta: U2FsdGVkX1+Gh6SZe34Pg5+qAcxxl8YI1EdKnuaXO/BXHCqD2JWmav5zW0z/rBDEGGre1SkcYhpDrCGRKKhx8HfJQiU/uZmL3KR2JFsvo3FH405HPVqOLgGe8+G+qbgPvGc3CqSHdVZ7LBNjK5EP/kyP4re6uffwoOCh3Dy+ky42CjXTKarsdMDhk/wGgCZ2fOUXTPHs8l8/9zEv0xVXiOci/aPV5RzREwJndD0uWMc9Qm3eiEzrhtlRjBty+bCsxREpVjqC8nhOEnCFALOS6YQpox9Yim3/ZvScdEhvK/GTVbR19jCP9rJKsWpuVD7TCo7DpZ1X6qL+HqBfrbqYVBl36pC7fXGsmfhh2gMpc1tanpjJ7qCOtWKBG57aS1vzXoCX4HqQD2kNm/67V0f+rm37X5IUUK4ByMI/1ZM4gJuNG53113KVQn5sjI6XzqXfcQiJADgv8yX+XPI10jG8fElpB5+ZZS+AH+xcl7ITL6NuFXKZastV0qO7PIE2rOqVaWSmfb70TImnqFST7lyYtdRAOMHBJVgOyHSoYyINlg7wGOFw190OhAdaBwKurLMah9HxbskceKitmiSt1RdMHT5k6kFJKdM/CIRE9CMg2NXHJST50WsR20FtGyizd4oVpAoYKG2lxudXd/1vr1q7Ax0+Jmh7BqxBVhTZL73OEsxu2QBX1SNf/YEfQOpAmjvxBRXe4upP/LtC2Q460iwp+gHwMWfV0Bi39w7YTA8wwRL7OtSn11e67j/Ygn2jyEVMZdHeRM38VGjIz4Z4kmU3wasyyzDuAKKJx6PjJ9qzQtErCDb8xYQMO+ogmqkt06s13lIpz9Tc4GU7/DjiCy1MeGv7zKX1FV2JZ9kfbVEKjFvGCZ0p9e3JuoNg+5v/aUjEpI91XI62ry0oVTIctXodmCuvBW+HbCbO1WS7kNoR/WqfUWBYrC1JCVCRsxM+/D4pef6Csxnmw8v+Mk+BCS5 LCVRR2R2 PSQSiMqNRknwlBt+xxpwLjXeqbWcH+pSxlBkAvaJjSfJ3gq4mapWBEAn6deJXDP+p9Dt52Xthlq3+h7zWMiuJD7eRnw6GHUbx45t0EYKPNsv3hd2XT7PwMlSDR0nvWRa13NmDB+nTGTObbv49mdyKNzaLrXazdjRe3TtxPUcIj2WYyF8XgGVnvssXtl4343Wiu+V4E1zPPj3IAQqGvZVtQ3pH3j6CkkZQrMCydAsYBchc4fi7fH6j3zVuFzMMW2Izq+DD39PYb/NJ7QLSodD+qVFm6xd7xJgnPuqGGkrdS7IiAeY3x9n0XSJQRX4sLfskK7t48TMeGl/PQfvC7sKhGP6j1bXIgKXyJmBBth5hWjy5ctSYnziD8Cl61wOBG84CbLN6reyF7G0brU/0EQSqDNgAOHkZlF9N94F9Jd4pJ2hIZi4= 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: Currently arch_validate_flags() is written in a very non-extensible fashion, returning immediately if MTE is not supported and writing the MTE check as a direct return. Since we will want to add more checks for GCS refactor the existing code to be more extensible, no functional change intended. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/mman.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h index 5966ee4a6154..c21849ffdd88 100644 --- a/arch/arm64/include/asm/mman.h +++ b/arch/arm64/include/asm/mman.h @@ -52,11 +52,17 @@ static inline bool arch_validate_prot(unsigned long prot, static inline bool arch_validate_flags(unsigned long vm_flags) { - if (!system_supports_mte()) - return true; + if (system_supports_mte()) { + /* + * only allow VM_MTE if VM_MTE_ALLOWED has been set + * previously + */ + if ((vm_flags & VM_MTE) && !(vm_flags & VM_MTE_ALLOWED)) + return false; + } + + return true; - /* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */ - return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED); } #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags) From patchwork Thu Aug 1 12:06:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750381 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 4D9F8C3DA4A for ; Thu, 1 Aug 2024 12:57:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEC0C6B0099; Thu, 1 Aug 2024 08:57:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C25506B009A; Thu, 1 Aug 2024 08:57:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC63A6B009B; Thu, 1 Aug 2024 08:57:36 -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 8E3646B0099 for ; Thu, 1 Aug 2024 08:57:36 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1CA271C40BC for ; Thu, 1 Aug 2024 12:57:36 +0000 (UTC) X-FDA: 82403678112.04.4DC0682 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 4332A160025 for ; Thu, 1 Aug 2024 12:57:34 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gn76kpXZ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1722517012; a=rsa-sha256; cv=none; b=cTpelp/w1fWTyBmdjcggjW8wO5jDcKRUcHl0AZlGwe/CclU77s73D/O9niDxpOx3DbApUC +pKv9ugWhI0QpXmIUnKlOzCwDo/eL3TUGXzVcB54+yLE5ndTA7080vVJ46OSanMO5vruth 3NRNbq4GwxK8Nt/A03F7pKoWwBvk5iY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gn76kpXZ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1722517012; 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=xE4r1OdMOuQOtvYbXqgXQT6HEL6+DhdOhpFAidzB71o=; b=8Z1X2svs2GkFcqXlNPRB6LAjueZvFhW6orrFtoeMQ0beNLjvW/lAWGcGR47BqhQmIkOLS8 ol0Sbc5oYNQTfI5VyDfNiFtnVrdCEvEUEN0PFjEwTo2ihV3PBIEWqhb1GlaUCDAb7HL4XA Tp/q90gdRctLxjrgHN2zpDWotpEkUEk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7EB026288A; Thu, 1 Aug 2024 12:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA5D0C4AF0A; Thu, 1 Aug 2024 12:57:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517053; bh=OvR6N9yV4HsQXOrwTY0B56Y1UKQlPL/MpYNNiWGIOU8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gn76kpXZGuovEJsswE8j2lOsgBW4PR578UDiThd4s4I4YoKJvfCqZ1DbymCf8xbuS X1VOWKfLhwcVY4x/7o6COOGPpHHtRj30f6+8qQT18mHHKmzfTHeh2Xn8DQWch4wQK1 cxBX1MypgoCqxGif2mx/sPN2jyddzQ4Dak828B+c0NQugWavtwya2f4qLq4NQzikc2 ufy8oYQxFvr/igSCWz/RQmXY+eMxi1Oqas371CoVkslDEjBkApbMoyAxOhB9FuJyHV zfRxmc0Z9gmNSXU8mEafsD7OCIHZ1ZKXLsBf9JYdybCT8eKt8/qRU5C5953UD9yNsg FqVwhIyJRtZWQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:29 +0100 Subject: [PATCH v10 02/40] prctl: arch-agnostic prctl for shadow stack MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-2-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=4893; i=broonie@kernel.org; h=from:subject:message-id; bh=OvR6N9yV4HsQXOrwTY0B56Y1UKQlPL/MpYNNiWGIOU8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YHrCxoJewftWxnfq1JlcPpYr/nO77UmMRV/g7S YVEk79WJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGBwAKCRAk1otyXVSH0KqxB/ 9V8lZDkQrrXcsvux9tk7R1eV9YCB9mCgv2Q4nH5xihY0ZzyoSsqiELgMjgt47Ir53+f8lbqNS7cyQB I+xudEB6RcvJF4uBteFTILgVTSp/QZWdfdvlP606m3rXGb2OVV+BTqc8JQTM+aM94uU1xP7QifRd22 iwljaiX/twQduRHonpm2IcsNgOEZIgG9EvS6b2pzPcyQnVma8Y37pKLarPPisLyolug0EvX2jH+Ca2 ZDHi1MtqM5/1pZvEEa17v+w7O01Tzz715NDODwbsM8fWGWjQ+/EYSNM/1DPYHUh3u3Ce8smfZ0m09p 2Grb0JOhTkKuKIk+M6U9e6lTwbhgzk X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 4332A160025 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: emfidxg3gdoajn35yhuit1xum9eeht4b X-HE-Tag: 1722517054-736562 X-HE-Meta: U2FsdGVkX1+ApfpuV+MqV5VeNYkd6V67stcraWsJ1AEzYd561SoYEYeVS8zUOAD4q24I5s59dRnBn5prHp2Fj/AmUmU26HrwhT/vyBtUZ05iHpRjVdur53GMf6IgFTo6V+3+RfShdaFdYPTfDRgIax89AmiCYV/oth4BSLbKmW2MYif95NoJqXdR3+UxKiFjsTdN2hiwR7kX+OjFs+7UXGnDnA5EF+D8ezlEW7Nl3uixrE32bE/k04udXz1Zy/XsBLqKmeQzZqwW6gFNYGddRYwzHtE+3DjYppCrzeFRQWBNrSKo1q5g3/WVQ0hjocPplpYeb72n0VHdfJsWdAybtDQNvawSzZkjH2bH0aEzPtBC0O/1BzYtsTXByZjws3FB6AeYmIGvJHXjw8az88NQfIWjdY668xMkcQ2xwfu7zTAnqwx1vCT1lfwJI1XKRL3bqFp9+yzq25KIBeYzTxr00lCbfrUbY42IXYEmypmicrBJ7QyBN72e5sVm/QlNEV1Gbf5urwRCzDKiYOn6IgPCD5J66o3FPAI9WDshF5xTkhD6F4MF68splqoC4r/+7m9A/1Iw/cBQvwnQy7tc3Urt2Un0MND25Ey+6lClg1gdLENaUfds61btl/X8w5OBz1vq76AGGFg8Y3FPSlevgXwcDYFyxp4w+NaSdX5BrzFRcH1TNLK0V+nDei5sz4CJuEloQeqBbooioyIPnp6EPWiEdzS7oO7CkT9mhw7+VgwOh5xVFqoQd+kL8XupJ50y4uGR3Oxx8QTybMMeHnrkmqK8u0vTqshvg6OY8eUr3mT5EGBJBTzOtEY8xerI4RquPf+jN/6tgFGGllLE4F2IDV4lSuHXxreXjEtMI0EWmkrBG7cYdtO7OKiXfLc22HqTMMZiaHTTUhM1NJblEvx+bn0+JIXW6D5oyPobdBYmB6ogyLa3joCTXKChiV43KF6iKC7pKrKGWuKgwTuRPX8uexl NGhzrTbS 2tG+gJXjtdlpBT2HWLbWdy/oFuAfoby7b+8gz8/YYLZnjHC8UKGVd4JgEjlxvLCaClFvnlr7hJbJJPvR2WZMiVe+C8EcACijii/l25eO81KSMLtRedOzORLAM8pX3qZLGBSlXzJqW/jIZ+yj9ehA2Gz4Z8OAvL6OP70ZWNgT4aL5dXRzxQj3SMkJOMBu19iTMJ0Ghl0i79gVaNzxqHrL/VRtFeF4aSGOUfzQsCQXzHN2/7nBQnpjdLzksZ48vUq09gljELKmeUH1iG56Z25nAa9v6GMegvmCgNrYeLuERUspJ8k2Kr5zkdYtzYwjPeK3YOe/qHK3OC4vXBC3bdzULBx2yeAsML7PNT2Gn154/Hp7b7+cuKlS+6kBrRpOJfxMN74SR 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: Three architectures (x86, aarch64, riscv) have announced support for shadow stacks with fairly similar functionality. While x86 is using arch_prctl() to control the functionality neither arm64 nor riscv uses that interface so this patch adds arch-agnostic prctl() support to get and set status of shadow stacks and lock the current configuation to prevent further changes, with support for turning on and off individual subfeatures so applications can limit their exposure to features that they do not need. The features are: - PR_SHADOW_STACK_ENABLE: Tracking and enforcement of shadow stacks, including allocation of a shadow stack if one is not already allocated. - PR_SHADOW_STACK_WRITE: Writes to specific addresses in the shadow stack. - PR_SHADOW_STACK_PUSH: Push additional values onto the shadow stack. These features are expected to be inherited by new threads and cleared on exec(), unknown features should be rejected for enable but accepted for locking (in order to allow for future proofing). This is based on a patch originally written by Deepak Gupta but modified fairly heavily, support for indirect landing pads is removed, additional modes added and the locking interface reworked. The set status prctl() is also reworked to just set flags, if setting/reading the shadow stack pointer is required this could be a separate prctl. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- include/linux/mm.h | 4 ++++ include/uapi/linux/prctl.h | 22 ++++++++++++++++++++++ kernel/sys.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3357625c1db3..96faf26b6083 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4201,4 +4201,8 @@ void vma_pgtable_walk_end(struct vm_area_struct *vma); int reserve_mem_find_by_name(const char *name, phys_addr_t *start, phys_addr_t *size); +int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *status); +int arch_set_shadow_stack_status(struct task_struct *t, unsigned long status); +int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status); + #endif /* _LINUX_MM_H */ diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index 35791791a879..557a3d2ac1d4 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -328,4 +328,26 @@ struct prctl_mm_map { # define PR_PPC_DEXCR_CTRL_CLEAR_ONEXEC 0x10 /* Clear the aspect on exec */ # define PR_PPC_DEXCR_CTRL_MASK 0x1f +/* + * Get the current shadow stack configuration for the current thread, + * this will be the value configured via PR_SET_SHADOW_STACK_STATUS. + */ +#define PR_GET_SHADOW_STACK_STATUS 74 + +/* + * Set the current shadow stack configuration. Enabling the shadow + * stack will cause a shadow stack to be allocated for the thread. + */ +#define PR_SET_SHADOW_STACK_STATUS 75 +# define PR_SHADOW_STACK_ENABLE (1UL << 0) +# define PR_SHADOW_STACK_WRITE (1UL << 1) +# define PR_SHADOW_STACK_PUSH (1UL << 2) + +/* + * Prevent further changes to the specified shadow stack + * configuration. All bits may be locked via this call, including + * undefined bits. + */ +#define PR_LOCK_SHADOW_STACK_STATUS 76 + #endif /* _LINUX_PRCTL_H */ diff --git a/kernel/sys.c b/kernel/sys.c index 3a2df1bd9f64..7e0c10e867cf 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2324,6 +2324,21 @@ int __weak arch_prctl_spec_ctrl_set(struct task_struct *t, unsigned long which, return -EINVAL; } +int __weak arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *status) +{ + return -EINVAL; +} + +int __weak arch_set_shadow_stack_status(struct task_struct *t, unsigned long status) +{ + return -EINVAL; +} + +int __weak arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status) +{ + return -EINVAL; +} + #define PR_IO_FLUSHER (PF_MEMALLOC_NOIO | PF_LOCAL_THROTTLE) #ifdef CONFIG_ANON_VMA_NAME @@ -2782,6 +2797,21 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, case PR_RISCV_SET_ICACHE_FLUSH_CTX: error = RISCV_SET_ICACHE_FLUSH_CTX(arg2, arg3); break; + case PR_GET_SHADOW_STACK_STATUS: + if (arg3 || arg4 || arg5) + return -EINVAL; + error = arch_get_shadow_stack_status(me, (unsigned long __user *) arg2); + break; + case PR_SET_SHADOW_STACK_STATUS: + if (arg3 || arg4 || arg5) + return -EINVAL; + error = arch_set_shadow_stack_status(me, arg2); + break; + case PR_LOCK_SHADOW_STACK_STATUS: + if (arg3 || arg4 || arg5) + return -EINVAL; + error = arch_lock_shadow_stack_status(me, arg2); + break; default: error = -EINVAL; break; From patchwork Thu Aug 1 12:06:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750382 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 8A17AC3DA4A for ; Thu, 1 Aug 2024 12:57:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 066C96B0082; Thu, 1 Aug 2024 08:57:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0175C6B009C; Thu, 1 Aug 2024 08:57:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6F206B009D; Thu, 1 Aug 2024 08:57:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CA0D16B009B for ; Thu, 1 Aug 2024 08:57:44 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5C77B160D4D for ; Thu, 1 Aug 2024 12:57:43 +0000 (UTC) X-FDA: 82403678406.11.0BC6942 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 7B8F8160012 for ; Thu, 1 Aug 2024 12:57:41 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=k9EWh0gX; spf=pass (imf08.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=1722517005; 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=70cjjLOtabb/rzl2w02OHZeRiB/3csN9WFGlBeL2SM8=; b=lvV5lrUkxQr5NDsXlYEEif+h0CKqzOGOhy1qtgmZAuKH+sG0vbz8DcVs+rgRWsPp6UWsLM wcQ8XCiihxZpMfm6hztSJVZvY7KHOIERy+RZ7QmMF1F9Lzp82ZHc3Vp0h/E8xRL4XI/IeL 6TjDnx+OPV7oUzL+NBYa7fhOX7yNErI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517005; a=rsa-sha256; cv=none; b=RM5ITnVQXkROPg72rFxkakSZuYZw5+dvLaoxORAQm27cQhgSchXU2vgPgbKLLRm0bbUXk5 27V/E3CCluqAbzdwvxXMzRbby8LTtdna/P6Cx9pqit7gdJQV6Ztc10gUGF/xDX3ile+AW7 ZeVZ8h71piV46eHnsxdvWLhGGUxv1QI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=k9EWh0gX; spf=pass (imf08.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AB80E62767; Thu, 1 Aug 2024 12:57:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EC12C32786; Thu, 1 Aug 2024 12:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517060; bh=2jWl08+8re+Jbyu9WlYwMAOos2oJrw5SQjRGnUXuA4U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=k9EWh0gXg6rjx7kV1lB1Gmt38FbXgl6/I7ewuvHjZKZKsi0Ra/eNEDb4+nkaWeebY 5fo+KHzl2gVZT5y4QEi94AFCr3yy8q0Y3qfsKo4MUU8ZvEpLuaXTE+gJP1/QJAFy6b ZFESzXLHeTvuf0gbP+smJF5PdWb79uTbdLNbHoM7qIVEW52ay89XQq3Sh1JchzEOGn vJeZOlSSSY5GbPB2qtoVLFB9VX16JELscHgpRYVwyYdxXfoIRQv+2ArLna84PZ0pA/ DxpPvqcJ3zRpN1CX47iKOu5nvE+8eTswjAlK6Uc34hqiDr+Esbw3xgOrUR21qH2t9A 3O+OwqSvPl7qg== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:30 +0100 Subject: [PATCH v10 03/40] mman: Add map_shadow_stack() flags MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-3-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=1825; i=broonie@kernel.org; h=from:subject:message-id; bh=2jWl08+8re+Jbyu9WlYwMAOos2oJrw5SQjRGnUXuA4U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YID0+m+ZzdQpJGH0gtPDP+bAsXULUCyyq8/y2t MduEdEmJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGCAAKCRAk1otyXVSH0Ot1B/ 4jaebyV1tIrvOIYxQh5wDbypCmbpdfYnw84eR5kyJZqQIRjZ+dK0lQJngqeHe4n89q7hMI4OUDMfSr Otel0Z609ebmO09EfOX6sKZzZ2/uru4+YnSoeGjvRZZsYsr1B+7FWG3o5mVY91e4Sdd+6ukU+qHmzS axuQgqxevf/x3L67X0UZGMdmC5B8jQ2x6Gu99RAzuYELIUE2nPQ1wCneKnvlyC+FPrLbjWdkIDKVN8 wmGHe42BNZh62DU3scRZYxWf6RdwGbFcR9PlKRfpI7Ocuez5/KqBYFTD1YXpI3HGD35BhAYcpFTswG yKHazykP6dg1NzH0pTMC7LYphwlbfE X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 7B8F8160012 X-Stat-Signature: 59a6g3s1j86forenk1fbt68t66ax7dh5 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722517061-309785 X-HE-Meta: U2FsdGVkX1//D/T2NDQqaojthssB8hK5n3c81SnEKArwh2RpYiJtF0PBHnuIIpZH90CroVPJZqTY1DWnT9p/YKO9wApI+vFwNiol5shYpWFlyg36k+oPhTi3xKJLoURY3jtKmZX8IBEc9Qd2y93bhDAKkd5UdobyQsj9Da3+YCmH72j+dFm0zV9nLJXMy5Qa/G6lf2ThIAF4scGMiPehCq365iP9zz0I5u55Er969mhdVnyHyjHpSAS63VBQzrdlOBNrIe96PF+mTezdZcDfSxudKUztGM2gVQu2gBfbc7ATOEt/YKTHOI3+g1XHc+RAHol9bK/FiGXif7OceplcjywbarNjqqRCjSFB5hS6w8cEqVqkH4qN+dTJI/VmTeu6763/u3BdwFI8S9P1vcGmSL1ewaQoeQGvNc7+gsoTv/AzjV1fWCt/PD0hReCylKIgwW/AY/S7KmPfMT/gzQZjeWOaPQn/X1Yd5tMOCdFARqFmttLgsNhmtHKf8xo933aX1BGfyOAlC51ZHE0lCtW40jOefCqBcJUMum2ewteZeu8yH3QvRYMOIn/Pa6HunpRY+gEhqfpDytbm1zG68ia13qXz3//4hvp4CTSvANh77QYTnllYler7ubR5xAqvB1xcT5O7QeKC7/EcbSdA7qLSBjp3DioilvX7VOEHkEedX8jUVSqY6A9caMdfWTISza4LlbcLs+XDMrCu2Py8C2O97ym0eLhFvYplZO7ESa2F2FiUp8swMqhglt6h0/Nx6q+UWLWUlyuFhRcoFhhL3TZjfCZlxW4gFBAxwMcHwYzc4oPNOu2bRgvL5q+IMoTldyncFRHEM5qvag6ake3Psvx/yInmYPQw5kSB5c9kTpovSUsxxrjPWmvByx5z48QDlTHTSqlJOvx4hbFiyELQP6m2ld7zprS0bpNflj4A385h/oHw3Wj1NELKfUpIiywxZ/pjFlReY9QRN4vmIkvbKUQ 85ua9AVZ b56ewxhm52xu584E+yxso40njRH9puhBojZcqsNL3cEJJVxqLZYDHkMSKWdAtrH8+dqwmZa/niWeTwLP1tTkstS82Xq+zxvP6kv+glMjEKN9c3qoKx1fWG+Cb7vxu0Wv6xthMyRnFAEUilsqMrPEQ8FahXZHpHK0TKeFM08lcu1EMUgVWfAA5oFu2ZJuY3bvqpbLXDmICWxdx+A56p226XNhlxwc0X7ikepxXLL/qY3tdJgcohhA04ZWOMVS2qRRQQhrl/gIBf62CVVMFHhhV0PQuYOfXcKA5wBBUlabKfyWcL3mZXhttrCXwpWq0iliiXMvUqpSjdYt0wKlY3jpXaNJf2aqvpzuvgPksLRjlhRV/OSz3r5Cw9OpecpwDXlnEiTnedTUizwe3q1u2kB3sClWCTtfmW4YPJJkj0QRaVaCsxM8= 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: In preparation for adding arm64 GCS support make the map_shadow_stack() SHADOW_STACK_SET_TOKEN flag generic and add _SET_MARKER. The existing flag indicats that a token usable for stack switch should be added to the top of the newly mapped GCS region while the new flag indicates that a top of stack marker suitable for use by unwinders should be added above that. For arm64 the top of stack marker is all bits 0. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/x86/include/uapi/asm/mman.h | 3 --- include/uapi/asm-generic/mman.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/uapi/asm/mman.h b/arch/x86/include/uapi/asm/mman.h index 46cdc941f958..ac1e6277212b 100644 --- a/arch/x86/include/uapi/asm/mman.h +++ b/arch/x86/include/uapi/asm/mman.h @@ -5,9 +5,6 @@ #define MAP_32BIT 0x40 /* only give out 32bit addresses */ #define MAP_ABOVE4G 0x80 /* only map above 4GB */ -/* Flags for map_shadow_stack(2) */ -#define SHADOW_STACK_SET_TOKEN (1ULL << 0) /* Set up a restore token in the shadow stack */ - #include #endif /* _ASM_X86_MMAN_H */ diff --git a/include/uapi/asm-generic/mman.h b/include/uapi/asm-generic/mman.h index 57e8195d0b53..d6a282687af5 100644 --- a/include/uapi/asm-generic/mman.h +++ b/include/uapi/asm-generic/mman.h @@ -19,4 +19,8 @@ #define MCL_FUTURE 2 /* lock all future mappings */ #define MCL_ONFAULT 4 /* lock all pages that are faulted in */ +#define SHADOW_STACK_SET_TOKEN (1ULL << 0) /* Set up a restore token in the shadow stack */ +#define SHADOW_STACK_SET_MARKER (1ULL << 1) /* Set up a top of stack merker in the shadow stack */ + + #endif /* __ASM_GENERIC_MMAN_H */ From patchwork Thu Aug 1 12:06:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750383 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 72621C52D54 for ; Thu, 1 Aug 2024 12:57:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 129F46B009D; Thu, 1 Aug 2024 08:57:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DB2A6B009E; Thu, 1 Aug 2024 08:57:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0BF46B009F; Thu, 1 Aug 2024 08:57:53 -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 D51DC6B009D for ; Thu, 1 Aug 2024 08:57:53 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9AE901C40BD for ; Thu, 1 Aug 2024 12:57:53 +0000 (UTC) X-FDA: 82403678826.17.BD9D6F5 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf24.hostedemail.com (Postfix) with ESMTP id 3711B180002 for ; Thu, 1 Aug 2024 12:57:50 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="nM/gS+qr"; spf=pass (imf24.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517014; 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=s1Apl5Jc/qwWGxy5IzIzCZxQzUVieWPUV/FiOQ2ejdU=; b=iVsZQzpFpYBNIz2Edo5Fy0rm3pRvJVh1CFzrLf7378jaKZkKJ8mHRQ13mmZ3N3a9huKqBA eKf1IqGvYMQOAnNJaC1N6UOZINe3CzeTOmDuTzUnRgLH291y+HnYLUA5KJRqjDNcszIyT3 kNk7zIeBtYxVfn9BOLAxbWpTYgqSJiY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517014; a=rsa-sha256; cv=none; b=Uj54/c6Vy7Sg+B01H2EgYvvxyiQyh4AlP62WDYteuqgn6OjB9uOdMiMdaUyAnidJTyQcVt cN4VHvEt0NL52+PtiGvAlIyx8AzCJ6mm3qvKnIArKvauDMf/p8iEQ6raBt6w9YxV/N/B8J 7MhMyo+NGBKpU/dn+EQd3RTaYLA7Jeg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="nM/gS+qr"; spf=pass (imf24.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4BDFECE19B6; Thu, 1 Aug 2024 12:57:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB533C4AF09; Thu, 1 Aug 2024 12:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517067; bh=3RZmbStJwVSGoP/qDNBFqPg5B/6FQNSgda/JKhBv7x0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nM/gS+qrFmEXsCA6RF2Xqdp3hb1CAKq9WGlHmbcwRTXnqJw63mJKa4Kb0O2iVyBX2 g+uUNVNRjO5ozwRIafO9FQN/TC2c9YJ54Kgb20htooXIcwdQdv0/WQvAb0B6YZiqwN V6Efuiql/CuGLVlN6wj5nbtZXYGIkaf7IyVu8aI2utkfhPBKvajQTPqGg1P5vk0rze 7MtTS4W1GnMoYc32N3Xl9mhD+/J57V+Rw0T3h5K0wrwT6eDPfmMWS/Bp6EviouyVku iYaaz+B9BVSeAENv0L1FLziwTmgtD7qWVp75kIlknntKSABmRyBsTOhcAkjitVxC2d oX1/sMdKfEtZQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:31 +0100 Subject: [PATCH v10 04/40] arm64: Document boot requirements for Guarded Control Stacks MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-4-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=1946; i=broonie@kernel.org; h=from:subject:message-id; bh=3RZmbStJwVSGoP/qDNBFqPg5B/6FQNSgda/JKhBv7x0=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YJBO3yLLrkfe904+TZtJB1T9HeB08OFT8n6HhY M3NNmXKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGCQAKCRAk1otyXVSH0B+qB/ 43pou9Y4TC/1pa0XTbag+sHQNoVFkuUIA8FSfx1e87YJGvqHTeNRK4JKwnIPZS8ZFD//FeU6sWUSfW yxOSuNd5EuCHGVVWwisTo696Z3sw6XMWW7d8fhRPIuFFtqtA6kpgUUm5VnWhlwsUMJLlyEvhPCLH9M W1uyrDqwl2iSR5m0UsF7EGNk5xhw5KPc8sOnTXdUsLVKW+omEqyEmUym6r/iwkWJKgT/pfEyZjPiOb 09Gkvy+2Bqy0iqZTzyLHdRiLMdV98L/zhHvVf6T0+hXGkl8wPotyUaXqIQUnOZ/tgnOUYdr26cwP2w XhAdMoByrIqOboCZuztVTcCPMQnZS1 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 4ns75d9qwsjt5hcj4eg3e5cqk6ctjc4c X-Rspamd-Queue-Id: 3711B180002 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517070-144604 X-HE-Meta: U2FsdGVkX1+yar5akzlheRLBHgo6sfyVImADV8RtpNOhIfd2U9qbvALsSl4656C2xfGb83cEXEBpOTuMs7V64iDoEXgUwArECy14nUI2fxg3XlCeJclocW7BVa0KdYxoNgsvgdWA4b7AW9u8FOsB8MHlOKjkCePFa3VJF++Lu2t/6/od2D9Ej8PzaFk2DI97ldWFS2WYdpiNZWoNvgTuUFY2VYqXDBwNGOZv5c0OJH9u+HO68ODQw7BzAxwqlKUnTrtzR7eh9KIS8JGqz2wGAp4l4Tpt9MRIRo1M6ML5u9TItTceh1dty4KUU0AN5fDyj2FWWrUivNevOmnHlG6lyDF/JIo53TW56leSR3EMzvhqgyrCydCPYssJg4Q41YisLvAWZc1WnzFE3C3AtI84Mmqzw7HsUEPm3ApxeSrmnlGFBYApTJj42Cgg5gR+ZrE/wf5x6JuH6/9TlFHt4nTyaBBsBrxmBlaM/U8Ov95U9yzeIlzT3R0rDmMNZlTg9Z4i2HzJCyC/iJfIw9fnZPeSc75Hx3gkZ5KeRbmI40NXHEKDSiAEGerhrmsv1iU0a2yvCO9B7F29VTwvPwquxVkRuEhU5/m1dXQeMnoujmCtWutTtPuSRN8B8Zp9JIri/7CyHv96u9VHQqI3JwImznxC+434yHsQ/VvER4684azssg23tRlhm50Fr8Pxl6SQdpeIh5/aTPP5R6SI0Ei8hJNOL1d7SV4dPMW9bG23V5kQ/8YxmdirCgzQr3DFRxbZDQk8RzgWvHy4j/zSo8XgugH53XIajaTA+Rknny6t2K3S87GuV7PSAyAr7lfmmvRLTG3k/p4zRxQL7KL/3/CBG1dXl9Hw3e/EyiRIMwhCGSpY8GewlUgjY1go3RUyy8CUX5XyT/tIaudINgTS89T1Efqz3KCM7nZSamZQRH48BFDc0GtKJgvUPtt+ZSrgOWRi8HeO0P0TAGhvPfwgKczcD/H R1xKlkHk HYW03ZRJMYs3EIVLYnprJoV4KDsJUOqmKsQ1zPh4ie5z1axuweauvcTcBUbgnD6rYp8pna/U9v3NMyJj3Ztg4IsMKc7sH6T1STy+w327Y0Wzm1BqXxjBwk8ymvnv1VTVbQg7p1j1qufoWm6RaORDSlaMiYAteHW9bVewn+CCVxGN7vFZsxoLS1r2tHptrIAa574BwQ0ITm2bgqdbd0AsOka8IPbTtcORqw/v3BzTKVDQJZEOVMK3M6klo9lJQxoTv+L+UFyupRXW3VqE+ZyvOGP1kWL6yAoO49C1C/6XC8no6dM3ERtueRdFpZGMS1JIlx1li 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: FEAT_GCS introduces a number of new system registers, we require that access to these registers is not trapped when we identify that the feature is detected. Since if GCS is enabled any function call instruction will be checked we also require that the feature be specifically disabled. Signed-off-by: Mark Brown --- Documentation/arch/arm64/booting.rst | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Documentation/arch/arm64/booting.rst b/Documentation/arch/arm64/booting.rst index b57776a68f15..f5b8e4bb9653 100644 --- a/Documentation/arch/arm64/booting.rst +++ b/Documentation/arch/arm64/booting.rst @@ -411,6 +411,36 @@ Before jumping into the kernel, the following conditions must be met: - HFGRWR_EL2.nPIRE0_EL1 (bit 57) must be initialised to 0b1. + - For CPUs with Guarded Control Stacks (FEAT_GCS): + + - If EL3 is present: + + - SCR_EL3.GCSEn (bit 39) must be initialised to 0b1. + + - If EL2 is present: + + - GCSCR_EL2 must be initialised to 0. + + - If the kernel is entered at EL1 and EL2 is present: + + - GCSCR_EL1 must be initialised to 0. + + - GCSCRE0_EL1 must be initialised to 0. + + - HFGITR_EL2.nGCSEPP (bit 59) must be initialised to 0b1. + + - HFGITR_EL2.nGCSSTR_EL1 (bit 58) must be initialised to 0b1. + + - HFGITR_EL2.nGCSPUSHM_EL1 (bit 57) must be initialised to 0b1. + + - HFGRTR_EL2.nGCS_EL1 (bit 53) must be initialised to 0b1. + + - HFGRTR_EL2.nGCS_EL0 (bit 52) must be initialised to 0b1. + + - HFGWTR_EL2.nGCS_EL1 (bit 53) must be initialised to 0b1. + + - HFGWTR_EL2.nGCS_EL0 (bit 52) must be initialised to 0b1. + The requirements described above for CPU mode, caches, MMUs, architected timers, coherency and system registers apply to all CPUs. All CPUs must enter the kernel in the same exception level. Where the values documented From patchwork Thu Aug 1 12:06:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750384 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 E70ABC52D54 for ; Thu, 1 Aug 2024 12:58:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 808356B009F; Thu, 1 Aug 2024 08:58:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B81B6B00A0; Thu, 1 Aug 2024 08:58:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67FEA6B00A1; Thu, 1 Aug 2024 08:58:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4A2516B009F for ; Thu, 1 Aug 2024 08:58:01 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EA55F120D98 for ; Thu, 1 Aug 2024 12:58:00 +0000 (UTC) X-FDA: 82403679120.30.063FEA4 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf13.hostedemail.com (Postfix) with ESMTP id 669ED20026 for ; Thu, 1 Aug 2024 12:57:58 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HJU0E+Fy; spf=pass (imf13.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517021; 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=+YMOH7SGjV5r/wRfXrKGxXbTlZDaSXg1HFoXUP1VHVM=; b=QKgm4OTrFuQKhRb94Ctvz7Ux43gpcTY8q4IJT6Tl/07N6XID+A6n/AG5ijHNAXVUC/gK+G t/edXpCU9GIJ6PFuMJcCwvarPR/vkUmHYY51XEaMKZBdKPc1/8BrY1Euj36lDSVRVw60XC d2WThO8pSbU9Qj41+lwOoXPfBDKZR2Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517021; a=rsa-sha256; cv=none; b=3r5bKU9y73ihZciCymSLCc+pKpt4V6mOCtPTbCzz9eiKKv/uthbAptQEqfzfaAQCubM7G5 GZURWU9Fyma7Oi1DWsAtUoRI9hqvo2mkivSwQpmuQgKwbDKrBu4nfilIbjDjmXSIIEcv6X dqBcP6CJgP5ffeErKXLkV9AxskMgnu8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HJU0E+Fy; spf=pass (imf13.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id F1CE6CE1979; Thu, 1 Aug 2024 12:57:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B369FC32786; Thu, 1 Aug 2024 12:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517074; bh=K9krRCbvH7YvJ22hr22iaSqAjeeG9fR/Lj3PkK3c1RE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HJU0E+Fy3pXzTTy/qw3hdomWGawEwi8taNnbgznBdhntqwPPfFVDoRJPQUdE5L5w6 6rp8LTz+DvpHNwUXYEFmCZhI1/AAAmfwnON5k1JuCDjEYnYydCfr5jRJvaxU/Qp/PC y1fJw1NwaD6MAyH9PU/FvQsZydAgHBxJNKA6cT2vQaPdWhqPBq4eMhMEkr6y3JLiue DixNGa6IpRXKgVjPG6SCV0jH+7kHquTUrmVpq1sLnvQCYDM6gn7LuDMldXGV8eL8zi kHHLuwuX/qmA+Y6TnqxubKoMFGRNe6ruICvKpikYiWbFiumhl5HNpY2z++/+3Ww3H0 w2p0qYnetQM1g== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:32 +0100 Subject: [PATCH v10 05/40] arm64/gcs: Document the ABI for Guarded Control Stacks MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-5-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=10734; i=broonie@kernel.org; h=from:subject:message-id; bh=K9krRCbvH7YvJ22hr22iaSqAjeeG9fR/Lj3PkK3c1RE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YJIJCwq2KZzv1i43es/92rtkSE5gmxwvGQaEBc 1Qw1DUiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGCQAKCRAk1otyXVSH0OjUB/ 9Z1M0U1ZyhlJl66bkUoB6231eLd2ontVjWDgT0JIyoYVU6XDFvP82UeNOQ5isHQVRYLNpsg6qY6Ytl TbvUDsi+P685/PuynFYnVjeUDUZcqcEDh0iWXa+hvwS04BPOQuDhpZHWYRS2IunfHvJtVxwusBxNb2 4dOwnsOHFR6m+NLKaVXk9oNthVl1XSnS+P4uZBBQGuzBcIR11LUWJ7HUfy/mxp61OExsaB3dEqYDEh MtezfOI6bnUQBrpWVfsumC64SkMXnuh8XPg/QJVlSa2Mydes/ECYQtRETBRAQ7C/LhkW3FxnjOdU2l DUTH7zyQAPb+27WOzdR/PPc1CwDEd7 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: byompkiipkjr3d644giqnguj89944k7f X-Rspamd-Queue-Id: 669ED20026 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517077-781411 X-HE-Meta: U2FsdGVkX19c6W/WMohx7ow3xiRVjQsFIWa3ZnsR5XzF2RZTSW8QJEOX4os+95S7v1uayLxhw8xjkQkOm2+Z5m6vpGkHIpK/Bn3cqmL3B6eXPxsM0n6SRPkgdNwuTKFZ7/uQO68/8OtVRQAmjopqjkcZ4omO+KKAoHu963kdpP3xYuJgRI4BBYEGi1+vFNCMGgBjWEAJHEW5xcVl45xASTlBj3tHzInHFi51vyhQ5TuAyziAYSOU+bz52vj+Sw9Wz7I9Qh9hkRSyvuFbPZj2S3rNeuunevdJKbhONXVplu+dNdaihZx+2DYBJj3ladpUAQoEFUuD2ora43bfWmo24/J9p2tiDaJDQGUCUDXM5yZFOwD2Nbirz1Q9QFtyQgEhiHrzZDzv86bP7a7RZXotajSqeC6+qPeuSFGRksLTzRM/h4mb8oSSINE3IwmBrIAFnMp5JMP5gzxh931PWJ3rY5/d67Sm80TowACKWhzFDSbuM3Y/kNIrSuz6t911wTwkBPtbYNv+Jdpq7RSj7tdePElbGm80S8JicnI5BR7yePM99zIMIbR/8ybRQS8FJarYe8pOu9Y+bn7qOQ/KbZAnRSGwKvSxhCWGK94iJRqbLy/rC/4MxeLZMUgm4MKievwBKBS1s5xFHb7cTBt2nbbRie/aJ3SenOzxxytXPuJXpHzYxyvmx5gdAfdebFwKyoiIhobIVYHcHL/DAWG0s5CaBdpR0Km/WLNWW09+8eWRJY5+judz6XgLFR7O3FLjfDqM4YMoiPPIEPPgfLmfszpcCqRDO7b84D5n8pcIllwdPMu/u00gPhpaAbVC5ZTXKyLRV+hmXUwVWz8m8N5BLejYs9ZylJYcLKBZBf0uFi56tGbHPHbqDiicsg+IhprEYug2zdVO8npp9gUL51/gUuNHMgQCn6+HQ+BY1LW9J9IPpFDi0Wo5qbbaV0s+pxdYjKnvvVyCsJOto9H2OozAh3+ TKu8ohYc cMICkH52kxpmk8ynRcZcBpUJ0qf26QwSW7z+nQcwmon6haYVw402xpWLaRkeBPq9c4TbdvzgHXtsYQhNv65vvhK+WlBTgW+ZAn6sE8UG9h7mX8ZzDdBV075t/3WeNxDGktqNNgzfXJoeeCCBZIXK6PHgNRCks0Xr2afnAvcVtdk/p23TiwPeJfLQE6KT2QJcY3MJVZ5pjGkiSU7PUER80NduZuzWsYDVy7X/J41ZqKr6miwJk5J5MX+FEc/T5BF2WR6ibYMHSKA8INCPBDRbHh6+4t+2DVw4zglWGtpy6E8zjKy1Qa5SxZIrP1CiHjPUUYitJzHJqynlEOTRnodLptsH0VBb1aVsdPXmtFKr1r+I1qydJYYmCVau/AJsZeQqjDoJ1 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: Add some documentation of the userspace ABI for Guarded Control Stacks. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- Documentation/arch/arm64/gcs.rst | 233 +++++++++++++++++++++++++++++++++++++ Documentation/arch/arm64/index.rst | 1 + 2 files changed, 234 insertions(+) diff --git a/Documentation/arch/arm64/gcs.rst b/Documentation/arch/arm64/gcs.rst new file mode 100644 index 000000000000..8b16394b4c29 --- /dev/null +++ b/Documentation/arch/arm64/gcs.rst @@ -0,0 +1,233 @@ +=============================================== +Guarded Control Stack support for AArch64 Linux +=============================================== + +This document outlines briefly the interface provided to userspace by Linux in +order to support use of the ARM Guarded Control Stack (GCS) feature. + +This is an outline of the most important features and issues only and not +intended to be exhaustive. + + + +1. General +----------- + +* GCS is an architecture feature intended to provide greater protection + against return oriented programming (ROP) attacks and to simplify the + implementation of features that need to collect stack traces such as + profiling. + +* When GCS is enabled a separate guarded control stack is maintained by the + PE which is writeable only through specific GCS operations. This + stores the call stack only, when a procedure call instruction is + performed the current PC is pushed onto the GCS and on RET the + address in the LR is verified against that on the top of the GCS. + +* When active the current GCS pointer is stored in the system register + GCSPR_EL0. This is readable by userspace but can only be updated + via specific GCS instructions. + +* The architecture provides instructions for switching between guarded + control stacks with checks to ensure that the new stack is a valid + target for switching. + +* The functionality of GCS is similar to that provided by the x86 Shadow + Stack feature, due to sharing of userspace interfaces the ABI refers to + shadow stacks rather than GCS. + +* Support for GCS is reported to userspace via HWCAP2_GCS in the aux vector + AT_HWCAP2 entry. + +* GCS is enabled per thread. While there is support for disabling GCS + at runtime this should be done with great care. + +* GCS memory access faults are reported as normal memory access faults. + +* GCS specific errors (those reported with EC 0x2d) will be reported as + SIGSEGV with a si_code of SEGV_CPERR (control protection error). + +* GCS is supported only for AArch64. + +* On systems where GCS is supported GCSPR_EL0 is always readable by EL0 + regardless of the GCS configuration for the thread. + +* The architecture supports enabling GCS without verifying that return values + in LR match those in the GCS, the LR will be ignored. This is not supported + by Linux. + +* EL0 GCS entries with bit 63 set are reserved for use, one such use is defined + below for signals and should be ignored when parsing the stack if not + understood. + + +2. Enabling and disabling Guarded Control Stacks +------------------------------------------------- + +* GCS is enabled and disabled for a thread via the PR_SET_SHADOW_STACK_STATUS + prctl(), this takes a single flags argument specifying which GCS features + should be used. + +* When set PR_SHADOW_STACK_ENABLE flag allocates a Guarded Control Stack + and enables GCS for the thread, enabling the functionality controlled by + GCSCRE0_EL1.{nTR, RVCHKEN, PCRSEL}. + +* When set the PR_SHADOW_STACK_PUSH flag enables the functionality controlled + by GCSCRE0_EL1.PUSHMEn, allowing explicit GCS pushes. + +* When set the PR_SHADOW_STACK_WRITE flag enables the functionality controlled + by GCSCRE0_EL1.STREn, allowing explicit stores to the Guarded Control Stack. + +* Any unknown flags will cause PR_SET_SHADOW_STACK_STATUS to return -EINVAL. + +* PR_LOCK_SHADOW_STACK_STATUS is passed a bitmask of features with the same + values as used for PR_SET_SHADOW_STACK_STATUS. Any future changes to the + status of the specified GCS mode bits will be rejected. + +* PR_LOCK_SHADOW_STACK_STATUS allows any bit to be locked, this allows + userspace to prevent changes to any future features. + +* There is no support for a process to remove a lock that has been set for + it. + +* PR_SET_SHADOW_STACK_STATUS and PR_LOCK_SHADOW_STACK_STATUS affect only the + thread that called them, any other running threads will be unaffected. + +* New threads inherit the GCS configuration of the thread that created them. + +* GCS is disabled on exec(). + +* The current GCS configuration for a thread may be read with the + PR_GET_SHADOW_STACK_STATUS prctl(), this returns the same flags that + are passed to PR_SET_SHADOW_STACK_STATUS. + +* If GCS is disabled for a thread after having previously been enabled then + the stack will remain allocated for the lifetime of the thread. At present + any attempt to reenable GCS for the thread will be rejected, this may be + revisited in future. + +* It should be noted that since enabling GCS will result in GCS becoming + active immediately it is not normally possible to return from the function + that invoked the prctl() that enabled GCS. It is expected that the normal + usage will be that GCS is enabled very early in execution of a program. + + + +3. Allocation of Guarded Control Stacks +---------------------------------------- + +* When GCS is enabled for a thread a new Guarded Control Stack will be + allocated for it of size RLIMIT_STACK or 2 gigabytes, whichever is + smaller. + +* When a new thread is created by a thread which has GCS enabled then a + new Guarded Control Stack will be allocated for the new thread with + half the size of the standard stack. + +* When a stack is allocated by enabling GCS or during thread creation then + the top 8 bytes of the stack will be initialised to 0 and GCSPR_EL0 will + be set to point to the address of this 0 value, this can be used to + detect the top of the stack. + +* Additional Guarded Control Stacks can be allocated using the + map_shadow_stack() system call. + +* Stacks allocated using map_shadow_stack() can optionally have an end of + stack marker and cap placed at the top of the stack. If the flag + SHADOW_STACK_SET_TOKEN is specified a cap will be placed on the stack, + if SHADOW_STACK_SET_MARKER is not specified the cap will be the top 8 + bytes of the stack and if it is specified then the cap will be the next + 8 bytes. While specifying just SHADOW_STACK_SET_MARKER by itself is + valid since the marker is all bits 0 it has no observable effect. + +* Stacks allocated using map_shadow_stack() must have a size which is a + multiple of 8 bytes larger than 8 bytes and must be 8 bytes aligned. + +* An address can be specified to map_shadow_stack(), if one is provided then + it must be aligned to a page boundary. + +* When a thread is freed the Guarded Control Stack initially allocated for + that thread will be freed. Note carefully that if the stack has been + switched this may not be the stack currently in use by the thread. + + +4. Signal handling +-------------------- + +* A new signal frame record gcs_context encodes the current GCS mode and + pointer for the interrupted context on signal delivery. This will always + be present on systems that support GCS. + +* The record contains a flag field which reports the current GCS configuration + for the interrupted context as PR_GET_SHADOW_STACK_STATUS would. + +* The signal handler is run with the same GCS configuration as the interrupted + context. + +* When GCS is enabled for the interrupted thread a signal handling specific + GCS cap token will be written to the GCS, this is an architectural GCS cap + token with bit 63 set and the token type (bits 0..11) all clear. The + GCSPR_EL0 reported in the signal frame will point to this cap token. + +* The signal handler will use the same GCS as the interrupted context. + +* When GCS is enabled on signal entry a frame with the address of the signal + return handler will be pushed onto the GCS, allowing return from the signal + handler via RET as normal. This will not be reported in the gcs_context in + the signal frame. + + +5. Signal return +----------------- + +When returning from a signal handler: + +* If there is a gcs_context record in the signal frame then the GCS flags + and GCSPR_EL0 will be restored from that context prior to further + validation. + +* If there is no gcs_context record in the signal frame then the GCS + configuration will be unchanged. + +* If GCS is enabled on return from a signal handler then GCSPR_EL0 must + point to a valid GCS signal cap record, this will be popped from the + GCS prior to signal return. + +* If the GCS configuration is locked when returning from a signal then any + attempt to change the GCS configuration will be treated as an error. This + is true even if GCS was not enabled prior to signal entry. + +* GCS may be disabled via signal return but any attempt to enable GCS via + signal return will be rejected. + + +6. ptrace extensions +--------------------- + +* A new regset NT_ARM_GCS is defined for use with PTRACE_GETREGSET and + PTRACE_SETREGSET. + +* Due to the complexity surrounding allocation and deallocation of stacks and + lack of practical application it is not possible to enable GCS via ptrace. + GCS may be disabled via the ptrace interface. + +* Other GCS modes may be configured via ptrace. + +* Configuration via ptrace ignores locking of GCS mode bits. + + +7. ELF coredump extensions +--------------------------- + +* NT_ARM_GCS notes will be added to each coredump for each thread of the + dumped process. The contents will be equivalent to the data that would + have been read if a PTRACE_GETREGSET of the corresponding type were + executed for each thread when the coredump was generated. + + + +8. /proc extensions +-------------------- + +* Guarded Control Stack pages will include "ss" in their VmFlags in + /proc//smaps. diff --git a/Documentation/arch/arm64/index.rst b/Documentation/arch/arm64/index.rst index 78544de0a8a9..056f6a739d25 100644 --- a/Documentation/arch/arm64/index.rst +++ b/Documentation/arch/arm64/index.rst @@ -15,6 +15,7 @@ ARM64 Architecture cpu-feature-registers cpu-hotplug elf_hwcaps + gcs hugetlbpage kdump legacy_instructions From patchwork Thu Aug 1 12:06:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750385 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 B8450C3DA64 for ; Thu, 1 Aug 2024 12:58:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FDDD6B00A0; Thu, 1 Aug 2024 08:58:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C17C6B00A1; Thu, 1 Aug 2024 08:58:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B0656B00A2; Thu, 1 Aug 2024 08:58:04 -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 0C8926B00A0 for ; Thu, 1 Aug 2024 08:58:04 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BC8E780D55 for ; Thu, 1 Aug 2024 12:58:03 +0000 (UTC) X-FDA: 82403679246.29.B131E25 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id E688D40006 for ; Thu, 1 Aug 2024 12:58:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Nmdd/qNO"; spf=pass (imf04.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=1722517026; 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=U9vHT9zxgnS0eUv37rwjV5gX2a+cK7BP1kcetq3hAiA=; b=jpFqcZv4QQkLBWk79brr4f+3/Yyj8XoYcQ1lOcbDjRcqZWn/9tYCIL5AeUE/XRn2NSZb9E M6bDPpC68z3iCGm/8wDXIrCmUXw/kwbnxGgNXhZS4wylgu+ZBjzJzAg6C8IybTMRFWAiu8 vCVLxjx8s76uCJOU+J2wSOhgpsYMWmM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517026; a=rsa-sha256; cv=none; b=acXIC37za45JOW8vYihqfIaxRRd3R4xUBYi16+1Rxh4VSql0OZZ9RrcAM7hYDrHfyRsD+l qeGaT9GPbkmdHkCzreStbxL18MLNFcd/OLUZeM9btMXro4aFrqy1bPCCitA0GsqR7kT6El INDmuk3vgYMwPnXDmUfCkaWOeY7pWCw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Nmdd/qNO"; spf=pass (imf04.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2D5416288A; Thu, 1 Aug 2024 12:58:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 805F3C4AF09; Thu, 1 Aug 2024 12:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517080; bh=mym7o+ur4BbRj2ASFXSNRXGOKmfB+ZB4m72hLojRIa4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Nmdd/qNOML0/WPSvFlhfPlPFhdWGDTeOehxKcqEpf3pUgk0DTgPcT6ho75GI2cH9s V9oFZAomCWM0OIH2upCKRhoVP+5d6N4VQz42KdMbbc4TAEQVeCDdkKwlswhdSkRwAr FUwVvQ9Z5lz/jE9sI8/DeuUqEy3W8GI6QftvN7ZtKtjB9jUws7JBoCyphjvomGDTE+ gFO4dEugK/8+qecErZI0sCkcKJEoS5uc/mfcjfIPkHNL3rO4K7sTrnouyFxgVR5CDL zLqVRlTkVNLsVVadLPewREgLENPUiZlzlh8MN1E1K1yocY/aH4Wimxuz2auCxdp3l1 Bpq4xZ+Uo4Upg== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:33 +0100 Subject: [PATCH v10 06/40] arm64/sysreg: Add definitions for architected GCS caps MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-6-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=1421; i=broonie@kernel.org; h=from:subject:message-id; bh=mym7o+ur4BbRj2ASFXSNRXGOKmfB+ZB4m72hLojRIa4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YKMuPchzO3os0nL3U57pumieXoSD2PfbwOG1FY wWpxjVmJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGCgAKCRAk1otyXVSH0JfMB/ 9S5qc+5UJ2Hq5Hh2gJZcqt5fs4hfsdHKXcwoKtpDSOxKNd+hIU23vQ23YrI62hlWogX++fZin4QYDT GOcCwT/cOUR3m/dL5FF4voHeOJTl2W7yFsUbSOey0f99FxqtjXHVe7w7DQvQrId6oU8t/lAsclZoHZ tQD9TJJJqolDvO5HE+DQ0fTh6WL5GECumUAW3lISgxymu//DrManuyXVjRouei1rgDvaJfd9mEbn8K hxDJrekIwc19/h44xJDi+e8sukKdHBCB2IAe8SSn7rqTq8apK5NDjamIvd72m5sbmWMbwAdHsJAqjc 1iMoQNDdS3yVBU5/TM8YlURU/7VMsc X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: E688D40006 X-Stat-Signature: kb564os9tec39aw8cro59eak6topsn5r X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722517081-993862 X-HE-Meta: U2FsdGVkX1/fvi4Zu3esGzlW+uXnNvn7Pdrp0E2qT0GYaOOP+AdzD6caug1VfSm3gqjXq3FM+Zo+4gg3yzRFwUQe15HXAU6I2LCZELKVJlMxsmrUepZ8rIFIbS/AbUK1OTiR3uJlzJmTCta2ZmTYZ0DyKHnCmwluOgeygCE5x1C++ULWUMHR+RHDBLDnZ+0PNgCa3WOppnMq6cLdxZNxSJ3YjAKHc+yb4CfwU96FPIkZqZD0OMWmNFIA5ckGpfvd+W5SRKCCN/b6dZ/kpFfej8K1ILmrAkahgyIfgWuYZS0Qt5vVTNPGyieBWIfsjNQu03RStRf3AywncJJMbK4ch7QBV/QenOnaqZmGq4SBf1RRrxosG/0UZ5eJkk+Aqkw4KGx65VBoAT0g5mgh36apukGtCbQljAL8PkjehX1V7NmNjoA7lT9POppMoewGt0TYLx9vx4LkY2cno/IK5FjDaGn9Uz/Sjnl2XlZHIM2T4uCilVItxsK3doEvI17I9s5ady3GqQp8P9Zr1ox3YzkAc4KBI+5acSh9VFzEIY1aqruFLrLtah33Fer0eTRRUlFES8tWbrqzDQ2Ev7L194jVmDC1aDwReZgBsc9TXJQQEFVl/kfyB4QOv1Q4TYuJCBsO3ML+8bDpzQAMOdwzP/b0Z6UwV0nAPzCHFs9hINg5d3JM7ltBTCyGrV04V5Sv3ZfrLopWVJhs8jqV1qNPrTsYZS2YFp2ixQVxGCD1Kt4GoOeHL10pgvsqgTMFIdJfzuH7+PGGDuDaTK9c/T8pDsvgjHDCifcWaAD6VB1OyedHGNOVEkrGav+HxLFibxftRYbRFExS/4yfaMKlruL1OdWpfsaZDsASzmX1mGsw6ae5GPKs960IA6IuFhJ1mXcMluc4ORgd3PYjE4dbXVZA+phjC3ugmXXbz6ioN20DULPuuWUXCcdkQq0KjY42M4GWxLG1YNYAvq7XOBpiajKu1Yi 8PfTiSq8 SOXgVsTcJccaqBxjFgw+uJ+5dGAsN6vxPF+MUmLraEF1+AuM0QEP9aHeMUsrv8gBw6YpoQpXeGfdpFF/effgKpzuUAFXRz0XeCXx7NWTBObraeU4uvvHv5eJs4LCSuX38fNmBEmsRCYLBfEoZavJSfQupTvvr+ek14RgCPybc+5VnEQzuHwOqh2r3O/xr+q8P0A8HYkywbsPLU3IWTxEfv4Sw/pLxdIgI4SbTUJFrJXMo0oNLtxAdQcagTCx8yQWNehVxgpIUPy/uGuSsz9YqfyI97vO4TTOi+Uoqwp1CQXxDlKiRxx/nF/njgXBZZ7ZSQOIb+f7GHUWeJ9FJmnevUMsrcIqNs+lpzxEx9nXFZyzdubIwTyF8B+iDOk7B33tHcpqz 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: The architecture defines a format for guarded control stack caps, used to mark the top of an unused GCS in order to limit the potential for exploitation via stack switching. Add definitions associated with these. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Acked-by: Catalin Marinas --- arch/arm64/include/asm/sysreg.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 4a9ea103817e..b8d8718a7b8b 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -1077,6 +1077,26 @@ #define POE_RXW UL(0x7) #define POE_MASK UL(0xf) +/* + * Definitions for Guarded Control Stack + */ + +#define GCS_CAP_ADDR_MASK GENMASK(63, 12) +#define GCS_CAP_ADDR_SHIFT 12 +#define GCS_CAP_ADDR_WIDTH 52 +#define GCS_CAP_ADDR(x) FIELD_GET(GCS_CAP_ADDR_MASK, x) + +#define GCS_CAP_TOKEN_MASK GENMASK(11, 0) +#define GCS_CAP_TOKEN_SHIFT 0 +#define GCS_CAP_TOKEN_WIDTH 12 +#define GCS_CAP_TOKEN(x) FIELD_GET(GCS_CAP_TOKEN_MASK, x) + +#define GCS_CAP_VALID_TOKEN 0x1 +#define GCS_CAP_IN_PROGRESS_TOKEN 0x5 + +#define GCS_CAP(x) ((((unsigned long)x) & GCS_CAP_ADDR_MASK) | \ + GCS_CAP_VALID_TOKEN) + #define ARM64_FEATURE_FIELD_BITS 4 /* Defined for compatibility only, do not add new users. */ From patchwork Thu Aug 1 12:06:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750386 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 A1250C52D54 for ; Thu, 1 Aug 2024 12:58:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34D766B0093; Thu, 1 Aug 2024 08:58:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AF4E6B00A2; Thu, 1 Aug 2024 08:58:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1295A6B00A3; Thu, 1 Aug 2024 08:58:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E48386B0093 for ; Thu, 1 Aug 2024 08:58:10 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9E7B41C408D for ; Thu, 1 Aug 2024 12:58:10 +0000 (UTC) X-FDA: 82403679540.25.9579FBD Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id DABDD4000B for ; Thu, 1 Aug 2024 12:58:08 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FJCzDaYT; spf=pass (imf17.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=1722517031; 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=J+17pLu3G7dDibf78evDF4ipjQkmkdK/v8qlZFUwd4k=; b=FtwmbdqBDDXXd9W3AHUcdHDbJPVC59yzpk7kVijeZBiXZ7nPToG4GcGBouKF7fTFvteUmo 5JAup+ADAirleB2ECK6SmaLIIMliBLq/KabojTY8fpwYRPubwBWyLbj8MybggqOgjYu99E i3Sut6VIRsl/glikxq7nl1+cuYMUkKY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517031; a=rsa-sha256; cv=none; b=gmunhm1BgO/175pcUaOR+l80674ElO+AiXGR+Q2/RNjY93Aij8M3dfndpKf2xZtV/m9tRN fqUojxNho7vdrUWV8t7CFZZ50RpvgyuSr2+FWLhonMdUgDbYHT5XADRahCf2Aj421+uBb5 e3yKXhfAt8vAgxUTgOxmkDd6hkxS5G8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FJCzDaYT; spf=pass (imf17.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0E21462898; Thu, 1 Aug 2024 12:58:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BEEFC4AF0A; Thu, 1 Aug 2024 12:58:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517087; bh=pr/SL5aXRHkEgbL61YT0WXgEv0CY13vhmdtve/jq07s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FJCzDaYTgHGPGRDGs3q91BDDMkyJYNXJ9l28iaaR4G/ZjvUUEUMEofxFR4EGbzrWK i7Ek/16URKLtwBc1hlMafY9YbSCGkquoX8rmFRCQ08rDxXFcDaR//nlZGW2QUEks1O HkFrj/gtGwWhWmpKSFsMS0n7QJdSe39Rzd6bhdG/8xKdSyOrts5Y/UKs3pOmNFqsRQ p48zboodXYB+6JXyVyxXF88GjyncMrpns+MDgNcJmtbK+ow9aQcBXNU2qrpqfqMQjT JjbdUytErk0J5QKWnXBEHc+ocova9NSO9/K7+/G0NOjVKONSV7LnqmxJbitAFz3DtP l2/FJGAFfHG+A== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:34 +0100 Subject: [PATCH v10 07/40] arm64/gcs: Add manual encodings of GCS instructions MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-7-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=2643; i=broonie@kernel.org; h=from:subject:message-id; bh=pr/SL5aXRHkEgbL61YT0WXgEv0CY13vhmdtve/jq07s=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YL5wsbsXpFLEnxHz0MZq4t/+nYJjX+FBLrDs1/ N1KvKSeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGCwAKCRAk1otyXVSH0ORxB/ 9s11x3nh7dQHtvX3MMe4dfLF77kaKt9nnh2hUEcXu6pG5/rLpFfae/LeU0oemP87Wwg8VI3Rc8GZA1 XFkfxYlXExPjnMj0q6PPaQ0GnI2ZFQ6xacPuGxoci7j79eZ6kxTRtRqol84eilLhP7ZofZtyUUnUaE CgzAkdr1bWGZLN++CxGV4YpKBICjj9LkdFKvT1HKMy8kwZklzUdGFEmbtBdk7rCi+m9P+PL0+g0prg uoVSgcUxvlnAu+/F8PQHPb/kvMXP1g0Ks4yKPB/nx0om9RFyY1BdkBB3EAo908dARyobtvzN6MaU5w Rl0zghQtR3bcLuKNMEY3/pLk1ooTRF X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: es759nnqmhhzbigdmo9yzxn443owu63y X-Rspamd-Queue-Id: DABDD4000B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517088-503311 X-HE-Meta: U2FsdGVkX19i/CE7n+A5Vnik3zpuaWgwmwbBdtYfu7kAF0uLwFPLKW+LxIdmYKkhkU8ug8qniAXC2DNoIjt1myYgs/eTcQLD93oZ/auo4Sv0VqT3HVlTySUiR3xP8Fl1q6ZBaUb2YDTEGHFzLuhZmcIow+yw+J8JEvZO2ruqWlEtww36z5wB/F4jlQ44Q/QHExy06DrI4XY8Bz2buSffUm2N172o/+ta8ZAFUbrTJkC7EehjYJI17+ujiiGq4rv7KHgelQb3olKrDJFg+aI4q2ceVpK7n5ZiLZxIBaB+vUxZZ5BeqDelcxAxya7PLixj3IACXaKyG2itkZcd9wRne7abkZDoFexAjqHRS+HpHXQYEiwH64OVDcPPkeCjNKLD1Adq7CGMLB5KQ3Jyf7QYdX02j3Uzb5YbxZn0A5Mv6fyuBzojcrBn/ytjRwet7BFohzCA6b1Gx42CHw2lBxLL2XXlXF+S9iw7eN5wKLPIVIOgGaIfd6/M7sVReHpz2JCMy3mLFih+GN1i2Nl0dwlAlXid0LwCEDMQhsUDa8RpccEQHwxiN7T/R20fDFa6KUeY0g5afGAT3zsDpwzv+3sjvCzvdg11VMaNxrET42Ik103i52Si8j9tIECR/j0zboNDWnm+VJt0VYPKAJaygdJBJHZlO2C9r2pWTGUplBiiDOwMClvOR73T35ubtKf5eRA2jzJJ3ZrJkxE43oD52meceGjUCelxZHNJ8Y2btswswyfjoKx5VzOxUheuxp0E6x/cTaN+CCDtsb9gAoirGmAtMx7bsE4tdA1HdecZoCttHNdN5pgV5XOwwizO8Zzx7ci4Ja+y+zpdPcteI1oxGhJi8qlUd53aeT3KG6An5A3pc55QEcwPi8EgD0ypBirJBNssyO4FZEM5FpFEH0gfdX7JpF4ron0qQCEuoOK0cQh+MFABl9UI7gQ0MhzXdlb6HUEMa/Zdc2QXsE8GKPivjF9 rpxLsRAN SrDNjwxlYZtNx3eWExEcCIs9KygNsHoqKXwqBX1cqdZkmVEQKUn7TehUX2UIgmt9QUw9Jh7VuGv/jTPNCJVDlBoriaI0FtRyqfti3A4Qm/8LSDEq7lek9Tx9z2mxYE9Rt13gt3cySmpO8WdoOX9yLFeei5fSa7mREXk4fGyS+dBm62/dEG8tN18WJBf06Pr0CxUFqevA6mD3iPXvZ6dwkZIziqTpb3duDAwVYkJMpipb5hh28UKnm78jFSSyA0b15ELvKUQkPhv/hOHER3TwqcnxlKXrEtBsKLCWuYjElCOTnFKmn54BbfS2PiXAEx5UMieg7MbV3D1Z7PpCMTCqZgkS4vxN9wFVoKuWOd+qIuWC0cFfL9jmKsY72+TY3SzqeMgfP 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: Define C callable functions for GCS instructions used by the kernel. In order to avoid ambitious toolchain requirements for GCS support these are manually encoded, this means we have fixed register numbers which will be a bit limiting for the compiler but none of these should be used in sufficiently fast paths for this to be a problem. Note that GCSSTTR is used to store to EL0. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Acked-by: Catalin Marinas --- arch/arm64/include/asm/gcs.h | 51 ++++++++++++++++++++++++++++++++++++++++ arch/arm64/include/asm/uaccess.h | 22 +++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/arch/arm64/include/asm/gcs.h b/arch/arm64/include/asm/gcs.h new file mode 100644 index 000000000000..7c5e95218db6 --- /dev/null +++ b/arch/arm64/include/asm/gcs.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 ARM Ltd. + */ +#ifndef __ASM_GCS_H +#define __ASM_GCS_H + +#include +#include + +static inline void gcsb_dsync(void) +{ + asm volatile(".inst 0xd503227f" : : : "memory"); +} + +static inline void gcsstr(u64 *addr, u64 val) +{ + register u64 *_addr __asm__ ("x0") = addr; + register long _val __asm__ ("x1") = val; + + /* GCSSTTR x1, x0 */ + asm volatile( + ".inst 0xd91f1c01\n" + : + : "rZ" (_val), "r" (_addr) + : "memory"); +} + +static inline void gcsss1(u64 Xt) +{ + asm volatile ( + "sys #3, C7, C7, #2, %0\n" + : + : "rZ" (Xt) + : "memory"); +} + +static inline u64 gcsss2(void) +{ + u64 Xt; + + asm volatile( + "SYSL %0, #3, C7, C7, #3\n" + : "=r" (Xt) + : + : "memory"); + + return Xt; +} + +#endif diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 28f665e0975a..6aba10e38d1c 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -502,4 +502,26 @@ static inline size_t probe_subpage_writeable(const char __user *uaddr, #endif /* CONFIG_ARCH_HAS_SUBPAGE_FAULTS */ +#ifdef CONFIG_ARM64_GCS + +static inline int gcssttr(unsigned long __user *addr, unsigned long val) +{ + register unsigned long __user *_addr __asm__ ("x0") = addr; + register unsigned long _val __asm__ ("x1") = val; + int err = 0; + + /* GCSSTTR x1, x0 */ + asm volatile( + "1: .inst 0xd91f1c01\n" + "2: \n" + _ASM_EXTABLE_UACCESS_ERR(1b, 2b, %w0) + : "+r" (err) + : "rZ" (_val), "r" (_addr) + : "memory"); + + return err; +} + +#endif /* CONFIG_ARM64_GCS */ + #endif /* __ASM_UACCESS_H */ From patchwork Thu Aug 1 12:06:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750387 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 987C3C3DA4A for ; Thu, 1 Aug 2024 12:58:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D8746B00A3; Thu, 1 Aug 2024 08:58:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 260DF6B00A4; Thu, 1 Aug 2024 08:58:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DC356B00A5; Thu, 1 Aug 2024 08:58:18 -0400 (EDT) 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 DF8EA6B00A3 for ; Thu, 1 Aug 2024 08:58:17 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9240E140D5F for ; Thu, 1 Aug 2024 12:58:17 +0000 (UTC) X-FDA: 82403679834.11.51DD4CF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id B12BB4002C for ; Thu, 1 Aug 2024 12:58:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MbNqHBPc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.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=1722517090; a=rsa-sha256; cv=none; b=Ed5MFUhSFT/Jy1tLtsh/1+t0wMrfjgAXypj2V7/RYaLDKiZ9xDzbNcYpz+CL0OBQn4ALxd MFlbPhbDM8ejb9pqK48G1NXXx4EIA9RxM0aGQdjIhuxkDRerqKxKm+skMmaC9YwckwJ3r5 jBmoKkcXaCDfKiQuoDQuSt3SF7XQQJc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MbNqHBPc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.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=1722517090; 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=+fN4ByY0FzRDwLIySX1hIe9Ll/YoCNC7ejriYTNI6D4=; b=MVi5CQ4XZQ32fgM2XC4JBmyDq6ZmnGIPTy1Q1fdPd2MV3VIGtau4JPcSotv3mBy4+T4PGz WO2Zy5TOuFeaqyFQW772K3P/dSSD/zFjBPtwWxfb/d/565kfHx4nOVvUrOxNoCnIVIHjbG ynbDjCmGgkgyXT4zpuZp+qOP2wGQdtk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D640862890; Thu, 1 Aug 2024 12:58:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4743BC4AF12; Thu, 1 Aug 2024 12:58:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517094; bh=9zyM2kDwaHrPoIdC+tOITu/EBfLF+6/APyyopskSW+Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MbNqHBPcT9Y5beIJ6gploRPX48lF/ic8+DFzi6qdc6cvt1vT0gJAFXuZWU/kINSbG w01rYdOQQA70NsmuDwunpJubsh8i49z3114zgqs38oC03JE2Bqoc6n80qPrvENvVII 81drmw9RC0wAULSAgtpeMwsJVVFhmHjeXiwAARS7LEA7/G0/xLGStM6i1X36yW9kla DOX+sdvAgON5kBgQ4fl7b16mFYaxAlkwxQdWUoOUlKpWlx2i9A9Jh1XksQdoAltZZH gr93pgYFmS5Q3Kyna7upwfm/6x7XCQYA0Sya8gOelUhPJsMBBrgnSlvAZwD8zwzTBc y0OUMFpqw4uNA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:35 +0100 Subject: [PATCH v10 08/40] arm64/gcs: Provide put_user_gcs() MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-8-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=1103; i=broonie@kernel.org; h=from:subject:message-id; bh=9zyM2kDwaHrPoIdC+tOITu/EBfLF+6/APyyopskSW+Q=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YMRl/JJcB0rkEcqgIQ8gNudAtrXaRRngscnrbl bPqr4syJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGDAAKCRAk1otyXVSH0FzhB/ 9vnbFMIfpN3H8ylPPtfhBn++BSFNylLU467N/+QYoDoXnkw48vtuHXvlXdbhmG/pVEekaIYqr4GbWj zTbVXnZdpLmf7S0M6QwCO4+jX59+0EOzOzIMR/69gC1VgZ4ZKDB5QA+Rx/l35VUF7O02mso6fO+HG0 2qbZzy/7tnkXVbPiyYZnF+OYGE+wK4xseNeRUDCnMYSKpPokJkZ1M86zvEhAkA9L9+nCGNYpPWot+T 3vcDQ8wwL6TUiu6/gDqeVp38IKPlTX3LZXVQecVANGqtSEzyzf+TT/qE0Fq7ArvcD9PXt2GrcIARrn lTxU0WZ6Qu9SZe+Heyb4/hIEo5nDr5 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Queue-Id: B12BB4002C X-Rspamd-Server: rspam01 X-Stat-Signature: 9uft6y99pquzqcn5x4msniomioycgor3 X-HE-Tag: 1722517095-472839 X-HE-Meta: U2FsdGVkX19wHZMZMET3kTqWqhFF5eSzgEPA903HzdJ20/nBvaP6XvYYDHWN/0e3wZlfCrnvC/KLzNUWB5Z/5kQk1TdsHPyJyRZAfze1oE8UZl+Q4biVWmml1nWaAIXzGZ0TkN61cwNyDNomkmafTcpmY3Stqgje/zKiB/qJFE5kDBTPVsG+Hib02fY4+Zug9zDo+pqSVIbcIygcmYqKoDvPHxEvKv2kQZWvFL0f3bQJQ32OwETmyilbjcJV6RV47dxu5Sorgcp/IuPa9Xi1b+BQoFebMSbKmWXXCPKGCHUJx3NLCHcLtIE6EXXlaWSsqKrnhXMOho2CpCW4w/PhoLctUmkPArewBIB8BzTIiDdda5h/+ehy9nvystYNQ05Fm9MKewz6xhNzap4/iL9HuqroNcpYh+xhOxpBf2LdQEymBPHOV2B8y9oQKMZYPT12BUxUAx1gEKArUm5U364ocM0kMAIJan9S/oUKBn06Lp0Xo5RWZ+9s1M5CsbMzqqaxKFAxyLft4L1ebrCU75loeYUrKhJzyT9MLYFJBi++bgXLpu719hMRTKDKHPLdxMiAmiNK/hcUw1KzivpX3XQ60j9gK8vcxzRdJoMfSN2l7dHe7u0aHjpszhM8PBEzj41ZLwMpAShDwInH2A7aqSoVFCFY72s4jYg1f1ZpkViBRPpcSNY9r44LwduHSWRdQUKEQ0OjOee87hyrbFJEN4/W3MyTm6nS+M7DWXbeTz479eNRHglo+yezmVrqsgJRqS2BwtlPEw8TiQscSOhTp2YBXCEsEiPZDpRezIwoXju4qMT7yChnY+z7CaFO1cvVvwEkIKanJbxaA5a3pQSMTo+vMw0r2qnmggezoh4yCZ1rgA7fRREhjrbnqxJkRu5ryOpsBb0z0Hl7YOEc0LRjqOGaoq1n1aLAAfQzHO+zEV6J3rTAmq9kYqEfzNSDgpUJGcRkPtob4YGN3UIBIO26/7O s3vXn3KJ JyCIR1tWoJyc8hRkg3VXj1mhDFlQ/chQep9wbWL7yyCE6DagAAb5LGd3+aDvcanea8j5V7dCHOUb1LyRkVftdf7YFe5LF3z4kt1OePHz8zyqZJfAa4LCQx+SOD8F2b8CTGQPdwC5ov42P9ZT5G343LM2TNjP8VFVQvs8SODrGa+px/QqmqpJImBQ0pkkIs8x8siiZzC1zbevA1V7BqWa5jNVm+LU5sAmMVyP9bY1ze9YbnRlklyzTBkhfX7TGg6swrW7CotMtMm1n6LVtuGw/mh9ygOYN6xTEYtEQJIRmEnxKI0mJ8ky4tGVoFE9YH2Gee4vHiW29iWRFZQbTMqeJwG74DHWfmeh8Id1sSUiTdy47Ox53Aqx1myai48ZedIBDC03h5U0hPgvz1z0DSDtdqslB31PJNU1dl74LiYYZN1djf3Q= 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: In order for EL1 to write to an EL0 GCS it must use the GCSSTTR instruction rather than a normal STTR. Provide a put_user_gcs() which does this. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/uaccess.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 6aba10e38d1c..ecdd47cf1d01 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -522,6 +522,24 @@ static inline int gcssttr(unsigned long __user *addr, unsigned long val) return err; } +static inline void put_user_gcs(unsigned long val, unsigned long __user *addr, + int *err) +{ + int ret; + + if (!access_ok((char __user *)addr, sizeof(u64))) { + *err = -EFAULT; + return; + } + + uaccess_ttbr0_enable(); + ret = gcssttr(addr, val); + if (ret != 0) + *err = ret; + uaccess_ttbr0_disable(); +} + + #endif /* CONFIG_ARM64_GCS */ #endif /* __ASM_UACCESS_H */ From patchwork Thu Aug 1 12:06:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750388 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 CF55EC3DA64 for ; Thu, 1 Aug 2024 12:58:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60CC16B00A5; Thu, 1 Aug 2024 08:58:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 596726B00A6; Thu, 1 Aug 2024 08:58:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40FD06B00A7; Thu, 1 Aug 2024 08:58:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1FB3B6B00A5 for ; Thu, 1 Aug 2024 08:58:28 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CAA7D160D45 for ; Thu, 1 Aug 2024 12:58:27 +0000 (UTC) X-FDA: 82403680254.25.1CB6BF7 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf29.hostedemail.com (Postfix) with ESMTP id 69C6012002F for ; Thu, 1 Aug 2024 12:58:25 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pTC4lgO7; spf=pass (imf29.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517050; 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=UPBStWM6YeANFGDZl+K7sYZhcCxUJS/7XncZR9RI7Zc=; b=n8xO8TMgiaMA9p/RA+RIQwIwhd0TzUSEvQMfIAV7nJZPY8xOb6Pji9+IYyHZZEPk6VE0ZV 2Xlwdz0yiAth/2q/XLR+vO0e694Ce1ifK0lFGUdt7GzAZy5zhH/ks/Doe9azroqD8GGyvV cGF5vW5XIOf/6Z6kI1Uvi6IiQoqwu1Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517050; a=rsa-sha256; cv=none; b=d6sUdBdFos5JIspX1dajud3TwqM5yR4KhJP1Wz9s0klHDuyFsZUPWPoMqF6cxr54KxBEn+ rJuRqLEmphKIb8jT1lB1peothLBsRP36NixmW+Oj4PmAVn0iOzMgB31hqxqpT2j59rWfUT 2UXUARiPcotx6fv1y1udLPVgKt6ijPE= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pTC4lgO7; spf=pass (imf29.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 6A245CE19B5; Thu, 1 Aug 2024 12:58:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DD58C4AF09; Thu, 1 Aug 2024 12:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517101; bh=n96ljJnJVMpYM9CVsfMUORPIasrMIuo5nt8SCuY5I/I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pTC4lgO7SQKGHaiX2nkMESdUjPENIlCeXI7cbdMEO1veZv+NnE7Q0HtzHnypIRSwX EFFbCP9R/odkVfMcUNhw2BYaIXYd3+HHHyjwGShekpbDTq/8639R57lZi260FRwS9W BXwQfAdQaytr8C0yGa+c68hCauRvpcE5dlS4czXMOBk4eaOepEeEMdHSJS4YgQtuZk I467IPjnvVLTzCPUkz/2CCGzWf602uS+MbKUA33Seoqav/yPBIg4Pmjhg1gOrHSJdQ mzerRki9mRWRzWC7SiWU82YMhlX5m5cdrQzDukG/jpa0w3ctN8oQ6BmSr2GFLvtm/r 68Ybg8kKNBgRg== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:36 +0100 Subject: [PATCH v10 09/40] arm64/gcs: Provide basic EL2 setup to allow GCS usage at EL0 and EL1 MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-9-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=2228; i=broonie@kernel.org; h=from:subject:message-id; bh=n96ljJnJVMpYM9CVsfMUORPIasrMIuo5nt8SCuY5I/I=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YMcSNTIJcJ2iVFyb/E14kVTlvrio58Ua+gwj4/ lAQflIiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGDAAKCRAk1otyXVSH0DvuB/ oDx/VdoNOsQl5QDmrDks6jRvVft2wlWPJjs7YotfALeKJpT6PRTjX/fHk0yQ3nT1TbsgavUVMh5ugk azWaDppWDeoeJyRUeR8AwqHPaLkF75qzW8tRm1tYmbjlUvU9Cs9kNG23dqrPxY48VY9JN/FknkR15Z vIT8K7Tidey9v247fvxyj4rfKz1arkjoyGZLJVMyWb6u9BHi66D9qeos14lTWlCqrtqjX8EJYBKS7r 3I0t3sTBFUAUPotD1oVJPOQb4oPqtBVJy9PMQP1Yq1fWgtYabT5l5VrcJQzcK+M8dNstOCEIZLt/rL V6ygoYoUMW539BYpF1RQrxycLsV1z0 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 69C6012002F X-Stat-Signature: 7k584ax61iho7ekqfgsp5w6ktaguqua8 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722517105-86123 X-HE-Meta: U2FsdGVkX19J1tj3gmOLpmSibzjhHgqSLM/vB59qJFFfKZGjLTN1jHJrIBCPmCzEm9LVCUIugwVYVxrmI1knjUiEYgPEqRTh6d/kIoy3FY0MNF/7SAQU3XsuxMd4lQ0t9EOCN6soikTmXkLEtiJX03tPAFaEQG4J0V2sZjJXfgi5eCoFSsAs10W4bqrCiLDwDTTtTzaOgoRS+XzvnWha1BAfY1mIVqZUaqmF1owpbbOB+vWRPg6b1MDWNGDj0kYZaeJ4od+Zr28zYtSt1hQPkdA4w3D8iXohMDYBl2yDD7tvRur/wFzQcWeox6gw2aoyEc1SJPTuP4xybvXcKUxCDbAGfBCylYSzCnL0Y82qQ7L8MscbKhpqIpCzZIKKvxcfazFIKuHTb61e46HMrqvdpt8rZUHjRk3GcbDjDo+PWM2IAeHsYgmjkAxj6VwMbe4FMz8jrdx+jnFsj7vchO4xw5mxtJUBwRZyAk5G9nSae4CS5Er/ZsQ+84ExVjszqAtYqdNtsRgSKHpc4gLNypdK7GP0K6Ou/pR9mVDDeD8ovnpKYgTWGkJ5JX8RhPuhJtxpKSXEzfKhF+xY/CkNClqbcrKBLSLJgtrbBiy4K2E6+p9TRiWPVgPX3Z3xBE0Na9H6OoE5m9oDIxXYGzmIaehUlMsbt7OTCXrjXmqtr/ERf+0LmeW0yqav/C8OZair65I/dJt6fH8e0tKtnnlynE3Okk5tjAnsP52Y0UGO903fhbC+8hHHaLPBqn1LeLQx9vzXPYXshoOP46lxHUB+vmKhW4qDOyLB6Nc/81MwYD8j2cvIFsy790b5WKiwlhy6cCVG3AD7H9CukSgdr1XIyNRnHVMTbI3FmxJM9SauA3A7Ad6KHgWGE9Lx2sn0jFRyPT1ubyL7tNeOMZIiTY6k9/QwusMgg6/EGJqBTbcPWYKQi94aQPYsQ83P6VsjZdG2gEQaxmOnrb7+s+VwAwIWquL 2EQEr0j4 QnNBOBs06ODiLuzUaZtteE16CHLD9YgQQh7LAedjDL/w48H08g66lgJr6+hftBobGfmDydeVNQSfdaioe5V0tvzzt33Z+MxKPi1Q8lAg4xs6x+urXqBh/bMwRDcD6TrtRqgTD+g9I7xvoV0AvjCEOhiC6EJfWP7QeW3RGWKyT7CLKHThpN5ufoUsMfGhqFXpPxsNvc+E1BHhD4w16/C7OXGX2MVdLvdlaM6MUYa2Zwmoy2kQkhnII6/UtkztghzNl5WMblKgWieoeceN6FRn0r8XQfv0WdNUe7IB4BnxWSVJowmCyNeVvTbUf0c97Vw3227Ev 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: There is a control HCRX_EL2.GCSEn which must be set to allow GCS features to take effect at lower ELs and also fine grained traps for GCS usage at EL0 and EL1. Configure all these to allow GCS usage by EL0 and EL1. We also initialise GCSCR_EL1 and GCSCRE0_EL1 to ensure that we can execute function call instructions without faulting regardless of the state when the kernel is started. Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/el2_setup.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h index fd87c4b8f984..09211aebcf03 100644 --- a/arch/arm64/include/asm/el2_setup.h +++ b/arch/arm64/include/asm/el2_setup.h @@ -27,6 +27,14 @@ ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4 cbz x0, .Lskip_hcrx_\@ mov_q x0, HCRX_HOST_FLAGS + + /* Enable GCS if supported */ + mrs_s x1, SYS_ID_AA64PFR1_EL1 + ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 + cbz x1, .Lset_hcrx_\@ + orr x0, x0, #HCRX_EL2_GCSEn + +.Lset_hcrx_\@: msr_s SYS_HCRX_EL2, x0 .Lskip_hcrx_\@: .endm @@ -191,6 +199,15 @@ orr x0, x0, #HFGxTR_EL2_nPIR_EL1 orr x0, x0, #HFGxTR_EL2_nPIRE0_EL1 + /* GCS depends on PIE so we don't check it if PIE is absent */ + mrs_s x1, SYS_ID_AA64PFR1_EL1 + ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 + cbz x1, .Lset_fgt_\@ + + /* Disable traps of access to GCS registers at EL0 and EL1 */ + orr x0, x0, #HFGxTR_EL2_nGCS_EL1_MASK + orr x0, x0, #HFGxTR_EL2_nGCS_EL0_MASK + .Lset_fgt_\@: msr_s SYS_HFGRTR_EL2, x0 msr_s SYS_HFGWTR_EL2, x0 @@ -204,6 +221,17 @@ .Lskip_fgt_\@: .endm +.macro __init_el2_gcs + mrs_s x1, SYS_ID_AA64PFR1_EL1 + ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 + cbz x1, .Lskip_gcs_\@ + + /* Ensure GCS is not enabled when we start trying to do BLs */ + msr_s SYS_GCSCR_EL1, xzr + msr_s SYS_GCSCRE0_EL1, xzr +.Lskip_gcs_\@: +.endm + .macro __init_el2_nvhe_prepare_eret mov x0, #INIT_PSTATE_EL1 msr spsr_el2, x0 @@ -229,6 +257,7 @@ __init_el2_nvhe_idregs __init_el2_cptr __init_el2_fgt + __init_el2_gcs .endm #ifndef __KVM_NVHE_HYPERVISOR__ From patchwork Thu Aug 1 12:06:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750389 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 2AC77C3DA4A for ; Thu, 1 Aug 2024 12:58:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B647B6B00A7; Thu, 1 Aug 2024 08:58:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEDBD6B00A8; Thu, 1 Aug 2024 08:58:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9409B6B00A9; Thu, 1 Aug 2024 08:58:35 -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 70AF16B00A7 for ; Thu, 1 Aug 2024 08:58:35 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 20E3340D7B for ; Thu, 1 Aug 2024 12:58:35 +0000 (UTC) X-FDA: 82403680590.18.6302228 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf28.hostedemail.com (Postfix) with ESMTP id A7775C0008 for ; Thu, 1 Aug 2024 12:58:32 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qScMxBIs; spf=pass (imf28.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517037; 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=GycIpknep37rYdVQ5s1q83aQmaLU2J/Dkh6k2oXEc/k=; b=XNIJ6w4uX81E5CH/829n+urdL/3hfUmD3pXK6NKb9hLl4SU7GRvXC/14oe5m4wRS77e8T7 VqlOBpEK54y4j/siOQMHxpFIhIo1eZnNwqnWejENV0zgiIC4VtQf8utx5l2ageUYhha6J6 kxx/Wk3Z/JGtZG87VgPBcYv6CeVENys= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qScMxBIs; spf=pass (imf28.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517037; a=rsa-sha256; cv=none; b=mxemxFQRbm82rVp2Wyws6Qm+JHkRvhh66B+B3YawpbOUFIkNkwrwXWFgxoapmbdYgLxrqd FdqZwRqR/T+fRy/0laxcJqYtQJY+X6CRxrzZrrMiNIoqz8SXgzENu1actMaSCSBJQTmYO2 j+4RGXuFIvzXMsNTCLiuCD/jXPQDdhY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2AE1FCE1979; Thu, 1 Aug 2024 12:58:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED585C32786; Thu, 1 Aug 2024 12:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517108; bh=7s/gHN1rW9TWM0RWrG/NmXj1X2oouK/u/2cODr8xaC4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qScMxBIszKrXZE6l4jPoTZd0nsXO1uelO8k1eOLYUYobg5sCv+WFBa/d9YsyPSjjE Z3j6LkQGPdSakAiJyW3ywm/GCPzVnFwElgiqof7vhrJX2QXsPqq5y0pLAMme20kovg 4N9nUNe+fShGNxKq9paQfEnIMMwvAbMfweChUFzIn+lCsfai4eJp1X0wVoD4A0UPqJ 7hGh+xa1HXikFeCOdh+57VLYWktfB1I6vBg3MPem/FMEiyccc3PegQIP8kXmxbXGij CL3VqAezLGfpJprR1gOrh3ZMaWOOl9hB2i8Khf5JXTuVWsbO7Xp5uOI1LAGDQrRteJ 74cl5kQDYkVzA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:37 +0100 Subject: [PATCH v10 10/40] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-10-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=2453; i=broonie@kernel.org; h=from:subject:message-id; bh=7s/gHN1rW9TWM0RWrG/NmXj1X2oouK/u/2cODr8xaC4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YNgfqa/ixM61jewvMBym4ukRMnWI/ViFp4+3Jz URec3AeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGDQAKCRAk1otyXVSH0An1B/ 42nmOBfn/4sSlWSLsHjdMFjPjyaLDIR7Dx9tGlYicIgU0lkdGVZEZk/Tk/sufifPGYX8G79vGolOK/ MczkShezUksVzrd1+DAMNjoHsukcOl8U3cqwFjCKW700My8kSSTR43ucvlPf9jlRzxlkRw+hU5upW8 PAr3+wx1mTca/ZynY3/XuSz3Udebj7h4fkiNPBzVU/kEnE/LJDLvcvsDSg7p1TziVpg7w6sr1noMu8 05mLN/s+AzWeWhuoJ/M774sJ6AvcfWn6lvHpKGctfqdo8u/MQ5oHFV7hUt3QR+nhcgJ8JvdKEeDRif TWMj6huJOHT/eJ7M+sNF3opx5AEHQG X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A7775C0008 X-Stat-Signature: nn68bereb5jdghb8n3d7r71fkapy6yfc X-Rspam-User: X-HE-Tag: 1722517112-106821 X-HE-Meta: U2FsdGVkX18/EDXzI9edpm/lJTzhELLvcxxVtvBXo9RmEHXOAPCiP1cU+EOTJGPj/QDfwo2TybrDrnB1w6DesDkaFZFZnPMuoz8w72LN5C4j8EGHtG8usjvi5iGX/wAw5Jlf//t6GCshA8VWywHp/hWE73n5n7Mo5ntPVvbWiyU/CMPllnQEHAsc1ECDXdgmO7NtlQ4Bv9SuSe+0TpFq/npR2cHqf4DX+XdvGAroFbU5Onv7BiuK/3OqPvsiVfQ+AGPoTlNdCodx+sMzwCvZ+wlJ4o+ssIlUJhXnVoDGA8xYcgjJep+Ui04utaZYYJMzvp0Fq7l/dV0U58LPlFIWOpsnNDKcWQBWQ6+aUAwO8R1F5Z6PZyaNZmxDTEQZosYPeQUzzD6kUpPLe3PjgozxlnzxwGohqe2rdR8MQUvO3T91H9xrvvD83RZgcu9Lr3rDtZs0/7yzr8zJ+/vVa7p+9VPgdrefgnzmHN0Qn4dCrxFTtBrxlFdKX4ZkgShz5oXKXnU/HJ9UD11kWt7eIMFBVyucLJt9bYjw/CN85Y3G7SP7eSwqolOlyrkumMQT71E+jQxAGhlWlE5+XhWaZKS7LFlgon3PSg7diFY1Dk/+f8Pb4LThpgFDdpTEXjL52lAvLtd2GypJpDpsilGqjWLl7L9ShYoJcke7Ku5TNeUb2C8n5t/dBB2SZ12ZdLnGBYOs/63PcJr/g7Fe00or+byR22r1wnIIUN5SU1rcdduB1Xyp81mlYWujBsyKQkc8W1pHFRepnGgrf8bfVPEyfuv6qd6WmWdbSuWf1k4zfuBFv6YQuEtOmARami7FYaK0NOOn/Mh5WMcDbghPWbZDEnqszysFjYFprDmCqEhzrNQHtW2hmwOzoLDtYnOVDJ6WHNTw3/IB1JcEGWkXCpB2jh9k32mfbBv62wwJHyvkd/G1SIem+Yqs69SxBJz60zpahG/Ol5bpfbR3BYsPyA+1qM3 OXCKV5GS 3R3wYfEfJMoPlP8cRln/afdIFPgWHKvC2zGroQQ4uGR4q9GZLpwsTYfPe5V5PD2e1Zp5bcR/ohlfdPFcuQcwiwGiXJc3F4qnrVZnNnlMWkTMzuQ0TM43wi0dBYIO/5hjVyNj5kQoEuX21umoGi/s7PxNStUYzurkUS5coyMxfYl+VfcASc2XJ1CyAdPGA2bO9FtXZoytDsyC1dKm2PFncSFZE/tsvcUy/OrfdW3VtQLHKdyOL9sX2Yqb+UpfZoabr96vbeFiZk+F5wwqWu727hR1JTLjG53ig3fhhOZpjZbmyV77z4joiSp3NS+Tl2BjnQcFcSKxTQN1BuqPPWDTTrXDZ8gVMetEP9OGYkwYpfhkxc5hAkKfjf82HxfNqnebBYrX6 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: Add a cpufeature for GCS, allowing other code to conditionally support it at runtime. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/cpufeature.h | 6 ++++++ arch/arm64/kernel/cpufeature.c | 9 +++++++++ arch/arm64/tools/cpucaps | 1 + 3 files changed, 16 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 558434267271..e0f0e4c24544 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -832,6 +832,12 @@ static inline bool system_supports_lpa2(void) return cpus_have_final_cap(ARM64_HAS_LPA2); } +static inline bool system_supports_gcs(void) +{ + return IS_ENABLED(CONFIG_ARM64_GCS) && + alternative_has_cap_unlikely(ARM64_HAS_GCS); +} + int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt); bool try_emulate_mrs(struct pt_regs *regs, u32 isn); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 646ecd3069fd..315bd7be1106 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -291,6 +291,8 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { }; static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = { + ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_GCS), + FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_GCS_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME), FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_SME_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_MPAM_frac_SHIFT, 4, 0), @@ -2870,6 +2872,13 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .matches = has_nv1, ARM64_CPUID_FIELDS_NEG(ID_AA64MMFR4_EL1, E2H0, NI_NV1) }, + { + .desc = "Guarded Control Stack (GCS)", + .capability = ARM64_HAS_GCS, + .type = ARM64_CPUCAP_SYSTEM_FEATURE, + .matches = has_cpuid_feature, + ARM64_CPUID_FIELDS(ID_AA64PFR1_EL1, GCS, IMP) + }, {}, }; diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps index ac3429d892b9..66eff95c0824 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -29,6 +29,7 @@ HAS_EVT HAS_FPMR HAS_FGT HAS_FPSIMD +HAS_GCS HAS_GENERIC_AUTH HAS_GENERIC_AUTH_ARCH_QARMA3 HAS_GENERIC_AUTH_ARCH_QARMA5 From patchwork Thu Aug 1 12:06:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750390 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 109F2C3DA4A for ; Thu, 1 Aug 2024 12:58:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B8CA6B00A9; Thu, 1 Aug 2024 08:58:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93F406B00AA; Thu, 1 Aug 2024 08:58:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 792F36B00AB; Thu, 1 Aug 2024 08:58:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 549A86B00A9 for ; Thu, 1 Aug 2024 08:58:41 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 086161C40B8 for ; Thu, 1 Aug 2024 12:58:41 +0000 (UTC) X-FDA: 82403680842.30.EE5019B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf24.hostedemail.com (Postfix) with ESMTP id 9F03D18002E for ; Thu, 1 Aug 2024 12:58:38 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ROUBXnl4; spf=pass (imf24.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517062; 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=N5xlaKfE1qe1MkU2t/MFh1LCl5bc+UWmzF2cua6bJB4=; b=iKWCS9GwpTiGnpc2Z5bi9vAzC4GwBdVXqJIMCsA6zmg4JLZgrwnMRLyLFiqkr35lidVtS9 w+RYvDmaQwkWGQ4+HCZc7b2WeKPusyRb1gr4UJoDOgnt7zGwqRZwM0aQvjgk3MD/Um+e8u My3IwdxvY83WfOqluXPAUB8FFMCyVy4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517062; a=rsa-sha256; cv=none; b=rN0zBaTzoPITQK6iqcLVxI4/vN+TTZlg4F26AfSh01zjFY2oukmZLrL+CGUxdrkn8cLMZB gdsRgAklDgmjtD/JnM4WWTQVqXUdz4BzCR75Dr+8xpIVRciyjC9+ktHRAW+qkDhRDU6l7V HYcaIBXYsvAG5hAdHBds9fV7UL+7XZc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ROUBXnl4; spf=pass (imf24.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 0044DCE19AC; Thu, 1 Aug 2024 12:58:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC1D4C4AF09; Thu, 1 Aug 2024 12:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517115; bh=WqKsS1qVwE6VKZ/8GkyAqMVM3MB00X49lYjibfc4BZQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ROUBXnl4pCUlqrD8GJYnW6TX3c+9d0zCM9U4fas+nBWuRkaQxwqdCtUnMKn8bqn4f gW4iKyPY2BVlKprVB71QI7AD33rbq+ETEhOL6iuO5JvB9SMkUrkTStZWPD1i68dhyb xrmgb+ZCT6FWojsUOZj6gd351PNsYtllWfnQ9H6jTgRUnAAwhl+SU8CZABDSrCminc eZ03nbwXn+jgVyL3n3WwLazRMvDgaaXLZFfeEFi/Z8UW9cKpE+wlA67ra7OMyRFL4M bMo93Hh5OBkmjVzrucQT7Ty5gGxK4EoGVmfiKpacjYLdiBgBtAmHlK6Bgcyy0QWbfp u9RKn2clTauWg== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:38 +0100 Subject: [PATCH v10 11/40] arm64/mm: Allocate PIE slots for EL0 guarded control stack MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-11-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=3028; i=broonie@kernel.org; h=from:subject:message-id; bh=WqKsS1qVwE6VKZ/8GkyAqMVM3MB00X49lYjibfc4BZQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YOlw9nLbDAyfViEdCcT1ji+c6735KeAWlvvJky itB7ZKSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGDgAKCRAk1otyXVSH0CDDB/ wI9T7bi6abhO/KUuxju+FabJ0MVht7CEjsBZwh9yuAMi4yLWNjlkcbPoiYxYxf+m4npTmnb92xs5+y HoCgsimyU+aKqsGKW8nKV97vp2l+XL0bVtlo0io9mbDGWnuR9SRwRjpCeYlvr2rNG5hKdKGNjO59Lg T+ofnDExR1esJIq07OYzfpCyYICWbVuwh6WapUICDZQ8TKk8wBmDpNXHSVaxX6TE8vCRIdzNk2NT+0 6G8IURvioQ2LXI6/BS7qAZHW7jrdkFCvuEBC6VwbGn1Y/ODhX142tes7v+8niLXK5tqhALMDxjY8CF 0rPaynHjFv2HxlL8DoQmbg6pdswtZW X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: sedqsofzk461cprymzrx447t6ymquktj X-Rspamd-Queue-Id: 9F03D18002E X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517118-639269 X-HE-Meta: U2FsdGVkX1/lbFG7mytJVZpcRGmhrAMSpRpwFzrR/f1rSd6Vv2bt70hWr16GzM6AmM0nXBl+0+C6FBeDDox7/YmYtI7Pe5WDvlDfMUGW2K3qTFcWLeIbxTqqeBa2Bs1KOWHIQith6U6Gs8PcegiAGfox0SaqtxdSu8fMDv65aaYl12V8yWsmF2jE3zObern86t8fTGIMPg/Xbn/C3aM6x8i0Pd2W2VRqjzlQQdOZqBslh5uSUR962vqFAL/M1RqE35JPes9TQUBRbT0EFSSXlA69uEYVN42pqymHTf0LIMIMX1Io5iKuAD6Z+mCGE3L0q/PdUGdhEasggLatpnIr3Hlu9bplGXzAktxgKQ1K1pEmjektvntdRjlAgbTEf/jXzMxJCCZ/tQ1gzWgD3RYfK7TJiDU6rAXEoSjphXmpw+GidZ4z1+Rts/0TpvIbgAP72kDpfUkuH732AyRbsKhNAaSTqA+eNnanthWP+/aEwzYI6FEsJg4LAokqLuANcCvLSByq8n0OsmWq7NS6hvI5qol1ru73+bm/wxsAyub+eFGTU1KzNF1nMaovmYH7GuKi4Oqk3srqfu/UMksF0vfxnVHk4Ot0cKcsyx8cz577olmfyBNDr6MhTo2uyT/prITrVCsmZ6ZfW1jU8/Fiq9IJxYT3da4bx+H2DQ432Mzp9tF7j1kxK0EXiU92O7tw2xPS7UAi70qEKYaXe/u4Ng8omi/pzRnnNqSrnqKG8ZkroC9KQzge0V+Cm9INlqsrlYZkLdwifS5uIBzE+RXd66D2nvJwp+qgkBTtsznLUewQ/OtYN7EzMUAAQLrAH/NtnUBbquiyjgBQRJtirunWyvbVRroAbSMrIHHljPoGzyUVN+5i5eN/0ga6uVbJN9V5GfOQDumqN9FMW9gujcrh+V9NZu74KHdrnS/qML9hPyvmYHuuq4JXQV9eCdjLaE21zLNy36hEM1ksP+qseNuiLFo /cq1xN8H NsKXLysleB4+tb1+toG8a2fHA+vrN4Z6uvLrb3EqNukERbgl4FZALd2lyRVM9wgQnzeJN9KN66IABHVEhNoHZjLsFvjIWhMShfgHVPbGlAtsr6N5zrl+u7g2NU/qZEnOB/xKlIxY7tElR0rQUQbfrzQtJop2u1V7+SxbcDPN/AtHwaC3dGkv7SPMDywYZRwhHK7LIT7BAqtmqCIH+yrlP2hx/wOt77mfvaVGKorHxmblSqhSBhdFGpleRkHJRe9F28jXdUNN3B2L3z0b2/kIobToGcy7x4v3YHsJGe55C7dDk2hixPSrhgXIEeJ/kGfVjrcUf+vowxCyGOf+KqgJ6Dws88huJn39R+7E+lk9706/qvh7iDeKFj34POpHij/qVPv+b 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: Pages used for guarded control stacks need to be described to the hardware using the Permission Indirection Extension, GCS is not supported without PIE. In order to support copy on write for guarded stacks we allocate two values, one for active GCSs and one for GCS pages marked as read only prior to copy. Since the actual effect is defined using PIE the specific bit pattern used does not matter to the hardware but we choose two values which differ only in PTE_WRITE in order to help share code with non-PIE cases. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/pgtable-prot.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index b11cfb9fdd37..545d54c88520 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -144,15 +144,23 @@ static inline bool __pure lpa2_is_enabled(void) /* 6: PTE_PXN | PTE_WRITE */ /* 7: PAGE_SHARED_EXEC PTE_PXN | PTE_WRITE | PTE_USER */ /* 8: PAGE_KERNEL_ROX PTE_UXN */ -/* 9: PTE_UXN | PTE_USER */ +/* 9: PAGE_GCS_RO PTE_UXN | PTE_USER */ /* a: PAGE_KERNEL_EXEC PTE_UXN | PTE_WRITE */ -/* b: PTE_UXN | PTE_WRITE | PTE_USER */ +/* b: PAGE_GCS PTE_UXN | PTE_WRITE | PTE_USER */ /* c: PAGE_KERNEL_RO PTE_UXN | PTE_PXN */ /* d: PAGE_READONLY PTE_UXN | PTE_PXN | PTE_USER */ /* e: PAGE_KERNEL PTE_UXN | PTE_PXN | PTE_WRITE */ /* f: PAGE_SHARED PTE_UXN | PTE_PXN | PTE_WRITE | PTE_USER */ +#define _PAGE_GCS (_PAGE_DEFAULT | PTE_NG | PTE_UXN | PTE_WRITE | PTE_USER) +#define _PAGE_GCS_RO (_PAGE_DEFAULT | PTE_NG | PTE_UXN | PTE_USER) + +#define PAGE_GCS __pgprot(_PAGE_GCS) +#define PAGE_GCS_RO __pgprot(_PAGE_GCS_RO) + #define PIE_E0 ( \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS), PIE_GCS) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS_RO), PIE_R) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_X_O) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RWX) | \ @@ -160,6 +168,8 @@ static inline bool __pure lpa2_is_enabled(void) PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW)) #define PIE_E1 ( \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS), PIE_NONE_O) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS_RO), PIE_NONE_O) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_NONE_O) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_R) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RW) | \ From patchwork Thu Aug 1 12:06:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750391 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 A8054C3DA4A for ; Thu, 1 Aug 2024 12:58:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0EA76B00AB; Thu, 1 Aug 2024 08:58:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E70EC6B00AC; Thu, 1 Aug 2024 08:58:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEB256B00AE; Thu, 1 Aug 2024 08:58:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3AE716B00AC for ; Thu, 1 Aug 2024 08:58:45 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D822AA741E for ; Thu, 1 Aug 2024 12:58:44 +0000 (UTC) X-FDA: 82403680968.27.8A72214 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id 19A5318000C for ; Thu, 1 Aug 2024 12:58:42 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OMtPH0QQ; spf=pass (imf24.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=1722517094; a=rsa-sha256; cv=none; b=nl6XmewAhGsLVmjo8T6HnPcPZ9dpa0OgYBglTUG16jQ2Jn8cqXFDCVLL26F8bCkA38YAwX b8mIVRNmf0XJlFhvH2AyDTi6luWZe0h5pUewOrbLC/aOrelGo1vQr0+CUQEaV6HWnYX9c0 vS2HUaGVGcLeXDor4XSUfbEsc+swRf0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OMtPH0QQ; spf=pass (imf24.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=1722517094; 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=rduCnP/qJ6ZTgC132xa6OYShmwb48ROC/5R9Zzk0HAE=; b=mKlPLg20+rWgjNdMrWYqvxK6Qz+1c1MaCQtM/Pw+89wOggiGIvVgSr+XsnfwYT34oNHX8J opBXTEbQNqs7lvKPGlbNRP58q+gKzjtpqyH4Ve4pvWHz4p41et7KIOBhsqhytxa9m/1Z+d oFUoPmbbIzkhTeKdyCe0BeMCB/vixLo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3BD716288E; Thu, 1 Aug 2024 12:58:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AC6DC32786; Thu, 1 Aug 2024 12:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517121; bh=yrclwp0293yC9GB/YqBAfQERM0nqbhUl6FyE+eoviK4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OMtPH0QQtyjuzyGFLmvxodnUhI1RcowGJgcVcqpXjp4OIMCKEYXxKeS0Zloiu6ACe 7Y0zfhO07G3VFrL/o+SIq6MmOl0CJLDz3Wt6U0/2E55zxehJVMzg68p8qQVBCwdKiZ anTd5o27Tlj8IjZenRvzKlL3K8DnhbnStCp2mm7Aj+m14jz3gCWAaY0P1ghrYK8ThN sZ0TjouWrlUahzC6QOq8d3RjUdUdVoo6Dt9TxzB077E65bzGk5bzRo6b5CF553uAV/ 6ys2f9aLFBLXha2iCi5+SRM03qQNBGQHs4Y6nVLW37PCjew/gusoTL2CruWyy1GzK8 6+IyQV6Ac1uTQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:39 +0100 Subject: [PATCH v10 12/40] mm: Define VM_SHADOW_STACK for arm64 when we support GCS MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-12-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=1520; i=broonie@kernel.org; h=from:subject:message-id; bh=yrclwp0293yC9GB/YqBAfQERM0nqbhUl6FyE+eoviK4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YPVQ6/NKZ2FgJD9BDBgenwO3uVt2vwx+JEk7wS a+dSp5eJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGDwAKCRAk1otyXVSH0PO9B/ 9FjPI6PZJke3DvcVt+TVF5+jjcO2FhunyyoZQBXwVwx0e14Z0TzTQv+M+eqDtAdVaXxEw+nVpGUhKj Rzyuud84uh5DfziIcGXe0HGokGGysRLk9OSG+dbJcWvI929qOFL/U5T2T/nCAnz61Mop8929qqKQFV W6vCejrk+xyxch2pG67qESCQw8vVyb6VAx2Z4PRuLxokX1bbhCX6+vRKt8Fv1dw01bV0RUfa8/6NsL vrLpbU65aCMhK4yG3IA5211146YV98aCoLl9L2ka2dgkMxupbf+n9aISI9eXd5SlWhJZBx2craAReK S2fhv2FZ2s1iixEVEAAABxmUNJ0aCK X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 816647rekaw74q9et4jmjprfshge6srg X-Rspamd-Queue-Id: 19A5318000C X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722517122-659656 X-HE-Meta: U2FsdGVkX19xUx2mdQbkj0yoq4bsGykbRyEjavUzKrnu6ZY79qqA2P0HgLkPoizmLJx8HETmu0YzZtnLgCAaKiS6vIhVAysCT0A08v7MPYHqt2ryhbVDUrip7huqDq8uTTQ3cAs3r+FYjo1/Y5D2ksnHZkDtMqlmfyCqjVlewZU58RzHcQ5FxBbFwneZrsvLvJUtkIeonoe5Ak70p427zQO/4rOu8IrpcW8RFRoP42OmacNLrMYL2S30BMiY7JUPnAbRWAiaO9XKLd09cqDcxYPCrYRf7UbuuKYLIt9OoVqar93dnZOipaj68wSl/POWF1mXuAa3S/UotvAwQRAZComz62FtQTEcRl0GvMb07vz6ejBNizo8rFg7NbMky+xmF/b+/5rI8dHP+jNFncdVLujWhshO0NvODoARtiFk+/T/LNb9BqTyFAo2On/WRuft63wuOaws9V8rsG9KkyJLWM8P+VGedLCy0yhUprJ3BqAHF+WWJPG5jI5zaI226FYFEfKaz6JbKTaBold6LQ3wITqdNy4mZ+7xC5lFAr4K053WAiAYyUWRQL8ZRX9+VELoe6ma/jy2wux2kftVCwz2RiVXoDsu9uti6Fdrh2nV/Oz66b6eh/+csb4mnTEt0M3eLgfKIshfTiFDMVUiGi91OMBlitRUASc1gr3CbVCnA1Jd+wWDrJWlm8WdoJ8UaCY0K52s4eta3oH46/rvcMc7DM37HU6DT/Bp1xctWlPVrd2Ah4JPJUO04hsjCV1RNL7zQxfv/JduYrYLnZZKBqFQ7cNlE0w8b0hwUYGSmbLN5si/hEdfzP+hnWIm6jHiS0/XS+QJT59Uf33gNU6+1dgt/dxmBmnIelHswAmsXf8fFwznrsa/zIrFrk+Sso7xMtMTncZNrCeud7TfHFkPJc2XCEq5asj9xDZGLtK+aORkKFp+FzgvTw2vn15OSRANqn5idsl1FuVxxSXUh1yVFcp yYilw2ec I9eVRO2WIvifg0N1TqcvXIoOLk3UuLzCAMXsmjeFu3nvYPU3DaIwXoBqaUhYlAZzIGquscUBnTUFBX13mBP21UvQZNqgYsUveE9WXgptlF2uYCpTOmL8v4A2r5rkiEyUpdx7mAOLPMrOWqZ3Tjp567ptCQhu7/jQqsaFvCBm6TRYfAxZJ/c2ScUwzuTncjtGNh58F6FokMJdA8xHFQ38Czlc5qVG5OG7jZaRwFdwEs4ZtA6GupwJQB8csMPgDBPySJ2ilpJg/NHk/io0IxdkERPxBkbgYblZ5BynGqCGET9ZKjciFz2WO4KZOsGQC0xuIPp0MlktAgjhUzh7Cogis+MrRBlYJDrOqHnE7B6QzGagcnA+XuYyR1JywGSTtMGrHeuXyS359OdK/nXOWpuTj1Vh6f7dMW/yH97PFktER/mCzeAA= 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: Use VM_HIGH_ARCH_5 for guarded control stack pages. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- Documentation/filesystems/proc.rst | 2 +- include/linux/mm.h | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index e834779d9611..6a882c57a7e7 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -579,7 +579,7 @@ encoded manner. The codes are the following: mt arm64 MTE allocation tags are enabled um userfaultfd missing tracking uw userfaultfd wr-protect tracking - ss shadow stack page + ss shadow/guarded control stack page sl sealed == ======================================= diff --git a/include/linux/mm.h b/include/linux/mm.h index 96faf26b6083..c6c7454ce4e0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -353,7 +353,17 @@ extern unsigned int kobjsize(const void *objp); * for more details on the guard size. */ # define VM_SHADOW_STACK VM_HIGH_ARCH_5 -#else +#endif + +#if defined(CONFIG_ARM64_GCS) +/* + * arm64's Guarded Control Stack implements similar functionality and + * has similar constraints to shadow stacks. + */ +# define VM_SHADOW_STACK VM_HIGH_ARCH_5 +#endif + +#ifndef VM_SHADOW_STACK # define VM_SHADOW_STACK VM_NONE #endif From patchwork Thu Aug 1 12:06:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750392 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 EED0EC3DA4A for ; Thu, 1 Aug 2024 12:58:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BBA46B00AF; Thu, 1 Aug 2024 08:58:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 722196B00B0; Thu, 1 Aug 2024 08:58:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FF2D6B00B1; Thu, 1 Aug 2024 08:58:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 209246B00AF for ; Thu, 1 Aug 2024 08:58:52 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D270CA0D6D for ; Thu, 1 Aug 2024 12:58:51 +0000 (UTC) X-FDA: 82403681262.13.4A95784 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 0CC9280012 for ; Thu, 1 Aug 2024 12:58:49 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dyQayV0f; spf=pass (imf30.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=1722517125; 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=avsILOT3E2XKHkvtmgvPkA3e9X+XY1/RIVi+DZAo1PA=; b=tBdoj0zah8nKZt9RaRR3WAVJqMBu8gGjazyj2Ft8+Bl8/DT5x1NhTqUezM+wpLQac7uQyQ bFX1OzX/+pWZ2expGWaMGsrNFTdGe2J2GLpRsA1NtqtDbAxwNeVfTpIeq65iGZhRLdy5m2 irB2ttH0Yvqn6y6sA/Mt0kdLzLgXHu4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dyQayV0f; spf=pass (imf30.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=1722517125; a=rsa-sha256; cv=none; b=CLt4FNjwMKpOBdbPXZulpy5IeQGe1fRJRFkhi8pKlTU9CppLu9YsKaA25eTr0ImKeUhbLZ TWYdGXmMYKqAwYfN2qT5lIR3PaIuIXgnDOK3K6RlKBFUjYfMWk5gMUSZ/0LYbPWOfUaThm 7Tpr33xqEH4AWsVsz+Uks2mhIkZk9zU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 33B4B6289F; Thu, 1 Aug 2024 12:58:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CF41C4AF0B; Thu, 1 Aug 2024 12:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517128; bh=iKC2Iasck77jV+Uk+oAXshC4xI2+EzWFpjmjkamUboo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dyQayV0fQPSZH8iBt3r920gWMR8PRqUKHxVxDgPQjyeJut555M3l4cDwsz+/L5qQS As1Fxhi/6bCXuwjr9NdjvBX6wDqf/Fxi3a8wGAE/qWUiZL5LYBhtTcPbxCWz/QML29 60npbjduYtAn0JzFHAUE8zwm6Q1kOxEoiKce7sC4wvjTflnDQ0DF9MalXGTrLYgS8F gXhhRz+nBXf6sqzaCfAlsMkL7do3RzBVthp97yDax4qvCcZ3OHQ8g2VY2PSqMAZLNd IxRDzjVoRVEX+F42dHQhDdgLvph86KDdI1LnkW1mniZkz3+zak2yx9Ro6Xt7xlGQRb XzXuKvipxoNHQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:40 +0100 Subject: [PATCH v10 13/40] arm64/mm: Map pages for guarded control stack MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-13-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=1838; i=broonie@kernel.org; h=from:subject:message-id; bh=iKC2Iasck77jV+Uk+oAXshC4xI2+EzWFpjmjkamUboo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YQi3D2wTTUJjuQQY3F7F1CBBVgw8rRNdzwjqNE tB9JpyaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGEAAKCRAk1otyXVSH0LglB/ 9TWv0MHUp/MwJEjSWgKUaa9AI9T9ei3Yo/iBGwhTkm2lo8TZTWMdtH0ztI+7/sV7Bv2+cOXKDxO8Wn xdLbDBsr/gw3zkkssfqjmj3brMAAxPZsleH+Lznr+NV+/0NRHmSZxbVAVa0JsJVu2db+gWre42Wu2T lPKPmT9WC8gLVXsjaY6dzYqMNV662wcZ41nyv8oPea28bIjpwZZNSJspMdUGqpSQdGnjZp/yxu68w5 Y//Qbhz9rxsr1xOKKwh14tKc+nbFMdl2zKPVWbv5yGUS5EZEVUxqENG9eNNKup/HT0n8dZcq3Yep9V Z6RDFNJfx4fCy4UAAQiNxjCf+kO5rX X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Stat-Signature: 7y1499cu4pyexf8fbjrpxfbr7rrrfdhz X-Rspamd-Queue-Id: 0CC9280012 X-Rspamd-Server: rspam11 X-HE-Tag: 1722517129-82857 X-HE-Meta: U2FsdGVkX197IpqoNlhn/zipe21d50f9stSaeHOWhpmnd6VYs8sAowqY+yj5yLXrbIFFTuSWbgt1YEHhss58A6TvbECIP4eFSfn77YGMvdr7hVJcLM/MMxV5sC8Fou/PcaKL5D2k+7NAwfecQWmyoK0MKJS/5u/TlAhp9J3M8Qu7Mqx0difE/sU6bSRz3do0fOs6+lHi97qk8dmZQIzm2dLCzvE1EiETiCvYlmh6qtv2HqU5epppu/BdPBCk3ADYnt38Y+CpXdDA+jymMtaH7f9IpkA2AmBUa5jiVamB65E6p3qm11hBzXNTkwwOS9QnHTT3aAhiM0yZI5+m6fxw56n2ftADhy38mpBKiNdW6mHX9ow0jAKWJTx2oLHxIHp4UodBHlvK/XqrpNVpAFmc7t6Vx3b6yrwKmx5HKNP2j53XmIE7+MgDToRe8bsTmYog3poG3GV7ghA7Pz8x7RIEn1pc2IrhZXluyrsC7pV/wwD2J6M5HItUxzCTix5xL01HRDEhwrvzaMKNLZb2SYifkWCimbui/L/1CwpHsd9BV8dFmJgiYOzb1luUii8tMRFuzw5v5k40IHG9CzLxUXYkB0dWt84+XJNFkJINKpzil5rvjS2S8IbZOkA2t8GHpQ5CxCNJG1JPfB6Dg+HNCKGtbmu95B3+At4XeawgSFzRZvTm3S2V8sR6UykvIWhcpvsaQBzVZGPryFe3zyhXb5rB7JA1uznPYNaYeVKc+kQzbNZtIqsDCas3RgqaNLjcvoYOUChcIqBYldTmWxud5flgBbnvOVqngm/kbiXmrbJfpHvNAu1ATVZkvIrB1d4h9pZtsSrRvRjmjLmYk1XHN/So8zexPC1+/ZEdArCB/I+PG7EjFq7AJcFQexl3dlP23qqf9fBIrNKzyY5KO4XzfxZrKWX2YZbWqYy57WmZNUFqXBYBcQ955UpvibIoHKGDdkfKloTvEiz2NdI+jpgpPAB A8gzGLhw UVQFRYMyFaRUgj7VItZt9I+jltZ6wzrHU6/vp1qMGfo1wGCNrfpEb5BPix/9faMfh0pPDgWWsjG9pgiz84V3yID648xtF8SIqaMazUPNtiahyOIbzLjI2KGxPqVMtVsUlGaZNnMMwANXx5ri1CvIBvxBUWNNILnOWhGNHCK97c9X3MrhxXjc6m7OoVTJedx35pTMNUpnRe+YpfcaohgQcAc0KI/ycZNgPa3V5658V+lm7BPX5gbNKSrMEnjx2d/fZx7UoHgFl6xEd5mMgrimnXHhVxugCnYvfgvECO5TC/PoDO4KwUoHKKlK3sXT+BR6lSI9gcDLtGRAQ8khriIhMJC5t7aWSiQC+FcXbFPgYSaCqO4qFpU+m7DTfxflPNAn37qaq 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: Map pages flagged as being part of a GCS as such rather than using the full set of generic VM flags. This is done using a conditional rather than extending the size of protection_map since that would make for a very sparse array. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/mman.h | 9 +++++++++ arch/arm64/mm/mmap.c | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h index c21849ffdd88..6d3fe6433a62 100644 --- a/arch/arm64/include/asm/mman.h +++ b/arch/arm64/include/asm/mman.h @@ -61,6 +61,15 @@ static inline bool arch_validate_flags(unsigned long vm_flags) return false; } + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { + /* + * An executable GCS isn't a good idea, and the mm + * core can't cope with a shared GCS. + */ + if (vm_flags & (VM_EXEC | VM_ARM64_BTI | VM_SHARED)) + return false; + } + return true; } diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 642bdf908b22..3ed63fc8cd0a 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -83,9 +83,17 @@ arch_initcall(adjust_protection_map); pgprot_t vm_get_page_prot(unsigned long vm_flags) { - pteval_t prot = pgprot_val(protection_map[vm_flags & + pteval_t prot; + + /* Short circuit GCS to avoid bloating the table. */ + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { + prot = _PAGE_GCS_RO; + } else { + prot = pgprot_val(protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]); + } + /* VM_ARM64_BTI on a GCS is rejected in arch_validate_flags() */ if (vm_flags & VM_ARM64_BTI) prot |= PTE_GP; From patchwork Thu Aug 1 12:06:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750393 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 A00CFC3DA4A for ; Thu, 1 Aug 2024 12:58:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 266BF6B00B0; Thu, 1 Aug 2024 08:58:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ED476B00B2; Thu, 1 Aug 2024 08:58:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 018006B00B3; Thu, 1 Aug 2024 08:58:58 -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 CC1566B00B0 for ; Thu, 1 Aug 2024 08:58:58 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8DBCFA6BF3 for ; Thu, 1 Aug 2024 12:58:58 +0000 (UTC) X-FDA: 82403681556.09.5DFCB01 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id ACE8340005 for ; Thu, 1 Aug 2024 12:58:56 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Lc2VtrSa; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.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=1722517131; a=rsa-sha256; cv=none; b=wQKPkZkXIrd8bcAt8INpXoL1jXDZ7+kovJzj4XOtkO1bhSbtCxWwYWyQIAf4LJz5jg3fzv ofAZtpJqKKJ/SLTqqf1RBcNcFiS9134kmVI1jPkSX10y2tJxA//DFHUAk3ca0K8XcMy7Gi N1KAo/LEPudLagDyGAxF161LTeIHtF4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Lc2VtrSa; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.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=1722517131; 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=MB9ShdJ//AJKp7KnVC+clON/hX2YB6kjPPmxeq9uxO4=; b=qcGs4nYP2eFq4lV9iNNfmsI/ObsKi3o2lOzhgiDXz5g78xZYl1RWx5oWQ5brzHYsSFKYk3 KlTMRB5zzLrZUSsReJvIh+CntKXAezwr/F806l0zXzZcf3E4OE6qOqR3b2hCOrgCM6FKoM 3U8sgCLE1dT0+cwtmRzVluZWOwxswb0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EB5776285D; Thu, 1 Aug 2024 12:58:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46D56C4AF11; Thu, 1 Aug 2024 12:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517135; bh=xossS2HqrkBDMWtdlnAZqELtip1cq4iphga412zWfzk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Lc2VtrSaehDUjYoWf6PiYqYXnkQ2kQkoazm1+3KZubpXUot4ouPvk1P0FJa7crvjk OuEEX/+dGLXLPyD97VPDi78n7Bc85R0iDJtNEjDgdGTsTXZUu6JZhCq8O8ZXTIJhSq vM1R0ZusO3AzfHvtCDIlCkAGmgYJWGP74hDad3EzyE4n+fR0msuI0NEdfAeGWub7/d ciCU57Y5d+cWjf6OKVUbKxy1FjO2/NBUPoSp/6Ez8yKcok890u6Y4lUL7l4oz6+w+G lk0Z+0ySarwCOucvlnjrL3j7W5vHx4KlQBpXsUnCMKfUsX2SWQhgEdz/j61dGPS4j3 cfBMN+01zQnNw== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:41 +0100 Subject: [PATCH v10 14/40] KVM: arm64: Manage GCS access and registers for guests MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-14-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=7311; i=broonie@kernel.org; h=from:subject:message-id; bh=xossS2HqrkBDMWtdlnAZqELtip1cq4iphga412zWfzk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YQ/T+BB+Z93oQBSjZAywi/P+Nx8EVKjuUaS715 C9vL/8SJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGEAAKCRAk1otyXVSH0Ji/B/ 9Gg1j9In0idh/ZRjEUDTjt8HHhczhLSqbVnta3Nad46+7NVICzVQiIH0haNI8X86B71oW7+8QeS2iS dBH9gx1Bz1Br5B4oTkJyCdeSdqge4aMj1GtbA6VItWCtZVWUZt7T0a6KlKufaTLzV5hAqN3P7jH/v0 pAdU7FxnO5fKHLUOYPsYl1Kca9qL8ENLHmBH/CFhgC1srsTe/akQ4Qv3R0QTDYHNu1yh9Jwg0q/EID cqpayNozEMBaZsM4rl1/LjpKDktWRm+553aFHHp7Bd9JUi/akSUl+YN3Wca7UtEWpKMEzJdTReQebq IkiBtDNAzSHU3CRtznbt1BXVC/4Tm+ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Queue-Id: ACE8340005 X-Rspamd-Server: rspam01 X-Stat-Signature: soybcgf4w9thzwhawjxinob3hebie6mr X-HE-Tag: 1722517136-538227 X-HE-Meta: U2FsdGVkX1/QNDgku3iEF09APzhBrX3Ft8QSrUvdLsdFgVgVBtAgG8TcBaO9XK4+9HeYNan/sxPCWPuXImvQi6m0Oe2moJeaoEIvv6lUIk6zUZ4I3hA8xOyu0IWX75CtlvE2BXyPcy5I/izSOUjpqczn0vIf282QT2xfF6HeJbkD7OTyhiveYZwwg/khmgCeii1nfseVxSWx3s+yck0EiCM8K/3VrhjyBnHlnuVKWx3H0HoiFgGdqzh3vIu5fd75e3kKuwkCuDVS7SxZIyMhFWYf3GCTqvOYXFzSl8VJ9JDYucroYHE6YNLwmLbvB5YJIRstQbdo/7FZEmjafSQTZH+0mwENovEor7xpdoXmqEQoMaz/Z8T+btnFkmQRuqTDVQOrBUAilAi/A2lPwKr8LFLSSjnryFo0kMHYEf7R/XQ6ZqNCbdpoGQqcdiju58jahCnYrIo2egR0Dsswy2IKO68kOpHOw04MYuvmofiiOBvptTT8umHdXlv0jPvxe7aAUUUfrPJXij7n33ydeRmrCnb9Y8CgXJ30FkDqmgIHrEO0wujyxAuTk6893a08SM6uT71Y+k4lcfJFi7yS6OHkqIVDzjGzktuwyZPrIeiKYg/HCKBIdDlTVB1DqIxOCxoWXw4/S6ONAx/kz8S4J5QFnrvWmyRcdnSpMIPC3r99VFxyLXIFIto9QGtJip7rE9jmHfNWzb+/tmo+J2Sqav5plqDDAJzHemUaUmLo+NmPQ0UbgWUqLTNngVpYQbEbfXFqSeuOv6pzR+KbmnK50mnWrLyg82V5kwdEBrq2atf8oWE+TspPUCdDzhUujlzZSieelHS3pGywWGfyIFo08AluE+xTA0Cc+YzHkIIbbpDrW2rlIAjoEQV/7V7Qav5Kh9ctCMnFdZeV6hmmSVv6uxTwgAoUnTPkEsXaN77RE3NhAA7uYdfwOx88GXHbgLQbJW/629NTdVulxl6wegRuky+ 0iosQIKg r9s4AF93fwNvHsZuBX+ulQO9X/mWK86UqvyiyZH2CWhvY56OTpnnzq4GOmvnf+gFas3hOAch0URfQTFXyRyRWpSWgM2fq37oL19RkKTvC/3C6OIzDIVQFUuh+3BJ/3xeBB4SFtrZQWfl99J+8k24WSKOuEdVmT26B0vgHSbSfoRhFg0PvbNuNCACx8h57H8dhKWRfXRhieCbkn0+xOLo4Qc2CVCsW2iddepM4vb9B7B1jqibRRbx7ZervUZ4AoiwBAQ0+4ex4Z/H3pHJLIImJLq6fQDd7wGpKc5HGaIcIyEecH9n4AedsZjs7fZ2tT8PDmyN6 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: GCS introduces a number of system registers for EL1 and EL0, on systems with GCS we need to context switch them and expose them to VMMs to allow guests to use GCS. In order to allow guests to use GCS we also need to configure HCRX_EL2.GCSEn, if this is not set GCS instructions will be noops and CHKFEAT will report GCS as disabled. Also enable fine grained traps for access to the GCS registers by guests which do not have the feature enabled. Signed-off-by: Mark Brown --- arch/arm64/include/asm/kvm_host.h | 8 +++++ arch/arm64/include/asm/vncr_mapping.h | 2 ++ arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 49 ++++++++++++++++++++++++------ arch/arm64/kvm/sys_regs.c | 12 ++++++++ 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index a33f5996ca9f..5818e4a1c2d1 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -446,6 +446,10 @@ enum vcpu_sysreg { GCR_EL1, /* Tag Control Register */ TFSRE0_EL1, /* Tag Fault Status Register (EL0) */ + /* Guarded Control Stack registers */ + GCSCRE0_EL1, /* Guarded Control Stack Control (EL0) */ + GCSPR_EL0, /* Guarded Control Stack Pointer (EL0) */ + /* 32bit specific registers. */ DACR32_EL2, /* Domain Access Control Register */ IFSR32_EL2, /* Instruction Fault Status Register */ @@ -517,6 +521,10 @@ enum vcpu_sysreg { VNCR(PIR_EL1), /* Permission Indirection Register 1 (EL1) */ VNCR(PIRE0_EL1), /* Permission Indirection Register 0 (EL1) */ + /* Guarded Control Stack registers */ + VNCR(GCSPR_EL1), /* Guarded Control Stack Pointer (EL1) */ + VNCR(GCSCR_EL1), /* Guarded Control Stack Control (EL1) */ + VNCR(HFGRTR_EL2), VNCR(HFGWTR_EL2), VNCR(HFGITR_EL2), diff --git a/arch/arm64/include/asm/vncr_mapping.h b/arch/arm64/include/asm/vncr_mapping.h index df2c47c55972..5e83e6f579fd 100644 --- a/arch/arm64/include/asm/vncr_mapping.h +++ b/arch/arm64/include/asm/vncr_mapping.h @@ -88,6 +88,8 @@ #define VNCR_PMSIRR_EL1 0x840 #define VNCR_PMSLATFR_EL1 0x848 #define VNCR_TRFCR_EL1 0x880 +#define VNCR_GCSPR_EL1 0x8C0 +#define VNCR_GCSCR_EL1 0x8D0 #define VNCR_MPAM1_EL1 0x900 #define VNCR_MPAMHCR_EL2 0x930 #define VNCR_MPAMVPMV_EL2 0x938 diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h index 4c0fdabaf8ae..ac29352e225a 100644 --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h @@ -16,6 +16,27 @@ #include #include +static inline struct kvm_vcpu *ctxt_to_vcpu(struct kvm_cpu_context *ctxt) +{ + struct kvm_vcpu *vcpu = ctxt->__hyp_running_vcpu; + + if (!vcpu) + vcpu = container_of(ctxt, struct kvm_vcpu, arch.ctxt); + + return vcpu; +} + +static inline bool ctxt_has_gcs(struct kvm_cpu_context *ctxt) +{ + struct kvm_vcpu *vcpu; + + if (!cpus_have_final_cap(ARM64_HAS_GCS)) + return false; + + vcpu = ctxt_to_vcpu(ctxt); + return kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64PFR1_EL1, GCS, IMP); +} + static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, MDSCR_EL1) = read_sysreg(mdscr_el1); @@ -25,16 +46,10 @@ static inline void __sysreg_save_user_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, TPIDR_EL0) = read_sysreg(tpidr_el0); ctxt_sys_reg(ctxt, TPIDRRO_EL0) = read_sysreg(tpidrro_el0); -} - -static inline struct kvm_vcpu *ctxt_to_vcpu(struct kvm_cpu_context *ctxt) -{ - struct kvm_vcpu *vcpu = ctxt->__hyp_running_vcpu; - - if (!vcpu) - vcpu = container_of(ctxt, struct kvm_vcpu, arch.ctxt); - - return vcpu; + if (ctxt_has_gcs(ctxt)) { + ctxt_sys_reg(ctxt, GCSPR_EL0) = read_sysreg_s(SYS_GCSPR_EL0); + ctxt_sys_reg(ctxt, GCSCRE0_EL1) = read_sysreg_s(SYS_GCSCRE0_EL1); + } } static inline bool ctxt_has_mte(struct kvm_cpu_context *ctxt) @@ -79,6 +94,10 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt) if (ctxt_has_s1pie(ctxt)) { ctxt_sys_reg(ctxt, PIR_EL1) = read_sysreg_el1(SYS_PIR); ctxt_sys_reg(ctxt, PIRE0_EL1) = read_sysreg_el1(SYS_PIRE0); + if (ctxt_has_gcs(ctxt)) { + ctxt_sys_reg(ctxt, GCSPR_EL1) = read_sysreg_el1(SYS_GCSPR); + ctxt_sys_reg(ctxt, GCSCR_EL1) = read_sysreg_el1(SYS_GCSCR); + } } } ctxt_sys_reg(ctxt, ESR_EL1) = read_sysreg_el1(SYS_ESR); @@ -126,6 +145,11 @@ static inline void __sysreg_restore_user_state(struct kvm_cpu_context *ctxt) { write_sysreg(ctxt_sys_reg(ctxt, TPIDR_EL0), tpidr_el0); write_sysreg(ctxt_sys_reg(ctxt, TPIDRRO_EL0), tpidrro_el0); + if (ctxt_has_gcs(ctxt)) { + write_sysreg_s(ctxt_sys_reg(ctxt, GCSPR_EL0), SYS_GCSPR_EL0); + write_sysreg_s(ctxt_sys_reg(ctxt, GCSCRE0_EL1), + SYS_GCSCRE0_EL1); + } } static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt) @@ -157,6 +181,11 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt) if (ctxt_has_s1pie(ctxt)) { write_sysreg_el1(ctxt_sys_reg(ctxt, PIR_EL1), SYS_PIR); write_sysreg_el1(ctxt_sys_reg(ctxt, PIRE0_EL1), SYS_PIRE0); + + if (ctxt_has_gcs(ctxt)) { + write_sysreg_el1(ctxt_sys_reg(ctxt, GCSPR_EL1), SYS_GCSPR); + write_sysreg_el1(ctxt_sys_reg(ctxt, GCSCR_EL1), SYS_GCSCR); + } } } write_sysreg_el1(ctxt_sys_reg(ctxt, ESR_EL1), SYS_ESR); diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index c90324060436..ac98d3237130 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2446,6 +2446,10 @@ static const struct sys_reg_desc sys_reg_descs[] = { PTRAUTH_KEY(APDB), PTRAUTH_KEY(APGA), + { SYS_DESC(SYS_GCSCR_EL1), NULL, reset_val, GCSCR_EL1, 0 }, + { SYS_DESC(SYS_GCSPR_EL1), NULL, reset_unknown, GCSPR_EL1 }, + { SYS_DESC(SYS_GCSCRE0_EL1), NULL, reset_val, GCSCRE0_EL1, 0 }, + { SYS_DESC(SYS_SPSR_EL1), access_spsr}, { SYS_DESC(SYS_ELR_EL1), access_elr}, @@ -2535,6 +2539,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { CTR_EL0_IDC_MASK | CTR_EL0_DminLine_MASK | CTR_EL0_IminLine_MASK), + { SYS_DESC(SYS_GCSPR_EL0), NULL, reset_unknown, GCSPR_EL0 }, { SYS_DESC(SYS_SVCR), undef_access }, { PMU_SYS_REG(PMCR_EL0), .access = access_pmcr, .reset = reset_pmcr, @@ -4560,6 +4565,9 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu) if (kvm_has_feat(kvm, ID_AA64MMFR3_EL1, TCRX, IMP)) vcpu->arch.hcrx_el2 |= HCRX_EL2_TCR2En; + + if (kvm_has_feat(kvm, ID_AA64PFR1_EL1, GCS, IMP)) + vcpu->arch.hcrx_el2 |= HCRX_EL2_GCSEn; } if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags)) @@ -4604,6 +4612,10 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu) kvm->arch.fgu[HFGxTR_GROUP] |= (HFGxTR_EL2_nPIRE0_EL1 | HFGxTR_EL2_nPIR_EL1); + if (!kvm_has_feat(kvm, ID_AA64PFR1_EL1, GCS, IMP)) + kvm->arch.fgu[HFGxTR_GROUP] |= (HFGxTR_EL2_nGCS_EL0 | + HFGxTR_EL2_nGCS_EL1); + if (!kvm_has_feat(kvm, ID_AA64PFR0_EL1, AMU, IMP)) kvm->arch.fgu[HAFGRTR_GROUP] |= ~(HAFGRTR_EL2_RES0 | HAFGRTR_EL2_RES1); From patchwork Thu Aug 1 12:06:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750394 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 499C9C3DA64 for ; Thu, 1 Aug 2024 12:59:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC3FB6B0083; Thu, 1 Aug 2024 08:59:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4E136B0088; Thu, 1 Aug 2024 08:59:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7AB16B00B2; Thu, 1 Aug 2024 08:59:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 836366B0083 for ; Thu, 1 Aug 2024 08:59:05 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4803E1A0502 for ; Thu, 1 Aug 2024 12:59:05 +0000 (UTC) X-FDA: 82403681850.11.1E4A856 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 7BB7E40016 for ; Thu, 1 Aug 2024 12:59:03 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lsWmVmR9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1722517138; a=rsa-sha256; cv=none; b=LME5x9ILRhh13/w2uNTHyXQD98JHp8PuN/yxes/JN1Awc8GMPnNfUO3lh8Rlwg+mJSXkcc 8I9CQYZJInUigAdSvoEGkP+zwH/ezvdzSMWTQhCXTxPSCfNLrLIhkIitYyZc5yCg7brcWA bzNS/ULULm6OY3Fd88REUXCANcBeR/o= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lsWmVmR9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1722517138; 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=uSxBp1zAPNCG/WW+ciyc1p5hTF1NYzwRxhjEafzS+o0=; b=Mt83iI/zTFv05Orcm2yOMmGFzcpaWSxlJ6TelQucg2oo02mfOJUHS4+MdkHm0toMhU9MBz gyOeM9/uZ9rH6B6Rd/ZCf/LasExXB4M8pm/QKDFqYGCk07UW9vyCKb4D3JELb//inryqN9 +bJNSk+cvTndA+LYb+n/QoSwQc9yFt4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BE89262862; Thu, 1 Aug 2024 12:59:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1867CC4AF10; Thu, 1 Aug 2024 12:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517142; bh=sqqkmEeL7tv5Wag3oPKgOfTAFLsGU8mgkKcr3MnXRIM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lsWmVmR9E2WgjWn+RgLL3PyZr6vGUhI7FHJzl1VUx+yXtAGp0+vgrsnRfEzxQPGF8 JEge+ccT2xkgSqTTKc43BQibLAN2Ff4RkJ4PJoSfiiHq36EdVEfRfqOICFTDHlyr8x GcgGDskfrMLd5JenB5QNSNHYQDdI7ih7Buhel8JcvWw7f6aINoluBytmA5D0QRg93r M4g7QjLRiu/6424aiBNTfRGzdx1eRsiBF6rKOsqNcy6Q0Pje228gBVVj5rtCSH76mR etppI/EaBZzCpoQY+V/GiPYFFQi1152aNx0npfmoX6t233KMZBi0w0WeQw939JZ31j Qp0K++dBcU8nA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:42 +0100 Subject: [PATCH v10 15/40] arm64/idreg: Add overrride for GCS MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-15-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=1899; i=broonie@kernel.org; h=from:subject:message-id; bh=sqqkmEeL7tv5Wag3oPKgOfTAFLsGU8mgkKcr3MnXRIM=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YRVVwOZRbiJRdOh866tHwB9fWzGXz1GHzjC2YM YZxFiIaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGEQAKCRAk1otyXVSH0Ct1B/ 4i8fM2n38TeqWSOYLe9SGZf9V0EGaItvppKspC2O9Iz6LH2Ki3Uhm1aT8Y/219upgO0Pj+lApVwGQW NJoYZbJheeyUYExsZxy/tPp8NHS5vzITfA2Uauqqqc+Le+nX15+BzBtpIlqEe7FaW868OZNMz7+cUE NY5EGIt/Rkcvg5lO6Zh5mhBk+ERk9BTebzF7n2p4U6EdNmoBKBDo0Dc99B9jLdaalcDyZomv2B9i4f cUzrB3doruk6EOc7m8qoe84G8yflvsOjTcQ4weBKJmDitZfwE3twjnQBhTvlIrzzN2Ne4Xg4t040jI 8Txlbbf0NgH23Nmed0MqnbBcOo6gIH X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Queue-Id: 7BB7E40016 X-Rspamd-Server: rspam01 X-Stat-Signature: b7oxezt6chudgnq5tuwp3j74k4659zb8 X-HE-Tag: 1722517143-842106 X-HE-Meta: U2FsdGVkX1+nWGlRAg9JsFJ6LpI2WPvDakqanXigk02cnIyW+1oNXntvCEfJPo5Jue9PvrLyjVVE6pQzg9B1hGI361HBJ27ZpV72u6NC1MCgMYOeJY6KmLqV3gNsxTo57stClSdI4GPJawCAr1E21gaSMsVeb9uuF7Aumdbcp9uiZojPL2er85BFQYwhBGzOQ2yrKuZ2hN/x6cFB8LGrSEmH2L7B2zBhx2Iygohohi/60VDx6NkS3v+XY5HgThZj2OWFHPh/OvhJM+7iRozh8vI1HzBLJoxzDVSsYYg7+VcKNLTmH3kwMRmwQV65BqvXd9dvKsdBXjSCuP0ea0VnoYnEt/LzfJ+fIqBxNwlTW4eZyaIwM8ShvshEOEHlqyTJYjlyOlyrgIURcb6U5rBEu9CL71zMd+xP1GGmXdFJxs5QAlN7gz97cugUi6bs9FpFRnxP/JxqStRy0sFE/hpjgEO8wdUpVImIWtYN95m9R6+vX+A/vn+aNi3Ey8+5JOKsnjWo8CBKkJGF85io3H7jKaRII98cg5URgTtqdDxDflyBgpXqBm3f8w03/qHrQkv2Xdb9KI9TxvWtsax1ChnrbCP0Bwoxa7V9Y18OMMLceNnUdBMSghNx4aCx/oDstfaihb4Tdq4ua7Mp3LDdVORuhV/ZYaMd++SmmoQ8S7qkujfiUvmSwuo5kqwZwGYQfNQfaUtK7Yj0ZpiZK46z7kdUYZpuRAZUbI1/cHcq3lBNMPjgLYnjeOG7c9MPXZ4HEldiDOU6YP18zaEKyf8pNPt6C8rbCT+0kTKW+GWWHNcZplKwWeutqFYsyTqpmKHcGypxuPUwG9+jmbPPZLAmRhWaTxrZBTqzfScnKGRuyOslvgTREGFWGGWfsgUWdud/9UJVHAo4MLb7O5LaYD8syReNN5gyOFvQOnuunvi7G+01+n0/4ruq2CRSrnNu4B1Wns/YUuFXwHQWmx8cqBJUKzh 09z7LXPV f/Qa/tTMQSoxTQtVrRaFkdxq0HESewUn8ugKlieo0LSWwSr7NX8rkr3UpRjTnA/41FLctfy3aQeDZh1rCBdQqqCgq17BoyZZmvlwNTZZdGlKQPu5ENyrgZxkf/Fns4z3qFqGQKzbMuk+VzX/Lkr+s6orDbtb50g1wUOTTs41mG0KI/DCfzVlyvqDsveHb2SxRLswQ9xmDYyDvxpFH4/B852DWzqRsKPbHHXTMPVZEI0MEt7GGcNaoR8fouVzKseFn5fs5n/LSYV1xXSkZImDUliRQwXZZ4hwk0OTJQ16PDoMQTbwdY/M6vvcS2NCZaVgIkAadnzfMNd40kEawlNjDHo24cWO8QTMVD2ARsJ0rsNAtK3DaOTwNzjMuAPxKPpvJHDe3 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: Hook up an override for GCS, allowing it to be disabled from the command line by specifying arm64.nogcs in case there are problems. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Acked-by: Catalin Marinas --- Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/arm64/kernel/pi/idreg-override.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index f1384c7b59c9..3006c1bd1af0 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -441,6 +441,9 @@ arm64.nobti [ARM64] Unconditionally disable Branch Target Identification support + arm64.nogcs [ARM64] Unconditionally disable Guarded Control Stack + support + arm64.nomops [ARM64] Unconditionally disable Memory Copy and Memory Set instructions support diff --git a/arch/arm64/kernel/pi/idreg-override.c b/arch/arm64/kernel/pi/idreg-override.c index 29d4b6244a6f..2bb709d78405 100644 --- a/arch/arm64/kernel/pi/idreg-override.c +++ b/arch/arm64/kernel/pi/idreg-override.c @@ -133,6 +133,7 @@ static const struct ftr_set_desc pfr1 __prel64_initconst = { .override = &id_aa64pfr1_override, .fields = { FIELD("bt", ID_AA64PFR1_EL1_BT_SHIFT, NULL ), + FIELD("gcs", ID_AA64PFR1_EL1_GCS_SHIFT, NULL), FIELD("mte", ID_AA64PFR1_EL1_MTE_SHIFT, NULL), FIELD("sme", ID_AA64PFR1_EL1_SME_SHIFT, pfr1_sme_filter), {} @@ -215,6 +216,7 @@ static const struct { { "arm64.nosve", "id_aa64pfr0.sve=0" }, { "arm64.nosme", "id_aa64pfr1.sme=0" }, { "arm64.nobti", "id_aa64pfr1.bt=0" }, + { "arm64.nogcs", "id_aa64pfr1.gcs=0" }, { "arm64.nopauth", "id_aa64isar1.gpi=0 id_aa64isar1.gpa=0 " "id_aa64isar1.api=0 id_aa64isar1.apa=0 " From patchwork Thu Aug 1 12:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750395 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 60653C3DA64 for ; Thu, 1 Aug 2024 12:59:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E72886B0088; Thu, 1 Aug 2024 08:59:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E21EF6B00B4; Thu, 1 Aug 2024 08:59:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC2EF6B00B5; Thu, 1 Aug 2024 08:59:15 -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 AA7B96B0088 for ; Thu, 1 Aug 2024 08:59:15 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 68BC1A7610 for ; Thu, 1 Aug 2024 12:59:15 +0000 (UTC) X-FDA: 82403682270.12.9933A4B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf23.hostedemail.com (Postfix) with ESMTP id 001A114002E for ; Thu, 1 Aug 2024 12:59:12 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P2aAxOpv; spf=pass (imf23.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517125; a=rsa-sha256; cv=none; b=7bAHAhh8NMHtxMjJbEsL+PXtzntY+9tgx9m/xpW2aHojCW1GvyAgzdNtEhGIdc0lhZ6LVG +6WE85LkYAe63vXKVMO5YwgLIQ5ueb4qowGsBMhtJg12pyEtiZlzGXPoerf+s/dkoWjVcg 9EZwaH4Ncz3Z4Y05Z/Yyk1VkytrwnhA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P2aAxOpv; spf=pass (imf23.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517124; 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=Fa0FshE3cbF5RRtwPvTYpx5rzUhOOB8bBWzBgT+zxBk=; b=BlWExAqpwmShgC2jlXza2tSi9pjCGND7boOkMDWdl+lsKuABOiByi6qonG7fRTSvZG+ZeK 4PYo/sDLvCcmHJ0jJudKRReaT+AI5vEJqL5vyr42o308lUwyTArskA6L4sIHzZvUgAvrQg xLCScZM/UlDFEGueGbfomvjd3hfa0xQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id F374FCE1849; Thu, 1 Aug 2024 12:59:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE845C4AF0A; Thu, 1 Aug 2024 12:59:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517149; bh=p+k0jTbaEA99trdr4pz3NzAF7Yf9BBO+B19MeJlSzs4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=P2aAxOpvDJCVbQojJ9kkL/0p1jNyh3RkZBHFselBqiDWXCW0nnIMKt3IiX1HP/Lov nkutr2v0fm25gEK3gZoDdSgmixgIVvq0UMFXFCKRSvyckadjMMk+T0hez85GDFgUmB nHzU2DiOZfbbpCTGo3PYfV4EOfVuu4v6i3Vt7Xm7RvjeW45joMiiN6E2BrN5kxwxvj IVt7/Z/Y9f3eknRPzhWUhp6xYXJIRLm7D2wA+fFxlqYoDXS12yOIU1ciS1LWtcs1IQ Pniipz/v/XBnLLHbeGRszNNQDtJ36bfy+r31S5pb9A/sHFZrMgh6n5O9TRbDa/YVnc cnGttAsUXJeLA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:43 +0100 Subject: [PATCH v10 16/40] arm64/hwcap: Add hwcap for GCS MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-16-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=3096; i=broonie@kernel.org; h=from:subject:message-id; bh=p+k0jTbaEA99trdr4pz3NzAF7Yf9BBO+B19MeJlSzs4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YSBKOey9Au/9HUMZhMesat8OM3JKKecV9+v3Nl K8XZbOOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGEgAKCRAk1otyXVSH0K+rB/ 9kzIKyQv+DBtJyO/wq++dRFdIkJlQbaYJOX5SYFg4n9tnCGfLydiZut128GSYqvvzyGt4TpWt8pUG4 ntnI3Zp+6CIrZ03fqhyL2sn7tbmGhJK7/MKvycFXdHF81NZHxWe7AnDxaV1q+OA080MeTM8TfmlqT+ gz9sec8C0qMNsRXLO3E/o0h+JuGLGAZrAix4ocp1WyWnVUhSOpHHSTOO0eOdn7kJrw1JwTyz4Fwvbt z3psPrrlb1hKxFhWZ/5El3qMk4QVLR8+0BCkh+minpRiwJTbK8l1XgIJchzyPlzjiZY0blCBq8Rcm4 21/4lMmm/yOw7bnpkLlOR/YnHAWHPJ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 8f84di33scmhn5z8gd9dnnjoectrm1sa X-Rspamd-Queue-Id: 001A114002E X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722517152-697422 X-HE-Meta: U2FsdGVkX19tm9vJgOeL8AmJDmvziYM/UhEZv4L2r7+JcBNrGibVJVHeJ5EkR5GTxsUMq3krUUX4spes/TG2Skq30Z0MHzN9GBXb9ARj9Kn4wXlb/Tg0Zp22908RC2I718CoDB0tmppUchT2vmMijvOZF8XmQVdu5SsIb6AuJXJ+4/lyKROzO4EZuQjjOIjf9d7LV0owbebvgTA2pI5cBs3MaAM/b2KxLUIa1OZp3qegrH4HI4tdzXUW1DeTtKcjxhYCQaoL/6nzBdtmg69g2lPfyB+rHRCEqyaMA09+OChlGyTfIMUWhJieXBqeSmJwXIGNiqMiv+l8c8zUz6rtpa+CXYYQ8iK147U/ggg/8GKxO3HKa3RgfTAaVQ52sDDfCMG5DuakFPJe+jTQbgpwL+OZs2Uwi69g2kel6OLijqiun7u5DFaSWPq4B6QN2W/6QIr++KsfhEy6PkuGKoJRonKPwWVqQYFSIQNu5XZqeSDSmdtSXImRM4D6Mfehky+j8orQFSvhV3L340s1t+BgETutmaBUUmV+HoZEPtBzWXvHBlHJ3VnOEqRXD9132V61Af81rb1kVGEIZ/q4IPXExnwWOF1xuayNTvdjowWmx7O0cIfLBkfxcCiy+oEdhP4iv2MxmQUEio9qqWOXK9m1MlPOuT5S6b3GA6ID6DmOEpi+2lxlwBsaM9eghk0PSkqoE44DVQtaZLsUiN5jiZFuWmQFOtx3AmvoGIAIwV61qdkB+jODICDttgX3wEbwL26lyUhJAk1VChLP37hA6TcRBI4d0eLQCaMKOMO9gV5ZmbxF+wDjEsZhG0/x7+t4zZ/1yT2yyCATp+4pVoLuSFSfQu8kJ9UFONDIlyyjcdmedhFlxD6Y/Br/7BaNTzImki1PHznsh8L+R/tJR0qgUsTudyg9W6y56tMCVYORqws8fB81010qND6UAmKOrC3jbtswqx56D2nbxMec4YY0r7H ZwVwT7Av IKXiCfnX31hbda0+3dwbyE4Jr6sIp6wxl9xai60LsHIxwGn+sJl19qW97C0Mv5eMp3A6joDaVv7AnNXipIKu0zNVeDJ+3dkZg14/msT34FG5toAYh1k/p4hjYrzAEKepjyfFp7AVHH2xY7kItT2BOXKhTi25Q6pIVS3PPVgez8lQwM7J4hbFxvAJwzqMcaaEa0L+ib+LG5ryilbBWl7P2+y74OUJ6s/IzCWmmqnWC0uUgu4FEQ2RSOXDhB56ay1uTD+fT01mTDczjPw5XnjFKpPa4L/yYNCbh1sm4iaJsWJ3P+RSlPiczxKlKr3NWgZKVRrMFc1UQ6+hz3jCHy5dLhOQTM2G1SVVh0zlLkQSTm7ZtmNNjes+uR+8T62+D/UL8+KjS 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: Provide a hwcap to enable userspace to detect support for GCS. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- Documentation/arch/arm64/elf_hwcaps.rst | 2 ++ arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/kernel/cpufeature.c | 3 +++ arch/arm64/kernel/cpuinfo.c | 1 + 5 files changed, 8 insertions(+) diff --git a/Documentation/arch/arm64/elf_hwcaps.rst b/Documentation/arch/arm64/elf_hwcaps.rst index 448c1664879b..cf87be078f33 100644 --- a/Documentation/arch/arm64/elf_hwcaps.rst +++ b/Documentation/arch/arm64/elf_hwcaps.rst @@ -365,6 +365,8 @@ HWCAP2_SME_SF8DP2 HWCAP2_SME_SF8DP4 Functionality implied by ID_AA64SMFR0_EL1.SF8DP4 == 0b1. +HWCAP2_GCS + Functionality implied by ID_AA64PFR1_EL1.GCS == 0b1 4. Unused AT_HWCAP bits ----------------------- diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h index 4edd3b61df11..fd7e162e7e39 100644 --- a/arch/arm64/include/asm/hwcap.h +++ b/arch/arm64/include/asm/hwcap.h @@ -157,6 +157,7 @@ #define KERNEL_HWCAP_SME_SF8FMA __khwcap2_feature(SME_SF8FMA) #define KERNEL_HWCAP_SME_SF8DP4 __khwcap2_feature(SME_SF8DP4) #define KERNEL_HWCAP_SME_SF8DP2 __khwcap2_feature(SME_SF8DP2) +#define KERNEL_HWCAP_GCS __khwcap2_feature(GCS) /* * This yields a mask that user programs can use to figure out what diff --git a/arch/arm64/include/uapi/asm/hwcap.h b/arch/arm64/include/uapi/asm/hwcap.h index 285610e626f5..328fb7843e2f 100644 --- a/arch/arm64/include/uapi/asm/hwcap.h +++ b/arch/arm64/include/uapi/asm/hwcap.h @@ -122,5 +122,6 @@ #define HWCAP2_SME_SF8FMA (1UL << 60) #define HWCAP2_SME_SF8DP4 (1UL << 61) #define HWCAP2_SME_SF8DP2 (1UL << 62) +#define HWCAP2_GCS (1UL << 63) #endif /* _UAPI__ASM_HWCAP_H */ diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 315bd7be1106..e3e8290a4447 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2994,6 +2994,9 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { HWCAP_CAP(ID_AA64ZFR0_EL1, I8MM, IMP, CAP_HWCAP, KERNEL_HWCAP_SVEI8MM), HWCAP_CAP(ID_AA64ZFR0_EL1, F32MM, IMP, CAP_HWCAP, KERNEL_HWCAP_SVEF32MM), HWCAP_CAP(ID_AA64ZFR0_EL1, F64MM, IMP, CAP_HWCAP, KERNEL_HWCAP_SVEF64MM), +#endif +#ifdef CONFIG_ARM64_GCS + HWCAP_CAP(ID_AA64PFR1_EL1, GCS, IMP, CAP_HWCAP, KERNEL_HWCAP_GCS), #endif HWCAP_CAP(ID_AA64PFR1_EL1, SSBS, SSBS2, CAP_HWCAP, KERNEL_HWCAP_SSBS), #ifdef CONFIG_ARM64_BTI diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c index 09eeaa24d456..2f539e3101ee 100644 --- a/arch/arm64/kernel/cpuinfo.c +++ b/arch/arm64/kernel/cpuinfo.c @@ -143,6 +143,7 @@ static const char *const hwcap_str[] = { [KERNEL_HWCAP_SME_SF8FMA] = "smesf8fma", [KERNEL_HWCAP_SME_SF8DP4] = "smesf8dp4", [KERNEL_HWCAP_SME_SF8DP2] = "smesf8dp2", + [KERNEL_HWCAP_GCS] = "gcs", }; #ifdef CONFIG_COMPAT From patchwork Thu Aug 1 12:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750396 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 329D1C3DA4A for ; Thu, 1 Aug 2024 12:59:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B40E38D0005; Thu, 1 Aug 2024 08:59:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA04F8D0002; Thu, 1 Aug 2024 08:59:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CB7B8D0003; Thu, 1 Aug 2024 08:59:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6C4F68D0002 for ; Thu, 1 Aug 2024 08:59:19 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 28D271C217D for ; Thu, 1 Aug 2024 12:59:19 +0000 (UTC) X-FDA: 82403682438.29.691B27E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 201CAC0015 for ; Thu, 1 Aug 2024 12:59:16 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="PJZOHb/1"; spf=pass (imf28.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=1722517112; 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=aCcddeKQgbpVCZ8gdJeklAiNqjTPhcrj/cmJQo+qFOI=; b=ad6KcL81WbD/zdXVBfhsC1S9LE4nfDSrI2o89g7tU26aHXP6ChoL79QU+p3tpa7qimulKb d4fxR990gTHO6UWXVU0s7QALsrD93DqKmTiIqCjtkmh4jcETw6D2FqIQrq4YPg14ExFnOo fZJnCqnCtPt30yyj8yUJK3Tm4u0Bb0o= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="PJZOHb/1"; spf=pass (imf28.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=1722517112; a=rsa-sha256; cv=none; b=dKWpg0+sgHEwfBdJ2Bs/P2BR0yHt89dQA1Jhp6vCs4YWW7uOuC+XWal2qrs7MpOeFVJHcr TVxYPG8l0Fa1k1ntOtWQvR4wQd4xTcDdCKHUO0EeMKgmdpnuOOiF0J4Yt5gtXSCMkTjUkD TwXq9EH4GmnLFfoRBVfMXmd+iHCCu14= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 60BF862890; Thu, 1 Aug 2024 12:59:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B45E3C4AF09; Thu, 1 Aug 2024 12:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517156; bh=e44VTA4PnVMnteUpPeHLUcAac2ATi0WZ4XE1rzWONBc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PJZOHb/1rk5ias0TkH1+lp9tf3RfEiXLHdimywGuaOsxW66xGBDCds/AKor2qBJyd PQcezUzVUv7P2/GQm7SC7mMwfCK83I/sx578k8YF+msBXpBnY13USv19aAnVtUcmBl PwprICHJrhoqtDukC/+4xSIsvXZyWUkxyj9uJ+iki+qthGnBa71Qz9S/YZlvaOI1+S xjHKvUtKsZWcM9RKNPRr23s2+S1jpKV6HJPm7RJqVri/cXs8Vvngd6bi3k0GcovC9v 5qLQD7ZWtP+npQaL/OJmhqDbC3aE7/MEd/tcpwddaAqxazLzudrBrFIuPFnjWA9vUR 0an5eoTSPkoaA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:44 +0100 Subject: [PATCH v10 17/40] arm64/traps: Handle GCS exceptions MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-17-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=6092; i=broonie@kernel.org; h=from:subject:message-id; bh=e44VTA4PnVMnteUpPeHLUcAac2ATi0WZ4XE1rzWONBc=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YTZ2OXDXa+2eEFmG18HUkUNJVoBLENhnowwk3M pJMAJNWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGEwAKCRAk1otyXVSH0DreB/ 44rFE5NIa7f0ekSD7bRHP+YY3kusEJHC9heJwpjFUZcu7mWz7EonBz/XE5H/hcyn5jhA4RshRZKcht u+Nt1uMV9XbpmQr2MnxA/yNdMDjlxVeryhlOZwqacK7go6kRJX6rjm5I7HrnKjPb1pbM9OOkiDXdwc VRCZVNj+MEKUKh/li4SuomJ+oWeqRN0Apxke22a0HBHjQ9MsmTvNrOupwQsceU/RGRF2I18KLEWb2y ufroiycB/F5BZ9mrdqza3eoKtir+Qye7D53HE+FuwQ/6Gx+u4DAql60juOgfVdB5AoRMh7D9e+V/bV pSItS+emAaddmFbyM2oGNSwpSPuA0V X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: xuasr3kg7zey3nh9o1fy45qac16e9t94 X-Rspam-User: X-Rspamd-Queue-Id: 201CAC0015 X-Rspamd-Server: rspam02 X-HE-Tag: 1722517156-270725 X-HE-Meta: U2FsdGVkX1+DjL8nW8/yhIdSoVpb9pbdakl0BW9N5EF76Dn9ze9wzgPH7cVGHBAiN6lsB79Qyv+mXe5EFASBM2BwxnSMB9gtzYrOpHlRpTyLE4SDUcEzFWyVLAZ6PKmkOUyK3SzzulAYaFKrkGxvE1RoV0FA+yZnoW2dkDOjhNP1RFOSa1cXe4INscdxyY+4uf+FCorm2a1HWZP9wmh+xIMhMDlkb4pznj+JQ8oevXnOw6k/7Qp+7LZWi1Xww0Smz3HzOoSrmFOo5dZOBZGjQcc6WWxV8E6h1odEC5GknynA7C7u5fjee4iNleG9y7/4wmIoitPlhh5oLrcJulYaaKUxkXWuzLrBr8txq6ykzXgeTupvFqYc8s1f6A1l+ly7q4k/tIJbvHtaAx5cMj0HlfJGmvmhCB9nuST82VTfKU4wgiju8yy7dSG38L+e65gwKFZiy6WFMyIDbshkfTMt7ORZ6T+F6fe11si/HUCwVAOcRzG/N+ffj5zoPHTA1waD3RwFrxFwZj/PmSSyyV/NAInQOE/4BaOeg7LhcuoZEDV1dd/gasjpA8RVRLU1n7uevbG7A/5ZV802SU8GoLWrhzXhXQmi1ssyxSIMpfqNybJloG9fdT2d1ArctV1nHct5It3EpOOJ5bXJc78op9Kmhh8P6zV8B/FwH0HUIB5DQXagV90PFVTdZ9NxpcbJFPwEeAtnt5sTD3i/r2G/SWqR314BN807HHwrzflY4GZR/0MajhqQeslkON3MftUmLhRfq1IKNkeweisJ+HSaeNhPrtPMJ3zpXEXojpN6e0EPtAdvq4nZbeaq2Tve2mUZi1SUxSX7KhC51O6wk9RAiaXZ8c+T+2HHazl/+DYjUcyGx0yGh/x7G0LhN4N7NQNEzZ8/eMbxoK8gm+u7YBsNRAulzlRE6n0mCZJOWOwyy/AQNLdlT5U62Trcw13ZJcu9oqMQRQYEWoWO8xhGjM+6txE nY7QXfzf OGwXBHAUybKPwW21ZDQqOAVDUSudvPeqnbfUpCJvn4S1OsulBi0VKKgLFLl4X6AP8TB6g+bT6W6yKfVNCaryPSCBLF3uk7MUZqbqYy4njYrp+9l2N8UHS7b9SFXZHd6F24YlMAqMth2iISkREsVmnSXjQ5mjF10prTxRWCLjXOp/6xVE4rkC3cpibomDt5oHEHhvPszJz13G+Nd3ZztLRClIzyC/Y6ekX+65MYd/whHuBO1dWDOV6Zxk1cLuaamNZENhwM9Nm58yx6yg9Z9NmW7FN2oqw9CdpR1fLFcQMXIBnBHPQefNJjA5VbwjnMnF9BxHk0U8Tuz5WxT5f0fWCQHiol0pNr8l1bNUVLXMaBeL0WzRgMW0jHWxybRdtD5Ki5+lW 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: A new exception code is defined for GCS specific faults other than standard load/store faults, for example GCS token validation failures, add handling for this. These faults are reported to userspace as segfaults with code SEGV_CPERR (protection error), mirroring the reporting for x86 shadow stack errors. GCS faults due to memory load/store operations generate data aborts with a flag set, these will be handled separately as part of the data abort handling. Since we do not currently enable GCS for EL1 we should not get any faults there but while we're at it we wire things up there, treating any GCS fault as fatal. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/esr.h | 28 +++++++++++++++++++++++++++- arch/arm64/include/asm/exception.h | 2 ++ arch/arm64/kernel/entry-common.c | 23 +++++++++++++++++++++++ arch/arm64/kernel/traps.c | 11 +++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h index 56c148890daf..0c231adf3867 100644 --- a/arch/arm64/include/asm/esr.h +++ b/arch/arm64/include/asm/esr.h @@ -51,7 +51,8 @@ #define ESR_ELx_EC_FP_EXC32 (0x28) /* Unallocated EC: 0x29 - 0x2B */ #define ESR_ELx_EC_FP_EXC64 (0x2C) -/* Unallocated EC: 0x2D - 0x2E */ +#define ESR_ELx_EC_GCS (0x2D) +/* Unallocated EC: 0x2E */ #define ESR_ELx_EC_SERROR (0x2F) #define ESR_ELx_EC_BREAKPT_LOW (0x30) #define ESR_ELx_EC_BREAKPT_CUR (0x31) @@ -385,6 +386,31 @@ #define ESR_ELx_MOPS_ISS_SRCREG(esr) (((esr) & (UL(0x1f) << 5)) >> 5) #define ESR_ELx_MOPS_ISS_SIZEREG(esr) (((esr) & (UL(0x1f) << 0)) >> 0) +/* ISS field definitions for GCS */ +#define ESR_ELx_ExType_SHIFT (20) +#define ESR_ELx_ExType_MASK GENMASK(23, 20) +#define ESR_ELx_Raddr_SHIFT (10) +#define ESR_ELx_Raddr_MASK GENMASK(14, 10) +#define ESR_ELx_Rn_SHIFT (5) +#define ESR_ELx_Rn_MASK GENMASK(9, 5) +#define ESR_ELx_Rvalue_SHIFT 5 +#define ESR_ELx_Rvalue_MASK GENMASK(9, 5) +#define ESR_ELx_IT_SHIFT (0) +#define ESR_ELx_IT_MASK GENMASK(4, 0) + +#define ESR_ELx_ExType_DATA_CHECK 0 +#define ESR_ELx_ExType_EXLOCK 1 +#define ESR_ELx_ExType_STR 2 + +#define ESR_ELx_IT_RET 0 +#define ESR_ELx_IT_GCSPOPM 1 +#define ESR_ELx_IT_RET_KEYA 2 +#define ESR_ELx_IT_RET_KEYB 3 +#define ESR_ELx_IT_GCSSS1 4 +#define ESR_ELx_IT_GCSSS2 5 +#define ESR_ELx_IT_GCSPOPCX 6 +#define ESR_ELx_IT_GCSPOPX 7 + #ifndef __ASSEMBLY__ #include diff --git a/arch/arm64/include/asm/exception.h b/arch/arm64/include/asm/exception.h index f296662590c7..674518464718 100644 --- a/arch/arm64/include/asm/exception.h +++ b/arch/arm64/include/asm/exception.h @@ -57,6 +57,8 @@ void do_el0_undef(struct pt_regs *regs, unsigned long esr); void do_el1_undef(struct pt_regs *regs, unsigned long esr); void do_el0_bti(struct pt_regs *regs); void do_el1_bti(struct pt_regs *regs, unsigned long esr); +void do_el0_gcs(struct pt_regs *regs, unsigned long esr); +void do_el1_gcs(struct pt_regs *regs, unsigned long esr); void do_debug_exception(unsigned long addr_if_watchpoint, unsigned long esr, struct pt_regs *regs); void do_fpsimd_acc(unsigned long esr, struct pt_regs *regs); diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index b77a15955f28..54f2d16d82f4 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -463,6 +463,15 @@ static void noinstr el1_bti(struct pt_regs *regs, unsigned long esr) exit_to_kernel_mode(regs); } +static void noinstr el1_gcs(struct pt_regs *regs, unsigned long esr) +{ + enter_from_kernel_mode(regs); + local_daif_inherit(regs); + do_el1_gcs(regs, esr); + local_daif_mask(); + exit_to_kernel_mode(regs); +} + static void noinstr el1_dbg(struct pt_regs *regs, unsigned long esr) { unsigned long far = read_sysreg(far_el1); @@ -505,6 +514,9 @@ asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs) case ESR_ELx_EC_BTI: el1_bti(regs, esr); break; + case ESR_ELx_EC_GCS: + el1_gcs(regs, esr); + break; case ESR_ELx_EC_BREAKPT_CUR: case ESR_ELx_EC_SOFTSTP_CUR: case ESR_ELx_EC_WATCHPT_CUR: @@ -684,6 +696,14 @@ static void noinstr el0_mops(struct pt_regs *regs, unsigned long esr) exit_to_user_mode(regs); } +static void noinstr el0_gcs(struct pt_regs *regs, unsigned long esr) +{ + enter_from_user_mode(regs); + local_daif_restore(DAIF_PROCCTX); + do_el0_gcs(regs, esr); + exit_to_user_mode(regs); +} + static void noinstr el0_inv(struct pt_regs *regs, unsigned long esr) { enter_from_user_mode(regs); @@ -766,6 +786,9 @@ asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs) case ESR_ELx_EC_MOPS: el0_mops(regs, esr); break; + case ESR_ELx_EC_GCS: + el0_gcs(regs, esr); + break; case ESR_ELx_EC_BREAKPT_LOW: case ESR_ELx_EC_SOFTSTP_LOW: case ESR_ELx_EC_WATCHPT_LOW: diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 9e22683aa921..d410dcc12ed8 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -500,6 +500,16 @@ void do_el1_bti(struct pt_regs *regs, unsigned long esr) die("Oops - BTI", regs, esr); } +void do_el0_gcs(struct pt_regs *regs, unsigned long esr) +{ + force_signal_inject(SIGSEGV, SEGV_CPERR, regs->pc, 0); +} + +void do_el1_gcs(struct pt_regs *regs, unsigned long esr) +{ + die("Oops - GCS", regs, esr); +} + void do_el0_fpac(struct pt_regs *regs, unsigned long esr) { force_signal_inject(SIGILL, ILL_ILLOPN, regs->pc, esr); @@ -838,6 +848,7 @@ static const char *esr_class_str[] = { [ESR_ELx_EC_MOPS] = "MOPS", [ESR_ELx_EC_FP_EXC32] = "FP (AArch32)", [ESR_ELx_EC_FP_EXC64] = "FP (AArch64)", + [ESR_ELx_EC_GCS] = "Guarded Control Stack", [ESR_ELx_EC_SERROR] = "SError", [ESR_ELx_EC_BREAKPT_LOW] = "Breakpoint (lower EL)", [ESR_ELx_EC_BREAKPT_CUR] = "Breakpoint (current EL)", From patchwork Thu Aug 1 12:06:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750398 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 AE279C3DA64 for ; Thu, 1 Aug 2024 12:59:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39DA18D0006; Thu, 1 Aug 2024 08:59:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32B3D8D0003; Thu, 1 Aug 2024 08:59:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 178D78D0006; Thu, 1 Aug 2024 08:59:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E90398D0003 for ; Thu, 1 Aug 2024 08:59:25 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B134AA6C82 for ; Thu, 1 Aug 2024 12:59:25 +0000 (UTC) X-FDA: 82403682690.16.3E8CE5D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id D33FD20022 for ; Thu, 1 Aug 2024 12:59:23 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hd+OXBiY; spf=pass (imf13.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=1722517106; 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=4/myyOyuMfX6crVwVKxf4MM/Wn31RwnDs+hGA/iV1EA=; b=Z4j4qZOZQN0ON4k5iJtCREv9ISx2UbegU9T5bcJtcgGrQnqvAUdeFBWbjIl8kFDAbVZTML vAP4hR35M4J9WJKVozzmOQERPkFxVYJA97gP346c3+oHdnIHhLGrCEc30EfiAPC6c6vESS OqFf+glPV1BuT8aPtHdWKQ8eaj5kaNM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517106; a=rsa-sha256; cv=none; b=eoqaI8uV6eGN9Lt/wn1lN0cwbrLF9+ggamacU8Nj6DJGKbiTzyOTBw1A/m9oQWOOxlrUij Rs4WquobOvNthCmUF7nzUotcijsK6Eyln2HNccDKLx7JRTQdWUFkmAJkCCzkpAcmHMHMwa J3aSuDAHXwE54Ntj9panWU1etIDAh00= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hd+OXBiY; spf=pass (imf13.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 16D7F6288A; Thu, 1 Aug 2024 12:59:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82677C4AF0A; Thu, 1 Aug 2024 12:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517162; bh=mCYEqlOLyPN0qEO0joq8aJDaO3kSWJXCOekmmHiOO54=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hd+OXBiYmYQ7Y//fkA4aEYz+PfLaULR587Lip2lLru+MeE0zfjQPmmTmggZAOSb6W Qr/IsWI1qHO3AyRzzFrYBNju3NZhRMbESgLPxjvupiritZVxcIdSBeZl1MoIipOJ41 qX5O9TlfdXxTXaPIlXxjFiZTknTnqaLW2wAhpigDusoe1aoMYhecrtjrCVxQ47zTtR j930gjTJ2dbrJ0EeIjSPhq3YhBPyS1VyW4+YMIUeCMHzfzxuRcdu7Irekyq+UOT7Gk o3qmQIQ4qW+FdbvIS/arc20i2UI1n+WQCyuBoo8kBohmY7nlHK41NtvjYN2Q1E0mnW UJGRnJzPbvaKw== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:45 +0100 Subject: [PATCH v10 18/40] arm64/mm: Handle GCS data aborts MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-18-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=3621; i=broonie@kernel.org; h=from:subject:message-id; bh=mCYEqlOLyPN0qEO0joq8aJDaO3kSWJXCOekmmHiOO54=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YTtyLs+vnIQBWnGfIVH8o2DnS3kjKCvjmb12p9 SZmL+AaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGEwAKCRAk1otyXVSH0AxZB/ wPhepfGMuxiO9PuNnOv6YrfgeBlsRwJvM/VUvi67zpKMpsBaAkgbb/2VWw/grqfKYNmhgW1gumwF6C tyVVQsT+s/EfexLl6BA26CVY7uXXlIp/0kXkFbMUqtlL1VQTL36JJqAqyXzSdCYCkeXmLh+wGD0f9e Kg5RUk1MX0Ch9escuRKahaaq7kI6zY1uH5zMeldSwh1bmAGX7N+kYxbINBnbp5LAqIY+DwUtEEN7C2 tsVyqoltrGCYqmb1W65kAyo5UKWnZ0QQ38AdwXRZiRNFImkRvBkwcUMZSX49aWKWsaAV98CGwC1Fwj 3QmFhr+QSiT5JnnL9eK6KF8bGEqgni X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 79eps5dh65zutedhczf3e5tjkewxiozc X-Rspamd-Queue-Id: D33FD20022 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517163-993081 X-HE-Meta: U2FsdGVkX19WfSCU1+Mu9d2KByXgUspvrxfwJmxgXKL4h3Kf7sM8891kS8fQqXDFMf9j3yOwo8W5gyROPya27doxNELPLQ12n8QZUZ7Vbz1eDKaysoc6EGpNWamPSmZxyyRW6E4XSu8i/TxBkBZHZBKU+Q++TyCsoVJK8P8Lo7ajGUjUzmC8JYmFeVTayQYLMj7O4psdgcsw/2T6HbUWymRFrbo1d8yp3LAr11SKjhgAWXox6Mo3BXBhOTWEZ3yoPFVOzFjz0h5aKwWr5nKcBiPUizvPlZYE6MBcAx06hLZG3E/gpIQiIzqRF6tZXCerPg+Y1mG3cICyCzYC44BsI3YBBMTJADDj+/Qb2ApezYBukScKVoeCSyb+x21McPcYkPzmgSxA4bXSHE8ckRUHOihE8V5HPml2VRuOvFzbV4RJsPFJLGd00Qf57r3ARHVE0+yJvqDY7UkN0M69NoBQno4SFH47MnVnRBCuDlAUL/g2x8khVKYTYB+nfGOesE4LlB4vL9IltWiT4D9mKFEl+qOF4PUQIaxD24U3+ofvz9AmKjHmTz/aUxXALSSzf/vj6Lh+Fj8xBWw23+sSPD/1tdTGu7a5SafYglXGKwHoVnN4OWGFJf/AtvqwQyNlyoP7+L80Bc9qllEr3EU8JMAiOfl/4RIlfjSQ+yNDTOjhIkUOtA5XTuV1yP+F5HMP+Nh1WLbLZNdOWPfvX90202mDyAnJwlv+lRPavu/klbboFkBbBmFHkOi6IXhEsA53WnFNegUOO/gMaRN6C28FYoNwGJEw1oEd7krg+KyTcedidrq8k2J54miz45SERvo990+7J+oPwZKPODBRqc7RZ1+Fc03IfI+OGd38bY2jz777L6tphcmlcJpaa53KIwB8jPr+5TH7LRnOHwEvC9jctZxoun/0Cc+Xf7BsLi61REEB1KrWuzg6/ABQhZiNsWQkyZ+vdmBJJvoCtlOlPPNe4ya Nl4Ts7U3 uiY2HHbM96TwNymFJ+mHGAmxPIaKmmbZQvejtO8vYBoHAf7+sSIfUGad7QZ1cLn+VzFhjsSWmJ9VcV0zc5FWZ4pOwj6TBjh8fG0KtWbjG/sR+MoiIHUYUhwGgyqx42C/I8s3VO1pOd5g1esB6qudyKxbT/ZOkA9rP7xXX1TgTHOwPSguS71Sr308L0ZPD2HGzfBZpxRNzgEtQ/o8dkmPewxpEpAMH1+fl9Gt9aZryeB2XFAMmWJTwk+QobuN0aHBh7xttlQ5zdn/26EIyKhsLFJ9Geqffp9D7maEN0dvlLc0vLKvCKZmn2H8F2nL/5tOKjQU0 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: All GCS operations at EL0 must happen on a page which is marked as having UnprivGCS access, including read operations. If a GCS operation attempts to access a page without this then it will generate a data abort with the GCS bit set in ESR_EL1.ISS2. EL0 may validly generate such faults, for example due to copy on write which will cause the GCS data to be stored in a read only page with no GCS permissions until the actual copy happens. Since UnprivGCS allows both reads and writes to the GCS (though only through GCS operations) we need to ensure that the memory management subsystem handles GCS accesses as writes at all times. Do this by adding FAULT_FLAG_WRITE to any GCS page faults, adding handling to ensure that invalid cases are identfied as such early so the memory management core does not think they will succeed. The core cannot distinguish between VMAs which are generally writeable and VMAs which are only writeable through GCS operations. EL1 may validly write to EL0 GCS for management purposes (eg, while initialising with cap tokens). We also report any GCS faults in VMAs not marked as part of a GCS as access violations, causing a fault to be delivered to userspace if it attempts to do GCS operations outside a GCS. Signed-off-by: Mark Brown --- arch/arm64/mm/fault.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 451ba7cbd5ad..0973dd09f11a 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -486,6 +486,14 @@ static void do_bad_area(unsigned long far, unsigned long esr, } } +static bool is_gcs_fault(unsigned long esr) +{ + if (!esr_is_data_abort(esr)) + return false; + + return ESR_ELx_ISS2(esr) & ESR_ELx_GCS; +} + static bool is_el0_instruction_abort(unsigned long esr) { return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_LOW; @@ -500,6 +508,25 @@ static bool is_write_abort(unsigned long esr) return (esr & ESR_ELx_WNR) && !(esr & ESR_ELx_CM); } +static bool is_invalid_gcs_access(struct vm_area_struct *vma, u64 esr) +{ + if (!system_supports_gcs()) + return false; + + if (unlikely(is_gcs_fault(esr))) { + /* GCS accesses must be performed on a GCS page */ + if (!(vma->vm_flags & VM_SHADOW_STACK)) + return true; + if (!(vma->vm_flags & VM_WRITE)) + return true; + } else if (unlikely(vma->vm_flags & VM_SHADOW_STACK)) { + /* Only GCS operations can write to a GCS page */ + return is_write_abort(esr); + } + + return false; +} + static int __kprobes do_page_fault(unsigned long far, unsigned long esr, struct pt_regs *regs) { @@ -535,6 +562,14 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, /* It was exec fault */ vm_flags = VM_EXEC; mm_flags |= FAULT_FLAG_INSTRUCTION; + } else if (is_gcs_fault(esr)) { + /* + * The GCS permission on a page implies both read and + * write so always handle any GCS fault as a write fault, + * we need to trigger CoW even for GCS reads. + */ + vm_flags = VM_WRITE; + mm_flags |= FAULT_FLAG_WRITE; } else if (is_write_abort(esr)) { /* It was write fault */ vm_flags = VM_WRITE; @@ -568,6 +603,13 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, if (!vma) goto lock_mmap; + if (is_invalid_gcs_access(vma, esr)) { + vma_end_read(vma); + fault = 0; + si_code = SEGV_ACCERR; + goto bad_area; + } + if (!(vma->vm_flags & vm_flags)) { vma_end_read(vma); fault = 0; From patchwork Thu Aug 1 12:06:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750399 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 BB812C3DA64 for ; Thu, 1 Aug 2024 12:59:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4395D8D0003; Thu, 1 Aug 2024 08:59:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C2218D0007; Thu, 1 Aug 2024 08:59:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 214808D0003; Thu, 1 Aug 2024 08:59:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F15D56B0089 for ; Thu, 1 Aug 2024 08:59:32 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B41D9160D28 for ; Thu, 1 Aug 2024 12:59:32 +0000 (UTC) X-FDA: 82403682984.09.D39B192 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf02.hostedemail.com (Postfix) with ESMTP id D72CC80017 for ; Thu, 1 Aug 2024 12:59:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SGbG9HSU; spf=pass (imf02.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=1722517115; 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=oe9Vexhwqj93GjpqzabS7C48jUF3MOTi7ueTZQ7hbvA=; b=ARv8L9oN9xg+igJpP0ggnyC+dOVuH/grWqiR3i2GVvGIggrmstyGCDZkoHTzTMYyGjlfq4 EorgYhH0TBC4gKSbuT8frK/HI4GYkq+aqLQxs8BZl5QnwMNRSx96xW0Tr36w7y0zj4bQ/f 2efjVE4J1UAqg1r7r7oG3u039OvVUxc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517115; a=rsa-sha256; cv=none; b=NYv7NI8AWLyfEFa4cSCHgeCtuPI47nIsduA7d1uQ/WfxlkEjtkZ9wrcIE45me2daebH6Mq ppM7UvsfMzriLOCrK5ibmUO0L/excXABy34ACQSn/e14XfN2/JigQw2e0FpxSOsD/eQNqA yfS/WB7e/XpObYo+i5MQTKwenarOe9U= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SGbG9HSU; spf=pass (imf02.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0B8C762862; Thu, 1 Aug 2024 12:59:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56BFBC4AF09; Thu, 1 Aug 2024 12:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517169; bh=LJRx9dbx6SCHWemf1Wkonmx6LcV5PPBkBodAHDEcEts=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SGbG9HSUe/7a3ExlPYPCv4L81giAZrIfuIgHOahyUE1y+liRYLKOTDH/4ugujV5AJ Yx9KGKXnA2zmSEKsdwrVWI2NMY4rzUgu15HBxTXtj74UADh8zMzoVoW+GPgoMlZ1HO IrSaWuThAnNJJ1K8GzlI0kjlG/NzuoGs0pObM6Ux0DZjFAtcf8fcroMamdazKixJBy EiuPtwWC6XiObL7ZxrkxvlRqJ7v+ujGC254EVqSoIkoa6TsiWq6PQuvOh21Fb7RNAu 4N6KNtWimUtC0eBrxxPnfb8sLYHPKDR5Qf9cad0Hxhvls7vo3O3fFuGI7RrO1NJkrb 2DXfG7dpJZ9CA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:46 +0100 Subject: [PATCH v10 19/40] arm64/gcs: Context switch GCS state for EL0 MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-19-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=6765; i=broonie@kernel.org; h=from:subject:message-id; bh=LJRx9dbx6SCHWemf1Wkonmx6LcV5PPBkBodAHDEcEts=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YU7fRD9Hg8vjWqmHFVnrRJhKG43A5c/5GNr8vv WGmGOmCJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGFAAKCRAk1otyXVSH0KgmB/ 4mAAl6dpDUJ+513JFxm8gMwmN8c/C3rsQdArwoDkfda+tiWMoZAvScNaIwibLzwvEJMxpldgs2RWql ueSBr2KKMOgrZsGWanCW7AIFQk1/kzHejFQnz5BxhONmn0RJ8vB21rfrW5KwiRm4OULvDyxc01RWNo DRR2/Q05gTaC0gwUwXDVii5ITTJE23qOA77TH3NS8OJiag+MCV7DFDuMRyxSN0mFdsO4yYoQMFc/ev NBtS2ZwBWiTB4hTZxJbfejjCHtV+APQUBwhPL8L77WHbYUIWRmNryLsCwiT3qM7PKSmRjecBlf+Pgz khi2R7Ve9atuRvFA3EjzSLTVDNrBxY X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: D72CC80017 X-Stat-Signature: mcergf168fnw7fug7uxy5ksu9ccz1mng X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722517170-812565 X-HE-Meta: U2FsdGVkX1/bs6jibTQpnqUTjl+Awq4FNEbmBESRdFwZhH8gyMHxS9HRdFOLTnXVgt7Gb/9w7TjwV7Mj3ZG/U01+B2KbV/13y9iMU8KZdbItfuOQhcODHFSi/LD4zABLcfDKd868BfnFjCg5N/9ImjLkuV+yJ1M5zbaa0VjB25fXqB3ThY7aPgwOaPB3tMrJKQgq4mjNNRRNojwZmyN7g27WyLtuRxgE6+SInD6z85zRhL4jOpRLKztKmJ+IocDNlPPRJQSXNBMFAQOm7LIyRsxEEMxtTh6C/G2V5f3kbeKYVGZxveYDBSrxCHglusseSTQv2ulc3FSabBp6XpB+tRXQnbqP8HAkn61LP0vNqL7vgNhglj6hdtaxRpy/YrDgfhWF7ZId4AZUC/QhRdSv+abhMGV4Hh21Zir5vPz3oNEZyEwvsKq1RXOcHO4qkUKcYpYYFeSeucssTemXalkkjoMk4V9iGeeTXvjhGWQexuDijyOqNFlOiWCTLcooxe72DcLW08WmKqz1ihsNKAzoKhRJ5bogARzsFNAno007OXCUwK+8j6K/QgXhsv7ZrEQWQVvAlfc1Ln1dQOo7iJ62qBC8g8zKfjobcGDtuCnxiyAEEHnrNCXqhD34EtZdQVT572c/f7NNCZ5j84Glfpe4oZoxzeno58PBnWB1PborIsmf6o79g0FmSwuMc0+uBxyrfKMR0IMT54s5h22ddBoj7jPmHZluT3ThvoAASBrUTQLrS/8YzByHMwxXgYo9vCWIAWWGu7dy1H8pKe5KM4e0i11v/Rfvhia50sBmi/oyWcS/C9BTD0ptCfepJhpMuKl7HwfBPUCAm/TgzLQ4REajtt1Fl3PFb9duwHiS8fkaIbpWZTFab53OIAU+v3gyyhsgU5dG6f7DcEsDlkm0+5+zqHD4uyIrp3VdlkAH5l3zfwa+17isqfkVm5nW9MhqGLmaXHT1aic82fZcmaWdh4d EsDQKiN2 +Kdm5sRe3x4+eu+xnA8DaYvGPbjgzwmK3cCIOQUGFqRSeWRXoBVHu4ZGQpm0am4SEajNBNxt6Xv1vmnm9dXPLOmkKfgcIL6NZWc4kZb1vv9PeD4TM3uV4iawm22+xcbt5rhsML4ONRYeOzQNLCiwE5Q6+fN03jxR15PQGQX5c+ZqwlFdYyKJ5uUPfbyYHoSGcj0SPntH95jZmjHp/80x0xBkse/3H93Dy3AiJmfuCf/3OsfC7s934DwGRk//FxkvfGI1Czpr4c8yj3dz4wRec1yQ6JnJj6cluhcV/4cgsk9x4uMYbv3SVuhxcXsRuqaNOy4497illcerCpYPhAWmDky0vp9Kj31DKXCJYVjTr/7tCQEK6BPbNfdMzCLn24IUGlxlR 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: There are two registers controlling the GCS state of EL0, GCSPR_EL0 which is the current GCS pointer and GCSCRE0_EL1 which has enable bits for the specific GCS functionality enabled for EL0. Manage these on context switch and process lifetime events, GCS is reset on exec(). Also ensure that any changes to the GCS memory are visible to other PEs and that changes from other PEs are visible on this one by issuing a GCSB DSYNC when moving to or from a thread with GCS. Since the current GCS configuration of a thread will be visible to userspace we store the configuration in the format used with userspace and provide a helper which configures the system register as needed. On systems that support GCS we always allow access to GCSPR_EL0, this facilitates reporting of GCS faults if userspace implements disabling of GCS on error - the GCS can still be discovered and examined even if GCS has been disabled. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 24 ++++++++++++++++ arch/arm64/include/asm/processor.h | 6 ++++ arch/arm64/kernel/process.c | 56 ++++++++++++++++++++++++++++++++++++++ arch/arm64/mm/Makefile | 1 + arch/arm64/mm/gcs.c | 39 ++++++++++++++++++++++++++ 5 files changed, 126 insertions(+) diff --git a/arch/arm64/include/asm/gcs.h b/arch/arm64/include/asm/gcs.h index 7c5e95218db6..04594ef59dad 100644 --- a/arch/arm64/include/asm/gcs.h +++ b/arch/arm64/include/asm/gcs.h @@ -48,4 +48,28 @@ static inline u64 gcsss2(void) return Xt; } +#ifdef CONFIG_ARM64_GCS + +static inline bool task_gcs_el0_enabled(struct task_struct *task) +{ + return current->thread.gcs_el0_mode & PR_SHADOW_STACK_ENABLE; +} + +void gcs_set_el0_mode(struct task_struct *task); +void gcs_free(struct task_struct *task); +void gcs_preserve_current_state(void); + +#else + +static inline bool task_gcs_el0_enabled(struct task_struct *task) +{ + return false; +} + +static inline void gcs_set_el0_mode(struct task_struct *task) { } +static inline void gcs_free(struct task_struct *task) { } +static inline void gcs_preserve_current_state(void) { } + +#endif + #endif diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index f77371232d8c..c55e3600604a 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -184,6 +184,12 @@ struct thread_struct { u64 sctlr_user; u64 svcr; u64 tpidr2_el0; +#ifdef CONFIG_ARM64_GCS + unsigned int gcs_el0_mode; + u64 gcspr_el0; + u64 gcs_base; + u64 gcs_size; +#endif }; static inline unsigned int thread_get_vl(struct thread_struct *thread, diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 4ae31b7af6c3..5f00cb0da9c3 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -271,12 +272,32 @@ static void flush_tagged_addr_state(void) clear_thread_flag(TIF_TAGGED_ADDR); } +#ifdef CONFIG_ARM64_GCS + +static void flush_gcs(void) +{ + if (!system_supports_gcs()) + return; + + gcs_free(current); + current->thread.gcs_el0_mode = 0; + write_sysreg_s(0, SYS_GCSCRE0_EL1); + write_sysreg_s(0, SYS_GCSPR_EL0); +} + +#else + +static void flush_gcs(void) { } + +#endif + void flush_thread(void) { fpsimd_flush_thread(); tls_thread_flush(); flush_ptrace_hw_breakpoint(current); flush_tagged_addr_state(); + flush_gcs(); } void arch_release_task_struct(struct task_struct *tsk) @@ -471,6 +492,40 @@ static void entry_task_switch(struct task_struct *next) __this_cpu_write(__entry_task, next); } +#ifdef CONFIG_ARM64_GCS + +void gcs_preserve_current_state(void) +{ + if (task_gcs_el0_enabled(current)) + current->thread.gcspr_el0 = read_sysreg_s(SYS_GCSPR_EL0); +} + +static void gcs_thread_switch(struct task_struct *next) +{ + if (!system_supports_gcs()) + return; + + gcs_preserve_current_state(); + + gcs_set_el0_mode(next); + write_sysreg_s(next->thread.gcspr_el0, SYS_GCSPR_EL0); + + /* + * Ensure that GCS changes are observable by/from other PEs in + * case of migration. + */ + if (task_gcs_el0_enabled(current) || task_gcs_el0_enabled(next)) + gcsb_dsync(); +} + +#else + +static void gcs_thread_switch(struct task_struct *next) +{ +} + +#endif + /* * ARM erratum 1418040 handling, affecting the 32bit view of CNTVCT. * Ensure access is disabled when switching to a 32bit task, ensure @@ -530,6 +585,7 @@ struct task_struct *__switch_to(struct task_struct *prev, ssbs_thread_switch(next); erratum_1418040_thread_switch(next); ptrauth_thread_switch_user(next); + gcs_thread_switch(next); /* * Complete any pending TLB or cache maintenance on this CPU in case diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile index 60454256945b..1a7b3a2f21e6 100644 --- a/arch/arm64/mm/Makefile +++ b/arch/arm64/mm/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_TRANS_TABLE) += trans_pgd.o obj-$(CONFIG_TRANS_TABLE) += trans_pgd-asm.o obj-$(CONFIG_DEBUG_VIRTUAL) += physaddr.o obj-$(CONFIG_ARM64_MTE) += mteswap.o +obj-$(CONFIG_ARM64_GCS) += gcs.o KASAN_SANITIZE_physaddr.o += n obj-$(CONFIG_KASAN) += kasan_init.o diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c new file mode 100644 index 000000000000..b0a67efc522b --- /dev/null +++ b/arch/arm64/mm/gcs.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include + +#include +#include + +/* + * Apply the GCS mode configured for the specified task to the + * hardware. + */ +void gcs_set_el0_mode(struct task_struct *task) +{ + u64 gcscre0_el1 = GCSCRE0_EL1_nTR; + + if (task->thread.gcs_el0_mode & PR_SHADOW_STACK_ENABLE) + gcscre0_el1 |= GCSCRE0_EL1_RVCHKEN | GCSCRE0_EL1_PCRSEL; + + if (task->thread.gcs_el0_mode & PR_SHADOW_STACK_WRITE) + gcscre0_el1 |= GCSCRE0_EL1_STREn; + + if (task->thread.gcs_el0_mode & PR_SHADOW_STACK_PUSH) + gcscre0_el1 |= GCSCRE0_EL1_PUSHMEn; + + write_sysreg_s(gcscre0_el1, SYS_GCSCRE0_EL1); +} + +void gcs_free(struct task_struct *task) +{ + if (task->thread.gcs_base) + vm_munmap(task->thread.gcs_base, task->thread.gcs_size); + + task->thread.gcspr_el0 = 0; + task->thread.gcs_base = 0; + task->thread.gcs_size = 0; +} From patchwork Thu Aug 1 12:06:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750400 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 7CC85C3DA4A for ; Thu, 1 Aug 2024 12:59:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10A526B0098; Thu, 1 Aug 2024 08:59:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08DBE6B00B4; Thu, 1 Aug 2024 08:59:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFFD46B00B6; Thu, 1 Aug 2024 08:59:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B4EC86B0098 for ; Thu, 1 Aug 2024 08:59:39 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 67ED71C3E52 for ; Thu, 1 Aug 2024 12:59:39 +0000 (UTC) X-FDA: 82403683278.23.3BEABB9 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf02.hostedemail.com (Postfix) with ESMTP id 8F71C80018 for ; Thu, 1 Aug 2024 12:59:37 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DQGqZA9k; spf=pass (imf02.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=1722517133; 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=dRorkG8eLLbC1xmdLxb1RNIu5h7M9BfVEs+ifgiS4E4=; b=NEkqwN5lUy+mdpyL822ALMLsJdyUvHy0FPXjomvjJMYNBzn1cOu7/9HtW4su477uz/VeBB UNdLhyPkO7Dv1hUk9GsDGw4PJ4xm2yob5VhTMfC6s8XU0BH9MJI8cCkEYiyCQE2ExT7nQP ZOGWvO2rJyAUQ4nfkq0YS0ctyMgsYNI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DQGqZA9k; spf=pass (imf02.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=1722517133; a=rsa-sha256; cv=none; b=rvYG0dUCvLB8YvhwNtry4TPVPL/HFaqKiKL3vTD70pT7/AmS0uoQez0ptdgItH+8Ym7M8Y MX8dvlthl/kJpRfvh8Bnjr+Wvb4N+fKE8iJQcEC9Hwb4SgcaruEg3WgPR/maRdCl44v+rP bn9SNeqtFwLLR2JhDM6Cv3YUz5vV4wk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D4A4F6289A; Thu, 1 Aug 2024 12:59:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A904C4AF0A; Thu, 1 Aug 2024 12:59:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517176; bh=B69uwIuCGaKqwsutt9MY1WdHU2Nd2UTBTyjAA6ycbjo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DQGqZA9kVe6Q06m1WoCxQtK4JmHaCPpb4APHp6BgHlF2FIIwvGPb6RMKgMR6P8mMf qdIPsYKbAUQsrXT4ri+ptZ9lB552puxtQ7wUs5eNGbzkurCzMiDov4kbExD3bYJ0t5 8mobtgZWomucDDY8HnCSAvFJB3RPpGjzndt9S/18dNbGD13FYZq279THnIqay1WAuC o7A+SJOgIczCFyX1wVa8RlCpu7hmtx/joBnXeO+9D4Jxw3kVHwvydW+0p35tLiLBaa 1uAbRdf+3Sx5x7qgSE6gyLbgxMKh86zRlnC1Ek4I2dXJjPIj7G4dsUAby1G1Z/LX5U t2xnnjMraHGcg== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:47 +0100 Subject: [PATCH v10 20/40] arm64/gcs: Ensure that new threads have a GCS MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-20-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=8544; i=broonie@kernel.org; h=from:subject:message-id; bh=B69uwIuCGaKqwsutt9MY1WdHU2Nd2UTBTyjAA6ycbjo=; b=owGbwMvMwMWocq27KDak/QLjabUkhrTVbaIy+vc4fr3IP/boS+1nK5mj83yC0g+vtfHZvszmSntz hVt+J6MxCwMjF4OsmCLL2mcZq9LDJbbOfzT/FcwgViaQKQxcnAIwkaNe7P/jJu88bVcme/NBi9/Eth nRZxnUt3guZ/T27860263to5xk0duraXbr/Y+qX2bK9RfLf5a72pQvumUYaX/dsfZcOdPFHQ0pHy9+ lHtbrZw8Lz1MkU/V4nd284a1xSWHz/0yWWpdsjh5yQr3dXMldivunr1R7FflLZdp25MWWbeZ/DUSTl hepN26eHJn08dPMrGCfhUW4ltZO0x0HXseTfEsdi3tM6k55ZB4fYfJmtrde9K2xamVMzHIs342mTOV n+mIIeuPq6k/e/cHnGhWXlGslyMuvuTiPUZ/0aT5J9vNV+RYaverCmWZHI/y69tpuIFphfNKR4lWs5 ML9x+XkZrNEHP34C8HucZJBYeTAQ== X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 8n99qz4muh6g4tkmdrgmm4bfo3fh7wzz X-Rspam-User: X-Rspamd-Queue-Id: 8F71C80018 X-Rspamd-Server: rspam02 X-HE-Tag: 1722517177-179464 X-HE-Meta: U2FsdGVkX18IlVtcDeoxWyLpNwEIlE4aKEG9jVZwO/Tv7K2AEXuQBuhllTocce3Us8bVvArOFoD3h5sLYKRvJcewC2xY3lSLtEZTbHA3tAVymSHg4EeS4wnLSBFp7ESRG5rPzAybASDh06j5CVitm0HDPaksLYZqg1cBwHgG5poBwGMHKdzuiUKbxVFdRde12ZT+nQUY8UabuLo3dHfkkkQWEZmK3LVYZ2Q50gAUjD1ZGLvk92ZrkmZGS6qDl88kj7vBTJy3JGqd1Old/hCCRRHkyNx2ZJijOzfcNT35u8D6hixCY3Pp8wXHYxy/z076M/e+SNEUqEB3wCMML/uEMMCGeaJOVC+JFwHZxLsxrwLTgSwRrWznlQxyhSpGNw3ZjnkO+jSZFeZTtdr5Em9Lj5bgKJV50cp4KR145AoeP86zatZ22uFNigNJRD/8lfY3E/BerieZCu6X01gpdOOIfXwotFXeyTZGgS8PC9bWzoiD0ME7OJdSYnjC/loCj7JiCkEcOPhxtuQgf8dTWEEgj1/Setk6OHNEJdMXNYlx7ctPPD8bvtVlttSPDLcZp1jlJibA2gbwDGaTerveZ8r+pWb+K4WXWsYHdUbtJAkZP3MnhCjeHoMq809NTIQ1WRnJ79sPao9ft8OYVRqZZ4D5feG+cDmxJqAD2kd9qLrQIlqoTb0thc1x8pN2vA6x9o78tB8umlgKlUw1WWZolBKEmZoR4Bsal/6Z9dZfJ4DWRHhdBmSEYtH0DadqiBpB1ZGwnOzGB5BdZeKotCSBdGgdD9KeMVqdLrdNQNRwLHmeI2UnOVSF4Cbh59KKSKe7P1syiJJOAURWX46ckkW+T+MLxQocvN0Y+nvuk2nLTbrcY7Tiv4Mz8/hWcMhg7ut4hiNk9nAFm8AZJtNAI5yr7TwGC9EnJRKSb8xPfrVxRlqK155l+9ETittCBhggE1duGG5wHnoor4wkVp8IPIudHRf v4LEOvTZ 4jh6XvYnDjz6lxJ3s2QYnzVTS7icUbwUTCcR+NqJzACnmgeBlp9baySPBG/86Rtiqok2jttH4Ejd4e5tY0eGefx2PsM9mGtYz5xzIoKR8aZjbMmcOA930PQZDiXRk1ryXdyxDU0v3zEpm3nYdWKkJnRpd59IRcIdwP9yLEDRnkDIFRk8sELJvcmQHVFoOMJUHsI0AbM18Du+5AsuiOQzeZ2ciq612AiUsuQGyC+Ja0BKQ2zbh15G+mx+lAoFIvxknajcyHyj6xsfgoFH0RgQinVrTlPtJWE1Ba6YFH5TF92Cydx2BhseiIZanuJC3Re+OWRqDdn5Gscl/e9S85qozLcVMlnz8fZ5tWLXZJhBaHlPmpwCTYoKQ0iNcyPUgbxfMtKii 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: When a new thread is created by a thread with GCS enabled the GCS needs to be specified along with the regular stack. clone3() has been extended to support this case, allowing userspace to explicitly specify the size and location of the GCS. The specified GCS must have a valid GCS token at the top of the stack, as though userspace were pivoting to the new GCS. This will be consumed on use. At present we do not atomically consume the token, this will be addressed in a future revision. Unfortunately plain clone() is not extensible and existing clone3() users will not specify a stack so all existing code would be broken if we mandated specifying the stack explicitly. For compatibility with these cases and also x86 (which did not initially implement clone3() support for shadow stacks) if no GCS is specified we will allocate one so when a thread is created which has GCS enabled allocate one for it. We follow the extensively discussed x86 implementation and allocate min(RLIMIT_STACK, 2G). Since the GCS only stores the call stack and not any variables this should be more than sufficient for most applications. GCSs allocated via this mechanism will be freed when the thread exits, those explicitly configured by the user will not. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 9 +++ arch/arm64/kernel/process.c | 29 +++++++++ arch/arm64/mm/gcs.c | 142 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) diff --git a/arch/arm64/include/asm/gcs.h b/arch/arm64/include/asm/gcs.h index 04594ef59dad..c1f274fdb9c0 100644 --- a/arch/arm64/include/asm/gcs.h +++ b/arch/arm64/include/asm/gcs.h @@ -8,6 +8,8 @@ #include #include +struct kernel_clone_args; + static inline void gcsb_dsync(void) { asm volatile(".inst 0xd503227f" : : : "memory"); @@ -58,6 +60,8 @@ static inline bool task_gcs_el0_enabled(struct task_struct *task) void gcs_set_el0_mode(struct task_struct *task); void gcs_free(struct task_struct *task); void gcs_preserve_current_state(void); +unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, + const struct kernel_clone_args *args); #else @@ -69,6 +73,11 @@ static inline bool task_gcs_el0_enabled(struct task_struct *task) static inline void gcs_set_el0_mode(struct task_struct *task) { } static inline void gcs_free(struct task_struct *task) { } static inline void gcs_preserve_current_state(void) { } +static inline unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, + const struct kernel_clone_args *args) +{ + return -ENOTSUPP; +} #endif diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 5f00cb0da9c3..d6d3a96cf2e4 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -285,9 +285,32 @@ static void flush_gcs(void) write_sysreg_s(0, SYS_GCSPR_EL0); } +static int copy_thread_gcs(struct task_struct *p, + const struct kernel_clone_args *args) +{ + unsigned long gcs; + + gcs = gcs_alloc_thread_stack(p, args); + if (IS_ERR_VALUE(gcs)) + return PTR_ERR((void *)gcs); + + p->thread.gcs_el0_mode = current->thread.gcs_el0_mode; + p->thread.gcs_el0_locked = current->thread.gcs_el0_locked; + + /* Ensure the current state of the GCS is seen by CoW */ + gcsb_dsync(); + + return 0; +} + #else static void flush_gcs(void) { } +static int copy_thread_gcs(struct task_struct *p, + const struct kernel_clone_args *args) +{ + return 0; +} #endif @@ -303,6 +326,7 @@ void flush_thread(void) void arch_release_task_struct(struct task_struct *tsk) { fpsimd_release_task(tsk); + gcs_free(tsk); } int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) @@ -366,6 +390,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) unsigned long stack_start = args->stack; unsigned long tls = args->tls; struct pt_regs *childregs = task_pt_regs(p); + int ret; memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context)); @@ -407,6 +432,10 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) p->thread.uw.tp_value = tls; p->thread.tpidr2_el0 = 0; } + + ret = copy_thread_gcs(p, args); + if (ret != 0) + return ret; } else { /* * A kthread has no context to ERET to, so ensure any buggy diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c index b0a67efc522b..b71f6b408513 100644 --- a/arch/arm64/mm/gcs.c +++ b/arch/arm64/mm/gcs.c @@ -8,6 +8,138 @@ #include #include +static unsigned long alloc_gcs(unsigned long addr, unsigned long size) +{ + int flags = MAP_ANONYMOUS | MAP_PRIVATE; + struct mm_struct *mm = current->mm; + unsigned long mapped_addr, unused; + + if (addr) + flags |= MAP_FIXED_NOREPLACE; + + mmap_write_lock(mm); + mapped_addr = do_mmap(NULL, addr, size, PROT_READ, flags, + VM_SHADOW_STACK | VM_WRITE, 0, &unused, NULL); + mmap_write_unlock(mm); + + return mapped_addr; +} + +static unsigned long gcs_size(unsigned long size) +{ + if (size) + return PAGE_ALIGN(size); + + /* Allocate RLIMIT_STACK/2 with limits of PAGE_SIZE..2G */ + size = PAGE_ALIGN(min_t(unsigned long long, + rlimit(RLIMIT_STACK) / 2, SZ_2G)); + return max(PAGE_SIZE, size); +} + +static bool gcs_consume_token(struct mm_struct *mm, unsigned long user_addr) +{ + u64 expected = GCS_CAP(user_addr); + u64 val; + int ret; + + /* This should really be an atomic cmpxchg. It is not. */ + ret = access_remote_vm(mm, user_addr, &val, sizeof(val), + FOLL_FORCE); + if (ret != sizeof(val)) + return false; + + if (val != expected) + return false; + + val = 0; + ret = access_remote_vm(mm, user_addr, &val, sizeof(val), + FOLL_FORCE | FOLL_WRITE); + if (ret != sizeof(val)) + return false; + + return true; +} + +int arch_shstk_post_fork(struct task_struct *tsk, + struct kernel_clone_args *args) +{ + struct mm_struct *mm; + unsigned long addr, size, gcspr_el0; + int ret = 0; + + mm = get_task_mm(tsk); + if (!mm) + return -EFAULT; + + addr = args->shadow_stack; + size = args->shadow_stack_size; + + /* + * There should be a token, and there is likely to be an optional + * end of stack marker above it. + */ + gcspr_el0 = addr + size - (2 * sizeof(u64)); + if (!gcs_consume_token(mm, gcspr_el0)) { + gcspr_el0 += sizeof(u64); + if (!gcs_consume_token(mm, gcspr_el0)) { + ret = -EINVAL; + goto out; + } + } + + tsk->thread.gcspr_el0 = gcspr_el0 + sizeof(u64); + +out: + mmput(mm); + + return ret; +} + +unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, + const struct kernel_clone_args *args) +{ + unsigned long addr, size; + + /* If the user specified a GCS use it. */ + if (args->shadow_stack_size) { + if (!system_supports_gcs()) + return (unsigned long)ERR_PTR(-EINVAL); + + /* GCSPR_EL0 will be set up when verifying token post fork */ + addr = args->shadow_stack; + } else { + + /* + * Otherwise fall back to legacy clone() support and + * implicitly allocate a GCS if we need a new one. + */ + + if (!system_supports_gcs()) + return 0; + + if (!task_gcs_el0_enabled(tsk)) + return 0; + + if ((args->flags & (CLONE_VFORK | CLONE_VM)) != CLONE_VM) { + tsk->thread.gcspr_el0 = read_sysreg_s(SYS_GCSPR_EL0); + return 0; + } + + size = args->stack_size; + + size = gcs_size(size); + addr = alloc_gcs(0, size); + if (IS_ERR_VALUE(addr)) + return addr; + + tsk->thread.gcs_base = addr; + tsk->thread.gcs_size = size; + tsk->thread.gcspr_el0 = addr + size - sizeof(u64); + } + + return addr; +} + /* * Apply the GCS mode configured for the specified task to the * hardware. @@ -30,6 +162,16 @@ void gcs_set_el0_mode(struct task_struct *task) void gcs_free(struct task_struct *task) { + + /* + * When fork() with CLONE_VM fails, the child (tsk) already + * has a GCS allocated, and exit_thread() calls this function + * to free it. In this case the parent (current) and the + * child share the same mm struct. + */ + if (!task->mm || task->mm != current->mm) + return; + if (task->thread.gcs_base) vm_munmap(task->thread.gcs_base, task->thread.gcs_size); From patchwork Thu Aug 1 12:06:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750401 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 11002C3DA4A for ; Thu, 1 Aug 2024 12:59:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 969FB6B00B4; Thu, 1 Aug 2024 08:59:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F2A46B00B7; Thu, 1 Aug 2024 08:59:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 746326B00B8; Thu, 1 Aug 2024 08:59:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 50BB86B00B4 for ; Thu, 1 Aug 2024 08:59:49 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1198680D56 for ; Thu, 1 Aug 2024 12:59:49 +0000 (UTC) X-FDA: 82403683698.27.AFE0413 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf17.hostedemail.com (Postfix) with ESMTP id 9F30C40021 for ; Thu, 1 Aug 2024 12:59:46 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GUkmhbKE; spf=pass (imf17.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517142; 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=e+GtNoZTL+PLww23zV5G42yIi6YXa+1nPigCcryYOuE=; b=Uv5/sGxpDIp7yMlD6ycyumlOgyiQqMRG4+Mhu30SimK9nlx90QfRWuOGGcEA1bgbjE4g/K MDiahV5Q1AJpdOtcRE6mA2kSuEk47NaWazX5aTR765/kx89uyrLFT0ORn9WMLvK4T0Q1MR ALZDWtLVgScLDUAtlk2rqrrWsI1G7qA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GUkmhbKE; spf=pass (imf17.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517142; a=rsa-sha256; cv=none; b=U7Wc0Wz2t0g+UaQPLzphTgB/8SX0GEljHxhshSL4kr5m8YDQ3RBAPPbXuxbzNcmZxsDJEp d3FufexGfim1hTw9jCNXgM8FG4CmC8J+apA1mJUGjcw6NnqXkbZoo6SnMwWcK9QCJ4AYE9 /vo1+OoHV1ylC9CVr7UiXfnDM9yCiw8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 12B4BCE1849; Thu, 1 Aug 2024 12:59:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3DA1C32786; Thu, 1 Aug 2024 12:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517183; bh=l/cgslNqipFgR1QPpcC58vps94W/JCkBuifrxenYdK8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GUkmhbKE+Q+QxkXEevPPCfiJRXd5FNakIcikzhEN2r+Y3716TgIqNQqi3/13TrKdN HIBgZQ/1SxhfeUku1mjS3dI9gJd5Y0/ivPkfcKPfKg5jlCt2uVtcovZSQiwB4bUAY1 60yd94kZUoDzqiPkoVcVrpqLeaIFFQp0zmet05AAhv8xve7WNP/maR57YBUIkEFAM0 ReBIG2n0DHxR5fn2goMGp20tPmqUycZyTj7dOsbsp4ZLaKI5uA18FfBlXS1JAaMxBP evqz3VGXwik6kkVPFN517NfkDbi0mWCXCoD94vwEkIkjYY2LMkGf9buq6RTQzNFkwa bloRRVzHt8Imw== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:48 +0100 Subject: [PATCH v10 21/40] arm64/gcs: Implement shadow stack prctl() interface MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-21-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=5708; i=broonie@kernel.org; h=from:subject:message-id; bh=l/cgslNqipFgR1QPpcC58vps94W/JCkBuifrxenYdK8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YW+701C0PZ1auv1x0ZYEkwavziBHutsB26kIic off1qfiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGFgAKCRAk1otyXVSH0KvmB/ wOu13MLk5RjXsF3gjaYR24ss/GiRkPXfkTMTPQb7ytIqHtjun7ntid2AAFcjdLng+3y+Ozw3Wfi0NK Tg4zsf7/hUv0Sr6rdDVaQWSz2RUqS5W4ARSC0sSjtOjTQx5ZRdj1o9kS2BXEqi0aJp/qLl+FHfQTnV 1G64p0RRP7baD+jgOSoWwFEU599l1245JyBmReBWlqt0Wo2i0ULYXqzzKKgapzB6wfLNmPCm680IX6 zf6mHYGwq63zPkix9zp3xpQHZ/bDHZ7NHyXJOzRJulz8dVKlrANaTJ1/QXaTfiFX6RJlG9LPOfNiBL 0Y1WZQwObI0/++tANtghpDMRAyN5dX X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 5uy8swjoqrnbe3s3eqcfdyukbntumhhn X-Rspam-User: X-Rspamd-Queue-Id: 9F30C40021 X-Rspamd-Server: rspam02 X-HE-Tag: 1722517186-486118 X-HE-Meta: U2FsdGVkX185fWJsO9MSYdK5EDb8Uo3bE301OLlK/0s+QWbqZr1aMTHeR8aYST9OGZyp9YwKlnnCzbW3hLjnIKqYXQ7Q9bjdQK6Cvxb/Ry6Lb8QpBL3Gh+BLr/gSmcw9Zcqz0gslg7O6oMh5wlkPS0oo7CluwCguNO2IhsbsBsgowIHvqiKWaet5uUIuecsG7ck+4F1EdvzfTrsjrnOyAR7w8jPyyfhbKugxkT1R9PMYCRZmAaTWI1maCQKpMz2QIi+wIRe3CxDu2bUFiPnpMYkAk8erLg6lB2d4/UpldB6Wc3pjrPn8nOjxkVyOzdErLunRA6FR0QjlZb22Y501feflARq8MMEivT7TTmxyDPaM98xQ1CuRDS3BKXgiF79Rz3P/IUn65ENujA0oGCa2fWsV0CvXtBIgVDgUmH3PMCxhszRumtefY7XYa8ZaJMcioLnTivAsKdx4rquadjekwER659vcVbLpGKHSpoTZ6RTlH+usnBTWYlANa9rCT1x1o80ICBjZSbp6byLuVZy9GmAfTgqEseXudMJssyMPbgZxWxNnMWjOOCb6/Bbjtd0XzK8iKOtw0WDU0Dp4PP7VD4FM1WzDP0fuqVxaNbFejOQ93z5rOmOPNOXfXUKyUWWaSaFLoVy6ABMKL+1HaV6axRLYqU9xDMkkJ7yid2TXhFdsISeZBOi7WcVvlklB+aV7jl/zC71G+Es9aRDlF99VC4YIFcdkHKigaK9gbRNQrYLFXQ/bhpUaU/a3WK212iDCinxrDQUCDCFT2s/i14Xx+oXBhLq9nwf4v4X40C8L0PX6Rvckx52oZalsrfszuqR7iiCpubG6lfjx/6xko+a2e4WiIRvUEj0sSDRP371dtjrYvwqy/3XLgYm9+E7vmZwG+K7Traox12Lg55EfB2ApRnNTZ7OygiGeuWMksWuR3CvNtt9YjPAT/A1FHmRq+oYNHmmM6OEKU5gabHBgce0 oGNinqeU Hs2CpQorjQx5iLofLeH+0i2kLqyaxNKIoY6K11MQul2SdZzQqynQzWUTZTCI6WJQupnnu4LHNMy/utNISrC0tMRyemGeGkcbm5ladGZXtNCqwangYuG/AuGfmHkE4oQkM90TVfAVABJXoeblKT5A414jZlIYEaRmX4jJQq7URpDdl3zLoaWOs+EFVewF86B91vfIBqgO7LUUO5LHJeWxK+5GsgJb9I3E+L8TFKgD8/MTMfHdfjR0qjHEkkEdIoulAnl59fLJu0lu8I0+LRMMN6uAr0RdhhT6uwG10LYbb522tDjtH5TqGAJv1ZpjImwBPN0ONe1YCFEyu7n8EZ80N3C1FGWmoviCqNwzir0PxU4s75n1Y6fpfDKfhQaCK3YIOtylP 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: Implement the architecture neutral prtctl() interface for setting the shadow stack status, this supports setting and reading the current GCS configuration for the current thread. Userspace can enable basic GCS functionality and additionally also support for GCS pushes and arbitrary GCS stores. It is expected that this prctl() will be called very early in application startup, for example by the dynamic linker, and not subsequently adjusted during normal operation. Users should carefully note that after enabling GCS for a thread GCS will become active with no call stack so it is not normally possible to return from the function that invoked the prctl(). State is stored per thread, enabling GCS for a thread causes a GCS to be allocated for that thread. Userspace may lock the current GCS configuration by specifying PR_SHADOW_STACK_ENABLE_LOCK, this prevents any further changes to the GCS configuration via any means. If GCS is not being enabled then all flags other than _LOCK are ignored, it is not possible to enable stores or pops without enabling GCS. When disabling the GCS we do not free the allocated stack, this allows for inspection of the GCS after disabling as part of fault reporting. Since it is not an expected use case and since it presents some complications in determining what to do with previously initialsed data on the GCS attempts to reenable GCS after this are rejected. This can be revisted if a use case arises. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/gcs.h | 22 +++++++++++ arch/arm64/include/asm/processor.h | 1 + arch/arm64/mm/gcs.c | 81 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/arch/arm64/include/asm/gcs.h b/arch/arm64/include/asm/gcs.h index c1f274fdb9c0..48c97e63e56a 100644 --- a/arch/arm64/include/asm/gcs.h +++ b/arch/arm64/include/asm/gcs.h @@ -50,6 +50,9 @@ static inline u64 gcsss2(void) return Xt; } +#define PR_SHADOW_STACK_SUPPORTED_STATUS_MASK \ + (PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_WRITE | PR_SHADOW_STACK_PUSH) + #ifdef CONFIG_ARM64_GCS static inline bool task_gcs_el0_enabled(struct task_struct *task) @@ -63,6 +66,20 @@ void gcs_preserve_current_state(void); unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, const struct kernel_clone_args *args); +static inline int gcs_check_locked(struct task_struct *task, + unsigned long new_val) +{ + unsigned long cur_val = task->thread.gcs_el0_mode; + + cur_val &= task->thread.gcs_el0_locked; + new_val &= task->thread.gcs_el0_locked; + + if (cur_val != new_val) + return -EBUSY; + + return 0; +} + #else static inline bool task_gcs_el0_enabled(struct task_struct *task) @@ -78,6 +95,11 @@ static inline unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, { return -ENOTSUPP; } +static inline int gcs_check_locked(struct task_struct *task, + unsigned long new_val) +{ + return 0; +} #endif diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index c55e3600604a..58eb48cd539f 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -186,6 +186,7 @@ struct thread_struct { u64 tpidr2_el0; #ifdef CONFIG_ARM64_GCS unsigned int gcs_el0_mode; + unsigned int gcs_el0_locked; u64 gcspr_el0; u64 gcs_base; u64 gcs_size; diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c index b71f6b408513..0d39829f862e 100644 --- a/arch/arm64/mm/gcs.c +++ b/arch/arm64/mm/gcs.c @@ -179,3 +179,84 @@ void gcs_free(struct task_struct *task) task->thread.gcs_base = 0; task->thread.gcs_size = 0; } + +int arch_set_shadow_stack_status(struct task_struct *task, unsigned long arg) +{ + unsigned long gcs, size; + int ret; + + if (!system_supports_gcs()) + return -EINVAL; + + if (is_compat_thread(task_thread_info(task))) + return -EINVAL; + + /* Reject unknown flags */ + if (arg & ~PR_SHADOW_STACK_SUPPORTED_STATUS_MASK) + return -EINVAL; + + ret = gcs_check_locked(task, arg); + if (ret != 0) + return ret; + + /* If we are enabling GCS then make sure we have a stack */ + if (arg & PR_SHADOW_STACK_ENABLE) { + if (!task_gcs_el0_enabled(task)) { + /* Do not allow GCS to be reenabled */ + if (task->thread.gcs_base) + return -EINVAL; + + if (task != current) + return -EBUSY; + + size = gcs_size(0); + gcs = alloc_gcs(0, size); + if (!gcs) + return -ENOMEM; + + task->thread.gcspr_el0 = gcs + size - sizeof(u64); + task->thread.gcs_base = gcs; + task->thread.gcs_size = size; + if (task == current) + write_sysreg_s(task->thread.gcspr_el0, + SYS_GCSPR_EL0); + + } + } + + task->thread.gcs_el0_mode = arg; + if (task == current) + gcs_set_el0_mode(task); + + return 0; +} + +int arch_get_shadow_stack_status(struct task_struct *task, + unsigned long __user *arg) +{ + if (!system_supports_gcs()) + return -EINVAL; + + if (is_compat_thread(task_thread_info(task))) + return -EINVAL; + + return put_user(task->thread.gcs_el0_mode, arg); +} + +int arch_lock_shadow_stack_status(struct task_struct *task, + unsigned long arg) +{ + if (!system_supports_gcs()) + return -EINVAL; + + if (is_compat_thread(task_thread_info(task))) + return -EINVAL; + + /* + * We support locking unknown bits so applications can prevent + * any changes in a future proof manner. + */ + task->thread.gcs_el0_locked |= arg; + + return 0; +} From patchwork Thu Aug 1 12:06:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750402 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 F13F7C3DA4A for ; Thu, 1 Aug 2024 12:59:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A6326B00B8; Thu, 1 Aug 2024 08:59:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 82FD46B00B9; Thu, 1 Aug 2024 08:59:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A8786B00BA; Thu, 1 Aug 2024 08:59:56 -0400 (EDT) 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 444986B00B8 for ; Thu, 1 Aug 2024 08:59:56 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E4C2BA779C for ; Thu, 1 Aug 2024 12:59:55 +0000 (UTC) X-FDA: 82403683950.23.E22AD5B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf13.hostedemail.com (Postfix) with ESMTP id 8421A20015 for ; Thu, 1 Aug 2024 12:59:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=f+gcjC8U; spf=pass (imf13.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517149; 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=Fc3efdaWdHZ66wwAfskzSCLEVc53sAtjfnpn9IMT5MI=; b=nfHkyAc4gmWkNpj/8YMIilxa4iOrryXOj3z1Jg2MwPmBINJB1VWBesGEjOgwE50LZx43C7 mqm1jpUYSKE+ARLVDTG8ngKesZ7WkGK00dUGgwP/dqrmfQ0dL6x938CVA7aTBDz3nOt55E gOL0Bqg2QhZoWlvEMYRarS7UEeTqymE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=f+gcjC8U; spf=pass (imf13.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517149; a=rsa-sha256; cv=none; b=vvZQjh81H0ONLtIe1RJgSfQUarcJkEgwHWgFwmyEl9zmND+hxQMxmWWofvxCItpM3v7IrP skL/q5oca0uRjlid7O/onShTz2ulkOYlCS0qh/ILR27WI3pyYWGh0YtNjEhASucpYu9bOw 7GIV8nGeKY8yK+O6w+X20yZx1TnvBQ8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id DECE0CE193F; Thu, 1 Aug 2024 12:59:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7C84C4AF09; Thu, 1 Aug 2024 12:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517190; bh=sHUTBcC9ajPqHUJTppDeK0B3kuOgTQJMo9ToCm1jbwg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=f+gcjC8U0DPC9CuVb9hizzrLAAK+UQ4RNTiDbO40spLPhXmrdjZh1UH7Ysws0Iy3F g5XzrUnTYPXWfPP/ApA+KHfbyxXbkQq+n6ctqR8btWf77VzdJvfjokIudQYe3QObZb 412kswTUa4acYd4oKwR5hCgQLRPO+Is+8AGse/LeIzY1Ut5IbYqRR8U2D282SpGEbM tQ5BFRkyvhxTL4MM0YegHjz7PAnmbejqSt6QVly2yZ56V2TH+3Sf2JVhxzVA7K7cOT TZEmFWVliuG0+RPnKnQb/rEQ2NSVglRQ4rN0BLrR2xyeJy1K1sKZuE/e9NFD0EACWP t5apF7XojBzYA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:49 +0100 Subject: [PATCH v10 22/40] arm64/mm: Implement map_shadow_stack() MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-22-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=2987; i=broonie@kernel.org; h=from:subject:message-id; bh=sHUTBcC9ajPqHUJTppDeK0B3kuOgTQJMo9ToCm1jbwg=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YXropMdlIS63qshvA6lvojkCo/oAO1adQXBQBZ Du9YUr6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGFwAKCRAk1otyXVSH0KkqB/ 4/6Y5UAvVw7VWYaEMICrtZg2DSoyU9nSsx2DULzGCY2jNoB49lfqczc/CSIkCdRyAuotj32onJgufj pKduK9m0qZx9Ob+aLo/exl96WDp0nsUmlbefih+oqecwlVtHnSbPTZTuFCpJkKDEEn9UykoGt6JthV O2s4dsnE5i97W3LA80/j8e4vtjd/PTN2RY2ltQ3diEG/YffcHg2W/twN1vBsbrob58yQjz2gMMaYL0 +Fq1SA3+ujMf9iwgmhW6W90O1/FB2S9WnCTeOm18Qd2ZmoDbK1gUc7476SyQWt0lfpyxnPzEFAy/6A xF+nEgrw9zHLV3CAbGKtwlwTT3VH63 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 5utz8ge7u8e68da68ue165cfhgh6ugbb X-Rspam-User: X-Rspamd-Queue-Id: 8421A20015 X-Rspamd-Server: rspam02 X-HE-Tag: 1722517193-955693 X-HE-Meta: U2FsdGVkX18Uko+FKRasf5Jao93pG+x/xUevWJxTLHVQC8k4ZDhwgu4Wez/l4BAjARTngjGA4f2Mvw6dRfRTehQh5JZw1jBMnDLsvBEOiAVg/KadxG5E1u0/DANpomFlFA0eZoUkU+SuVeKPbuflCR+6KSMFr8JzU9YyM3uy8FzCUg4iqfsPPx3ae/JO62kJtjPmaU4YNNXvGpldfN/aHCE7puyS5QSZKQOJxBCzt3PAPkRGlrVVSP7kCTj2bbmUzz7KVIbVOB2KtTgggcHtS5eqCxQpFEE5bRUA9chfSC1nBl+azL2WkZ1BBVQyRAUv5M9aK3Q6kR4fAVltaVn25YRhOle5G5Yil5GhhXUc4sMMhxfaYnFWQ2aKSQUvJzrzpp9oU2kNbXZGW83ocAQfZ1kUsB2hFRX2cxF740jtU/istLiwDYbKuZQ4lB/XOo1cjGGzVxwirt+Y0WLSmyWXTNgm6PtswvNa4u1nEyWtAT9yLobp1UDQBEaWtSgOp+QH1IJfoac5bWbb056+GNqgsV0ANXJLIbzNeTb2mqRt4RMtKCwRwLyzFgbQjyKb9Zx4KgTy9yuDoOa528tf1cdOpgJUQNtIgndYMkBg5IADFjhVONbAlScLJ1RHbkmS5WdFnAXyXhQSKAKzKgnbIkOXr874JtNuYhKbuVIrMfO/sBlLAdswdRxRhSFDUIo97R+4b4FevZPvl/LDZTXqq5zZQZuo5EGXVK1o9BdUw0IK24Byp+QsZhE2R5b1FTXgnv8qXCaruSgPr4pJNA0vrE7Cf25dael5NOe+5v7h/v9Q1k3cagUUFtMVr5Lzh26OjrrjUOgybtX4IuEC4Nmu0/ISwoeLCmix314Slpgi1rR9p0EmBb2//wBsv3ZC3/Gf0/D5uYhpj59FRCuQAD7aTqIGZhuCDHRrpj1S+22gFFKCKzsvZjAhu9qhDRKBEMfEs0dgtZXo8QNtiNkiEm97Fiw rta9RHz0 6tZIxvK1M04X8mUdfQBIpSVROZzBXvzJ3eGQ1sCOg+JxsCOVslONUnHcqoAa9yd46A1FfzljR9hfFo82nEqCHzR8eFvbmKlmvP1G0L8L9kRAEO9smc1DYcMcDd1VL2tvGEdrzq6TW8SUBtrJCIxbQ2hoV9EtGWRXZi8pFAVn7WpBygEPnl6Qr4E2A9ZXjF02cFvQfs5uNOos0lh5HScRCRVsiaZkOJXcv+Z4YQxwlAywbgW0JXjPDkFpes3L8Sscb8lw46hI0Kd6RpEDBsPfgrBnEfBxqGfMaEZnEAm1AJmTooV35NU4kYBNO4LloPdEFBH3KJE22CIHm+ErRM871/RZVPOT/p8/mGld+85Xvme4kwLFaEyGMrx6eTwqFcKbs7fheyHCrm9iGPq5TGzLzgcfBRAGEQ9HlnRWzIiWjrZpGuFM= 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: As discussed extensively in the changelog for the addition of this syscall on x86 ("x86/shstk: Introduce map_shadow_stack syscall") the existing mmap() and madvise() syscalls do not map entirely well onto the security requirements for guarded control stacks since they lead to windows where memory is allocated but not yet protected or stacks which are not properly and safely initialised. Instead a new syscall map_shadow_stack() has been defined which allocates and initialises a shadow stack page. Implement this for arm64. Two flags are provided, allowing applications to request that the stack be initialised with a valid cap token at the top of the stack and optionally also an end of stack marker above that. We support requesting an end of stack marker alone but since this is a NULL pointer it is indistinguishable from not initialising anything by itself. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/mm/gcs.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c index 0d39829f862e..6703c70581a4 100644 --- a/arch/arm64/mm/gcs.c +++ b/arch/arm64/mm/gcs.c @@ -140,6 +140,67 @@ unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, return addr; } +SYSCALL_DEFINE3(map_shadow_stack, unsigned long, addr, unsigned long, size, unsigned int, flags) +{ + unsigned long alloc_size; + unsigned long __user *cap_ptr; + unsigned long cap_val; + int ret = 0; + int cap_offset; + + if (!system_supports_gcs()) + return -EOPNOTSUPP; + + if (flags & ~(SHADOW_STACK_SET_TOKEN | SHADOW_STACK_SET_MARKER)) + return -EINVAL; + + if (addr && (addr % PAGE_SIZE)) + return -EINVAL; + + if (size == 8 || size % 8) + return -EINVAL; + + /* + * An overflow would result in attempting to write the restore token + * to the wrong location. Not catastrophic, but just return the right + * error code and block it. + */ + alloc_size = PAGE_ALIGN(size); + if (alloc_size < size) + return -EOVERFLOW; + + addr = alloc_gcs(addr, alloc_size); + if (IS_ERR_VALUE(addr)) + return addr; + + /* + * Put a cap token at the end of the allocated region so it + * can be switched to. + */ + if (flags & SHADOW_STACK_SET_TOKEN) { + /* Leave an extra empty frame as a top of stack marker? */ + if (flags & SHADOW_STACK_SET_MARKER) + cap_offset = 2; + else + cap_offset = 1; + + cap_ptr = (unsigned long __user *)(addr + size - + (cap_offset * sizeof(unsigned long))); + cap_val = GCS_CAP(cap_ptr); + + put_user_gcs(cap_val, cap_ptr, &ret); + if (ret != 0) { + vm_munmap(addr, size); + return -EFAULT; + } + + /* Ensure the new cap is viaible for GCS */ + gcsb_dsync(); + } + + return addr; +} + /* * Apply the GCS mode configured for the specified task to the * hardware. From patchwork Thu Aug 1 12:06:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750403 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 EB102C3DA64 for ; Thu, 1 Aug 2024 13:00:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 79BDD6B00BA; Thu, 1 Aug 2024 09:00:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71E0F6B00BB; Thu, 1 Aug 2024 09:00:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 598846B00BC; Thu, 1 Aug 2024 09:00:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 338AA6B00BA for ; Thu, 1 Aug 2024 09:00:00 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E20D780D5B for ; Thu, 1 Aug 2024 12:59:59 +0000 (UTC) X-FDA: 82403684118.25.C051EB0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf02.hostedemail.com (Postfix) with ESMTP id 199D680028 for ; Thu, 1 Aug 2024 12:59:57 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LOKxC2BE; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf02.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=1722517156; a=rsa-sha256; cv=none; b=6fuI6JWfQN/Ck7T4eeJFMRpTMzE0dPRlpa0lnYNmVeSQ6b29nqoWPomza3pNfb8e3gWjIG PE3QmOtUxRUyuK7nyXb4vbzGsPuyI4HqT3dzlZXEk5U0feiBLTrhTXmpT5kqbezO/ShXoT UAhjvNRa/dips6tWBufLJK56e5O7no8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LOKxC2BE; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf02.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=1722517156; 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=q3mMMJqc9hcPcKKyi0bs/sNguX8AFY5itYEFvsSCOVs=; b=mWuL8amn6l6rC4aanHjdrCsWGmBDbvbFikffHLHicKRd97qKPY17j3POo33GTH+l03FSBr Ksdsqz/RE6MkW21/hJijsiF0Sg3yerqLwRMjj0x/6FYwOTS8I+JHEQ0yV06qKMPrp+dLOX jkLWbIV9ubWUxuEIv786w/Nz8qtQgBU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 54CCE6285D; Thu, 1 Aug 2024 12:59:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DB4DC4AF10; Thu, 1 Aug 2024 12:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517197; bh=spmcAZuGAEVkEAa67eKDQiXBrVNYqAUzr8CNYTcqBhY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LOKxC2BEeYpWK9TNAcSxZylJbNNavaok4F0MVQF42q8Yo5nRUBk81Vc5hp7w8/t92 LsMDgWc+InmcMqTWZD6/69VxGqhn8WSc/jepxE26Xfnyufj0nXumjxFlUBsNs+QANO wsGcFRMs/c40JG6FRb87QyriRPmvRVk4y2Ueek2ZXoweeHhDkcfCMIx6NCHhu+OnHD YO1IoJd/zisL3Wcvob81CPlcsh03PkB3id0JEO9TBq9xv16rzrNf9kw01lIOzHrOlJ BPOAOCgy24R5t6/RMkEItz3FZv8lRmR9ooY2c9yLuM8DFfv5iJv87hNem9uBs53/KE +CzqmqoYAM82A== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:50 +0100 Subject: [PATCH v10 23/40] arm64/signal: Set up and restore the GCS context for signal handlers MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-23-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=7410; i=broonie@kernel.org; h=from:subject:message-id; bh=spmcAZuGAEVkEAa67eKDQiXBrVNYqAUzr8CNYTcqBhY=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YXZ0sZoZTGjIVJ72pSAZqpftvV6uf/BnLmr3c6 L0bOK56JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGFwAKCRAk1otyXVSH0IjCB/ 0Z23quOTSlgLwveoWe21ZO693B3sCcrTDtGb3Hzg4WDqZ9uj/j5i/qrMK30dEijKL3tVwAWZetJbdC 2WG7GAoVWlYz7NSgLF035utHXv7atop4YfEsC7gtLxA3fUFhs4nfAKdQ3QBa0T2W5eGma/lSl2Ca2G 8SqGzsnLGC73oBvSORZGQIzSGU1pObqpdFs7BzC52aKp5o9M0CUN9tf8euB48ecU6cKYR/CE0ojMzE t7N1Q2iznMqMTGkqCNnAbigvxKWgEbj1tVQWHryOfxEqXcYnua5swm2P24nYFFDEJ/lQZOfaH6F9+S Q3xoDOzW11CtSxHYGrsPj4nh7AhDpR X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 199D680028 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dtb4dfe8kxsaamzj4mj9jqxq548tr438 X-HE-Tag: 1722517197-826889 X-HE-Meta: U2FsdGVkX1+hdQbX+KiDqvnq1ixMsk4Qf4vcmx1E69i0QzLsFCJLniiqatnmu1SiTIX+5l02+O1HzlDvEka3IPhX3QVmEGh0RD1PJWHmtoLLim04ffP5b03pCCEwPuCEcWZFWGhb91NvrDtNXg9IT6Djzldf01/ofEYEFBIM+nWPta8GBHCaol5v2oRzTJxNwtNzusTU9gFz/EV6AxIIIAXWPvjbpf/ypd0Mo2MSsGAI92/vwjWf540SwF7anaNphgFC3ehrsWMTcu9diga0ew4bOY4KI8W1TiDS1BJOa93lsPoBeHDqPlP8Jw7xx05XNHre3DpuTytGJ8UzmQLFbZwepQsiRVtfSI7whpl8Dp3cJg3T5QDFZVZ1RyPJ6gRn9LlR+hS3bEADQfJQM5sfEUnhkxjLX/7SZIfxOYKvSOsLxQd3TmHl21F5ekdTVVewFB71nuPSIXF7u4hE32drZe+LmRXsjXWMalBTOgSiDxXxHRyc+POjmxbhKzal359cFf8bAYShzAvnI/kvxO/WXgHT/FWt1irh7Ms3bg2xV3GaXdTtLe+HVD05BjmP2sPI3XabfJt2t1qZd/Nb3FHkMJfYTQfF1j6Bs3WmtiSW0F5iQEJeWrA1JwoK7TYcCUZtuie1ANJJJyPp5GQrsUxepj1lAGl3Hqp4t+ZcvomLl53Zm3ZstleFRe1Lg89/cq5RL5gNf/A0HePhPiVcanfnaP3o5n/dmhW+2qElojFh/NUK7QaSH/q15GYAbq3sDnpDxcAkg4CbcN9ZwVInilG5rSSPoWheSk6YtAneP8fcI1fLc8T8cossqUaGXujlZeNN6Z2eAYwePUgSpmkth4g2FyVp9wapj6k/Zo2yGm8YT8MQDjZnoI1glVp1Pb31s5FvSTT7mzwbRQbDCrzdJlkL0A3Xc7xuLePxPNFBFb7p7JodndbFlqMGwOSbjTclo0o9eiGgbX4ScdGoMpWCMCx eTZY/8W1 +PXrNa07Aqnjxc2KdrJ/Dxsr0OItivCUsRuU9OgDXh4RJ2/hlFScVup5LgRp/Q7pvyzfPZcbRae/4B1KIvRFKjcWyoRFvK9MvpgffswB21FNMXTVC+cKaqdpQv0QNTr6pA5VXMdEyM5F0SZVlaLE+vztbPVKCJnkRd61498fQo/K9m1FBYhKBMkV/5Y4ThG0sitzN/uJU0asODUXNqlwMiApLR54Z97R8U7brEJEZpYi8jcgjLj93CaFhEU7ET12ZWfbgnbXC23xewZzG23YmP+BURrqY6Zd/ib4a0/RWi18HCw2z2HGo/O4xnxap79Vv09It7cQ3YWw4YPO3D1AKYX48GkWunHU8hLbJSQGkSKDGU+YUvgfUIpdUzz1XMzRMIyiS 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: When invoking a signal handler we use the GCS configuration and stack for the current thread. Since we implement signal return by calling the signal handler with a return address set up pointing to a trampoline in the vDSO we need to also configure any active GCS for this by pushing a frame for the trampoline onto the GCS. If we do not do this then signal return will generate a GCS protection fault. In order to guard against attempts to bypass GCS protections via signal return we only allow returning with GCSPR_EL0 pointing to an address where it was previously preempted by a signal. We do this by pushing a cap onto the GCS, this takes the form of an architectural GCS cap token with the top bit set and token type of 0 which we add on signal entry and validate and pop off on signal return. The combination of the top bit being set and the token type mean that this can't be interpreted as a valid token or address. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 1 + arch/arm64/kernel/signal.c | 134 +++++++++++++++++++++++++++++++++++++++++-- arch/arm64/mm/gcs.c | 1 + 3 files changed, 131 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/gcs.h b/arch/arm64/include/asm/gcs.h index 48c97e63e56a..f50660603ecf 100644 --- a/arch/arm64/include/asm/gcs.h +++ b/arch/arm64/include/asm/gcs.h @@ -9,6 +9,7 @@ #include struct kernel_clone_args; +struct ksignal; static inline void gcsb_dsync(void) { diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 4a77f4976e11..a1e0aa38bff9 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,37 @@ #include #include +#ifdef CONFIG_ARM64_GCS +/* Extra bit set in the address distinguishing a signal cap token. */ +#define GCS_SIGNAL_CAP_FLAG BIT(63) + +#define GCS_SIGNAL_CAP(addr) ((((unsigned long)addr) & GCS_CAP_ADDR_MASK) | \ + GCS_SIGNAL_CAP_FLAG) + +static bool gcs_signal_cap_valid(u64 addr, u64 val) +{ + /* + * The top bit should be set, this is an invalid address for + * EL0 and will only be set for caps created by signals. + */ + if (!(val & GCS_SIGNAL_CAP_FLAG)) + return false; + + /* The rest should be a standard architectural cap token. */ + val &= ~GCS_SIGNAL_CAP_FLAG; + + /* The cap must not have a token set */ + if (GCS_CAP_TOKEN(val) != 0) + return false; + + /* The cap must store the VA the cap was stored at */ + if (GCS_CAP_ADDR(addr) != GCS_CAP_ADDR(val)) + return false; + + return true; +} +#endif + /* * Do a signal return; undo the signal stack. These are aligned to 128-bit. */ @@ -860,6 +892,50 @@ static int restore_sigframe(struct pt_regs *regs, return err; } +#ifdef CONFIG_ARM64_GCS +static int gcs_restore_signal(void) +{ + u64 gcspr_el0, cap; + int ret; + + if (!system_supports_gcs()) + return 0; + + if (!(current->thread.gcs_el0_mode & PR_SHADOW_STACK_ENABLE)) + return 0; + + gcspr_el0 = read_sysreg_s(SYS_GCSPR_EL0); + + /* + * GCSPR_EL0 should be pointing at a capped GCS, read the cap... + */ + gcsb_dsync(); + ret = copy_from_user(&cap, (__user void*)gcspr_el0, sizeof(cap)); + if (ret) + return -EFAULT; + + /* + * ...then check that the cap is the actual GCS before + * restoring it. + */ + if (!gcs_signal_cap_valid(gcspr_el0, cap)) + return -EINVAL; + + /* Invalidate the token to prevent reuse */ + put_user_gcs(0, (__user void*)gcspr_el0, &ret); + if (ret != 0) + return -EFAULT; + + current->thread.gcspr_el0 = gcspr_el0 + sizeof(cap); + write_sysreg_s(current->thread.gcspr_el0, SYS_GCSPR_EL0); + + return 0; +} + +#else +static int gcs_restore_signal(void) { return 0; } +#endif + SYSCALL_DEFINE0(rt_sigreturn) { struct pt_regs *regs = current_pt_regs(); @@ -886,6 +962,9 @@ SYSCALL_DEFINE0(rt_sigreturn) if (restore_altstack(&frame->uc.uc_stack)) goto badframe; + if (gcs_restore_signal()) + goto badframe; + return regs->regs[0]; badframe: @@ -1130,7 +1209,50 @@ static int get_sigframe(struct rt_sigframe_user_layout *user, return 0; } -static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, +#ifdef CONFIG_ARM64_GCS + +static int gcs_signal_entry(__sigrestore_t sigtramp, struct ksignal *ksig) +{ + unsigned long __user *gcspr_el0; + int ret = 0; + + if (!system_supports_gcs()) + return 0; + + if (!task_gcs_el0_enabled(current)) + return 0; + + /* + * We are entering a signal handler, current register state is + * active. + */ + gcspr_el0 = (unsigned long __user *)read_sysreg_s(SYS_GCSPR_EL0); + + /* + * Push a cap and the GCS entry for the trampoline onto the GCS. + */ + put_user_gcs((unsigned long)sigtramp, gcspr_el0 - 2, &ret); + put_user_gcs(GCS_SIGNAL_CAP(gcspr_el0 - 1), gcspr_el0 - 1, &ret); + if (ret != 0) + return ret; + + gcsb_dsync(); + + gcspr_el0 -= 2; + write_sysreg_s((unsigned long)gcspr_el0, SYS_GCSPR_EL0); + + return 0; +} +#else + +static int gcs_signal_entry(__sigrestore_t sigtramp, struct ksignal *ksig) +{ + return 0; +} + +#endif + +static int setup_return(struct pt_regs *regs, struct ksignal *ksig, struct rt_sigframe_user_layout *user, int usig) { __sigrestore_t sigtramp; @@ -1138,7 +1260,7 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, regs->regs[0] = usig; regs->sp = (unsigned long)user->sigframe; regs->regs[29] = (unsigned long)&user->next_frame->fp; - regs->pc = (unsigned long)ka->sa.sa_handler; + regs->pc = (unsigned long)ksig->ka.sa.sa_handler; /* * Signal delivery is a (wacky) indirect function call in @@ -1178,12 +1300,14 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, sme_smstop(); } - if (ka->sa.sa_flags & SA_RESTORER) - sigtramp = ka->sa.sa_restorer; + if (ksig->ka.sa.sa_flags & SA_RESTORER) + sigtramp = ksig->ka.sa.sa_restorer; else sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp); regs->regs[30] = (unsigned long)sigtramp; + + return gcs_signal_entry(sigtramp, ksig); } static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, @@ -1206,7 +1330,7 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, err |= __save_altstack(&frame->uc.uc_stack, regs->sp); err |= setup_sigframe(&user, regs, set); if (err == 0) { - setup_return(regs, &ksig->ka, &user, usig); + err = setup_return(regs, ksig, &user, usig); if (ksig->ka.sa.sa_flags & SA_SIGINFO) { err |= copy_siginfo_to_user(&frame->info, &ksig->info); regs->regs[1] = (unsigned long)&frame->info; diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c index 6703c70581a4..30614f4ad164 100644 --- a/arch/arm64/mm/gcs.c +++ b/arch/arm64/mm/gcs.c @@ -6,6 +6,7 @@ #include #include +#include #include static unsigned long alloc_gcs(unsigned long addr, unsigned long size) From patchwork Thu Aug 1 12:06:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750404 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 1B156C52D54 for ; Thu, 1 Aug 2024 13:00:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7B4C6B00BC; Thu, 1 Aug 2024 09:00:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A041C6B00BD; Thu, 1 Aug 2024 09:00:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 859006B00BE; Thu, 1 Aug 2024 09:00:07 -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 5C4D26B00BC for ; Thu, 1 Aug 2024 09:00:07 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 089991A0D2B for ; Thu, 1 Aug 2024 13:00:07 +0000 (UTC) X-FDA: 82403684454.22.5050009 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 1BED840040 for ; Thu, 1 Aug 2024 13:00:04 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HpYaP2MI; spf=pass (imf11.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=1722517148; 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=N0Y/al1sp3Chtq8s1ZQyOSzTSotGRiWlj3PteLBX1bY=; b=vWUDAmdYLmAsu3gZ8rr14ysOCOYn22G3U2MdCeBkBgfcNvXHyx+yh51GtpsylV7YuU3MJM LbtJld8xNQATEnFidolBu/RpkiGa8lhUPBy+Sq3fu9LSK3lKJ7y7vRUsHg5mssuBco5xBh AgNggDIsQba039K7lDi29ndwkkdIyhA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517148; a=rsa-sha256; cv=none; b=lCGE+AgqWfB4iWYw/3sXkczPGHHcxBn9N5yARIqhoKXodQZx1ywDQ99vlxHebNALo1T78J bympwN/iY2VXdYznjMnMk2KLwXQvBa3K88APoon2/pm1GQ3SQEgny+h4QmrSKbiseFcaJZ niHNBOrGeLJKD61XQJpaAMEen7hMqbA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HpYaP2MI; spf=pass (imf11.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1B34862862; Thu, 1 Aug 2024 13:00:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75C8FC32786; Thu, 1 Aug 2024 12:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517203; bh=kpYoeEKXM/IVjTgCGNGqe131qZl9kDt0bNYWPvrqBbk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HpYaP2MI+mP0WS66w50alD68EsWa5FHYkuAoNe7krHyq4k2kWBVMBZP0yX0DsQjaG 9FknGSb9amgoKDpkG9qxU5PlFfePzuIRrG2/bwq4mWOFuumIzaNY70UR9EUltyaFC9 qbXFWafbtC9r1lSGZxjIDbLeF2871t8Yj77zb/C4fNlwX80r48OMWqXNDJisAzHE0L Yh6QD+b+WYJ02pRTKHYZxCUP0IosMaq8rpxVPoo/MJw3JiKPx+2V2PpDePUaZ5le/0 +qCC/c1Ge5pVpzCsODOURH+DK/Yqa/JBL2fPuPhMwSboa5khQAudsc6gDHo3YammpU Z5Jts9QA2f4Fg== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:51 +0100 Subject: [PATCH v10 24/40] arm64/signal: Expose GCS state in signal frames MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-24-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=6063; i=broonie@kernel.org; h=from:subject:message-id; bh=kpYoeEKXM/IVjTgCGNGqe131qZl9kDt0bNYWPvrqBbk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YYxABEbOuonpSgRJMOS5HfKbwvlkvC8WJQtg89 D4P8dNWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGGAAKCRAk1otyXVSH0HkaCA CAk+bQRSEGsLGc+biG2RDA3oWgUHaFwyKIU14RadwVXvjgocjWKvZb/Wp99dluj/hVUKcbfe+VZhND SM4eRNao2rOTfdCR2v6KW3n8s4sSrmPwYwdq45PhzCUVnNbkpJ5Cxbe2GzfIjcP3O8QnXeR+j1djjr 2xfeTgQbTg+ehHo4j6F0u2nPFs7POZQVKZ8GiES0XRpRFl5oKgPZXj4ORR34/6XIN+8mpEhcOffuXv LBNUsUuyoj1aY9IhwTGPE1Iy8KaLPu8F/lsm+InhK8c25MvyKwZqoMsEJRO0zsjCXFNKQVVuBuS/bY KWFKXGUNqIYelhSio94GVc2LBWDxZ8 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: zfq4y1g3zknk4wy8sxkqw857ruga91ad X-Rspamd-Queue-Id: 1BED840040 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517204-351181 X-HE-Meta: U2FsdGVkX1815ko8J7WwYvLZOnCjPoV1KRdTDJHizLRxZhMP+ZdR935mFmvwDBSKEBXOabUTnVGso8oaw+NUVbGy8yN2A9BiIbQYENkkZJaM15EDuvyetRZ6RdY9Nr3wSVm6/rnJnRRqbnElYIhWF2nTZLNrd2ityj+LKWsjgfMdt1osoPAWfrLEjBiMi+Uz3SmyT6g38a2g6BKWMs1VSW6ZBB8EzDNA9FxDm9AcoKENJike6ymQyTo9YqMPGvtokZUrIAKBv7xqBUHq6EJrTCqk1eBNt7ZOFlpfpmZgXry0+jlfZp35UKX+z3wIzdAbk7sIPOTS4Q1bRYEjii6Jg22ua4FXaruilh9Og0/iW7OPmvEfZg6Idn0ropZfWjorACPBaRHfaFN/Wuun7qtNAr0juDLrM7kPcYnPDeU8mp1AASf2srPCY1em6fcqTr0IZaQI/4mmEM5fg93GsNlwYIt0NvQFcs9j8On0cIBOwiOWJ7dUNijjalKJGg4wuDicZK1R7aKYHulxUBqMN+cxMRXKph3hwxhlg/kpJUnnDt9E+mtmMBfiDVxmplthONH8qkNDg4d9dPW3925HUmhV5UDV+REohQo/GSrTCvOboIXWGsloGlx+QjE020pwya2BZwOxZ4GzoLzy++c0c2KKOrK2B9tl+Yv3iOXm9wHsEIEZfjKG7k1wBU0KS0xpdL+Bs2VaELX+gkAhpQh8m1EnY9Z2eJGyTQ5VP7//zJAGeHz4wrkD78eTFnA0WUyl/h92Vvq5R2xsgiPJjx0d0ftsQz3G6fwLHWqUhXW2XOzLCXyNZdHe7knDIQOZoiPc8vR+4gcAd501i1R686KcdGtksBn73o5OkaXGFqud9d5B9XJxuCHqbkYcFLCQ8KLW4Puo0Liyeva9el+Hrm2F/AW8TwLLGQPpQ6Ng2SQRw3VEuu0xoOmVpDnwoZmSKSJYyU679JHnAWykHorQA3WpKkd hh830nMQ YMjnwB095sNwBsNUIxtFNJwfFhwpGHowp17WDP3+nOD50x2Et/gDDYsYMMj/aB1cZ4HjrToPq3eWF3T3+YOqH/LeSKIse8K03WtFT9V9XPipA5f+Exyz6cbIzRzdbRqiZMXhzvzWQR/9RuFy4Akhyx0L9z5EocO0b0tvrhGDLHRFhlLlk0Qf/CW/EUlrVFOdFcoV3ThzPEMxEH0owbt+3TnCwdVpATIymghUOgtHGC43jrday7JYJGDQVrEm4Ghv2oJO7M6P5qVkiObQflutj2mI9XCIyUkWm96EHbCwLwrHchUn9kYu5ttJ/yGyuTynXglvjcRc2XIrFufIZw5dMS9iprGjc12Hip7GWa337dfW7F6zBPj/G2ov4V5ShzJZQWb+P 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: Add a context for the GCS state and include it in the signal context when running on a system that supports GCS. We reuse the same flags that the prctl() uses to specify which GCS features are enabled and also provide the current GCS pointer. We do not support enabling GCS via signal return, there is a conflict between specifying GCSPR_EL0 and allocation of a new GCS and this is not an ancticipated use case. We also enforce GCS configuration locking on signal return. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/uapi/asm/sigcontext.h | 9 +++ arch/arm64/kernel/signal.c | 106 +++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/arch/arm64/include/uapi/asm/sigcontext.h b/arch/arm64/include/uapi/asm/sigcontext.h index 8a45b7a411e0..c2d61e8efc84 100644 --- a/arch/arm64/include/uapi/asm/sigcontext.h +++ b/arch/arm64/include/uapi/asm/sigcontext.h @@ -176,6 +176,15 @@ struct zt_context { __u16 __reserved[3]; }; +#define GCS_MAGIC 0x47435300 + +struct gcs_context { + struct _aarch64_ctx head; + __u64 gcspr; + __u64 features_enabled; + __u64 reserved; +}; + #endif /* !__ASSEMBLY__ */ #include diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index a1e0aa38bff9..6db364beb024 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -88,6 +88,7 @@ struct rt_sigframe_user_layout { unsigned long fpsimd_offset; unsigned long esr_offset; + unsigned long gcs_offset; unsigned long sve_offset; unsigned long tpidr2_offset; unsigned long za_offset; @@ -217,6 +218,8 @@ struct user_ctxs { u32 zt_size; struct fpmr_context __user *fpmr; u32 fpmr_size; + struct gcs_context __user *gcs; + u32 gcs_size; }; static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) @@ -636,6 +639,81 @@ extern int restore_zt_context(struct user_ctxs *user); #endif /* ! CONFIG_ARM64_SME */ +#ifdef CONFIG_ARM64_GCS + +static int preserve_gcs_context(struct gcs_context __user *ctx) +{ + int err = 0; + u64 gcspr; + + /* + * We will add a cap token to the frame, include it in the + * GCSPR_EL0 we report to support stack switching via + * sigreturn. + */ + gcs_preserve_current_state(); + gcspr = current->thread.gcspr_el0 - 8; + + __put_user_error(GCS_MAGIC, &ctx->head.magic, err); + __put_user_error(sizeof(*ctx), &ctx->head.size, err); + __put_user_error(gcspr, &ctx->gcspr, err); + __put_user_error(0, &ctx->reserved, err); + __put_user_error(current->thread.gcs_el0_mode, + &ctx->features_enabled, err); + + return err; +} + +static int restore_gcs_context(struct user_ctxs *user) +{ + u64 gcspr, enabled; + int err = 0; + + if (user->gcs_size != sizeof(*user->gcs)) + return -EINVAL; + + __get_user_error(gcspr, &user->gcs->gcspr, err); + __get_user_error(enabled, &user->gcs->features_enabled, err); + if (err) + return err; + + /* Don't allow unknown modes */ + if (enabled & ~PR_SHADOW_STACK_SUPPORTED_STATUS_MASK) + return -EINVAL; + + err = gcs_check_locked(current, enabled); + if (err != 0) + return err; + + /* Don't allow enabling */ + if (!task_gcs_el0_enabled(current) && + (enabled & PR_SHADOW_STACK_ENABLE)) + return -EINVAL; + + /* If we are disabling disable everything */ + if (!(enabled & PR_SHADOW_STACK_ENABLE)) + enabled = 0; + + current->thread.gcs_el0_mode = enabled; + + /* + * We let userspace set GCSPR_EL0 to anything here, we will + * validate later in gcs_restore_signal(). + */ + current->thread.gcspr_el0 = gcspr; + write_sysreg_s(current->thread.gcspr_el0, SYS_GCSPR_EL0); + + return 0; +} + +#else /* ! CONFIG_ARM64_GCS */ + +/* Turn any non-optimised out attempts to use these into a link error: */ +extern int preserve_gcs_context(void __user *ctx); +extern int restore_gcs_context(struct user_ctxs *user); + +#endif /* ! CONFIG_ARM64_GCS */ + static int parse_user_sigframe(struct user_ctxs *user, struct rt_sigframe __user *sf) { @@ -653,6 +731,7 @@ static int parse_user_sigframe(struct user_ctxs *user, user->za = NULL; user->zt = NULL; user->fpmr = NULL; + user->gcs = NULL; if (!IS_ALIGNED((unsigned long)base, 16)) goto invalid; @@ -758,6 +837,17 @@ static int parse_user_sigframe(struct user_ctxs *user, user->fpmr_size = size; break; + case GCS_MAGIC: + if (!system_supports_gcs()) + goto invalid; + + if (user->gcs) + goto invalid; + + user->gcs = (struct gcs_context __user *)head; + user->gcs_size = size; + break; + case EXTRA_MAGIC: if (have_extra_context) goto invalid; @@ -877,6 +967,9 @@ static int restore_sigframe(struct pt_regs *regs, err = restore_fpsimd_context(&user); } + if (err == 0 && system_supports_gcs() && user.gcs) + err = restore_gcs_context(&user); + if (err == 0 && system_supports_tpidr2() && user.tpidr2) err = restore_tpidr2_context(&user); @@ -999,6 +1092,13 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user, return err; } + if (add_all || task_gcs_el0_enabled(current)) { + err = sigframe_alloc(user, &user->gcs_offset, + sizeof(struct gcs_context)); + if (err) + return err; + } + if (system_supports_sve() || system_supports_sme()) { unsigned int vq = 0; @@ -1099,6 +1199,12 @@ static int setup_sigframe(struct rt_sigframe_user_layout *user, __put_user_error(current->thread.fault_code, &esr_ctx->esr, err); } + if (system_supports_gcs() && err == 0 && user->gcs_offset) { + struct gcs_context __user *gcs_ctx = + apply_user_offset(user, user->gcs_offset); + err |= preserve_gcs_context(gcs_ctx); + } + /* Scalable Vector Extension state (including streaming), if present */ if ((system_supports_sve() || system_supports_sme()) && err == 0 && user->sve_offset) { From patchwork Thu Aug 1 12:06:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750405 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 D061AC3DA4A for ; Thu, 1 Aug 2024 13:00:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01C4D6B00BE; Thu, 1 Aug 2024 09:00:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE65F6B00BF; Thu, 1 Aug 2024 09:00:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D87376B00C0; Thu, 1 Aug 2024 09:00:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B111A6B00BE for ; Thu, 1 Aug 2024 09:00:19 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C679DC0D7A for ; Thu, 1 Aug 2024 13:00:18 +0000 (UTC) X-FDA: 82403684916.30.5E2A433 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf18.hostedemail.com (Postfix) with ESMTP id C80211C0041 for ; Thu, 1 Aug 2024 13:00:15 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Dheqn+Er; spf=pass (imf18.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517188; 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=V+n35PJ4/w7NXYgL0xegfC30fzD71ASm6FfCB9JQvUM=; b=cHT8WdhUwfjzRL5jtWtvJgERZ1w4AYzcrbYdCQ+KvStRrQMK4vr/4naOw0N0zjC5yLxtM4 83tKO/pKCdf4HqPqixF+Ozn0zzW2vnf2+4hFBS44S1mE8x5//Dg/HQ3aJ2LcUXcq6lMhrM i2WsjIee9YkljxkzrMylHt1XkJsm4Sg= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Dheqn+Er; spf=pass (imf18.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517188; a=rsa-sha256; cv=none; b=1VZfRGkRDxf2kR9zmEcj/zu1W3+9R6/j9YVYMf1+K/JPEECkc15bo2N33v6NqLlBaVWr9s HXDjp356utydkfIy9kyhIDCrdTti80+EY+A6LJSwR7/+kEbc8vAVBIKMU4P+Yua14gD4hq UuzhxZCTu/y8XAMqN3c/UtQYEis5lbI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E44D7CE1979; Thu, 1 Aug 2024 13:00:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FD54C4AF0B; Thu, 1 Aug 2024 13:00:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517212; bh=qLuXO3WTZsbuYPpzI7zPKGWHTzDvnQwqGL+bk49RD84=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Dheqn+Er6K11xumhJm42mkUH/V7BIqmVa/iaUhbLT0jqde2poT1dilAKQaj5xsg0L VxQ9SJxd8/RFbjKJCOu8oJEW6BDmvRl03413uvYRs6uhCAOTy35x9VXCZaUW57+FsX 2BAHe3+KUigfMELUPUutEhIP/pwh624TysFBtYrvIbT6f93BkH9t2TsQRDyOeuYDp/ sMpeuwLzAaL9/W4qDNApw/jL5BFjT9ylRbgT1mL1pFK7owhWk/N3jZGn5CNZflGE2E xa8Fc93BAcyOuQD5jfu3Kwq1s1V9p6ugiaBtkk7Uz2ZTgT4Pd9IjYWA4O2k+05IDpz M/k9jblxqgkNQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:52 +0100 Subject: [PATCH v10 25/40] arm64/ptrace: Expose GCS via ptrace and core files MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-25-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=4329; i=broonie@kernel.org; h=from:subject:message-id; bh=qLuXO3WTZsbuYPpzI7zPKGWHTzDvnQwqGL+bk49RD84=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YZdr9yBWnPgAW1Nv82TOSwbwqggX1VEHC21A4j hNX0TrGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGGQAKCRAk1otyXVSH0AikB/ 9sWpL54fumavcASUqLReoawLgEeBl9wJ+bMblvLr0+Roh6ZW9WRvzXzjwjYy3z90LD+QiF+pOWYYKn rMuKsJ6z2XqtvIIPNTg4P5ZpRdaZz5ovIAmWMklsYJUqYTG6DeVZJxKfevQKp1fcEjU9iK0mmr8dzm bs356DGI6A3Wy9ao30yyJ4Rt0qxmbvfBxBXQj5COujItl8o3sX32OVLk+C0gEHJf4Xn3lb3HQ8vugL vUh7A991IJ9nrzKKl2NNDXS+QDQe8r+9touJ4jmUprC2B04ZC9udRJ9bYqTIUOCNUR/5Uc1DjAHDAy TO3LJWVaDm0aS/6SPugD5WXUGJvot7 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: C80211C0041 X-Stat-Signature: 4sz74t3mc1y6gomsrdh5fqbj8hfn1fim X-HE-Tag: 1722517215-967508 X-HE-Meta: U2FsdGVkX1/iEgvR8sZ9zyZ09nlkhJBAIrLoT8KS/vZEM+feTTY5jNj0Apaw3Au3NMHAX/EqaGTybrrBJJL8Vi3eMUHzVP4qyJ2t3rqeDByCUMz88YhgY8zS8PLxAXGkdbWN3mjy2P1AsVO4vMlKWNJI7f1fnI89qLz8b1Hjb5Ygp5ZHs4DChhXO2YL2+1rNKUx//EewyZhq8uaVr7HUyxrT/V1fRd0+Npg2EopLsAFq8N6s+aqAjHcxMmdLj4XId2F0NvjXLpF+jvFUpmpuhWbSRdoZDfaef/MU1yJneTTCABHLArCs3nykUaHI/M2CGCu5ja0XL8i0OZuE/KCaGVc2elNp5+fZhPBVu7qq10VFneyS9kOrzi1FTHvN4UB9dxfeA5rJlsw/6m7G6EZ1pPes6wB5JM6pGrkkIIHcLw7qeDB8pDsghzOl5WpJoqXBwrBSWQyhOhUmQ3x6mc9Lwats1Ow6scLF8AN9OhE3ZsiruJjP8fa62ubIaQOkxXQgFzDnKw9qN8TK2wIZhvgfmRnj5WsDtRSq8cS8o/oo/nYyEumOklMTcNLLIJjVgYnc7luIAfTdQTiBKxF9M552Ri/OWJQCxDLilk0Svt2Rgz7fUeXtrBR8ToxC5SBeTLqocGZ/c+bOD4eKjY6+trJw4eUWbKmS/UZh44jD8MS+lVmVRZvIJqCXJcuVOst/bOctyjh8cnR0LZNPvyAnPAXKofqRT3FDNDmdcXW+ofyVi4J7YQiqsAl59KcCQYyG3/dYmsNicirXxVqdhhAbENogH8dNqMAFk/ayu8uRkSMq3CrKybr73KifUrl6lT6ut/bAEIxq9kxntzhatONSHsfe6g2jLmU2PsTYKdAIKNWykBjKs8SEARWsxckgTakm2yXRD8U//gEHfqVEKv+Qg7shmia+b8oYbAnrxOZ5zk9bsGmDICSxUfCqHzLs1fkTmQBLPp5R8FeXXQ7ESRdPyIj e1anl3DP 6f6wRVbB5Rq3Cy7U4/+KxycL+nmETCsIjBSGktWCEI6zrv6bg5AZeo4Qe9cCuMTA0Ct42OxEcb4cF10PZBMDBOHMyWksVgRhYwBg/ZOzCJq9Y9PE39XZJTzoma0px6SrA392T8dsdKG3bGGJMkwDjOAfrA0cXYztScjXofHq9T5/6E43SbhIKNOg3mDKIPtCgyFjp5bJNxwOUJwM/iDwJ79w98+9ag8X5acXmcgQpJplXXlb0XPQdHc96THLSJb8uqaGe8CbivZGjb5RbdJYVEXZaAhQ9jTg/3YyHDADu+jysfqAbrspHYnQUdxgB+Jv+ZjwiNjPhZwx6LGQ0id3MZF2tlXHimmDmfrpTzkf39dkyxwYPxa0Sz0n/WyXKg3wwluey 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: Provide a new register type NT_ARM_GCS reporting the current GCS mode and pointer for EL0. Due to the interactions with allocation and deallocation of Guarded Control Stacks we do not permit any changes to the GCS mode via ptrace, only GCSPR_EL0 may be changed. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/uapi/asm/ptrace.h | 8 +++++ arch/arm64/kernel/ptrace.c | 59 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/elf.h | 1 + 3 files changed, 68 insertions(+) diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h index 7fa2f7036aa7..0f39ba4f3efd 100644 --- a/arch/arm64/include/uapi/asm/ptrace.h +++ b/arch/arm64/include/uapi/asm/ptrace.h @@ -324,6 +324,14 @@ struct user_za_header { #define ZA_PT_SIZE(vq) \ (ZA_PT_ZA_OFFSET + ZA_PT_ZA_SIZE(vq)) +/* GCS state (NT_ARM_GCS) */ + +struct user_gcs { + __u64 features_enabled; + __u64 features_locked; + __u64 gcspr_el0; +}; + #endif /* __ASSEMBLY__ */ #endif /* _UAPI__ASM_PTRACE_H */ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 0d022599eb61..9db0b669fee3 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -1440,6 +1441,51 @@ static int tagged_addr_ctrl_set(struct task_struct *target, const struct } #endif +#ifdef CONFIG_ARM64_GCS +static int gcs_get(struct task_struct *target, + const struct user_regset *regset, + struct membuf to) +{ + struct user_gcs user_gcs; + + if (target == current) + gcs_preserve_current_state(); + + user_gcs.features_enabled = target->thread.gcs_el0_mode; + user_gcs.features_locked = target->thread.gcs_el0_locked; + user_gcs.gcspr_el0 = target->thread.gcspr_el0; + + return membuf_write(&to, &user_gcs, sizeof(user_gcs)); +} + +static int gcs_set(struct task_struct *target, const struct + user_regset *regset, unsigned int pos, + unsigned int count, const void *kbuf, const + void __user *ubuf) +{ + int ret; + struct user_gcs user_gcs; + + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &user_gcs, 0, -1); + if (ret) + return ret; + + if (user_gcs.features_enabled & ~PR_SHADOW_STACK_SUPPORTED_STATUS_MASK) + return -EINVAL; + + /* Do not allow enable via ptrace */ + if ((user_gcs.features_enabled & PR_SHADOW_STACK_ENABLE) && + !(target->thread.gcs_el0_mode & PR_SHADOW_STACK_ENABLE)) + return -EBUSY; + + target->thread.gcs_el0_mode = user_gcs.features_enabled; + target->thread.gcs_el0_locked = user_gcs.features_locked; + target->thread.gcspr_el0 = user_gcs.gcspr_el0; + + return 0; +} +#endif + enum aarch64_regset { REGSET_GPR, REGSET_FPR, @@ -1469,6 +1515,9 @@ enum aarch64_regset { #ifdef CONFIG_ARM64_TAGGED_ADDR_ABI REGSET_TAGGED_ADDR_CTRL, #endif +#ifdef CONFIG_ARM64_GCS + REGSET_GCS, +#endif }; static const struct user_regset aarch64_regsets[] = { @@ -1628,6 +1677,16 @@ static const struct user_regset aarch64_regsets[] = { .set = tagged_addr_ctrl_set, }, #endif +#ifdef CONFIG_ARM64_GCS + [REGSET_GCS] = { + .core_note_type = NT_ARM_GCS, + .n = sizeof(struct user_gcs) / sizeof(u64), + .size = sizeof(u64), + .align = sizeof(u64), + .regset_get = gcs_get, + .set = gcs_set, + }, +#endif }; static const struct user_regset_view user_aarch64_view = { diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h index b54b313bcf07..77d4910bbb9d 100644 --- a/include/uapi/linux/elf.h +++ b/include/uapi/linux/elf.h @@ -441,6 +441,7 @@ typedef struct elf64_shdr { #define NT_ARM_ZA 0x40c /* ARM SME ZA registers */ #define NT_ARM_ZT 0x40d /* ARM SME ZT registers */ #define NT_ARM_FPMR 0x40e /* ARM floating point mode register */ +#define NT_ARM_GCS 0x40f /* ARM GCS state */ #define NT_ARC_V2 0x600 /* ARCv2 accumulator/extra registers */ #define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note */ #define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */ From patchwork Thu Aug 1 12:06:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750406 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 D9A0AC3DA64 for ; Thu, 1 Aug 2024 13:00:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65D896B00C0; Thu, 1 Aug 2024 09:00:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E5DD6B00C1; Thu, 1 Aug 2024 09:00:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4389C6B00C2; Thu, 1 Aug 2024 09:00:26 -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 21A556B00C0 for ; Thu, 1 Aug 2024 09:00:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D05F31C40CA for ; Thu, 1 Aug 2024 13:00:25 +0000 (UTC) X-FDA: 82403685210.28.C7ADF1A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id D16CEA003A for ; Thu, 1 Aug 2024 13:00:23 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Zdk/HN3V"; spf=pass (imf15.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=1722517179; 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=moSjIro1rCziUa1GHcyaGnSJrQya9rKM/lUeW/vDHA8=; b=gnuSzvwCHdoGnaa34BTR+3mUH96E/NiBjQm4WPZNVwHdJ2B7qK+wx0CFfM+oNLCBn+XLzK fY+ZqGPfGATTRH1adIvg/4KMkUQXMrxAK1SVqNdOWFUGfeKixxnVL4Re914T5r5yBLHU6i IZWb8SpAtoWLExPgPRgL8miCBwqcjBk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Zdk/HN3V"; spf=pass (imf15.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=1722517179; a=rsa-sha256; cv=none; b=3kpSXWxsH3Jveo/4Cg05n17L5q6PymQnXdOn7heHri7eYGVGDHr6lDGEKtiPPO6Ij/eVjE RGW3r3gO0Q73R/5hPgpfCqC1stt0vYa1CKHsnrKHF0EzYkwmkXaHMz9p7Chd68wvtKFmH0 10F844rGObORmPDBZCd0KKVb2mS83d8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 12FE2628A3; Thu, 1 Aug 2024 13:00:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A461EC4AF09; Thu, 1 Aug 2024 13:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517222; bh=jCz9TB/T2gtL+Dj1sBbCVvFYWqxLMS2lgt+ihDoyD98=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Zdk/HN3Vv5MCR9tWdyaa/VEftixl5lcXiTlx9bdPKbc6eaT3FWEIZma95Z+GhffvM EcnEtjxjUMY7BtJNNzPCC7DDT43xLDYiM+AZJdYOlDlAIPK9JiTcxM9ZYM42+e7C+U 9M+FRULwYAKFy9B+Z/awaXXUyELOAV1XBrU0mp4w/mkVPsn/eOz7VKSFLsmAIwwW7B lew6XfI7DwPM58JgIGVw2nkB0gIogzXMI6WGBoekN/T1iW0VC3dDiHWS29AQH9c6VV IV9oIsnZ+4eQBNTMn/6CGQLJ5TBXgVfn0mxsqA1OzKNu7nMhgKP1rnDfsJkBxLzSKi FYf/bx/yCadnw== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:53 +0100 Subject: [PATCH v10 26/40] arm64: Add Kconfig for Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-26-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=1438; i=broonie@kernel.org; h=from:subject:message-id; bh=jCz9TB/T2gtL+Dj1sBbCVvFYWqxLMS2lgt+ihDoyD98=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YaZfoQpmqEUbybjMAYNvLQbJaJ5ach0jFFKMwt WAXMRf6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGGgAKCRAk1otyXVSH0GzQB/ 0VUEM5IVaWGWCtsoHGuHQHdtM8+bn0nEmmu8lC+oIKaYCzNy9VMZzgyUqowYnTd7bPlWUz/Y86I44V RwpJj/EKex2ZFhiaMSKwZKk5ZycQwwdhmGqd8wkhELOTAU5tPmelrk1C5oPSDSLU5/cK5yCygjrcBh KSD25yGvlDBzmQwU8A2hU2FXizsVvxQGd/XPIkN4qnQLAWZKEaHYFH8a475LGnHg8uUfsFCToCPjWh 6YUfe9z6iCQUb0w218AdqDzqriKwGOuLBU2jkxLaydWomcfvewT1WWRsu2cMVLqUa0d9CiOZRK5wBg Uww68Gf9sKSJ6c/5O3iLSaPKkTUUYX X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: ag8iwiyiwo6dmajoxtjdu8tuo5iakqh5 X-Rspam-User: X-Rspamd-Queue-Id: D16CEA003A X-Rspamd-Server: rspam02 X-HE-Tag: 1722517223-478114 X-HE-Meta: U2FsdGVkX1/PwNMOhE+AxVlTJZeH9opTS66sO60WgXLwUv3BPAzAkZNQQmHaywaNeye8iUKNYo6tNFIYvUv4yPEmdEEs3Gekc8AtpjE8ubL0uV0e+nhudCoy0CZxKdXEM3fttZPRg8p4NI592wa2vG6V3VJQozA++cfB+fRqH0UVdMwofK6WKdZjyQ1N95ttOycjyc7GgYxeBrLiN6SL3FufJwSncvQK49M5r0eQCMeGpTgKWSqj4oqA7UQftylbssA5dUzKw1D+RsIa7kqjbl/jsiQOW8cZlaiweOFjJBu9R1WB9Hv2BJ/s/zS6HRm+yirullQ6MDbLEQ1xIciIyFZMiSz7LH3blOZgt46g8WIpoIe0ImmlQShKOppe7yM60Zu5HqM52YXmnq9IsWmhkhcAriXpN7cnJsoOmdrQFghp5wWWbZ5YDn6QgrLD9ocnSSOxNOEOMg6xV3S9E/1iKdQgebG+jO5A4j8fO2eohhIHwBLBsxtKLliNw0yoO9u36e3qGOleD92HqUE7Aoh+J8sb/2UaPBnsdTg0yx6JcN08CHWUtf5Ig++5yWaqA4enYTBN8623ChKFumx7g/EV3w5k6RRqItDsV0Bd4mFTiSPSn6+EFtficR3aoTl8tomHs4ghA2k4TmePBXKQGKVc9rasX6GXYPrFpEFxYR48/8C4e+4MVlmEp28K1ej8K9IPCL4R3/Vc0tzF84Lig0LjUImMPMopKxJcLp2ftEA3QWbPHryW4gKcau3hqz3SAQV+rlOtxjeattkpXi31OzztLPB24+KII1BQhrmpgJKkA5bTIVVHJEckbtexj9lH53/NW8S406ToIeOC8pafmenGthinDPSOW/TmW+3b28G3O62YnOKM+ubYS2TWjPKe8QlV2TZhFDemqZDyTBS+jsUfO0V2G9RhUrXRJ1sY9/RV6jMuEQPZPrHfu9Bjal+vVVVA9ll5F1ad8X4R65WdFww kyeOKV8N OLJ728YZRachr1nAGDPWaWZ9PsE0dTHEe9QxHERA5drG72EIMeKFOvlSBLsGRI4EkXbFypJQieS686D5hJFL9Lu3nrRkToQoeLZrkmvUKxff4tsT6VhIAtoWoEUi/wuNxgfwV5S+W0EPRiAjBDVdh0W8x61d5qBF0fHVPr0sffrDDAwLLfUEGXxIYGqRJgQsBfrIsk24cpBScnp6BHNxeuYkKlb6Pv5dhU/uYklh0PzFFkV28dlADsTGpwY3Fhtc6PIxmqZpREy52KP1TC4xRlB+vtowdclyQtg2cnmaEbXFtwDoUaRy4yaatNWKMOtY938Fcuw3IWHvh2wlxp5p9ZyHvVtiShC7KDCpV2rRQgZHteFQMMOFxntBdSqPTe44YxWUR 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: Provide a Kconfig option allowing the user to select if GCS support is built into the kernel. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/Kconfig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index b3fc891f1544..83e27857bc6a 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -2127,6 +2127,26 @@ config ARM64_EPAN if the cpu does not implement the feature. endmenu # "ARMv8.7 architectural features" +menu "v9.4 architectural features" + +config ARM64_GCS + bool "Enable support for Guarded Control Stack (GCS)" + default y + select ARCH_HAS_USER_SHADOW_STACK + select ARCH_USES_HIGH_VMA_FLAGS + help + Guarded Control Stack (GCS) provides support for a separate + stack with restricted access which contains only return + addresses. This can be used to harden against some attacks + by comparing return address used by the program with what is + stored in the GCS, and may also be used to efficiently obtain + the call stack for applications such as profiling. + + The feature is detected at runtime, and will remain disabled + if the system does not implement the feature. + +endmenu # "v9.4 architectural features" + config ARM64_SVE bool "ARM Scalable Vector Extension support" default y From patchwork Thu Aug 1 12:06:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750407 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 5E3D4C3DA64 for ; Thu, 1 Aug 2024 13:00:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9C386B00C2; Thu, 1 Aug 2024 09:00:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E230D6B00C3; Thu, 1 Aug 2024 09:00:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9F936B00C4; Thu, 1 Aug 2024 09:00:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A2DC76B00C2 for ; Thu, 1 Aug 2024 09:00:36 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E649F120DBA for ; Thu, 1 Aug 2024 13:00:35 +0000 (UTC) X-FDA: 82403685630.24.745AC9C Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf29.hostedemail.com (Postfix) with ESMTP id 446E6120031 for ; Thu, 1 Aug 2024 13:00:32 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tnrq9/ql"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517187; a=rsa-sha256; cv=none; b=5Ue+jpafxRjelSmO7myEh3d9R7lrlvg04hk09xNHmHheyljkY+iEeQ64GCA/B13WUL0BG+ lUTv/aN6Tvf8ssuQFZpgEGeurCtAPm5H4JLA3H1+UXvfzLSv9jNNvchfqP+tblJuwSi0gL SDYlM/UQZfyxqD5Ovm8UcS2xbLIFhSQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tnrq9/ql"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517187; 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=lx1e4QZxBbCVWVB0QayIR7s4g0rsUX9FuY+HasyH2g8=; b=CN711SpW2DpgcMBfIseZF8fQB4bR9hfrDss2bCgR9qg/n6mhhETrfN1IaPzE2Ql0WTErFo JT53TTgbXqeNKLFQnxNvCkaR8hBekYhxj0vygHNvRxLU70etQXjW2qElhsw5rXudtzKSKh EglswKn8fapo0tq+XgDrbAOpga+PBCY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9700ACE19AC; Thu, 1 Aug 2024 13:00:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2541C4AF14; Thu, 1 Aug 2024 13:00:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517229; bh=oHs0edHK2ZH//P9wlXUiorha791DOO+hA3lq1vKIHRU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tnrq9/qlz5GnEEEFFRetjGPSOWedcxCUE1yGkiFYjdws0U4itg41NBfsVY86Lvk6s X+IpjSv62kIwlCfYN7eFvhz2sW+UwETmWdFlmMGMFBidDKWrg0ZHqgdbRt2HYW3gQn MG0H6C/C54Id6g9ZGXA/pI+OHLR78Pd+3YU2MnbvW5YX/lYP8SuwmT0Nc9rNUHMH8J QQOUeJTOom0yMSM3cBtJB4pqkkaZuDFclam5qISOmDOEzSnDQHeIdlYsrj37iRvIV/ 3S0HHqq5YrZzkG0PsWgDt1Bg9UNBEFSgAE3wRUe8TprSjqCD4zoYzazrxW12lBGKYr x3cLNAUNqLeaw== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:54 +0100 Subject: [PATCH v10 27/40] kselftest/arm64: Verify the GCS hwcap MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-27-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=1288; i=broonie@kernel.org; h=from:subject:message-id; bh=oHs0edHK2ZH//P9wlXUiorha791DOO+hA3lq1vKIHRU=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YaR7eUIgxap135hy7ONIfzK5DCkSb7UQJMKMtp D592qJmJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGGgAKCRAk1otyXVSH0ElPB/ 9ZXbE8s9vC+GQ95xVWW0x7DnbqqIxaDtNFUU54+Bf2g/sdyJFD0Kv9WAVrRQ0V5fpTxUrG23xXlFEF J1/nVz4ngvN+k2sXHHFlopJP23BUioBPLP2iyFvBtipYkXYxoDtbDG/SdYZipAfT+j+XnW+A9umF4l HNyylEPIp+P/zoxBJ1R1j0+MPSQH1BAW3YC4I6It2Qij0MQL36gOOXr9/HmD/+89eFIdD45LPvQv1V ms1MF+qnajf1TQk3xpz5BTikAATCVwNJTZ9+Y1zsa54sW3wPp3OAnksvOzBDEsuUtusvS52+wgxyen dp/nWQzMiCu0D823CItebJZbVulSjq X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 446E6120031 X-Stat-Signature: z8w8fxirkgcd86oh3r9rirwj7px5nmpg X-Rspam-User: X-HE-Tag: 1722517232-250936 X-HE-Meta: U2FsdGVkX19/rX/JWbt0FYz2TXk9G/dOYbhUxnELf1IQX6unUQNj3bWZFT2321dUm3SR045dGVGL37V+QEso3B+/mZDH2PvBaUG30kcdNAUniKOOqZJFKIdcgiCwYKPluecOvEmoDWKS8ri4agRTNiOIwFd070DA4797HXo1Tb4Z4SXCvAG3DnlWZ58iBNtlF8gmHqa3yydEMh1QWAOFOLws9oWIXhEOk68nXxXe29PYNaFd0O3ArNcArDSNIykvcNsaAJKT+z82+9AGFe9oG2NjsFg39paWfssQkdDPPKC/RmuNNqjjMs54+FQ27y990Mc4ruQ+UN7vk3fdjI4kE9RkoZxrkCrMchhQLlLntdrHHtQkaNV4zhmVeDgXbRbdkw4WMJZ0gGVW+vl6c9thvuj6px2+lVDyR878ZIXv6g/w1cG3Gn6WdBqhDN856bcr9K9z0MmstNLg4ev7dxUW9VuV337w8Mu4uWCjqBzczB2KMUo6ay/1HtINVZ5OiuIWUI8aVEy/9O5gKLYsL3liHwLbkPErAXeqgq5Nr1UBlzGVGz0HGX2kyIko+jfE3p4DW2C7MCDgwQ3xiFSN0M8JVfYgAa4MRCBu5wG0dlhAwwtXC5XxM7hh/+VFyAyX0ISxZsgrKNx3+k8+OaZuPiZH31+1+KZ+iDyqbwIXuooUyr5wAAnlSOHMKxuyELl/1q1BPd3ROEVY4djkOKkvAFqbbrdy2k0r+euqnLUDBu1E6llpBsX0hYNIgsvkyaDrI9DDGDfyaBVjYdEs5UXldGNyBVj4aIi6hAn91/0Ck4T4xw8W/3UbkS4lpkJFt0mcHNAN3e6hBu13t4/vArtkdPWYGvk5AsYyV7y5Xo/YlQ1q/EsLXCnB65LQlCiYtK30Ar7gC8sUaAEmeGSnvdxhJR+hnX4+259JTTSRJIr2vyqarBMBYxOp3HPsD0CRp9i+KcA+DM4YZ+LpWIvFYg87L88 qPzqGvmK ka1Tto3Z2owo+D/OB43qXY9vRXvZjJnuJgynF+qjkVvp1tq9b0iu+5RvzSEF/eYmIe0ZdfpBE5VOwG7plRdyOGFxrXLt7y2xNtL6eo/jBm1/sZLdOMM+cv+8x3ZOQ1pvW6OwYgBXEQtHvc4ZyTEcHyEtV6D4iWgzF+Rxu5sLO08vtMcGJm5eMPj37CujPCvDOXByu4vFk7NEVMuY3wYIOiZIRu9LDaUdBMKc8snWaQkDqfyc+aaqIxb0b5FR/MGh8/u6QmMhMRfhnDgrg7oCFiIVzNPm5ucp7rMSmBodp0+dQFlwGrYULgD67r3omDEWagGxBtq2slh+NvtXNV1rC0jVi9MieZ+f5umaA/uOua/1MnpZPLLhsjP3xHA== 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: Add coverage of the GCS hwcap to the hwcap selftest, using a read of GCSPR_EL0 to generate SIGILL without having to worry about enabling GCS. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/abi/hwcap.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/arm64/abi/hwcap.c b/tools/testing/selftests/arm64/abi/hwcap.c index d8909b2b535a..dc54ae894fe5 100644 --- a/tools/testing/selftests/arm64/abi/hwcap.c +++ b/tools/testing/selftests/arm64/abi/hwcap.c @@ -98,6 +98,17 @@ static void fpmr_sigill(void) asm volatile("mrs x0, S3_3_C4_C4_2" : : : "x0"); } +static void gcs_sigill(void) +{ + unsigned long *gcspr; + + asm volatile( + "mrs %0, S3_3_C2_C5_1" + : "=r" (gcspr) + : + : "cc"); +} + static void ilrcpc_sigill(void) { /* LDAPUR W0, [SP, #8] */ @@ -528,6 +539,14 @@ static const struct hwcap_data { .sigill_fn = fpmr_sigill, .sigill_reliable = true, }, + { + .name = "GCS", + .at_hwcap = AT_HWCAP2, + .hwcap_bit = HWCAP2_GCS, + .cpuinfo = "gcs", + .sigill_fn = gcs_sigill, + .sigill_reliable = true, + }, { .name = "JSCVT", .at_hwcap = AT_HWCAP, 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 From patchwork Thu Aug 1 12:06: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: 13750409 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 010F9C3DA4A for ; Thu, 1 Aug 2024 13:00:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E4556B00C6; Thu, 1 Aug 2024 09:00:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 795E96B00C7; Thu, 1 Aug 2024 09:00:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6353E6B00C8; Thu, 1 Aug 2024 09:00:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4491E6B00C6 for ; Thu, 1 Aug 2024 09:00:47 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 87772120D67 for ; Thu, 1 Aug 2024 13:00:46 +0000 (UTC) X-FDA: 82403686092.17.AEC0F9E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 8F729120031 for ; Thu, 1 Aug 2024 13:00:44 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BeDPSC+s; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.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=1722517239; a=rsa-sha256; cv=none; b=XMaCbN6zB+WbTeytH8wSCPUtXJPMwGvQTRjn6tqYk8rzKMCGsk96CBFNAfNpLlvdX6hRiD AgyGRfJ6VKyd25HDp7qwcMV0fT1kqh//bTI7hIrYJyXDrW/pljmYpDt+fUNPT62sDhkrxE m01IPEKQbalrYMUOZNJaYaFj/IqViBs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BeDPSC+s; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.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=1722517239; 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=IfgKesjS90GRp51P7JpwI8TFVKD8QBnSEkCAxrkao8Q=; b=gRfspsDq0zWGbB0ntAOuM1p3Ip/2vRb6Aa4k/5HRTiXgvGFDFeK1C1lOlxB8bTOjZ9V/lu P6hzaEv5Z0OpCmLsLPeqkXNG/jYQTVXrk6gGD4VEgeJaK4ece1QjxNG01fyT0Wuwy6p0rW rrWCtV3EoKz1xXvSjk77yud0VFceDnc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C891062864; Thu, 1 Aug 2024 13:00:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27AEAC4AF0F; Thu, 1 Aug 2024 13:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517243; bh=b9Gx7QUiEPIAdR9RNFo057BasR3/TeEIE9B40jmDJ/c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BeDPSC+svn9jwZ5HO/dupvJkJ+PBmmW9gsAmHLvayeZzSX8Pr0bdYPgA7jak1loAG B+uFxjpvPSKnLe9VaN/Hlx7dl+x/cqqPwzW7yFwl42FezkGYJiZN5RCg9+cL1GKlel hyNKn4hrTImC+r+ryQAO+gyOhsxyza1wdGUrMl+hMtYqKJ3sctWYb+MRxx9F8lf/hq AnucC0+Di4cr2GDyoAFoNgeWce0gSe/fC9ceMx9WMu0F+SYnoIrtWWV67/YXMXM5zH dzBjJNaYYqVheTGKdo3bvH2fiTYpPrhOSPFpxnXYKzNJKXaUHR2l72RHB5pjJrFUXZ msXrY9gmhemOA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:56 +0100 Subject: [PATCH v10 29/40] selftests/clone3: Enable arm64 shadow stack testing MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-29-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=1471; i=broonie@kernel.org; h=from:subject:message-id; bh=b9Gx7QUiEPIAdR9RNFo057BasR3/TeEIE9B40jmDJ/c=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YcGlhpOj6DsmlrQLB9sFNjFcmtR7a/7hcuDPJi 1WPfvR2JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGHAAKCRAk1otyXVSH0N2DB/ 4u1y7NKCOY37zU67JkUPEpNLsIl+VxURgETEUY2dZxEx6yYfE1aGAywt3yaSnGUEbwMW6edKYAUchr 4lX1kFqnAkhrcwH/nHkE9EbHAp4S4onx5plRdvTdDXwbgmz9ElwxH6PAqrgAMAIjlcAemgMh1vsL8Y Jg0/iFzW4BJk+Rce85J3+MBPkk3olEf8DTdwKM+HBVHKZp7ROhXC+Nae32yoRdbOhKnyP9M7hapDmf uhlvd8GF7sxAUK3Kn9pUCmdB6uiYGekqzCCdForvtzIVTGBYp26p5Q3D2VBstoD/ZA/AUXheARDpJB N5WUxquIwZz86X9UXY/FGZfGSvrPm7 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Queue-Id: 8F729120031 X-Rspamd-Server: rspam01 X-Stat-Signature: uo5d55kjt7o8ix8t67xn7gnegwpk8dyi X-HE-Tag: 1722517244-920552 X-HE-Meta: U2FsdGVkX1/DLIKV1OXUWoH1yj8aVf2n23i1VLEiGSV+xUS/ATVY0Km4pxVbk+f3IMKmjaErBpptm48p/Gc3HSW61lrOa05pYVN/mrXnBJujh83+TkDBJi4Zsd3JAZy492zrUDLEKtIHKM0V5stw7b38q/i6dSVyl+d1HP9YoRW9PZ1LmuMgYzfx3RxEoYk6dfK+EWrGl13R3qFPfvXL2gYIjWDjvSvJ1kvQ7i1MmSNX23mIHcq1s0ubfZYpUvGQrp7752telr6JqlsP51FNh7GihByu5q0heWHGuGi0D2PrBzFhLTvlf02puoViD9M4gv0/cBiGONH7QpJvsfkwSOEIbkIA1qtVD4zBdg3Z8tWvjACGzXxrSWaF4mTViam+gF0Wbt0tGd2WC0AtHvd/lWdloxlAY1MI0/i82imPZ7SFJDA7OjFSLfMuU0JxFCBvUjS32mvHDL3tcxpceiepB7Ew3FsEPiP5/blOxG8X20Tb72B6AdItlz6Qt2Aeun8OLn/llB2zaHDiaQXpbmBBZyy5Rq+YgG5GIBV95tk0r85zllCETSmWdJpCLHOBRugDSvB+IHBZa0nSu5UxuEAtiA1GDxzAkDNvSSzwy1rLB3k6ELDk0I28y9g81dJm9UgtHtWR9Pz/xdoPTeMMAszKfZBpIfJs9fS1xe0w+qQI6Dbjb2aJ5pmO/BA9bZgaGWZ9bkonAxufdBcf7zv/vwMthz/sySUDRkoR9e3nXwC2CuVVRXjcBLyhCHRuCz3qNBNWK2O1baM6jh3oG9VI7Nh98ziNf0RB70SgNL5jN23bF0C7thNBmUcAJ1wcOqEhSxf8C8qmu/uc30KNPHnX41utve3QJ5v08Mf2lfC0XUx2JUDO4zpECT+LUE0Be0SfkwynCvfKy74s48VL694DqbyaaWMbHt18IXFghz9m44r7+mf7mnYdoS+sg6V+lRN4qYesHUwdlFFL5zhWi6IscnF NFfynMRz 13yEsWk8CIvPFUGWKMsjbiL6FcJt+FdVrSUirbX0aXPYdVRvnJGMtmtRttXA+eIwoq6q/lIrsAd93tqIBk40UulmceewODySlNbwpkxsXHVRe684D7eZjOBKGAJHd7/Crt3ZdEnLPMpg+TqdJ5ti/ni/2m79RFPczfb2T8T77DQk8SS/TK6U0G3v0MuBBwHQABVq0oBZk+L2mAvdTle3KZHWN5aEPUACBBvhb2T3XGuqkOvzQe6t2S70R1FNCXRTMbEiMv/ABYbG+rXFM1qOy5YeupKgbNbrKoKhDH5sMPqzUCFRiqxiifExsOkO4abgj4qU7 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: In order to test shadow stack support in clone3() the clone3() selftests need to have a fully inline clone3() call, provide one for arm64. Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3_selftests.h | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/testing/selftests/clone3/clone3_selftests.h b/tools/testing/selftests/clone3/clone3_selftests.h index 38d82934668a..e32915085333 100644 --- a/tools/testing/selftests/clone3/clone3_selftests.h +++ b/tools/testing/selftests/clone3/clone3_selftests.h @@ -69,6 +69,32 @@ static pid_t __always_inline sys_clone3(struct __clone_args *args, size_t size) return ret; } +#elif defined(__aarch64__) +static pid_t __always_inline sys_clone3(struct __clone_args *args, size_t size) +{ + register long _num __asm__ ("x8") = __NR_clone3; + register long _args __asm__ ("x0") = (long)(args); + register long _size __asm__ ("x1") = (long)(size); + register long arg2 __asm__ ("x2") = 0; + register long arg3 __asm__ ("x3") = 0; + register long arg4 __asm__ ("x4") = 0; + + __asm__ volatile ( + "svc #0\n" + : "=r"(_args) + : "r"(_args), "r"(_size), + "r"(_num), "r"(arg2), + "r"(arg3), "r"(arg4) + : "memory", "cc" + ); + + if ((int)_args < 0) { + errno = -((int)_args); + return -1; + } + + return _args; +} #else static pid_t sys_clone3(struct __clone_args *args, size_t size) { From patchwork Thu Aug 1 12:06:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750410 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 1B91FC3DA64 for ; Thu, 1 Aug 2024 13:00:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA5246B00C8; Thu, 1 Aug 2024 09:00:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A53226B00C9; Thu, 1 Aug 2024 09:00:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CD056B00CA; Thu, 1 Aug 2024 09:00:57 -0400 (EDT) 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 6C3EB6B00C8 for ; Thu, 1 Aug 2024 09:00:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DE6C2A0D6B for ; Thu, 1 Aug 2024 13:00:56 +0000 (UTC) X-FDA: 82403686512.19.E278096 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf15.hostedemail.com (Postfix) with ESMTP id DAE51A003B for ; Thu, 1 Aug 2024 13:00:53 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YaeczFSW; spf=pass (imf15.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517225; a=rsa-sha256; cv=none; b=PQAxmr0mXHCfa5Uk/NOCaYbYkfjupNfg2ykF0ywcfpAfjoq60p3Eu54v0Ci3DZ4LHAv435 X44TzK83HCj5FIlJSbbTta2C8bm7q2+S++EarBhkUVCpP0lmfB2dF139iOHZMNBYdRXGqV 8PS+MN2qmkp4iZhzflzet3JG4nPZgGc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YaeczFSW; spf=pass (imf15.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517225; 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=ni0Kxk3yWVfTWSbrVjjhIlms208eOmetcRX6FMFodsY=; b=3GtK/hIlKUcZshqeRI6k6Y21j3bPMHdQowTszqUEvhVldCOGR0l1benmfmfpcv3m3w4CQC 6MSDZgCsIY+dyWES94QXXbGSyxyAFE+Kg+TbKnJFr9B7NZgz01EhuqeA4PIaOx/uzDGO16 60DNvaRs8vsXhaUMMOmFEbBznbXfg6Q= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 234C0CE18F9; Thu, 1 Aug 2024 13:00:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9507C32786; Thu, 1 Aug 2024 13:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517250; bh=daws7+gY8b6XFlV57O+J5ZaQ5dAS4S0GI4Vh7sgzmHk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YaeczFSW/0sQVi4Y5MZxG0vXvCbqJ3B5xzzE5AP9dTzYvhAzl/vQ3+MYM6uYprAOe 70sA7AYgAVjQD2r6xVtm2I+QdnfpYpgb38IG0UvMK88+S9If+ArSDMipaZa139A8Aa amnSXsdY0QAmRVZRHyUaLz9RHZvhUZEBoD1RNXnhXsJM/Oh5kw5Ir48Lb5Uc+P48GC L1EMrJ1FWOTRIyygtumExRrL5WQTM+hzMyVys/ZrDZ/E5Yx1aFTNNf4YfF085NmlYT 7xGguAyHeqD58lUBuw4xsj6qRJLzqe34cjOTUlZlt3PSgLpNFkepoD/v9BoZcVi5hn GMKYDblaFYphA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:57 +0100 Subject: [PATCH v10 30/40] kselftest/arm64: Add GCS as a detected feature in the signal tests MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-30-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=1894; i=broonie@kernel.org; h=from:subject:message-id; bh=daws7+gY8b6XFlV57O+J5ZaQ5dAS4S0GI4Vh7sgzmHk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4Yd/AayJpdDJb2tH+bu+tocCjvDaVO7v9RFDWZu YTIKLIeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGHQAKCRAk1otyXVSH0Ji6B/ 49n/gPVSOC0zUdOFsKaXyNbeJnnjaeAF6Gi0yO/OvRf6VhmA1x9nevcrHxGpv9DmgkfvS1ypLr5tnA i4w0As1xKtNtyuW7oYQecE0S2I8n9mVnIQt+N5kfwKwsHQr+n/GJCNd29oNl4QZIEeFqOVYeu/6a0b HB/wcdBizcnOfVCSchCJZPMPOyeBHkP5+q+4FiTIPtAddvi9WiYoYv1IDkYLyarNhgHtFWHNEl0MhV UiHVNfUn0FsTrxnnEaml6vKI7WrzvQKeELLE4SHw6rHgudllTAtV1UffSDB5Kuidf6INcLHWx0iECg FQCqn39dvgOsLwpZxr5jqd2j64PGrJ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 41rx8huxh37pwcwf1y8qy81aaotfbfud X-Rspamd-Queue-Id: DAE51A003B X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722517253-879837 X-HE-Meta: U2FsdGVkX1/47uGHNhlIEYBEoXI0masRVEyywTCRe5ToPmxrLdxnob5XhTbDiFHthJkUNrrIck3/7iC6KcNk/GQ5+WEqiPF5RXeeD0AzkvUKjthf4G+TzXr70APU5NF0PCP9k38DdwX7CsDq+xq0kI6e4EkizOL/yP1ouwg4Cu1xP1v84mRLKhQNYi5xBitX+bcGdvm6WuLAnswSzzFjvbHWeJlnqjKWH3Sv1/AwSqpKB76/rbh5vmEnoaRY438ms5D8ZfkQsz6ZjPCRszVQ7W4xk/LU4/OrnwChbBmypu+d8wGQeWJ+l3rINW3hEBocW07nc3fGUPffVwVrbGx18gHHSyRs/EbdPzLkR52JaOGp7zYkwPwRQBhpO9dKN14FR1t3+hqbaDraiu0TJHRao5wGXgRj7yFD1RjJRd6QgtI2GXjAzVIZ2bKDjTJOjLoLqaNZctr5fAYszu4pcCMlelaTNNt7pGaHXyKpX+NMtMSZaMKiNU+O0wALYWuzXBlUjvZWBaX/vNnVk9dJEjag7kxA4CWJ59TB2kzHfETlTAhexUcDqlc9hGb7r+0QTEZj+tQ98zNG7F3El0K1WcDK6Ka4RrNgnv1Fs3I4wsjojoMPHGLWYkRAGGyMQiNOAyvuAWYmTWJlgaIACpWRIiqco0TbCnAW+yfXSbKwLy2msLdSIM0aDBbDxxjKAY+H3qvSnDO2eIbsUNrr6m2HVGuQbrGPMLkdGDAjXwsKRaiZdLPoU9zSyJEKf2eSZP+SIypnqWm0a5DJPdJth0Tlvplms9Lq28smiu8fA/rJLeUVxf2maDsWhlgfE7yJ+2fqgbLfNu9SiQj3ydNH5z5uxa3t0RHd6HeqY5RpRUWgQILZh5B9fQ5WTysF5t4Qoqwf+wOTAbn12v5Xaoi85zT/dOdS47jcldUirn8A7xqxKjOBgdmk3K9H1KTf3PpP5+mVCz/Vt9ZA3JjFuTrTYtM4AZB vnc05725 cf7lL2aqDc4rtBAb+0bMLS2m6Z9ndnAkDptHSDBSSAaSaYLSrx+bFRUZ+udooIAonnNGrhvxmk9bHbi7VMIVycCP3oiM3Dx0s+nw6NEkXPykPQpLA0jgbm6C0aFYnDb62ukupxE1nbXVPnA2faR8QCvi6NLOaanBrDGPjDUK3M2zdMQ6bwEnuEc1shC1ZUcGu7YiJlNZTys1gxNhIZMc1Ul0SxlXW5mNqQ/ugPWdvwDIVsSjDVlOdLhEzpcyCH/yYqrYueQ1JHFYLlfMohdt1jh/gmXQXBA6oh5+KyE+cfVvBplNI+PMGGg0vKob+H92L6COfTNXfcvrQQz7y33Yl6oMvpIt+EaIexb5LnrtkNdVR83M9GksRtBXuOg== 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: In preparation for testing GCS related signal handling add it as a feature we check for in the signal handling support code. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/test_signals.h | 2 ++ tools/testing/selftests/arm64/signal/test_signals_utils.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/tools/testing/selftests/arm64/signal/test_signals.h b/tools/testing/selftests/arm64/signal/test_signals.h index 1e6273d81575..7ada43688c02 100644 --- a/tools/testing/selftests/arm64/signal/test_signals.h +++ b/tools/testing/selftests/arm64/signal/test_signals.h @@ -35,6 +35,7 @@ enum { FSME_BIT, FSME_FA64_BIT, FSME2_BIT, + FGCS_BIT, FMAX_END }; @@ -43,6 +44,7 @@ enum { #define FEAT_SME (1UL << FSME_BIT) #define FEAT_SME_FA64 (1UL << FSME_FA64_BIT) #define FEAT_SME2 (1UL << FSME2_BIT) +#define FEAT_GCS (1UL << FGCS_BIT) /* * A descriptor used to describe and configure a test case. diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/tools/testing/selftests/arm64/signal/test_signals_utils.c index 0dc948db3a4a..89ef95c1af0e 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.c +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c @@ -30,6 +30,7 @@ static char const *const feats_names[FMAX_END] = { " SME ", " FA64 ", " SME2 ", + " GCS ", }; #define MAX_FEATS_SZ 128 @@ -329,6 +330,8 @@ int test_init(struct tdescr *td) td->feats_supported |= FEAT_SME_FA64; if (getauxval(AT_HWCAP2) & HWCAP2_SME2) td->feats_supported |= FEAT_SME2; + if (getauxval(AT_HWCAP2) & HWCAP2_GCS) + td->feats_supported |= FEAT_GCS; if (feats_ok(td)) { if (td->feats_required & td->feats_supported) fprintf(stderr, From patchwork Thu Aug 1 12:06:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750411 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 B3DF0C3DA64 for ; Thu, 1 Aug 2024 13:01:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48B066B009A; Thu, 1 Aug 2024 09:01:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 413E96B00CA; Thu, 1 Aug 2024 09:01:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28B7A6B00CB; Thu, 1 Aug 2024 09:01:01 -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 075206B00CA for ; Thu, 1 Aug 2024 09:01:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B4F5B1C4098 for ; Thu, 1 Aug 2024 13:01:00 +0000 (UTC) X-FDA: 82403686680.14.2EE76BF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id 57CF0A0035 for ; Thu, 1 Aug 2024 13:00:58 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZAUnG7gy; spf=pass (imf25.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=1722517201; 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=5eBWEluxA75mkTzkT1Wn6Xubbm059W8B8emCrmFOIYI=; b=XmPtlx/FxBlzGB8bkRsL848IxLxJ+HS+8JpjQ713upXY2aqTOHF4Mtq6s13+5C5HvCo07/ cm/VHZfRQcbVCpqU5+DFLsZvtEFc0/16S++r0haWHNyltmcy3DdZsXQfXIdkzMcrEj7K8V oa0SVSS7gZ8j3xSsQyYY5e7PqDH3apE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517201; a=rsa-sha256; cv=none; b=8hf5xLoMRyO3WRMU6nqJ/t3MH4hvW/QZPMZqJqYPRENXd2O5Dc5VzIb9NTDiWh5/uNZbN6 U3D6jvfovUQ7PqT1N0zxf9zPhtg70f5QzB+rQ+JmdExnKK5HXmpsbYYe9muMTyGbos1xEP qxPC7Phb6/jYEuYCbHJLRhb5wsTQE6g= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZAUnG7gy; spf=pass (imf25.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7346E62850; Thu, 1 Aug 2024 13:00:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C837AC4AF0A; Thu, 1 Aug 2024 13:00:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517257; bh=sPSz542BQgC8GDr8WCulUI2iE6roG4Js5HwD3OcoqCo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZAUnG7gymw3ama46N4/FSDxSkR6dolweB/eurjLYlAnm9DLowUGKqcj7YqINGC+uj 8HTwVpyNStWp08+y3E2ISQEhbnaEsEDOOsMyJDIMovAiFVpgrUVzjTc6Fzff1xAo6P NsmhUz3gsA3y+FnV4UnLlGhUyOzmRgpnZtLqrP78J8DCfwokXMbOzvXajVyn/14NjF ExlFSy68rqNsm05R8bNTJfpJwPwchXZNvHkOxwVGR3TaweNxzlMfILcTC5tAnFHizm F2vIDbFxuDuPBfG0wHbwGaUjWnz6X/l+Se/Es9JGGP0GW3nCRoB7wv14Fm8VG2uM7B cSyLTYYRcdj4g== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:58 +0100 Subject: [PATCH v10 31/40] kselftest/arm64: Add framework support for GCS to signal handling tests MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-31-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=1664; i=broonie@kernel.org; h=from:subject:message-id; bh=sPSz542BQgC8GDr8WCulUI2iE6roG4Js5HwD3OcoqCo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YehzAb9JAu3bcFU1tOhATrFl7Jobwqpz0k6Kx0 4Nt/ApiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGHgAKCRAk1otyXVSH0HeQB/ 4r2nNmyla5byu5l9a+dzkSs2P7VDc57ojHjMgUHaxYSGDO5UZe7asC3ePZ0AjtK1zU/AepiUi5IEvT ZG3t5pco4RLuWa6DfFqJyzCiXyhzRq3ydh+yaptLtFfdBWMp0mMp+uXLHNRFjsu55OHXS6bt2eP3am ajrJDyiATeO/DeDHObUcHTJX+aFIk+V7urQv6jeJaZdyB0mL0wEFHuwQ0RA2No44U72IFcrjY5U+Wt bhYy+0SykeTjQc+Q7ob9QIwQqnnd9KxRv2qi482zdXbC1wc3F6P7b3PHZHGywBZdDNS2ptnfL22Ed+ wtDYRLVKGjK9pDzEgdKczzr6s1FElI X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: wixb9nncuobbgm4kfjz8ykt53k4ykana X-Rspamd-Queue-Id: 57CF0A0035 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517258-830160 X-HE-Meta: U2FsdGVkX1/M39aJTem493qiVrgRu8vL578zQ1Hz4KpUEU//lmHGUNExiPf7EeBaDQUtSFt1HZ7nqcsnRm6pvY558lCmACzFw5T8S9yDm+B+f/bsl7Iz84xNnWOB097/smkRw9Or0CgK+0xZ/AGhovXzsDMyQQlvVzV9+ZlwkPaitzgfLCjCjUj5XiEctwNzaCXbanmRYrriyP/B5q2XUEIyvfs5XrNe+u55tmf6t/qCh5bfDoQ22tXvFBefPWP2eee+EdAB21+hBnQ3N/CnsIeza8bk/IuDsj6tnP6538a3jTU3jHMJLrU+1YFmmGM9cGtQ1ii22b2sXjEORxwLq1vq6r2nhlxuUllXJCE3G74unrmrv3JM7Bef+8Cno9MWG9jo73wcsdpWBzrKJBXKrISIvydfiXQp8sibUGufOLgwvPMmm/70E5Nq6A7l9tMOC6wouIQG1glCD6b8mBtRDI2hrktKf1Mc5zyldXJxyrMZEmTuy3zTnik4ihjkN9uxSh8U0JosW4xy4Kmx/3VX5z+f5Dr4mUjFmgRaS+PEICZH+cG7P2IK6k95Oc+t7lnq7N2Rw1hboqwro9Dv5pOXUSKjkKHGLK2i6BrwXd1f09UlR3/sW+2NzhmGEk5Shq1Kgkkb5iVXH4+vTb+K6i0WQsfFZZMdyxmeqVB+56kAxs8M4jh9555oOCGKjAi4DXSkUEepBPYOwDpEIVa4u3rz6Df51cHRXIlyO5+4zodOjwSGv4qnnuZy2+SGWiY7+DlTpRNchrmvSKnk4d8Uqmavg3lkTRnyphWMMA98JpB7i8a1CvcYSLUj7h0GPQaEpbQhRSI7yQO+Xa6XI6SaF4BJfCbUqOmNOXnEyyxVb8TxHQhukLeM0SB7eN5kjpFKrOiiljUJ9DTOiiCSiSGKYkfSukoYc3pjF2Yi/Q2ezo2866N2DUov7m03VVraXBB2InIU9G2kqtJI0gu9pzN8jzs mrgpNWIy Y1DY8VTVb6sc2dtyaxOPQY20N1G3XMLgFEaV3fJdPVBBUuCxk5yGnFbU6zBgLMBevCOu2euLC3atV0Rf04M+y8XCceBm15t1O0F/bD1mAnZZGIRLIn5VqEUFoGHdMf789QCaSpb5z2YqOToLfDj4TixYrQs6EN1myMSMp9WZq99l5Le6pyM7g0NG6PI4Zn761kzy5rkGLcZQHkxCCyhMIyvIlo6K8HFg201y+WoFfaUqeSyu1nSG724MaDQbHC3WWFjcG5sYCK/F1rNu2geVvbZOLD58t94C3l/TmbHAehzMgXNWbr1mlKR181D8e+T8Wus0TY4fmXzQk52g9VP2rMkav8osYCy0z/XXZiZ4JP3SVDWNS+dhowrvILYbSCjDr+oGP 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: Teach the framework about the GCS signal context, avoiding warnings on the unknown context. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/testcases/testcases.c | 7 +++++++ tools/testing/selftests/arm64/signal/testcases/testcases.h | 1 + 2 files changed, 8 insertions(+) diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.c b/tools/testing/selftests/arm64/signal/testcases/testcases.c index 674b88cc8c39..49d036e97996 100644 --- a/tools/testing/selftests/arm64/signal/testcases/testcases.c +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.c @@ -217,6 +217,13 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) *err = "Bad size for fpmr_context"; new_flags |= FPMR_CTX; break; + case GCS_MAGIC: + if (flags & GCS_CTX) + *err = "Multiple GCS_MAGIC"; + if (head->size != sizeof(struct gcs_context)) + *err = "Bad size for gcs_context"; + new_flags |= GCS_CTX; + break; case EXTRA_MAGIC: if (flags & EXTRA_CTX) *err = "Multiple EXTRA_MAGIC"; diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.h b/tools/testing/selftests/arm64/signal/testcases/testcases.h index 7727126347e0..dc3cf777dafe 100644 --- a/tools/testing/selftests/arm64/signal/testcases/testcases.h +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.h @@ -20,6 +20,7 @@ #define EXTRA_CTX (1 << 3) #define ZT_CTX (1 << 4) #define FPMR_CTX (1 << 5) +#define GCS_CTX (1 << 6) #define KSFT_BAD_MAGIC 0xdeadbeef From patchwork Thu Aug 1 12:06:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750412 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 03903C52D54 for ; Thu, 1 Aug 2024 13:01:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 943F36B00CB; Thu, 1 Aug 2024 09:01:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CC746B00CC; Thu, 1 Aug 2024 09:01:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 746316B00CD; Thu, 1 Aug 2024 09:01:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 54ED36B00CB for ; Thu, 1 Aug 2024 09:01:11 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CA8DB1A0D11 for ; Thu, 1 Aug 2024 13:01:10 +0000 (UTC) X-FDA: 82403687100.16.9499C26 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id 6E29CC0005 for ; Thu, 1 Aug 2024 13:01:06 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=chYxdKgK; spf=pass (imf22.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517211; 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=WWCcnUoJjrrALxAjBZhPpvknZTOgZ9IOR5Q3O7LGZXc=; b=w5S8727gbE3byxrogk9d8iwxHQiaecXc52CLcNwjp6ETJQwJnoN5+sn9qOkeQRI8eKmV3O ObtSufBce2pNWnTAzlLb7TK9ow6YuYqTmSVIMNoR+hTtSm2TJfahzY4B0HJPenyNsKScVq sEkLge1gdUJqyIhmwSlS9OlC4LUNpkY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517211; a=rsa-sha256; cv=none; b=hrfWiwnVMWexu4tWTGMuWIbdLGLFUAThYIaEVx6EOfVBe4eVapuwrZE6M2VYBByX7z4gpB qrz2gImfaUGlAaK1Yc4/+0vBwFqGbUkSvVNqb3OoecjYn2j62V3HahVN+l39DatC/CZQBh hbmcjTMaGmEe5PF/1lOGc5ySLUJrW7Q= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=chYxdKgK; spf=pass (imf22.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id AE878CE19AF; Thu, 1 Aug 2024 13:01:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91CD2C4AF0A; Thu, 1 Aug 2024 13:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517264; bh=+guAOBhRmIfgEVfzNIbxa5iAcbQBA9Aonxf7B+eDgYE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=chYxdKgKEN/P6WhtjSlCRHRkRW2Bij5hb+Y7VAQJKyCvKoPomyYMt8eArd/MVWIK8 61GY9dsmfiCU5Jys/qtBCj6COundf1HHTWMcw143MpEsvQEW5kNgUxBEhy7QxfbBp1 l5nVQ1KwuENodPcsuuvbuCUzld7ZZ0nlWbrzovrigtEAjwpSaB1Le0b6wP1F7Bl2aw hSuxIPdajC4F0ApEoZI98nrjUc94Q5ofvfoAg+78wxlkVvsJ4DU/7ibQoPGPURV7sn yAzCuvwyZFbXTbWSoScHdaLvR4B1W51AYxojkTbz41SdPUFXkfsDk+kMlXfOIRnphm hpY62eQpLtzuA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:59 +0100 Subject: [PATCH v10 32/40] kselftest/arm64: Allow signals tests to specify an expected si_code MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-32-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=2693; i=broonie@kernel.org; h=from:subject:message-id; bh=+guAOBhRmIfgEVfzNIbxa5iAcbQBA9Aonxf7B+eDgYE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YeUXoUQw/9I7ybFQmVQ8h2lcPYkdDrKBsETSxM MBjWXMSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGHgAKCRAk1otyXVSH0KVCB/ 4gRjlP4/lp0JabZj5jZ4yViyk5smTqzwWsY4ENeCSjsgUO8f9bx1pGhzfjIQTxvGmkdsS5tQ7QhxIN fIPGi7IZXlzFmZa9T8S9M9tMgZrfDWs/9RohnqVFwJZ8HosQgIvEx041S4+1/z52tEYmC7GHKvM/Cx c9iY8K4DddJGJMT0l7dlRvXBwOLTXRf2E1rRcUa/yZsOFS1rCP05axTuU6MaC5yvT96WZL58hYdvn8 RdBPuIl7oV8XA40gGkZAshXYW5ICmSFqcw+SwiPHGqGSScN5TFR8tt/1J+hpoTLzX5V/O8H2gCzK2p 1qmfLZxLZVb6xcXZEc/UB9a4Qfow3n X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 3fk1mhhxqjc99h6w3wsitttrar7fwejb X-Rspamd-Queue-Id: 6E29CC0005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517266-171975 X-HE-Meta: U2FsdGVkX1/p9xL0DJdKF9S9VEBknhQp0vlmdyn9rX0TR9LnBdP847yDyTJoBjXaGSULsAcAO1bY5a77KbHM5yrEUlJYTKqtJyenzlZu6/FDIi+tLS8vCU2Oz8scpLmkU0dSk9WuH1GDJY7Np9cvm5ojWwMPAL71GNEan8Lzfq9ScXHVUIpcU9xMiPJSuJrvjeENFsFspDXOocRR3omdeuIqqf0TQIG20c+q2CRXxwnbJ18Fkb+4I82jH8ShY3Kl3ienJki6hhxFeyRy3P5j0rpuqVaY7jexOIBM6rrbyLunvsMZ+MoE5GBcLkeq/0X/4uAgjYxRQ+pkALb5emFLRWqpomQzogl9ZTS9T+joCrifVfz/NfOKtU9N23ffcSp5Ti1mDkPYTa2qrtCqn4Ppjh24deG0PhUbUAFJZmv97cdbC1utiTTBgRdDw9De0hKKPKiQcYcpRtebrt1651jYoYn0Q4MZP8uwwbJIupOp7G87F4DwB0Ut0n4661TJL/PmEAlhET1WEDFBUpXK9YqbIH5MzEQBdVt0Z6K7d+F54TciTZ58lUDZk9Q6zfbUP/jZt/wELrVU+6nX3m+XgdwLpmckRI7wnVDrCU5wHoe0acec+hOzUX1+k/8HGrPT01BzsX8hTTI8SBm/IOCO6/t7h5BKOS1pNIY3x80qZD9dhPgUlvzxq+Gn3IhKsXuNPNqgHeJXGAZ/B0ZTeS7JPESFJOuG81L8n6JjBChUI1j53ADusuFlPMn+ab9gfMbxCias/pJdXTXtYKjp62E9OYGKpGk0/aJgVUcWselH+f5vXDfo9ITXDWphzyKeAbqC9h73YaNwgj3dCXzfUMXCVkHuFXIx0DFKmqf0M2rI7FJJDIeLBBNu7RZ9drwedMjPOdtUKrV9uBsvV7CWB0XnzqNB6aFbJ5DcLL9hkE1g1W9XLvXSxM7atjMM74WFnVqWdWaP8sS+o+9SUvyDe1GHuL2 CgsZcT2F klNcyohvz2We2JXxzEBYxgJK7CAcLxrek+mH/emWFQayBKpngrvWgTH7a3nEPDuZg/Zbl2kPiLjvjAmwdtrfrto85q9XQkm1jtVSaz6bsy2/SmNIlB+hZ9/OW4tEkMT7wahhOK3LZ3kjjMvui5rzdgsZ7Et6WzAOrtcy05Nm21lMK9xn2LNeAGtiGB1eJb8BzSWnL48BjjFn7esBw5qQvtzL2/S683wL9GnpMoSb91hrfhEEk+JXtuL/baJvqo1M/FOXLQL3pXu2pDklyJzvQWnDZaLK4iAMXcjL6VCrFO9m4i6yplP1VomkTO6YEiwWZG+YO+GZw2NWHKr3WH3na4gU2Te2WaDjg3x9fqi/KTUjhy7+vpQZcjvq6dkkzJzUckeBVu1ZbrTExOZjLS8moFNzWzSR08yVdAxMuVUhK6ohcjLM= 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: Currently we ignore si_code unless the expected signal is a SIGSEGV, in which case we enforce it being SEGV_ACCERR. Allow test cases to specify exactly which si_code should be generated so we can validate this, and test for other segfault codes. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- .../testing/selftests/arm64/signal/test_signals.h | 4 +++ .../selftests/arm64/signal/test_signals_utils.c | 29 ++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/test_signals.h b/tools/testing/selftests/arm64/signal/test_signals.h index 7ada43688c02..ee75a2c25ce7 100644 --- a/tools/testing/selftests/arm64/signal/test_signals.h +++ b/tools/testing/selftests/arm64/signal/test_signals.h @@ -71,6 +71,10 @@ struct tdescr { * Zero when no signal is expected on success */ int sig_ok; + /* + * expected si_code for sig_ok, or 0 to not check + */ + int sig_ok_code; /* signum expected on unsupported CPU features. */ int sig_unsupp; /* a timeout in second for test completion */ diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/tools/testing/selftests/arm64/signal/test_signals_utils.c index 89ef95c1af0e..63deca32b0df 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.c +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c @@ -143,16 +143,25 @@ static bool handle_signal_ok(struct tdescr *td, "current->token ZEROED...test is probably broken!\n"); abort(); } - /* - * Trying to narrow down the SEGV to the ones generated by Kernel itself - * via arm64_notify_segfault(). This is a best-effort check anyway, and - * the si_code check may need to change if this aspect of the kernel - * ABI changes. - */ - if (td->sig_ok == SIGSEGV && si->si_code != SEGV_ACCERR) { - fprintf(stdout, - "si_code != SEGV_ACCERR...test is probably broken!\n"); - abort(); + if (td->sig_ok_code) { + if (si->si_code != td->sig_ok_code) { + fprintf(stdout, "si_code is %d not %d\n", + si->si_code, td->sig_ok_code); + abort(); + } + } else { + /* + * Trying to narrow down the SEGV to the ones + * generated by Kernel itself via + * arm64_notify_segfault(). This is a best-effort + * check anyway, and the si_code check may need to + * change if this aspect of the kernel ABI changes. + */ + if (td->sig_ok == SIGSEGV && si->si_code != SEGV_ACCERR) { + fprintf(stdout, + "si_code != SEGV_ACCERR...test is probably broken!\n"); + abort(); + } } td->pass = 1; /* From patchwork Thu Aug 1 12:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750413 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 C7387C3DA4A for ; Thu, 1 Aug 2024 13:01:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54C246B00CE; Thu, 1 Aug 2024 09:01:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D5726B00CF; Thu, 1 Aug 2024 09:01:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34ED76B00D0; Thu, 1 Aug 2024 09:01:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 168676B00CE for ; Thu, 1 Aug 2024 09:01:20 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C36EA140D6F for ; Thu, 1 Aug 2024 13:01:19 +0000 (UTC) X-FDA: 82403687478.15.CA474E5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id ABB2D4004E for ; Thu, 1 Aug 2024 13:01:13 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eiQC9tfE; spf=pass (imf04.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=1722517229; 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=hj3WhFaOCpjNcMMrW6j26CW97t/N+Ei51YtOEHgyON4=; b=zhvHto6xlC0sMVxu+XR+6Lq09w3eTjsAAShqJEMtBLaWwVzrz16zKvY1xSqk/lCZwGcu09 CC8uL/3tolD0ZS2Z8xvWl/VYewrLdcAV5u1rEu+W8+vqi31QYcaiZGQoA02WGz698DVWmg KgI8vgG2+2Wz1KnftGqRPvbW6yCN510= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eiQC9tfE; spf=pass (imf04.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=1722517229; a=rsa-sha256; cv=none; b=gXU/MOKIdaV47oKlPeyFdvoW4wE1zqBc3lgcNwmjNoc8tUKLUaYZaoOH53rOqIHOiAgYPI zS9qlprKlc/Me35u8zBQBt+YyV009UyZRs3jXKZEJ2c5uemwMxPVqqCPDDm4KETWfPuTc3 b0b4OBAw6A0fI4lnQzwCvq3HsmDnny0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BB67E62862; Thu, 1 Aug 2024 13:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 760D5C4AF09; Thu, 1 Aug 2024 13:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517272; bh=LmUMQLV4QzyWbEviejJtcrr2Je4DeKbVGxPr/Gcjy80=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eiQC9tfEj2yzbkQUVXuEHA5FOCUQHlZsCNGDpYBeDhIZahyslRfPpjWdlSGLz6loU S4s88Lq5J29Pt50M3T98bU6+aWK7vhZwQgr3yZ3Y7UsrlpN5arpGSPNb5Rk99niNo/ TgsAQutH5c759cE6VN50T/zDAEZwjnkXlQWXW6N8AZRTv1i0lVUaPYG7bnMjaD/AXJ 0dv7guXmbq8WvESmD5D3celWtH45rjAsGVMPjiHlxN/IJUvQKYAQsJrv/XWHTRNgNH Kw3X9fCFajCuE/P7ul7zOiyesfJYpFAl3j/nUk4Ji/lEVLP+EYu+9URKrgefd5yVn6 Ui0PXtb0gB6gQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:00 +0100 Subject: [PATCH v10 33/40] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-33-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=3656; i=broonie@kernel.org; h=from:subject:message-id; bh=LmUMQLV4QzyWbEviejJtcrr2Je4DeKbVGxPr/Gcjy80=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YfZHSTRLe1W0pE6ZV+ChRvx8M1mI3slzwhZw3O nR/3G/6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGHwAKCRAk1otyXVSH0Da/B/ kBN10pM9iQ0M7RJ7DnXB/XtakgurlZID9xXfbmSA521fi6o3bzBiw7Aib7wVwjLCx7C7kZevZNYB0D gUkpZv4ysXJ78OKkGw3ePtUD+gbK/YXk+qfsu6aqiNBo/6kIPlInroTz76OU30v5XYBRtv0qGjr8z4 HKl65vUzC/F7YW5uYWYbJg5qIroL3CNndMIbnKDTDBg/YYNpY993oea/y8Y3HxOCrMESy0p4Yhv+hi o4cUmtfZidJsNsh8Eu7WMIaoGJosFAcaEAgp/x6nFlkooNF89WsuySwLaR+t2/ZDSMyAcbBL8OKKR1 /7etPpNbJS7ZWvNxQ6rNYNZ2bSQUvo X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: bt39ck4hrzgikj9ewf93o8strkqread8 X-Rspam-User: X-Rspamd-Queue-Id: ABB2D4004E X-Rspamd-Server: rspam02 X-HE-Tag: 1722517273-103507 X-HE-Meta: U2FsdGVkX19zb+s5JB40+XSrwHFvqVezfi9rGCn9VO/zDCxUEWHnZd9KGMRyaL1FmayKdRX/WfNNH2Y3RlwNM+MM18ps1YvcWqCPUk7gk9dVHac1eE/4uUrM03f672Ajy1bBWXojp01H+MgSmoevxpcqpofc8pVlj/ThuvwdwWnD/k5PedZdCCIDqfuHADPVW+1xbPL7U6ivsfWgZsEgOJKLTwvFc9tRcu3qMvt2jHsdezzK2Cl6IVNLFzb2nPhsErwL65KJ9lOpkL0PbMjuf5kufcgZB1YJe0OhQ7YekPo7jLeJIaOmxvkTNS8fH+t7HddrbNP9w/WdqZJuV8FJKTY0vilZUfW+BTrQO3C5yx9JiKZX/7eWfsl0J3dfi+jRp+ZHGuYSct2+QqbDCbNx+YGsOU1FzAMXfIA134rErejvbA1MuZ4/NUozz32chB4W38YVxqU9FUWgKbXHhNj8hidmciIh5GRpvza4uJwY/xFMjOsFyp+4GjKW4QRcmMPZkibwlT9KZxfWn2Vwn22tmO1dUV6efRx2SjMGgwD7ntN6401sRxSHXkS4761X5Y+dX1isQZBfOoncWvJXaWXcgvCd8rRS/YhMayMmN40XVAMBqbLGpg53Wl0KcBiB1HmwJFSIRHlRuePlXFaaX2uw06kX2A/eExJkJTb85ZnmYxkJ3512kJiIm6KkzObCzNQZsoYdOlouwjfyBJiNldsDS3F4Vq2famp3EhRIIxJo7K1ry2fsWblZlQdVfown5doQBs6LB1sUtb/IcQdo3ysKsuOBWqnwPv75wCs+oAUt+WOrrTzTRm0WmCysJzW1QWPBSsrXj6iEpmbsHfv6R2OL7cYwdUT5ZLCrjJavGM91IOUc7iKYuv3kUmXHq51JFNoZ+yH6MfEC8pawURKB4yxf/HlAhF2wiH+z9fMmXpatMzW/ihHbL3GzacBr609RyTMr5s+FCo1IhlXCtGwBwgm rAPWK2YX fRGE2W5VFCb0aHHx4NjfM2LjIa6+qTw4It0ucPFn1O42ldpFwNU58Eo4SoAKYBwMDtnFl8jsqMvX1F2icN5r5ReLMIGEqSx0N0Lny+A93w5YRAyc33od+9t/inknpqJdqqAI7kLMNGN+OaQE8kSOLc9LTWn5H0DaFJ//cpku1ORzBdFd2ST2zmErpUKRkPBUDe5K2q0VDlfNoxdj4pZ2sy1d7nDRQXbEH8BbNvYUlgf/YSxMcp96SW9+Ka9WTFBRJ6SKTFuOUWxqp/D7C1jqZyPTzY45DJ7HuE+yrbSQYrtPcFbfn6DceAnTrZ/PXABvzLkLcgOhL94wABE+hJY8q2JgRBniSDxN2SDjI7K+3EciprDUIq+Em/hZ5YRaxMvu3NYOk 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: Since it is not possible to return from the function that enabled GCS without disabling GCS it is very inconvenient to use the signal handling tests to cover GCS when GCS is not enabled by the toolchain and runtime, something that no current distribution does. Since none of the testcases do anything with stacks that would cause problems with GCS we can sidestep this issue by unconditionally enabling GCS on startup and exiting with a call to exit() rather than a return from main(). Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- .../testing/selftests/arm64/signal/test_signals.c | 17 ++++++++++++- .../selftests/arm64/signal/test_signals_utils.h | 29 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/signal/test_signals.c b/tools/testing/selftests/arm64/signal/test_signals.c index 00051b40d71e..30e95f50db19 100644 --- a/tools/testing/selftests/arm64/signal/test_signals.c +++ b/tools/testing/selftests/arm64/signal/test_signals.c @@ -7,6 +7,10 @@ * Each test provides its own tde struct tdescr descriptor to link with * this wrapper. Framework provides common helpers. */ + +#include +#include + #include #include "test_signals.h" @@ -16,6 +20,16 @@ struct tdescr *current = &tde; int main(int argc, char *argv[]) { + /* + * Ensure GCS is at least enabled throughout the tests if + * supported, otherwise the inability to return from the + * function that enabled GCS makes it very inconvenient to set + * up test cases. The prctl() may fail if GCS was locked by + * libc setup code. + */ + if (getauxval(AT_HWCAP2) & HWCAP2_GCS) + gcs_set_state(PR_SHADOW_STACK_ENABLE); + ksft_print_msg("%s :: %s\n", current->name, current->descr); if (test_setup(current) && test_init(current)) { test_run(current); @@ -23,5 +37,6 @@ int main(int argc, char *argv[]) } test_result(current); - return current->result; + /* Do not return in case GCS was enabled */ + exit(current->result); } diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/tools/testing/selftests/arm64/signal/test_signals_utils.h index 762c8fe9c54a..1e80808ee105 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.h +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h @@ -18,6 +18,35 @@ void test_cleanup(struct tdescr *td); int test_run(struct tdescr *td); void test_result(struct tdescr *td); +#ifndef __NR_prctl +#define __NR_prctl 167 +#endif + +/* + * The prctl takes 1 argument but we need to ensure that the other + * values passed in registers to the syscall are zero since the kernel + * validates them. + */ +#define gcs_set_state(state) \ + ({ \ + register long _num __asm__ ("x8") = __NR_prctl; \ + register long _arg1 __asm__ ("x0") = PR_SET_SHADOW_STACK_STATUS; \ + register long _arg2 __asm__ ("x1") = (long)(state); \ + 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; \ + }) + static inline bool feats_ok(struct tdescr *td) { if (td->feats_incompatible & td->feats_supported) From patchwork Thu Aug 1 12:07:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750414 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 B82A6C3DA4A for ; Thu, 1 Aug 2024 13:01:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C7456B00CF; Thu, 1 Aug 2024 09:01:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34F2F6B00D1; Thu, 1 Aug 2024 09:01:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 153716B00D2; Thu, 1 Aug 2024 09:01:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E3A786B00CF for ; Thu, 1 Aug 2024 09:01:23 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 994FD160D57 for ; Thu, 1 Aug 2024 13:01:23 +0000 (UTC) X-FDA: 82403687646.02.5B8A685 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 883C140019 for ; Thu, 1 Aug 2024 13:01:21 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ayaX3GuU; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1722517235; a=rsa-sha256; cv=none; b=gfmOw9QIPXYyjb8F4pUCd6/QSr0VSwCW9WUSR4TiW5TyXHhzyzn4d2fTlKyzw3l/fM66v5 Y+/YlMdYdbGY9Zg2XOGuEo+xwGjXRFQUfpM7QrIlDOWxUWH/M+H9Mq3gtM04LKhmavO9mX nu0BoBTY2hgk4aSmlgOI4l9fkaIcb5g= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ayaX3GuU; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1722517235; 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=3Jha9xXlI6eXPmoCvZEt3tepTTT+aH8aO/t6Ev+AFq8=; b=iAMjNNnrAG8Z2sMFAHVjOpRHom4jLNzi0BBWzvj1Urn4AfpZON87dGxxceT3awuXL8JZmf pFkGe0v8MtP6RFdmzOy3p8IhdkmtnyMCwm8jzemuDyvUXaaB99tBJW/x4DZpjkoDIVqgOP GkDrjsQFMrorDVri17wox6j+yD8L51c= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 65CD462850; Thu, 1 Aug 2024 13:01:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E75CAC4AF0E; Thu, 1 Aug 2024 13:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517280; bh=uHJiYcvljzUX8f4hJI4pgvGmhWWcFPMp0a5s58eHg1Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ayaX3GuUmEObcdw2HR6SEFudNwbWd2hjrsXSJOWDGX/mV+/UdrF7D5LI6c2J7166V xfs1ZJJqSddX3B3BEAnFTT4Bj7DRpivNDjZd5ZFZz/AT6CmAuECjcK6yzKTbneyrfn x0eKyl9/hmCRZflkxodkMfv6SAGG8aLoPcbTQ8icOqPQVhs0+dhbaIhdA5Glki8qYo y0j8srJ0ufuHY9hxc4QQz939oJR24U28Kx0tQ7QdfjYr+Za2aO5gEeXVg++t9FNwDL 0JpJhFAkae7pKtG9Dk69ZAICzQgEv+BNDT2pj/RxMMkFra/9Q02IyftUusrCPp7B75 7Ituw/5JwZ+DQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:01 +0100 Subject: [PATCH v10 34/40] kselftest/arm64: Add very basic GCS test program MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-34-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=13330; i=broonie@kernel.org; h=from:subject:message-id; bh=uHJiYcvljzUX8f4hJI4pgvGmhWWcFPMp0a5s58eHg1Q=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YgCsZl4Gyc5WSVYob506UdT6IRLc3qvnSV1EGk 5BwZSa6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGIAAKCRAk1otyXVSH0LUOB/ 9H4yiDH3Qn7SkhrJd9KEgJjz3fdwYEmK0of6LYlEShnvCs2ykSw+V14fj4ZESVicIXsWbTj9/U+Vuv 7m/fxKf7k7mYQgXMbie31g9KHdpb2IUlSNTwClNNTZ/cO/L4M4TlKjRSRcoASrhvRHCTVACgHixpKL 0H6AriSkmvYa7SdNHPD834kmymPbpWXd+cok5y5w3xXCN5ROAZIVmuCB8sprCiBcxazmNUWkpTpzqh wQRPqL6Ptf4mD90EJ1vJYVVm7qEraLEVRthmCnG6S/w03ROYZFMf9wlwErEcX4xtVNHposWCkQxP56 7V3QjlZ4pvZ7LI/4DtOEjYRHzT8gXr X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 883C140019 X-Stat-Signature: fytc164krs5btn4rpk7fwfk43eez4rge X-Rspam-User: X-HE-Tag: 1722517281-768298 X-HE-Meta: U2FsdGVkX185S2PBZksHsot8bcRxrHKyxFL/I7Aqy04ycI80cEFb+sRJL+lB/sdaW4EouWQG5lh1jJA978o6yZogGqd+FtAVXyXVFr8G/rddwk13Ar1z6eKKRd5RaMiPNGRFq82T/kXex+E1sRPeQkcIQ0meAWLu9xukAfZYQ56zhDYQgTnfxxYdwg4m63/aNlHwaN/R1wGy3xz2erVfiTGTgYtLfMQda3v//XjPB6AGCU3ZkROXfdMMAddbZ6tH++AnTOpMa25Sfph+l59M4csXf3/94OLxB2kW9T5WHViAwk5/5Cupz4ToKcW94qOG5Co2LRgvWlPw/jTZhtuRCYDJ5qbozfEU49kR1CrU7UgojQibfsYpQUec7FJkjS9hDfAGCAAZJsXIZuwWQ/8XFVI1WRUK/d53VmWWZbTEu1Q1J1WlZh6x9QLxc7g/nrvEVPqk8oZ3Y3RoPsgsf7tluOU8DKNoZpDipXhMabhVT1kiFRIAWKdg1S9TITjj1vsQgpJq52l6SSk/wUN4Fpipt8xW35LEREiltpxP+k+/+/LhzFZWabR+xBmZf5wRFCkQIwuY5R4abMrADYBoh9flICGIrw5B45WomSPbah2HrkYs0I/DHMtjSAG2AXRF3FtLtjWAE25hAvbK/Ff5IlkJGQFRBEk46RIOLd04Kfh4allAMfrbWVdwmfe8bOp0MCn3ethOHx1f4x4rgjrTxefL2GQ9ulynoRBJnaTDWYDLmbJY5u45tEEpRoTrq4XLGc20MLbXNrlAhACp595hygM98E44zfo7dnbqqVNdOCGNCaLJN0q7GujSQdmJsamQ0C4oExgCOBS5uJNkLR4PtOHZBsTEATfR8/GrvV2LEr4W2E5GkAMiRYIe8Arh4e9YprqJeGQZKlrGtMFu/m68Y6+/5zpZAFTNbwpx4hfYq12kFLfevfs7PnWqopDy/uVL44+2EBOW0wwH7iUcckwBq17 CZQdw5g8 UflRtbFNodKQ8hj+BQrpJ1eeLD7dKvqnu29PB0MEXccv++dOmxkAveYk0Yvz7iHuV1YQLEc5KFlTFmCsjjo21PO2RIfKRPHIrAGRb6UW9+X/Jx1IX6zddx/aSVtZZJZ6tjVh4QBaKjCmBSTEjK9s9AJThNNEM40t/gW1soAzXNpwPaJBzst7VKwu+orfwyBhfse2mN+qTUnmwOZOV1FOAonZptui78z8M/IcM7BDBQ92tGpNFFO5TiPLoy7d0nXy3eYbX0QyT9sSRF9gfp1p+/KgEWM/Sq9IUecB5pRYLQsEeTXp9u1CgUUb1E+B09LHft50dTxDRWcCv6oTi7swjg2qVdPV3CRYf39rAfhrwTNHYAlxtWpeTRxjflhGBjJtglssd 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: This test program just covers the basic GCS ABI, covering aspects of the ABI as standalone features without attempting to integrate things. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/Makefile | 2 +- tools/testing/selftests/arm64/gcs/.gitignore | 1 + tools/testing/selftests/arm64/gcs/Makefile | 18 ++ tools/testing/selftests/arm64/gcs/basic-gcs.c | 357 ++++++++++++++++++++++++++ tools/testing/selftests/arm64/gcs/gcs-util.h | 90 +++++++ 5 files changed, 467 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile index 28b93cab8c0d..22029e60eff3 100644 --- a/tools/testing/selftests/arm64/Makefile +++ b/tools/testing/selftests/arm64/Makefile @@ -4,7 +4,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),aarch64 arm64)) -ARM64_SUBTARGETS ?= tags signal pauth fp mte bti abi +ARM64_SUBTARGETS ?= tags signal pauth fp mte bti abi gcs else ARM64_SUBTARGETS := endif diff --git a/tools/testing/selftests/arm64/gcs/.gitignore b/tools/testing/selftests/arm64/gcs/.gitignore new file mode 100644 index 000000000000..0e5e695ecba5 --- /dev/null +++ b/tools/testing/selftests/arm64/gcs/.gitignore @@ -0,0 +1 @@ +basic-gcs diff --git a/tools/testing/selftests/arm64/gcs/Makefile b/tools/testing/selftests/arm64/gcs/Makefile new file mode 100644 index 000000000000..61a30f483429 --- /dev/null +++ b/tools/testing/selftests/arm64/gcs/Makefile @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2023 ARM Limited +# +# In order to avoid interaction with the toolchain and dynamic linker the +# portions of these tests that interact with the GCS are implemented using +# nolibc. +# + +TEST_GEN_PROGS := basic-gcs + +include ../../lib.mk + +$(OUTPUT)/basic-gcs: basic-gcs.c + $(CC) -g -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ + -static -include ../../../../include/nolibc/nolibc.h \ + -I../../../../../usr/include \ + -std=gnu99 -I../.. -g \ + -ffreestanding -Wall $^ -o $@ -lgcc diff --git a/tools/testing/selftests/arm64/gcs/basic-gcs.c b/tools/testing/selftests/arm64/gcs/basic-gcs.c new file mode 100644 index 000000000000..3fb9742342a3 --- /dev/null +++ b/tools/testing/selftests/arm64/gcs/basic-gcs.c @@ -0,0 +1,357 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 ARM Limited. + */ + +#include +#include + +#include + +#include +#include +#include + +#include "kselftest.h" +#include "gcs-util.h" + +/* nolibc doesn't have sysconf(), just hard code the maximum */ +static size_t page_size = 65536; + +static __attribute__((noinline)) void valid_gcs_function(void) +{ + /* Do something the compiler can't optimise out */ + my_syscall1(__NR_prctl, PR_SVE_GET_VL); +} + +static inline int gcs_set_status(unsigned long mode) +{ + bool enabling = mode & PR_SHADOW_STACK_ENABLE; + int ret; + unsigned long new_mode; + + /* + * The prctl takes 1 argument but we need to ensure that the + * other 3 values passed in registers to the syscall are zero + * since the kernel validates them. + */ + ret = my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, mode, + 0, 0, 0); + + if (ret == 0) { + ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, + &new_mode, 0, 0, 0); + if (ret == 0) { + if (new_mode != mode) { + ksft_print_msg("Mode set to %lx not %lx\n", + new_mode, mode); + ret = -EINVAL; + } + } else { + ksft_print_msg("Failed to validate mode: %d\n", ret); + } + + if (enabling != chkfeat_gcs()) { + ksft_print_msg("%senabled by prctl but %senabled in CHKFEAT\n", + enabling ? "" : "not ", + chkfeat_gcs() ? "" : "not "); + ret = -EINVAL; + } + } + + return ret; +} + +/* Try to read the status */ +static bool read_status(void) +{ + unsigned long state; + int ret; + + ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, + &state, 0, 0, 0); + if (ret != 0) { + ksft_print_msg("Failed to read state: %d\n", ret); + return false; + } + + return state & PR_SHADOW_STACK_ENABLE; +} + +/* Just a straight enable */ +static bool base_enable(void) +{ + int ret; + + ret = gcs_set_status(PR_SHADOW_STACK_ENABLE); + if (ret) { + ksft_print_msg("PR_SHADOW_STACK_ENABLE failed %d\n", ret); + return false; + } + + return true; +} + +/* Check we can read GCSPR_EL0 when GCS is enabled */ +static bool read_gcspr_el0(void) +{ + unsigned long *gcspr_el0; + + ksft_print_msg("GET GCSPR\n"); + gcspr_el0 = get_gcspr(); + ksft_print_msg("GCSPR_EL0 is %p\n", gcspr_el0); + + return true; +} + +/* Also allow writes to stack */ +static bool enable_writeable(void) +{ + int ret; + + ret = gcs_set_status(PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_WRITE); + if (ret) { + ksft_print_msg("PR_SHADOW_STACK_ENABLE writeable failed: %d\n", ret); + return false; + } + + ret = gcs_set_status(PR_SHADOW_STACK_ENABLE); + if (ret) { + ksft_print_msg("failed to restore plain enable %d\n", ret); + return false; + } + + return true; +} + +/* Also allow writes to stack */ +static bool enable_push_pop(void) +{ + int ret; + + ret = gcs_set_status(PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_PUSH); + if (ret) { + ksft_print_msg("PR_SHADOW_STACK_ENABLE with push failed: %d\n", + ret); + return false; + } + + ret = gcs_set_status(PR_SHADOW_STACK_ENABLE); + if (ret) { + ksft_print_msg("failed to restore plain enable %d\n", ret); + return false; + } + + return true; +} + +/* Enable GCS and allow everything */ +static bool enable_all(void) +{ + int ret; + + ret = gcs_set_status(PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_PUSH | + PR_SHADOW_STACK_WRITE); + if (ret) { + ksft_print_msg("PR_SHADOW_STACK_ENABLE with everything failed: %d\n", + ret); + return false; + } + + ret = gcs_set_status(PR_SHADOW_STACK_ENABLE); + if (ret) { + ksft_print_msg("failed to restore plain enable %d\n", ret); + return false; + } + + return true; +} + +static bool enable_invalid(void) +{ + int ret = gcs_set_status(ULONG_MAX); + if (ret == 0) { + ksft_print_msg("GCS_SET_STATUS %lx succeeded\n", ULONG_MAX); + return false; + } + + return true; +} + +/* Map a GCS */ +static bool map_guarded_stack(void) +{ + int ret; + uint64_t *buf; + uint64_t expected_cap; + int elem; + bool pass = true; + + buf = (void *)my_syscall3(__NR_map_shadow_stack, 0, page_size, + SHADOW_STACK_SET_MARKER | + SHADOW_STACK_SET_TOKEN); + if (buf == MAP_FAILED) { + ksft_print_msg("Failed to map %lu byte GCS: %d\n", + page_size, errno); + return false; + } + ksft_print_msg("Mapped GCS at %p-%p\n", buf, + (void *)((uint64_t)buf + page_size)); + + /* The top of the newly allocated region should be 0 */ + elem = (page_size / sizeof(uint64_t)) - 1; + if (buf[elem]) { + ksft_print_msg("Last entry is 0x%llx not 0x0\n", buf[elem]); + pass = false; + } + + /* Then a valid cap token */ + elem--; + expected_cap = ((uint64_t)buf + page_size - 16); + expected_cap &= GCS_CAP_ADDR_MASK; + expected_cap |= GCS_CAP_VALID_TOKEN; + if (buf[elem] != expected_cap) { + ksft_print_msg("Cap entry is 0x%llx not 0x%llx\n", + buf[elem], expected_cap); + pass = false; + } + ksft_print_msg("cap token is 0x%llx\n", buf[elem]); + + /* The rest should be zeros */ + for (elem = 0; elem < page_size / sizeof(uint64_t) - 2; elem++) { + if (!buf[elem]) + continue; + ksft_print_msg("GCS slot %d is 0x%llx not 0x0\n", + elem, buf[elem]); + pass = false; + } + + ret = munmap(buf, page_size); + if (ret != 0) { + ksft_print_msg("Failed to unmap %ld byte GCS: %d\n", + page_size, errno); + pass = false; + } + + return pass; +} + +/* A fork()ed process can run */ +static bool test_fork(void) +{ + unsigned long child_mode; + int ret, status; + pid_t pid; + bool pass = true; + + pid = fork(); + if (pid == -1) { + ksft_print_msg("fork() failed: %d\n", errno); + pass = false; + goto out; + } + if (pid == 0) { + /* In child, make sure we can call a function, read + * the GCS pointer and status and then exit */ + valid_gcs_function(); + get_gcspr(); + + ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, + &child_mode, 0, 0, 0); + if (ret == 0 && !(child_mode & PR_SHADOW_STACK_ENABLE)) { + ksft_print_msg("GCS not enabled in child\n"); + ret = -EINVAL; + } + + exit(ret); + } + + /* + * In parent, check we can still do function calls then block + * for the child. + */ + valid_gcs_function(); + + ksft_print_msg("Waiting for child %d\n", pid); + + ret = waitpid(pid, &status, 0); + if (ret == -1) { + ksft_print_msg("Failed to wait for child: %d\n", + errno); + return false; + } + + if (!WIFEXITED(status)) { + ksft_print_msg("Child exited due to signal %d\n", + WTERMSIG(status)); + pass = false; + } else { + if (WEXITSTATUS(status)) { + ksft_print_msg("Child exited with status %d\n", + WEXITSTATUS(status)); + pass = false; + } + } + +out: + + return pass; +} + +typedef bool (*gcs_test)(void); + +static struct { + char *name; + gcs_test test; + bool needs_enable; +} tests[] = { + { "read_status", read_status }, + { "base_enable", base_enable, true }, + { "read_gcspr_el0", read_gcspr_el0 }, + { "enable_writeable", enable_writeable, true }, + { "enable_push_pop", enable_push_pop, true }, + { "enable_all", enable_all, true }, + { "enable_invalid", enable_invalid, true }, + { "map_guarded_stack", map_guarded_stack }, + { "fork", test_fork }, +}; + +int main(void) +{ + int i, ret; + unsigned long gcs_mode; + + ksft_print_header(); + + /* + * We don't have getauxval() with nolibc so treat a failure to + * read GCS state as a lack of support and skip. + */ + ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, + &gcs_mode, 0, 0, 0); + if (ret != 0) + ksft_exit_skip("Failed to read GCS state: %d\n", ret); + + if (!(gcs_mode & PR_SHADOW_STACK_ENABLE)) { + gcs_mode = PR_SHADOW_STACK_ENABLE; + ret = my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + gcs_mode, 0, 0, 0); + if (ret != 0) + ksft_exit_fail_msg("Failed to enable GCS: %d\n", ret); + } + + ksft_set_plan(ARRAY_SIZE(tests)); + + for (i = 0; i < ARRAY_SIZE(tests); i++) { + ksft_test_result((*tests[i].test)(), "%s\n", tests[i].name); + } + + /* One last test: disable GCS, we can do this one time */ + my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, 0, 0, 0, 0); + if (ret != 0) + ksft_print_msg("Failed to disable GCS: %d\n", ret); + + ksft_finished(); + + return 0; +} diff --git a/tools/testing/selftests/arm64/gcs/gcs-util.h b/tools/testing/selftests/arm64/gcs/gcs-util.h new file mode 100644 index 000000000000..1ae6864d3f86 --- /dev/null +++ b/tools/testing/selftests/arm64/gcs/gcs-util.h @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 ARM Limited. + */ + +#ifndef GCS_UTIL_H +#define GCS_UTIL_H + +#include + +#ifndef __NR_map_shadow_stack +#define __NR_map_shadow_stack 453 +#endif + +#ifndef __NR_prctl +#define __NR_prctl 167 +#endif + +/* Shadow Stack/Guarded Control Stack interface */ +#define PR_GET_SHADOW_STACK_STATUS 74 +#define PR_SET_SHADOW_STACK_STATUS 75 +#define PR_LOCK_SHADOW_STACK_STATUS 76 + +# define PR_SHADOW_STACK_ENABLE (1UL << 0) +# define PR_SHADOW_STACK_WRITE (1UL << 1) +# define PR_SHADOW_STACK_PUSH (1UL << 2) + +#define PR_SHADOW_STACK_ALL_MODES \ + PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_WRITE | PR_SHADOW_STACK_PUSH + +#define SHADOW_STACK_SET_TOKEN (1ULL << 0) /* Set up a restore token in the shadow stack */ +#define SHADOW_STACK_SET_MARKER (1ULL << 1) /* Set up a top of stack merker in the shadow stack */ + +#define GCS_CAP_ADDR_MASK (0xfffffffffffff000UL) +#define GCS_CAP_TOKEN_MASK (0x0000000000000fffUL) +#define GCS_CAP_VALID_TOKEN 1 +#define GCS_CAP_IN_PROGRESS_TOKEN 5 + +#define GCS_CAP(x) (((unsigned long)(x) & GCS_CAP_ADDR_MASK) | \ + GCS_CAP_VALID_TOKEN) + +static inline unsigned long *get_gcspr(void) +{ + unsigned long *gcspr; + + asm volatile( + "mrs %0, S3_3_C2_C5_1" + : "=r" (gcspr) + : + : "cc"); + + return gcspr; +} + +static inline void __attribute__((always_inline)) gcsss1(unsigned long *Xt) +{ + asm volatile ( + "sys #3, C7, C7, #2, %0\n" + : + : "rZ" (Xt) + : "memory"); +} + +static inline unsigned long __attribute__((always_inline)) *gcsss2(void) +{ + unsigned long *Xt; + + asm volatile( + "SYSL %0, #3, C7, C7, #3\n" + : "=r" (Xt) + : + : "memory"); + + return Xt; +} + +static inline bool chkfeat_gcs(void) +{ + register long val __asm__ ("x16") = 1; + + /* CHKFEAT x16 */ + asm volatile( + "hint #0x28\n" + : "=r" (val) + : "r" (val)); + + return val != 1; +} + +#endif From patchwork Thu Aug 1 12:07:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750415 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 3EE95C3DA64 for ; Thu, 1 Aug 2024 13:01:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C51626B00D3; Thu, 1 Aug 2024 09:01:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDAE56B00D5; Thu, 1 Aug 2024 09:01:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A06CC6B00D6; Thu, 1 Aug 2024 09:01:35 -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 755956B00D3 for ; Thu, 1 Aug 2024 09:01:35 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 21705A0D6E for ; Thu, 1 Aug 2024 13:01:35 +0000 (UTC) X-FDA: 82403688150.10.36A8F3D Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id D64F7C0032 for ; Thu, 1 Aug 2024 13:01:30 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rjNx+0z9; spf=pass (imf22.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517234; 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=VeamJlV2DiQBwOmPZxweMEuePscrjEwMn5NOxSIjeUw=; b=hFm7ElfOaTcF1LE88Aq3h8+x4t6/um+Hs8NpCJJyqa1EW2Y/rb4KFRwcqsl4I1ktYPzlpD HHe93MWBuPK7gu2ZQEJL8XAa7gQ1pZ0Ah7kV1gopXV9gcicrLZkCj7Bi4jXAzlnohwiysH ts7nERwX3iDA225ZcwPLMAuIrhrvp5Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517234; a=rsa-sha256; cv=none; b=BzmfqEAG+BqoOBhQkK+AlwJg0DwlhNm6kBOKePaBQb2id0fvrP60uywFjyAQ7M+WagQomS d6YVGTxNjwEEUFAim8HLG9JA2wN5lNrN6scogRj47g9Sgjyhd7QMrpdEEFYnzZg7jKzNKK cooSgYTCm1MMmryybtmE/3rDtEYoyZI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rjNx+0z9; spf=pass (imf22.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9D103CE1902; Thu, 1 Aug 2024 13:01:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8696AC4AF09; Thu, 1 Aug 2024 13:01:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517286; bh=4Pvpbla/MCf5qguJKCtCW70h2zwnlYD2LzmYy5wIfuw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rjNx+0z9cL05TVlcJL+/xyaZIQ89XVnEb1lvXXQaLUYki5GBImGfON4YC+3iXnibP 5/hKuDo4EpnKEpDhX05KBuKZxLR4prQfRnXrANJW6ta81n04yB5iA703E4U7ZoBZI3 +cq33pyigpj3Qaqdu7aB+DcfuOF3R64sBDY9lpGM/mOSTTmq1F6Ktxdzor2Y8yGrnh fncQKqMikW1D2UbupbRfWGbIWm71xoXV0SF/KcSCIqQYqrxszyzbylxHxA7VAeLhF2 Pt0YPqiuquAJXkFdDWv/jBS2zs67l3BZO2VHde8HrN7KMxZouqOCX+9yXzzVeXL60+ jTb/hRuEB76Zg== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:02 +0100 Subject: [PATCH v10 35/40] kselftest/arm64: Add a GCS test program built with the system libc MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-35-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=21309; i=broonie@kernel.org; h=from:subject:message-id; bh=4Pvpbla/MCf5qguJKCtCW70h2zwnlYD2LzmYy5wIfuw=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YhKe0uJC+VXhB7n8D7gl6LM1rHk+Av1hpKADWU +Pu3d3+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGIQAKCRAk1otyXVSH0DMlB/ 49yF50lRQY8bs+hbeG5itYWQ+CFbkp7ZV5O4TabDeqb0aZWv3tvDzCujtewED/qg9exlk3I1OaSZ93 671PyIqr+Ipb/FtH0megIhNcnvKgn7SXMJ00xYN3WxQ/tLFLeMi9+/ql4kphrf7tE+9rke+0Go0so4 iy3lC8/xHxtDJQWjSyrkugoK/1Zw7+T81LyLmSuH18NtFtR5w/aYmNNvMBnXMEhpJY0R6JvosgYokp I7znI/mgq27mfhZQwaBg6b4ciUxzSsDPFGuC0Z1ruUwo4RZmSMHa3QP5Eu7dsvq+CpFRgHcXstNcnm hZ9qRQIPLzNunoRgmRhO4cA3GA0gzi X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D64F7C0032 X-Stat-Signature: jhaknxw7addnj69tqutyecbprwa8fyn5 X-HE-Tag: 1722517290-481496 X-HE-Meta: U2FsdGVkX1+zgS0wgRJse6al5Djv8DjeJjLqDi3XxsrAUyowj0mW2G3O4QzrUAIheZeEsVo8wF0+y3/pCbK2wAvQ2fredtNg/8KnT7C5dZOQglHgL/Y0+M2R5gbKr0vRfyVK37Yzw6NkSGNsMXiMuVOGGIA3BL5M3tQFCn1v4OCwb6Au3NJA09lbh2eSjMf2Tqxel5FVFh8dEbDkJ/hvrkZmIG/rB0wwU10LJTXAf1PSXu2s3gfyFrfh1HjUdayVZOQZpgEQs3mXSFWdCn/nIDSNiDUvmAEqOp9ZqL7BAtb05C8LYPNct2LtHFrk90xxkV0CA+d2txYzzEOf8u1Rzz+jB/86vmOLPOHCDa+Kl3KECDUPCEjDbnykl3edkWaXksJwhKCkENOrWoeAygt9CPQMF84OuTnextX4sePW0Q7b2S/xqE6ix02Ck71DMWXNYnLymS5nnXT+bo3uoaLvCGCl6XLUnUXVHTKSRbVoPfG+uZ5tQGQg7RmyYjDd1ThTX7XkSv/JuQRONP3eScBYld5mXm8nL3ll8Pe/cybGRXQ5VuzvNrUzrgwNxg5Dmu+rQhV2yYhij9rrwNO8oDf/gdTqiRScVsTc2KXwy8GLwkVdfwZaVxUIuuYwHHnJMD224aJghlw8p7TfMGGFKIUmqIsNScKCoMd+vKPBDsAz3ZVoP+Y/WgKnxvPFwHk4ohFhrmWATIZQp3pNEXmgUhb/Bz5CEshyVAPbZFunbChfwiRaM598WQQtYpc9SvwJDeG6876JHMc2tOl04C2iv1xCA8HG+oLPQOHgrAkDWRiK6vaYoD1UK6UNjKXVedWkcZHC9W5qT125PHLsrWJ0hlAfcEsXIxbxDbu1kOV47gWifLXduc2gK1Vu4azXR6op68aVB4CtRIB/3t2USOvdU6q7x2OmunjiOpfnuQrNFrmYFDAGySd/vwIxZ8kGqNFDpaDq0iYgm/wOau2KCE7VbxS rNYMQzA9 l2anghU5dZQGQU5u1E6QzZ7sEIXAmhlKoVCmiPY5QHu+NRFvH2+q73/UFalrqDy34DFqPVokG/hlD79waGRZp5NFBqmx29dgahAzMkwbCJWUn8VrpLaYGIuN9GyKtc6dBejjoljHrNsMmGws/79csQTnx1oa8v1qHBumvH4G6UdbQ8PSAh6ciWN6Rgz7Q3oGSh4hn0ZJv49v4kTqZK9MV6HgkoQc9hgy11UAgoisG33aaU4AHYhktkRUM3QR6srN/aQEClkOQso3eVQFRTqHlA1dP7CuVaGCv7fGrD9q3awp2ydasX6zFfpxNhOr7YZRGBqdlVXfdKfaPCPGyon6xDhtPJlrTqiUCvL7Q0thVfCW8VQUbeVF+4ClNve2af4kHpTx2 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: There are things like threads which nolibc struggles with which we want to add coverage for, and the ABI allows us to test most of these even if libc itself does not understand GCS so add a test application built using the system libc. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/gcs/.gitignore | 1 + tools/testing/selftests/arm64/gcs/Makefile | 4 +- tools/testing/selftests/arm64/gcs/gcs-util.h | 10 + tools/testing/selftests/arm64/gcs/libc-gcs.c | 736 +++++++++++++++++++++++++++ 4 files changed, 750 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/gcs/.gitignore b/tools/testing/selftests/arm64/gcs/.gitignore index 0e5e695ecba5..5810c4a163d4 100644 --- a/tools/testing/selftests/arm64/gcs/.gitignore +++ b/tools/testing/selftests/arm64/gcs/.gitignore @@ -1 +1,2 @@ basic-gcs +libc-gcs diff --git a/tools/testing/selftests/arm64/gcs/Makefile b/tools/testing/selftests/arm64/gcs/Makefile index 61a30f483429..a8fdf21e9a47 100644 --- a/tools/testing/selftests/arm64/gcs/Makefile +++ b/tools/testing/selftests/arm64/gcs/Makefile @@ -6,7 +6,9 @@ # nolibc. # -TEST_GEN_PROGS := basic-gcs +TEST_GEN_PROGS := basic-gcs libc-gcs + +LDLIBS+=-lpthread include ../../lib.mk diff --git a/tools/testing/selftests/arm64/gcs/gcs-util.h b/tools/testing/selftests/arm64/gcs/gcs-util.h index 1ae6864d3f86..8ac37dc3c78e 100644 --- a/tools/testing/selftests/arm64/gcs/gcs-util.h +++ b/tools/testing/selftests/arm64/gcs/gcs-util.h @@ -16,6 +16,16 @@ #define __NR_prctl 167 #endif +#ifndef NT_ARM_GCS +#define NT_ARM_GCS 0x40f + +struct user_gcs { + __u64 features_enabled; + __u64 features_locked; + __u64 gcspr_el0; +}; +#endif + /* Shadow Stack/Guarded Control Stack interface */ #define PR_GET_SHADOW_STACK_STATUS 74 #define PR_SET_SHADOW_STACK_STATUS 75 diff --git a/tools/testing/selftests/arm64/gcs/libc-gcs.c b/tools/testing/selftests/arm64/gcs/libc-gcs.c new file mode 100644 index 000000000000..937f8bee7bdd --- /dev/null +++ b/tools/testing/selftests/arm64/gcs/libc-gcs.c @@ -0,0 +1,736 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 ARM Limited. + */ + +#define _GNU_SOURCE + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "kselftest_harness.h" + +#include "gcs-util.h" + +#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; \ +}) + +static noinline void gcs_recurse(int depth) +{ + if (depth) + gcs_recurse(depth - 1); + + /* Prevent tail call optimization so we actually recurse */ + asm volatile("dsb sy" : : : "memory"); +} + +/* Smoke test that a function call and return works*/ +TEST(can_call_function) +{ + gcs_recurse(0); +} + +static void *gcs_test_thread(void *arg) +{ + int ret; + unsigned long mode; + + /* + * Some libcs don't seem to fill unused arguments with 0 but + * the kernel validates this so we supply all 5 arguments. + */ + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &mode, 0, 0, 0); + if (ret != 0) { + ksft_print_msg("PR_GET_SHADOW_STACK_STATUS failed: %d\n", ret); + return NULL; + } + + if (!(mode & PR_SHADOW_STACK_ENABLE)) { + ksft_print_msg("GCS not enabled in thread, mode is %u\n", + mode); + return NULL; + } + + /* Just in case... */ + gcs_recurse(0); + + /* Use a non-NULL value to indicate a pass */ + return &gcs_test_thread; +} + +/* Verify that if we start a new thread it has GCS enabled */ +TEST(gcs_enabled_thread) +{ + pthread_t thread; + void *thread_ret; + int ret; + + ret = pthread_create(&thread, NULL, gcs_test_thread, NULL); + ASSERT_TRUE(ret == 0); + if (ret != 0) + return; + + ret = pthread_join(thread, &thread_ret); + ASSERT_TRUE(ret == 0); + if (ret != 0) + return; + + ASSERT_TRUE(thread_ret != NULL); +} + +/* Read the GCS until we find the terminator */ +TEST(gcs_find_terminator) +{ + unsigned long *gcs, *cur; + + gcs = get_gcspr(); + cur = gcs; + while (*cur) + cur++; + + ksft_print_msg("GCS in use from %p-%p\n", gcs, cur); + + /* + * We should have at least whatever called into this test so + * the two pointer should differ. + */ + ASSERT_TRUE(gcs != cur); +} + +/* + * We can access a GCS via ptrace + * + * This could usefully have a fixture but note that each test is + * fork()ed into a new child whcih causes issues. Might be better to + * lift at least some of this out into a separate, non-harness, test + * program. + */ +TEST(ptrace_read_write) +{ + pid_t child, pid; + int ret, status; + siginfo_t si; + uint64_t val, rval, gcspr; + struct user_gcs child_gcs; + struct iovec iov, local_iov, remote_iov; + + child = fork(); + if (child == -1) { + ksft_print_msg("fork() failed: %d (%s)\n", + errno, strerror(errno)); + ASSERT_NE(child, -1); + } + + if (child == 0) { + /* + * In child, make sure there's something on the stack and + * ask to be traced. + */ + gcs_recurse(0); + if (ptrace(PTRACE_TRACEME, -1, NULL, NULL)) + ksft_exit_fail_msg("PTRACE_TRACEME", strerror(errno)); + + if (raise(SIGSTOP)) + ksft_exit_fail_msg("raise(SIGSTOP)", strerror(errno)); + + return; + } + + ksft_print_msg("Child: %d\n", child); + + /* Attach to the child */ + while (1) { + int sig; + + pid = wait(&status); + if (pid == -1) { + ksft_print_msg("wait() failed: %s", + strerror(errno)); + goto error; + } + + /* + * This should never happen but it's hard to flag in + * the framework. + */ + if (pid != child) + continue; + + if (WIFEXITED(status) || WIFSIGNALED(status)) + ksft_exit_fail_msg("Child died unexpectedly\n"); + + if (!WIFSTOPPED(status)) + goto error; + + sig = WSTOPSIG(status); + + if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &si)) { + if (errno == ESRCH) { + ASSERT_NE(errno, ESRCH); + return; + } + + if (errno == EINVAL) { + sig = 0; /* bust group-stop */ + goto cont; + } + + ksft_print_msg("PTRACE_GETSIGINFO: %s\n", + strerror(errno)); + goto error; + } + + if (sig == SIGSTOP && si.si_code == SI_TKILL && + si.si_pid == pid) + break; + + cont: + if (ptrace(PTRACE_CONT, pid, NULL, sig)) { + if (errno == ESRCH) { + ASSERT_NE(errno, ESRCH); + return; + } + + ksft_print_msg("PTRACE_CONT: %s\n", strerror(errno)); + goto error; + } + } + + /* Where is the child GCS? */ + iov.iov_base = &child_gcs; + iov.iov_len = sizeof(child_gcs); + ret = ptrace(PTRACE_GETREGSET, child, NT_ARM_GCS, &iov); + if (ret != 0) { + ksft_print_msg("Failed to read child GCS state: %s (%d)\n", + strerror(errno), errno); + goto error; + } + + /* We should have inherited GCS over fork(), confirm */ + if (!(child_gcs.features_enabled & PR_SHADOW_STACK_ENABLE)) { + ASSERT_TRUE(child_gcs.features_enabled & + PR_SHADOW_STACK_ENABLE); + goto error; + } + + gcspr = child_gcs.gcspr_el0; + ksft_print_msg("Child GCSPR 0x%lx, flags %x, locked %x\n", + gcspr, child_gcs.features_enabled, + child_gcs.features_locked); + + /* Ideally we'd cross check with the child memory map */ + + errno = 0; + val = ptrace(PTRACE_PEEKDATA, child, (void *)gcspr, NULL); + ret = errno; + if (ret != 0) + ksft_print_msg("PTRACE_PEEKDATA failed: %s (%d)\n", + strerror(ret), ret); + EXPECT_EQ(ret, 0); + + /* The child should be in a function, the GCSPR shouldn't be 0 */ + EXPECT_NE(val, 0); + + /* Same thing via process_vm_readv() */ + local_iov.iov_base = &rval; + local_iov.iov_len = sizeof(rval); + remote_iov.iov_base = (void *)gcspr; + remote_iov.iov_len = sizeof(rval); + ret = process_vm_readv(child, &local_iov, 1, &remote_iov, 1, 0); + if (ret == -1) + ksft_print_msg("process_vm_readv() failed: %s (%d)\n", + strerror(errno), errno); + EXPECT_EQ(ret, sizeof(rval)); + EXPECT_EQ(val, rval); + + /* Write data via a peek */ + ret = ptrace(PTRACE_POKEDATA, child, (void *)gcspr, NULL); + if (ret == -1) + ksft_print_msg("PTRACE_POKEDATA failed: %s (%d)\n", + strerror(errno), errno); + EXPECT_EQ(ret, 0); + EXPECT_EQ(0, ptrace(PTRACE_PEEKDATA, child, (void *)gcspr, NULL)); + + /* Restore what we had before */ + ret = ptrace(PTRACE_POKEDATA, child, (void *)gcspr, val); + if (ret == -1) + ksft_print_msg("PTRACE_POKEDATA failed: %s (%d)\n", + strerror(errno), errno); + EXPECT_EQ(ret, 0); + EXPECT_EQ(val, ptrace(PTRACE_PEEKDATA, child, (void *)gcspr, NULL)); + + /* That's all, folks */ + kill(child, SIGKILL); + return; + +error: + kill(child, SIGKILL); + ASSERT_FALSE(true); +} + +FIXTURE(map_gcs) +{ + unsigned long *stack; +}; + +FIXTURE_VARIANT(map_gcs) +{ + size_t stack_size; + unsigned long flags; +}; + +FIXTURE_VARIANT_ADD(map_gcs, s2k_cap_marker) +{ + .stack_size = 2 * 1024, + .flags = SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s2k_cap) +{ + .stack_size = 2 * 1024, + .flags = SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s2k_marker) +{ + .stack_size = 2 * 1024, + .flags = SHADOW_STACK_SET_MARKER, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s2k) +{ + .stack_size = 2 * 1024, + .flags = 0, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s4k_cap_marker) +{ + .stack_size = 4 * 1024, + .flags = SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s4k_cap) +{ + .stack_size = 4 * 1024, + .flags = SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s3k_marker) +{ + .stack_size = 4 * 1024, + .flags = SHADOW_STACK_SET_MARKER, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s4k) +{ + .stack_size = 4 * 1024, + .flags = 0, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s16k_cap_marker) +{ + .stack_size = 16 * 1024, + .flags = SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s16k_cap) +{ + .stack_size = 16 * 1024, + .flags = SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s16k_marker) +{ + .stack_size = 16 * 1024, + .flags = SHADOW_STACK_SET_MARKER, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s16k) +{ + .stack_size = 16 * 1024, + .flags = 0, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s64k_cap_marker) +{ + .stack_size = 64 * 1024, + .flags = SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s64k_cap) +{ + .stack_size = 64 * 1024, + .flags = SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s64k_marker) +{ + .stack_size = 64 * 1024, + .flags = SHADOW_STACK_SET_MARKER, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s64k) +{ + .stack_size = 64 * 1024, + .flags = 0, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s128k_cap_marker) +{ + .stack_size = 128 * 1024, + .flags = SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s128k_cap) +{ + .stack_size = 128 * 1024, + .flags = SHADOW_STACK_SET_TOKEN, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s128k_marker) +{ + .stack_size = 128 * 1024, + .flags = SHADOW_STACK_SET_MARKER, +}; + +FIXTURE_VARIANT_ADD(map_gcs, s128k) +{ + .stack_size = 128 * 1024, + .flags = 0, +}; + +FIXTURE_SETUP(map_gcs) +{ + self->stack = (void *)syscall(__NR_map_shadow_stack, 0, + variant->stack_size, + variant->flags); + ASSERT_FALSE(self->stack == MAP_FAILED); + ksft_print_msg("Allocated stack from %p-%p\n", self->stack, + (unsigned long)self->stack + variant->stack_size); +} + +FIXTURE_TEARDOWN(map_gcs) +{ + int ret; + + if (self->stack != MAP_FAILED) { + ret = munmap(self->stack, variant->stack_size); + ASSERT_EQ(ret, 0); + } +} + +/* The stack has a cap token */ +TEST_F(map_gcs, stack_capped) +{ + unsigned long *stack = self->stack; + size_t cap_index; + + cap_index = (variant->stack_size / sizeof(unsigned long)); + + switch (variant->flags & (SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN)) { + case SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN: + cap_index -= 2; + break; + case SHADOW_STACK_SET_TOKEN: + cap_index -= 1; + break; + case SHADOW_STACK_SET_MARKER: + case 0: + /* No cap, no test */ + return; + } + + ASSERT_EQ(stack[cap_index], GCS_CAP(&stack[cap_index])); +} + +/* The top of the stack is 0 */ +TEST_F(map_gcs, stack_terminated) +{ + unsigned long *stack = self->stack; + size_t term_index; + + if (!(variant->flags & SHADOW_STACK_SET_MARKER)) + return; + + term_index = (variant->stack_size / sizeof(unsigned long)) - 1; + + ASSERT_EQ(stack[term_index], 0); +} + +/* Writes should fault */ +TEST_F_SIGNAL(map_gcs, not_writeable, SIGSEGV) +{ + self->stack[0] = 0; +} + +/* Put it all together, we can safely switch to and from the stack */ +TEST_F(map_gcs, stack_switch) +{ + size_t cap_index; + cap_index = (variant->stack_size / sizeof(unsigned long)); + unsigned long *orig_gcspr_el0, *pivot_gcspr_el0; + + /* Skip over the stack terminator and point at the cap */ + switch (variant->flags & (SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN)) { + case SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN: + cap_index -= 2; + break; + case SHADOW_STACK_SET_TOKEN: + cap_index -= 1; + break; + case SHADOW_STACK_SET_MARKER: + case 0: + /* No cap, no test */ + return; + } + pivot_gcspr_el0 = &self->stack[cap_index]; + + /* Pivot to the new GCS */ + ksft_print_msg("Pivoting to %p from %p, target has value 0x%lx\n", + pivot_gcspr_el0, get_gcspr(), + *pivot_gcspr_el0); + gcsss1(pivot_gcspr_el0); + orig_gcspr_el0 = gcsss2(); + ksft_print_msg("Pivoted to %p from %p, target has value 0x%lx\n", + get_gcspr(), orig_gcspr_el0, + *pivot_gcspr_el0); + + ksft_print_msg("Pivoted, GCSPR_EL0 now %p\n", get_gcspr()); + + /* New GCS must be in the new buffer */ + ASSERT_TRUE((unsigned long)get_gcspr() > (unsigned long)self->stack); + ASSERT_TRUE((unsigned long)get_gcspr() <= + (unsigned long)self->stack + variant->stack_size); + + /* We should be able to use all but 2 slots of the new stack */ + ksft_print_msg("Recursing %d levels\n", cap_index - 1); + gcs_recurse(cap_index - 1); + + /* Pivot back to the original GCS */ + gcsss1(orig_gcspr_el0); + pivot_gcspr_el0 = gcsss2(); + + gcs_recurse(0); + ksft_print_msg("Pivoted back to GCSPR_EL0 0x%lx\n", get_gcspr()); +} + +/* We fault if we try to go beyond the end of the stack */ +TEST_F_SIGNAL(map_gcs, stack_overflow, SIGSEGV) +{ + size_t cap_index; + cap_index = (variant->stack_size / sizeof(unsigned long)); + unsigned long *orig_gcspr_el0, *pivot_gcspr_el0; + + /* Skip over the stack terminator and point at the cap */ + switch (variant->flags & (SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN)) { + case SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN: + cap_index -= 2; + break; + case SHADOW_STACK_SET_TOKEN: + cap_index -= 1; + break; + case SHADOW_STACK_SET_MARKER: + case 0: + /* No cap, no test but we need to SEGV to avoid a false fail */ + orig_gcspr_el0 = get_gcspr(); + *orig_gcspr_el0 = 0; + return; + } + pivot_gcspr_el0 = &self->stack[cap_index]; + + /* Pivot to the new GCS */ + ksft_print_msg("Pivoting to %p from %p, target has value 0x%lx\n", + pivot_gcspr_el0, get_gcspr(), + *pivot_gcspr_el0); + gcsss1(pivot_gcspr_el0); + orig_gcspr_el0 = gcsss2(); + ksft_print_msg("Pivoted to %p from %p, target has value 0x%lx\n", + pivot_gcspr_el0, orig_gcspr_el0, + *pivot_gcspr_el0); + + ksft_print_msg("Pivoted, GCSPR_EL0 now %p\n", get_gcspr()); + + /* New GCS must be in the new buffer */ + ASSERT_TRUE((unsigned long)get_gcspr() > (unsigned long)self->stack); + ASSERT_TRUE((unsigned long)get_gcspr() <= + (unsigned long)self->stack + variant->stack_size); + + /* Now try to recurse, we should fault doing this. */ + ksft_print_msg("Recursing %d levels...\n", cap_index + 1); + gcs_recurse(cap_index + 1); + ksft_print_msg("...done\n"); + + /* Clean up properly to try to guard against spurious passes. */ + gcsss1(orig_gcspr_el0); + pivot_gcspr_el0 = gcsss2(); + ksft_print_msg("Pivoted back to GCSPR_EL0 0x%lx\n", get_gcspr()); +} + +FIXTURE(map_invalid_gcs) +{ +}; + +FIXTURE_VARIANT(map_invalid_gcs) +{ + size_t stack_size; +}; + +FIXTURE_SETUP(map_invalid_gcs) +{ +} + +FIXTURE_TEARDOWN(map_invalid_gcs) +{ +} + +/* GCS must be larger than 16 bytes */ +FIXTURE_VARIANT_ADD(map_invalid_gcs, too_small) +{ + .stack_size = 8, +}; + +/* GCS size must be 16 byte aligned */ +FIXTURE_VARIANT_ADD(map_invalid_gcs, unligned_1) { .stack_size = 1024 + 1 }; +FIXTURE_VARIANT_ADD(map_invalid_gcs, unligned_2) { .stack_size = 1024 + 2 }; +FIXTURE_VARIANT_ADD(map_invalid_gcs, unligned_3) { .stack_size = 1024 + 3 }; +FIXTURE_VARIANT_ADD(map_invalid_gcs, unligned_4) { .stack_size = 1024 + 4 }; +FIXTURE_VARIANT_ADD(map_invalid_gcs, unligned_5) { .stack_size = 1024 + 5 }; +FIXTURE_VARIANT_ADD(map_invalid_gcs, unligned_6) { .stack_size = 1024 + 6 }; +FIXTURE_VARIANT_ADD(map_invalid_gcs, unligned_7) { .stack_size = 1024 + 7 }; + +TEST_F(map_invalid_gcs, do_map) +{ + void *stack; + + stack = (void *)syscall(__NR_map_shadow_stack, 0, + variant->stack_size, 0); + ASSERT_TRUE(stack == MAP_FAILED); + if (stack != MAP_FAILED) + munmap(stack, variant->stack_size); +} + +FIXTURE(invalid_mprotect) +{ + unsigned long *stack; + size_t stack_size; +}; + +FIXTURE_VARIANT(invalid_mprotect) +{ + unsigned long flags; +}; + +FIXTURE_SETUP(invalid_mprotect) +{ + self->stack_size = sysconf(_SC_PAGE_SIZE); + self->stack = (void *)syscall(__NR_map_shadow_stack, 0, + self->stack_size, 0); + ASSERT_FALSE(self->stack == MAP_FAILED); + ksft_print_msg("Allocated stack from %p-%p\n", self->stack, + (unsigned long)self->stack + self->stack_size); +} + +FIXTURE_TEARDOWN(invalid_mprotect) +{ + int ret; + + if (self->stack != MAP_FAILED) { + ret = munmap(self->stack, self->stack_size); + ASSERT_EQ(ret, 0); + } +} + +FIXTURE_VARIANT_ADD(invalid_mprotect, exec) +{ + .flags = PROT_EXEC, +}; + +FIXTURE_VARIANT_ADD(invalid_mprotect, bti) +{ + .flags = PROT_BTI, +}; + +FIXTURE_VARIANT_ADD(invalid_mprotect, exec_bti) +{ + .flags = PROT_EXEC | PROT_BTI, +}; + +TEST_F(invalid_mprotect, do_map) +{ + int ret; + + ret = mprotect(self->stack, self->stack_size, variant->flags); + ASSERT_EQ(ret, -1); +} + +TEST_F(invalid_mprotect, do_map_read) +{ + int ret; + + ret = mprotect(self->stack, self->stack_size, + variant->flags | PROT_READ); + ASSERT_EQ(ret, -1); +} + +int main(int argc, char **argv) +{ + unsigned long gcs_mode; + int ret; + + if (!(getauxval(AT_HWCAP2) & HWCAP2_GCS)) + ksft_exit_skip("SKIP GCS not supported\n"); + + /* + * Force shadow stacks on, our tests *should* be fine with or + * without libc support and with or without this having ended + * up tagged for GCS and enabled by the dynamic linker. We + * can't use the libc prctl() function since we can't return + * from enabling the stack. + */ + ret = my_syscall2(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &gcs_mode); + if (ret) { + ksft_print_msg("Failed to read GCS state: %d\n", ret); + return EXIT_FAILURE; + } + + if (!(gcs_mode & PR_SHADOW_STACK_ENABLE)) { + gcs_mode = PR_SHADOW_STACK_ENABLE; + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + gcs_mode); + if (ret) { + ksft_print_msg("Failed to configure GCS: %d\n", ret); + return EXIT_FAILURE; + } + } + + /* Avoid returning in case libc doesn't understand GCS */ + exit(test_harness_run(argc, argv)); +} From patchwork Thu Aug 1 12:07:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750416 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 F10C1C3DA64 for ; Thu, 1 Aug 2024 13:01:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F116E6B00D5; Thu, 1 Aug 2024 09:01:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E997E6B00D7; Thu, 1 Aug 2024 09:01:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3A746B00D8; Thu, 1 Aug 2024 09:01:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B009B6B00D5 for ; Thu, 1 Aug 2024 09:01:37 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 48BE2A7796 for ; Thu, 1 Aug 2024 13:01:37 +0000 (UTC) X-FDA: 82403688234.28.64078CC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 08EBF40043 for ; Thu, 1 Aug 2024 13:01:34 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TRZMtadn; spf=pass (imf11.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=1722517289; 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=qeTei2+Rv9TmGzFj/jgAMv84+i3cbC0I/TqETm/VMk4=; b=KkEkDkri0bO70mdGX9dZRnmVQuI77dzdQdtc0ZdcvJZVnqWypprVlsYGBLRE8Nj9AO5xw+ z4ru0CIYoI6mglL1CODvSO6LYCkD+GiPXbANWjZinGBSfpbgjtHDMvlcve4odf12zqZjNI q4iluQZ2Hr1AaCaSg1CF/iFTd4EqUI8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TRZMtadn; spf=pass (imf11.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=1722517289; a=rsa-sha256; cv=none; b=WagTcOswu7WeSDtXDTVltmIA+8Ni9NwUEU4X3jsKMWo/WYQGGea1UzMkGoem3/s69RD889 d8qsvLVVGCbTFIEFBG/dlCRoY3ehxZ45+YyowQm0WLY60xAChJ0uVIiaOXRDp2qHhdNhOB xkuyLx95t18D3WxPtSV/ozSLidvTSKY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 09CC162862; Thu, 1 Aug 2024 13:01:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D11CC4AF16; Thu, 1 Aug 2024 13:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517293; bh=/b4fLgBxrOG/LTGvqBDUXcUFQWiOWxSYArOHQoaOV+E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TRZMtadndFAu91GtDPbe4hs8r0BhRJ1xXnKfpX3TNlmP1OMNvhjnmqGpuLOFiIt0l YioayN2cPoiE12vzJ4GIZptBIWXuUff6UPAGEgtxd/IjWbfGsO7Pe+wwwPapXqm1Cw HVycdeBhdDef4rT52xtGIoPQ5mFaXUx4/+P8cEPSDDuNGxUWupMpRH6k//MhDhBi7Z u7itQgCkCvyhxoNX+k4lqz2kzvwB0L8gIpzGeSQfdh5kJCcBLJQTAl37PzbYZQfU4e iSZFYDMyt/78oQeZNzVdEq38vY0d1XJvOg8GKVlCMnDuyuDG/cB+BhJgAolgbFWBiM AJPAQqcjwU7zA== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:03 +0100 Subject: [PATCH v10 36/40] kselftest/arm64: Add test coverage for GCS mode locking MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-36-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=7382; i=broonie@kernel.org; h=from:subject:message-id; bh=/b4fLgBxrOG/LTGvqBDUXcUFQWiOWxSYArOHQoaOV+E=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YhfQLguYdwaf40RAFxGT++va2Yk/g2Je2Nj4M2 0FHHERGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGIQAKCRAk1otyXVSH0MSKB/ wIa+YZJDrdKEOJe1WZdjPgO+Y9XcfDcFjbwA1+VQm6G4V9R8aHmjbirJvqlNfwvNnFSBMsL4Uqywax /OLM9xW7BnMyPQ37h1Fhytv/+jQHhcFiB2XWre9jBJhVora2g7H9HC03qHhfVWF5YhhUEw130IT14w TKbmOsVuQvaEVsmNLQwaz7Op1S60YopvZIOul7P+Uh+jvyB22NfyEXWT4pFiNqEAWrXoUbXo8BZQai /p1D2+A8dWPJSbiMnF9HAbNSQWFHFnnxUpNOGc8L/4C489WMgcSIPGoO/6GSeqZ6uZjZYu8KdXvQvc C3Mf3nJVFT5d/AabfAWFXNhOnapFmS X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Stat-Signature: uuo47iws7u8ocxzq9hp5gy1ofrjikxoh X-Rspamd-Queue-Id: 08EBF40043 X-Rspamd-Server: rspam11 X-HE-Tag: 1722517294-201460 X-HE-Meta: U2FsdGVkX19w/+eXno1REkehJ2fl8UvtCdKRdhEoHaDVpYjHGb0mL/3wZBHmY6u39BqKxFYZXkHGxnhc2FEBJPxy1JtfEBQR+hJoCX+mcJrbx8pEkDy30RnLi4FfWqch3Ccid8eYCqmcfDQGGCABP1BxioHlbhc2HpEdhDY3tO2gwnFaGg5cqnJ6Xl3NEFWwH4zTPbYG8Yk5uCSTrTs+idWs0a6p9UlZ8bHQMcVuksmFDCATPz/4dwL168K7Sf8Z9kuaBhwsGVdwLsqgRiLaHJKFiqnDCc+hnk6J+bBOT5ChPxNwZniH86RnMO5BMhNSkQGDasTcr6Sc8LrefRB+tQSj7a4WjnuHf4FayBmc09etvNCnVk27Pm5scRcmQTZpS4W1OwAKBg4nuL8fQdPfOVFhlbzJ5DHOt2JM5GnvIG07g/kfpyEnEfJcGcojFPZC5+AvS59YydVbhQiNIQYRBdbrG/9K7Dc0M/AuNPo2luKE53GZaxy3qZGGfCFksPlOHVah+DxGs/GUyXO4Rj1hDs4CbZ54Ojp/TEFEjx+t/FQzSlwRw4IkVH+3NwvQTwrDDpCqOAV4dVq+bBR4U9xfnk2cwB3Yq5yFGnIkoCMnF1v2CAhBD5QtndgdXfF8766KHE9Ts/0ZYp14j7V1iqDcGlxZL8Z5YdvlqBPIDCMQw6OL7eQJYUqzmCn5KVPRsJIh18QAYsdZhbQHfKVVRhLrr6EwqUXL2xLoyoDxFLNl0UiroTTkSA9EI8r3gOtJcCixu+3VXbIG/vG1iYlQnZipSEb19JNGtiTKs/jey6sW7ZFlcgvtWsaugaCYimyWLe8Wysg8CU9aVYL7HVP23cZ5Z+iq/4THQw8f9T/CWIBk+M4oTMnvOZfoNYGDtmaJ/Jl035faotGmnJg0WiOATSSWK6k12dDHNmWPrier1IubtqPxWopGDOyCQTa328eNoTVk/m2/hudM5E6gU5DLD/g a9lF65fx SOL8HWuDdG23om1WxWh5eLOeHZlS9SR899sCkWLu2rOk/wODuyqgWONY9CuMQFXzZbisxM/RcfIlnEMN77NJ2ZF4PHIpCHqeYIDhYh37P37aIxljkbJVJCbZLdeq7gbRmK5k0XzInFHXHasKVqRXNg+R5iisJ/eArxSxASultlPycUqo6psG1IktlMrxBSsubLXZ2CPEYfHn/tNlS7HplxMvlgaEN5rFYJ5PD6FLKqDcSxW+hGyNhImpnGmIQ7mHyuU50pZou/Dy6hwxGbeatsRy2AVtOMqTOJ5t4DhU9HlZmRx2scDoQzSXJjIlpXZVO47X+8tuOl5jo4NGonrgLgx7MSEH515iSZtyUELXuhR6uOF/jmWtXfG8fLK8IKs06g1sW 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: Verify that we can lock individual GCS mode bits, that other modes aren't affected and as a side effect also that every combination of modes can be enabled. Normally the inability to reenable GCS after disabling it would be an issue with testing but fortunately the kselftest_harness runs each test within a fork()ed child. This can be inconvenient for some kinds of testing but here it means that each test is in a separate thread and therefore won't be affected by other tests in the suite. Once we get toolchains with support for enabling GCS by default we will need to take care to not do that in the build system but there are no such toolchains yet so it is not yet an issue. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/gcs/.gitignore | 1 + tools/testing/selftests/arm64/gcs/Makefile | 2 +- tools/testing/selftests/arm64/gcs/gcs-locking.c | 200 ++++++++++++++++++++++++ 3 files changed, 202 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/gcs/.gitignore b/tools/testing/selftests/arm64/gcs/.gitignore index 5810c4a163d4..0c86f53f68ad 100644 --- a/tools/testing/selftests/arm64/gcs/.gitignore +++ b/tools/testing/selftests/arm64/gcs/.gitignore @@ -1,2 +1,3 @@ basic-gcs libc-gcs +gcs-locking diff --git a/tools/testing/selftests/arm64/gcs/Makefile b/tools/testing/selftests/arm64/gcs/Makefile index a8fdf21e9a47..2173d6275956 100644 --- a/tools/testing/selftests/arm64/gcs/Makefile +++ b/tools/testing/selftests/arm64/gcs/Makefile @@ -6,7 +6,7 @@ # nolibc. # -TEST_GEN_PROGS := basic-gcs libc-gcs +TEST_GEN_PROGS := basic-gcs libc-gcs gcs-locking LDLIBS+=-lpthread diff --git a/tools/testing/selftests/arm64/gcs/gcs-locking.c b/tools/testing/selftests/arm64/gcs/gcs-locking.c new file mode 100644 index 000000000000..f6a73254317e --- /dev/null +++ b/tools/testing/selftests/arm64/gcs/gcs-locking.c @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 ARM Limited. + * + * Tests for GCS mode locking. These tests rely on both having GCS + * unconfigured on entry and on the kselftest harness running each + * test in a fork()ed process which will have it's own mode. + */ + +#include + +#include +#include + +#include + +#include "kselftest_harness.h" + +#include "gcs-util.h" + +#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; \ +}) + +/* No mode bits are rejected for locking */ +TEST(lock_all_modes) +{ + int ret; + + ret = prctl(PR_LOCK_SHADOW_STACK_STATUS, ULONG_MAX, 0, 0, 0); + ASSERT_EQ(ret, 0); +} + +FIXTURE(valid_modes) +{ +}; + +FIXTURE_VARIANT(valid_modes) +{ + unsigned long mode; +}; + +FIXTURE_VARIANT_ADD(valid_modes, enable) +{ + .mode = PR_SHADOW_STACK_ENABLE, +}; + +FIXTURE_VARIANT_ADD(valid_modes, enable_write) +{ + .mode = PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_WRITE, +}; + +FIXTURE_VARIANT_ADD(valid_modes, enable_push) +{ + .mode = PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_PUSH, +}; + +FIXTURE_VARIANT_ADD(valid_modes, enable_write_push) +{ + .mode = PR_SHADOW_STACK_ENABLE | PR_SHADOW_STACK_WRITE | + PR_SHADOW_STACK_PUSH, +}; + +FIXTURE_SETUP(valid_modes) +{ +} + +FIXTURE_TEARDOWN(valid_modes) +{ +} + +/* We can set the mode at all */ +TEST_F(valid_modes, set) +{ + int ret; + + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + variant->mode); + ASSERT_EQ(ret, 0); + + _exit(0); +} + +/* Enabling, locking then disabling is rejected */ +TEST_F(valid_modes, enable_lock_disable) +{ + unsigned long mode; + int ret; + + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + variant->mode); + ASSERT_EQ(ret, 0); + + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &mode, 0, 0, 0); + ASSERT_EQ(ret, 0); + ASSERT_EQ(mode, variant->mode); + + ret = prctl(PR_LOCK_SHADOW_STACK_STATUS, variant->mode, 0, 0, 0); + ASSERT_EQ(ret, 0); + + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, 0); + ASSERT_EQ(ret, -EBUSY); + + _exit(0); +} + +/* Locking then enabling is rejected */ +TEST_F(valid_modes, lock_enable) +{ + unsigned long mode; + int ret; + + ret = prctl(PR_LOCK_SHADOW_STACK_STATUS, variant->mode, 0, 0, 0); + ASSERT_EQ(ret, 0); + + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + variant->mode); + ASSERT_EQ(ret, -EBUSY); + + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &mode, 0, 0, 0); + ASSERT_EQ(ret, 0); + ASSERT_EQ(mode, 0); + + _exit(0); +} + +/* Locking then changing other modes is fine */ +TEST_F(valid_modes, lock_enable_disable_others) +{ + unsigned long mode; + int ret; + + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + variant->mode); + ASSERT_EQ(ret, 0); + + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &mode, 0, 0, 0); + ASSERT_EQ(ret, 0); + ASSERT_EQ(mode, variant->mode); + + ret = prctl(PR_LOCK_SHADOW_STACK_STATUS, variant->mode, 0, 0, 0); + ASSERT_EQ(ret, 0); + + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + PR_SHADOW_STACK_ALL_MODES); + ASSERT_EQ(ret, 0); + + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &mode, 0, 0, 0); + ASSERT_EQ(ret, 0); + ASSERT_EQ(mode, PR_SHADOW_STACK_ALL_MODES); + + + ret = my_syscall2(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, + variant->mode); + ASSERT_EQ(ret, 0); + + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &mode, 0, 0, 0); + ASSERT_EQ(ret, 0); + ASSERT_EQ(mode, variant->mode); + + _exit(0); +} + +int main(int argc, char **argv) +{ + unsigned long mode; + int ret; + + if (!(getauxval(AT_HWCAP2) & HWCAP2_GCS)) + ksft_exit_skip("SKIP GCS not supported\n"); + + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &mode, 0, 0, 0); + if (ret) { + ksft_print_msg("Failed to read GCS state: %d\n", ret); + return EXIT_FAILURE; + } + + if (mode & PR_SHADOW_STACK_ENABLE) { + ksft_print_msg("GCS was enabled, test unsupported\n"); + return KSFT_SKIP; + } + + return test_harness_run(argc, argv); +} From patchwork Thu Aug 1 12:07: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: 13750417 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 8514AC3DA64 for ; Thu, 1 Aug 2024 13:01:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A1D76B00D7; Thu, 1 Aug 2024 09:01:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32AC36B00D9; Thu, 1 Aug 2024 09:01:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A3556B00DA; Thu, 1 Aug 2024 09:01:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E49136B00D7 for ; Thu, 1 Aug 2024 09:01:45 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3A5AE140D4C for ; Thu, 1 Aug 2024 13:01:45 +0000 (UTC) X-FDA: 82403688570.06.18E488D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id DAE3E14003D for ; Thu, 1 Aug 2024 13:01:41 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QeLlBHsh; spf=pass (imf23.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=1722517257; 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=gBkkGTg9iwkURdLLuf+UpkR7ejhULQidz4/W46P4K/c=; b=SsitSb+ynu77Kvk7yMq1Dm/8G2xfaS2M3p0XxQ9OnjQXw4xo/iw0Z9N/bh1Y9zsrpFsU+E zGeE58exomim0z60dMy+toUsXsFapNZX0AQGqrxjy9V8/iUr1wfh1kQKtH/u7vHTNkO8nA lMyo+k/ARVJMLVsaEVTXDziP0NujbLk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QeLlBHsh; spf=pass (imf23.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=1722517257; a=rsa-sha256; cv=none; b=SRNU+UlmQRpkqt1s+Rw5cT5NCMk664E252PiDj03yBZytl1y3LRdDTusPcj10JfKcbbyv6 2kaPuIUgShAwCnLlKo1TGAxkjrEbrJx4vEpSxiJlo65JjuvbenC1wrbxqRgKv/5ZEMgtnA v51c/LokMn1BgR0/JAiV9vLarlO9hZM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D709262864; Thu, 1 Aug 2024 13:01:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28AD9C4AF0F; Thu, 1 Aug 2024 13:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517300; bh=6kf8vUeE2/3/9q62BhJqQa6tQ8qTDalv3nPeOQkuUQk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QeLlBHshq5P3qUUyfk8CRsRNpyqn0q57xNSDHPTQ6q1hGzJWNs7qGlaOJIGObFmE+ +K7CJRAveGuipAwXMwq5q9D8OTdH+cPigG3T08ObXRZTQed2/245kPDwVGxjlfU372 U6lz/IxwXQuNFMD41f8cTskuzUxtBh4ekcSGDr8Jlns1YvB+6SFED8gkTLAiZcnTrn LuJQ9+urmKyxyHj5P3x+s/TaASKq6bDfBdnLZzBjGtM9XuHa2bhbrUEN9xmS8k3GKd oOV40cTBc967x5JL8iSK1RpHh3zhNfJksh6haNjSxsR3JLWpGbQkXVyzSTeJKcJdtY pqLjCVcN/gdgA== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:04 +0100 Subject: [PATCH v10 37/40] kselftest/arm64: Add GCS signal tests MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-37-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=7642; i=broonie@kernel.org; h=from:subject:message-id; bh=6kf8vUeE2/3/9q62BhJqQa6tQ8qTDalv3nPeOQkuUQk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YiilzosoycWemp86oXN2aAuvoGrtbZAHaiddpG iIMJiUGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGIgAKCRAk1otyXVSH0DZUB/ 0TviaWwxSqh8BYp1zmU3cW61qEV3ideNIDwUSV+cLGZ+YR5Qzcp9E26Z7asPuhrUPHthXHL707fs8D VjVJzMku6aMeNJYxh360l8WTipPLqNFZ+UJ0cU9fbdPhbo8IyITKMmqn+EZIuFfLEMgfVjraFT5ggf fGE/19A+C75FGjCKT66LLzTU9WERRUohuNmyY95fidM8uuYcZdlP8IebAYK63KxpNM0gUmi8/MVQuZ YVKh30mJt7L+oZQA1xXtHAez0wx8f3oBLc9GWjftEtdDAayngF6ZffIKlEiNHKxXQQevQqnBwDBZ6x sLbAlttxAm9Ek0MvtSwXEYqHV01QSq X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: axih8e6rk7uuzeexertims5c97ct5mbk X-Rspam-User: X-Rspamd-Queue-Id: DAE3E14003D X-Rspamd-Server: rspam02 X-HE-Tag: 1722517301-85727 X-HE-Meta: U2FsdGVkX18CwB+ojyi/ZHUH4XeUxPIT85DA1Wjq3apM4py1bctc2E7SLIrQADv4935/koXDu7Sb4X2Qa/HuO+OFEV1iu+9hz7m8IhA31Ic4t9TUtNbFqj16wUR+fxfr9P7LSpyafJTutqXxPQUbpJxQXyagWT+Dkl+/7uoJyNUgH3eusDlD/hBz2yg1KM5vDoRXWSg8EAgco2lEGwoAJ36x9uC05lygtw1zI73NG691+8BqM0mJRkBqgOEOqoHVJHayaenXd/byeAo8QG0tfroCvD1/UwwYAkMYYW5KTzICSBsHFivxVsHXsYnaw763shY787GgDZnWQjuO7krM/ByruhAxDtl7M05FfFfPIYUiUwBLGbCEtQKYFp40tsw+0IMXLnKdNucvUPscx9MUltl4r3A3wR7KI0I4ij1BH+X+y56jFPIYEa6tbuEDN+ScEDk9mmk8u+HGrCKMje+PyhfVADA15UcBWedSQRuDub+Gf4+5stmelZko1fab2UK1M8Uo9U1O8S4bAKiK+3g2Fczu4rjykAEhUVWxVMTPRgozC+dfwh7qpSuum4q7NhiwWJMC6UBb2BfCpkyZAVf0mPvwG1ZXbf1aAHYO2+/EvP2WhMHpzrOl+bj+jp2i1UKJoggzKWXx+j4pXjxnkzVk69QoeRS2Qun+s7NlbtlsWcuzVxKShArt+a7nI2XWYzxA/afZeXW0siwpPjDy5kIesY8qp4MhVDNUfbW2LqCq+SaYS8R73VD0Fsg9BsyxYWbew1OMhrLYyrz77a2V5nT5Ckwdtg9FCODmz6NcJTq2g+V/IgwgNH0mql6kTRZax7F24mdUgbw6aPmVSM5Rqv0i9oUYfMryTctFIt7IcNso4+cQVHrb+sBCq7e7cte4pUCTvEWCvH/r0/34uSKmtJdMzlWwmM7kXamvohuRBSt2gCLZqjvyFSe1WxvpXxopQj7ubi9ygdpiuo+M75A/nJd ro5rdICb ZqbCGIX/Tzk3xrr5RS+ePHHJYSJVNxo7/WZ7Bsmpk+SSA8GD+7zeHR5KVVDHL9+fUhf7rf2BVFnv2Wg4F4fKMlFdoJTJVtm6k2T3Omc98VULlC4ZTTv4znnnZ+fU7kBFWSLT+2JVeAMmfHMzSofK1zBvrtfDm0GDtBcvcAovJsm8q2xWouKV2YPI+CoffK/Q8BuL3jl1Eycg+JYC0epFU764DYSXb3r27pHBgDeWrOdP4k+ai7XNlGcDp80ORS1+dSML4rCjx+P4b4kAQmtxFqP96DigdbnzXyT4GVCGXpVbENfjqOFxynB8KPA7t+kFCZBNzZp5uBZxHXNK+UVZHQmB9FwdMZ6SEpwW8SUR6fZ8r004YzBRevI5PATFyJh1ZMt0Q 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: Do some testing of the signal handling for GCS, checking that a GCS frame has the expected information in it and that the expected signals are delivered with invalid operations. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/.gitignore | 1 + .../selftests/arm64/signal/test_signals_utils.h | 10 +++ .../arm64/signal/testcases/gcs_exception_fault.c | 62 +++++++++++++++ .../selftests/arm64/signal/testcases/gcs_frame.c | 88 ++++++++++++++++++++++ .../arm64/signal/testcases/gcs_write_fault.c | 67 ++++++++++++++++ 5 files changed, 228 insertions(+) diff --git a/tools/testing/selftests/arm64/signal/.gitignore b/tools/testing/selftests/arm64/signal/.gitignore index 1ce5b5eac386..75d691c13207 100644 --- a/tools/testing/selftests/arm64/signal/.gitignore +++ b/tools/testing/selftests/arm64/signal/.gitignore @@ -2,6 +2,7 @@ mangle_* fake_sigreturn_* fpmr_* +gcs_* sme_* ssve_* sve_* diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/tools/testing/selftests/arm64/signal/test_signals_utils.h index 1e80808ee105..36fc12b3cd60 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.h +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -47,6 +48,15 @@ void test_result(struct tdescr *td); _arg1; \ }) +static inline __attribute__((always_inline)) uint64_t get_gcspr_el0(void) +{ + uint64_t val; + + asm volatile("mrs %0, S3_3_C2_C5_1" : "=r" (val)); + + return val; +} + static inline bool feats_ok(struct tdescr *td) { if (td->feats_incompatible & td->feats_supported) diff --git a/tools/testing/selftests/arm64/signal/testcases/gcs_exception_fault.c b/tools/testing/selftests/arm64/signal/testcases/gcs_exception_fault.c new file mode 100644 index 000000000000..6228448b2ae7 --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/gcs_exception_fault.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 ARM Limited + */ + +#include +#include +#include + +#include +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +/* + * We should get this from asm/siginfo.h but the testsuite is being + * clever with redefining siginfo_t. + */ +#ifndef SEGV_CPERR +#define SEGV_CPERR 10 +#endif + +static inline void gcsss1(uint64_t Xt) +{ + asm volatile ( + "sys #3, C7, C7, #2, %0\n" + : + : "rZ" (Xt) + : "memory"); +} + +static int gcs_op_fault_trigger(struct tdescr *td) +{ + /* + * The slot below our current GCS should be in a valid GCS but + * must not have a valid cap in it. + */ + gcsss1(get_gcspr_el0() - 8); + + return 0; +} + +static int gcs_op_fault_signal(struct tdescr *td, siginfo_t *si, + ucontext_t *uc) +{ + ASSERT_GOOD_CONTEXT(uc); + + return 1; +} + +struct tdescr tde = { + .name = "Invalid GCS operation", + .descr = "An invalid GCS operation generates the expected signal", + .feats_required = FEAT_GCS, + .timeout = 3, + .sig_ok = SIGSEGV, + .sig_ok_code = SEGV_CPERR, + .sanity_disabled = true, + .trigger = gcs_op_fault_trigger, + .run = gcs_op_fault_signal, +}; diff --git a/tools/testing/selftests/arm64/signal/testcases/gcs_frame.c b/tools/testing/selftests/arm64/signal/testcases/gcs_frame.c new file mode 100644 index 000000000000..b405d82321da --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/gcs_frame.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 ARM Limited + */ + +#include +#include +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +static union { + ucontext_t uc; + char buf[1024 * 64]; +} context; + +static int gcs_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc) +{ + size_t offset; + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); + struct gcs_context *gcs; + unsigned long expected, gcspr; + uint64_t *u64_val; + int ret; + + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &expected, 0, 0, 0); + if (ret != 0) { + fprintf(stderr, "Unable to query GCS status\n"); + return 1; + } + + /* We expect a cap to be added to the GCS in the signal frame */ + gcspr = get_gcspr_el0(); + gcspr -= 8; + fprintf(stderr, "Expecting GCSPR_EL0 %lx\n", gcspr); + + if (!get_current_context(td, &context.uc, sizeof(context))) { + fprintf(stderr, "Failed getting context\n"); + return 1; + } + + /* Ensure that the signal restore token was consumed */ + u64_val = (uint64_t *)get_gcspr_el0() + 1; + if (*u64_val) { + fprintf(stderr, "GCS value at %p is %lx not 0\n", + u64_val, *u64_val); + return 1; + } + + fprintf(stderr, "Got context\n"); + + head = get_header(head, GCS_MAGIC, GET_BUF_RESV_SIZE(context), + &offset); + if (!head) { + fprintf(stderr, "No GCS context\n"); + return 1; + } + + gcs = (struct gcs_context *)head; + + /* Basic size validation is done in get_current_context() */ + + if (gcs->features_enabled != expected) { + fprintf(stderr, "Features enabled %llx but expected %lx\n", + gcs->features_enabled, expected); + return 1; + } + + if (gcs->gcspr != gcspr) { + fprintf(stderr, "Got GCSPR %llx but expected %lx\n", + gcs->gcspr, gcspr); + return 1; + } + + fprintf(stderr, "GCS context validated\n"); + td->pass = 1; + + return 0; +} + +struct tdescr tde = { + .name = "GCS basics", + .descr = "Validate a GCS signal context", + .feats_required = FEAT_GCS, + .timeout = 3, + .run = gcs_regs, +}; diff --git a/tools/testing/selftests/arm64/signal/testcases/gcs_write_fault.c b/tools/testing/selftests/arm64/signal/testcases/gcs_write_fault.c new file mode 100644 index 000000000000..faeabb18c4b2 --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/gcs_write_fault.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 ARM Limited + */ + +#include +#include +#include + +#include +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +static uint64_t *gcs_page; + +#ifndef __NR_map_shadow_stack +#define __NR_map_shadow_stack 453 +#endif + +static bool alloc_gcs(struct tdescr *td) +{ + long page_size = sysconf(_SC_PAGE_SIZE); + + gcs_page = (void *)syscall(__NR_map_shadow_stack, 0, + page_size, 0); + if (gcs_page == MAP_FAILED) { + fprintf(stderr, "Failed to map %ld byte GCS: %d\n", + page_size, errno); + return false; + } + + return true; +} + +static int gcs_write_fault_trigger(struct tdescr *td) +{ + /* Verify that the page is readable (ie, not completely unmapped) */ + fprintf(stderr, "Read value 0x%lx\n", gcs_page[0]); + + /* A regular write should trigger a fault */ + gcs_page[0] = EINVAL; + + return 0; +} + +static int gcs_write_fault_signal(struct tdescr *td, siginfo_t *si, + ucontext_t *uc) +{ + ASSERT_GOOD_CONTEXT(uc); + + return 1; +} + + +struct tdescr tde = { + .name = "GCS write fault", + .descr = "Normal writes to a GCS segfault", + .feats_required = FEAT_GCS, + .timeout = 3, + .sig_ok = SIGSEGV, + .sanity_disabled = true, + .init = alloc_gcs, + .trigger = gcs_write_fault_trigger, + .run = gcs_write_fault_signal, +}; From patchwork Thu Aug 1 12:07:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750418 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 BED96C3DA64 for ; Thu, 1 Aug 2024 13:01:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D9C66B00D9; Thu, 1 Aug 2024 09:01:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 462B46B00DB; Thu, 1 Aug 2024 09:01:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28CCC6B00DC; Thu, 1 Aug 2024 09:01:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 01C776B00D9 for ; Thu, 1 Aug 2024 09:01:53 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B14AF1C40BE for ; Thu, 1 Aug 2024 13:01:53 +0000 (UTC) X-FDA: 82403688906.11.F1EA653 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf02.hostedemail.com (Postfix) with ESMTP id E44FC8002F for ; Thu, 1 Aug 2024 13:01:50 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="pzVg7+/x"; spf=pass (imf02.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517254; 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=ATGQv1Fy8tCwEjrXqi4sVPw1g1DJeBETlNX6hQiCSiw=; b=NLowFyLZ4rRjXTfT1x6EsrNfdiDgdPBMtTLxfB0GxxdxyFvN34c+RWLMch53v3aA/53Cyn InaSDVC0unfvjaGJw8Z6eJy2KYskv41FCyYhWcc0yBg7nYnP4tN2kDt2LLWk9TpFA4sPWX icbvXXtw7VfyAcf/fJByFI1EMFDnVRI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517254; a=rsa-sha256; cv=none; b=FUG485Wr+80BAP6G845mA5TONE3YJ+qDK9Bi4fcoKO70gnKDMmudbCF3vTvkXJkLVmFIpK z+LN9hD8X/VAMX4lUgtz8rYRWDe4OUzxictDjRTvIgKyrJ/T+GB838a49Mu7fb3N5iznNN UPLDK28DRPQ5YR81TQ+sKOTQvfLmCrQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="pzVg7+/x"; spf=pass (imf02.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id BF8CECE1979; Thu, 1 Aug 2024 13:01:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDE5DC4AF14; Thu, 1 Aug 2024 13:01:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517307; bh=jSXzBeczkE/zmgGrav1T+XnCBgKzY5Y6eHZrGHb1C0U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pzVg7+/xpGNuVIg3E2BurD7FfwDX9/7C36QqM8DXasjbtcHXbuOZtFtg+oQvCDuHV /ONFvUsptD8SfYvs+m5IeIalCYEC4OJ1rjjkBcS0zApMHk+EO983MD4ssLc+CorpWN vNsYgSlogK0jQkhP+VktqrZfTJrbZwykJcXdV+XxKSN35ma7w65hZXZNVe3fLzedUh Ft6Bv0i10i6vgDCW2tR+XHvxa8hCBSesF6V+vH03u8NOUqqQ44zPo/BoT3UcgOawtI ggr5LSnDWhKkkH1LnpyvEXHauL6e94fMEIEXhtvqCTNfGw3NWbTa9skmL7kRuFtbfr V5rHeDY9EqCdw== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:05 +0100 Subject: [PATCH v10 38/40] kselftest/arm64: Add a GCS stress test MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-38-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=21194; i=broonie@kernel.org; h=from:subject:message-id; bh=jSXzBeczkE/zmgGrav1T+XnCBgKzY5Y6eHZrGHb1C0U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YjGf2NxfKpXLFStPXpejB78ks3wtqlvOWpsoup BYIO+uiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGIwAKCRAk1otyXVSH0PSPB/ 9IhHy1MvZqXQgJAeRxSVUNezmMwlG0G46pkjA4WedyLu+UOnN8/8V0ECI8tIg9HZhWwzZ2XLnz7oLR 0dR4k+S/eQLA3m+RJ3ZmMMJMCixYxT/6iUPoGehglMegt3/ndQ1bm2nDHNr2+uMMRY5/+oUhVYUHp9 Y9Ohh9M9YWzc83BtQHx7K30Rf8uGPP8cCPr1yWcgv5EiZqTBbUZR6C8F835w/LILZdDHyGU71IPexI AreHOtAhlHrRvgmGvIaT4q3HQxVGBFFqnCULs+2hp5hr37qXJlNCf5hdsSEdXcSUH8fYqi9n/azZuc ZRwDQ3FApD2AOqHqcJOaT3pPqJThcn X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E44FC8002F X-Stat-Signature: rhpnz8pgfdkssci4nrddb9a5hotqqiyt X-HE-Tag: 1722517310-469858 X-HE-Meta: U2FsdGVkX1+xfLU8Md29v/HFgriQfvy1/Y5i6jfufqlCa7T3pPoFTOor0daetTcD336Zo9LrMPAkkw930OVbWURi4+YhMqvOhmTx+KMi2INMHHKTre2SL3hQMvuNfZz09xaZ6SSo6XGksctLYIczL4kHRueW7ocQ8geUspmnV+F0cF/e7rmRdymuZGaNosf3OnHhDPqDDCjiekLJ6u4Xqe5MvPaGlVrueHJhLTDB/5s9RdEDzDfU3fenUT1GDz5RaKcEH96FwlK78ThBXxs6uWwMqkJ7cfm6vD9iNrBTw40BxfQ08QvrRaOu7xOju1F9bPfH2Ffl2LcfZpxzqNGUJjQTP7OUvhvJlV2rY3IrWqAGKkKfWu/xymJxOZmCgbmA6i8xR/E75bZfpHhkpmjrUeu+juDSwi2HTt4LZEsqRfXLxma6HbbRqsniLLafcXnUqisOdAXu0CBSTeCzX31Y2qUZ8cjRIEPmDCzNrHAxvOgkKiKbSh3bBOVu7IsGZM8XA7H055TDTjNooPMTS34IWu3GEwiEvtAtgdYacEI70JbVHdEhHIkg/Q0jT8wDyPNlm61dk4weAt6RDUWc7EQRpanATh+a7L2CpL4AEbOWpzxhzE7LaG2vcE60CaXmCWPBEorMdkvFlRVXwgT0IgjKVOoCXHzlk6ZORV5EO9+YzBk/j3D0GAoDdAjIaRBfWTwSLL8jQTIRm0o96IZVlAfMMEmxE9RIIwCXnhL6A9AbhkyUO2V/iYRLS4lsgAK5avFTZuLzeMlvBRrfwejWnDtTRb54N/QtJSP8RlNuvsUrwiKZ46huToR6D7C9r5eJX6JILCPRbbxaxdMKOK122HDh0oS7gErdtBy2pXyIHH3IkMQ0dRAmusOi3e7Lqgdc8Z7M9ILlnw/tXMcExYXj+ljTtLHL/OQt/74dt5a2eahxfkL9XhtqyoJ/P2j9aQ1NeC/gju65h+uTEpoOhGBRCV7 m/T2yM0O MoOkF5G9FlUYaVD/RtDly3rHE0YQxzXZaZxqGm4eO69nknMJPBc1e6tAKIhEVoy+f36eDjCySAF/eqiYiCjI64cPTEIEHD9McPcrpYjpjK6tH05ekxOIScLWuJow8z/rtdYOTqMwQONjOJ2eFaQW0l6AGCYEeNa3FmiskFESXDVuCaxipMwCc0x/cpJ4f9mtqYmYSeBrxhJWfIM+7Kde5LcULoeUQeZz/exrK/CorZoP+rsASogXzB+BRpsmwXWYIa9Ypg8cEE74jGDTor5rrmr10cVMGr+EWGWXv34BSqhCnrMAKYFRT1BIuNTXy1PuyKAJ4FavoMqEt1POaIwLts09j62JE+aP22qoaPkz3tYmLna1BYTgnCfcwPxDA54hE+Qsi 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: Add a stress test which runs one more process than we have CPUs spinning through a very recursive function with frequent syscalls immediately prior to return and signals being injected every 100ms. The goal is to flag up any scheduling related issues, for example failure to ensure that barriers are inserted when moving a GCS using task to another CPU. The test runs for a configurable amount of time, defaulting to 10 seconds. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/gcs/.gitignore | 2 + tools/testing/selftests/arm64/gcs/Makefile | 6 +- tools/testing/selftests/arm64/gcs/asm-offsets.h | 0 .../selftests/arm64/gcs/gcs-stress-thread.S | 311 ++++++++++++ tools/testing/selftests/arm64/gcs/gcs-stress.c | 530 +++++++++++++++++++++ 5 files changed, 848 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/gcs/.gitignore b/tools/testing/selftests/arm64/gcs/.gitignore index 0c86f53f68ad..1e8d1f6b27f2 100644 --- a/tools/testing/selftests/arm64/gcs/.gitignore +++ b/tools/testing/selftests/arm64/gcs/.gitignore @@ -1,3 +1,5 @@ basic-gcs libc-gcs gcs-locking +gcs-stress +gcs-stress-thread diff --git a/tools/testing/selftests/arm64/gcs/Makefile b/tools/testing/selftests/arm64/gcs/Makefile index 2173d6275956..d8b06ca51e22 100644 --- a/tools/testing/selftests/arm64/gcs/Makefile +++ b/tools/testing/selftests/arm64/gcs/Makefile @@ -6,7 +6,8 @@ # nolibc. # -TEST_GEN_PROGS := basic-gcs libc-gcs gcs-locking +TEST_GEN_PROGS := basic-gcs libc-gcs gcs-locking gcs-stress +TEST_GEN_PROGS_EXTENDED := gcs-stress-thread LDLIBS+=-lpthread @@ -18,3 +19,6 @@ $(OUTPUT)/basic-gcs: basic-gcs.c -I../../../../../usr/include \ -std=gnu99 -I../.. -g \ -ffreestanding -Wall $^ -o $@ -lgcc + +$(OUTPUT)/gcs-stress-thread: gcs-stress-thread.S + $(CC) -nostdlib $^ -o $@ diff --git a/tools/testing/selftests/arm64/gcs/asm-offsets.h b/tools/testing/selftests/arm64/gcs/asm-offsets.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tools/testing/selftests/arm64/gcs/gcs-stress-thread.S b/tools/testing/selftests/arm64/gcs/gcs-stress-thread.S new file mode 100644 index 000000000000..b88b25217da5 --- /dev/null +++ b/tools/testing/selftests/arm64/gcs/gcs-stress-thread.S @@ -0,0 +1,311 @@ +// Program that loops for ever doing lots of recursions and system calls, +// intended to be used as part of a stress test for GCS context switching. +// +// Copyright 2015-2023 Arm Ltd + +#include + +#define sa_sz 32 +#define sa_flags 8 +#define sa_handler 0 +#define sa_mask_sz 8 + +#define si_code 8 + +#define SIGINT 2 +#define SIGABRT 6 +#define SIGUSR1 10 +#define SIGSEGV 11 +#define SIGUSR2 12 +#define SIGTERM 15 +#define SEGV_CPERR 10 + +#define SA_NODEFER 1073741824 +#define SA_SIGINFO 4 +#define ucontext_regs 184 + +#define PR_SET_SHADOW_STACK_STATUS 75 +# define PR_SHADOW_STACK_ENABLE (1UL << 0) + +#define GCSPR_EL0 S3_3_C2_C5_1 + +.macro function name + .macro endfunction + .type \name, @function + .purgem endfunction + .endm +\name: +.endm + +// Print a single character x0 to stdout +// Clobbers x0-x2,x8 +function putc + str x0, [sp, #-16]! + + mov x0, #1 // STDOUT_FILENO + mov x1, sp + mov x2, #1 + mov x8, #__NR_write + svc #0 + + add sp, sp, #16 + ret +endfunction +.globl putc + +// Print a NUL-terminated string starting at address x0 to stdout +// Clobbers x0-x3,x8 +function puts + mov x1, x0 + + mov x2, #0 +0: ldrb w3, [x0], #1 + cbz w3, 1f + add x2, x2, #1 + b 0b + +1: mov w0, #1 // STDOUT_FILENO + mov x8, #__NR_write + svc #0 + + ret +endfunction +.globl puts + +// Utility macro to print a literal string +// Clobbers x0-x4,x8 +.macro puts string + .pushsection .rodata.str1.1, "aMS", @progbits, 1 +.L__puts_literal\@: .string "\string" + .popsection + + ldr x0, =.L__puts_literal\@ + bl puts +.endm + +// Print an unsigned decimal number x0 to stdout +// Clobbers x0-x4,x8 +function putdec + mov x1, sp + str x30, [sp, #-32]! // Result can't be > 20 digits + + mov x2, #0 + strb w2, [x1, #-1]! // Write the NUL terminator + + mov x2, #10 +0: udiv x3, x0, x2 // div-mod loop to generate the digits + msub x0, x3, x2, x0 + add w0, w0, #'0' + strb w0, [x1, #-1]! + mov x0, x3 + cbnz x3, 0b + + ldrb w0, [x1] + cbnz w0, 1f + mov w0, #'0' // Print "0" for 0, not "" + strb w0, [x1, #-1]! + +1: mov x0, x1 + bl puts + + ldr x30, [sp], #32 + ret +endfunction +.globl putdec + +// Print an unsigned decimal number x0 to stdout, followed by a newline +// Clobbers x0-x5,x8 +function putdecn + mov x5, x30 + + bl putdec + mov x0, #'\n' + bl putc + + ret x5 +endfunction +.globl putdecn + +// Fill x1 bytes starting at x0 with 0. +// Clobbers x1, x2. +function memclr + mov w2, #0 +endfunction +.globl memclr + // fall through to memfill + +// Trivial memory fill: fill x1 bytes starting at address x0 with byte w2 +// Clobbers x1 +function memfill + cmp x1, #0 + b.eq 1f + +0: strb w2, [x0], #1 + subs x1, x1, #1 + b.ne 0b + +1: ret +endfunction +.globl memfill + +// w0: signal number +// x1: sa_action +// w2: sa_flags +// Clobbers x0-x6,x8 +function setsignal + str x30, [sp, #-((sa_sz + 15) / 16 * 16 + 16)]! + + mov w4, w0 + mov x5, x1 + mov w6, w2 + + add x0, sp, #16 + mov x1, #sa_sz + bl memclr + + mov w0, w4 + add x1, sp, #16 + str w6, [x1, #sa_flags] + str x5, [x1, #sa_handler] + mov x2, #0 + mov x3, #sa_mask_sz + mov x8, #__NR_rt_sigaction + svc #0 + + cbz w0, 1f + + puts "sigaction failure\n" + b abort + +1: ldr x30, [sp], #((sa_sz + 15) / 16 * 16 + 16) + ret +endfunction + + +function tickle_handler + // Perhaps collect GCSPR_EL0 here in future? + ret +endfunction + +function terminate_handler + mov w21, w0 + mov x20, x2 + + puts "Terminated by signal " + mov w0, w21 + bl putdec + puts ", no error\n" + + mov x0, #0 + mov x8, #__NR_exit + svc #0 +endfunction + +function segv_handler + // stash the siginfo_t * + mov x20, x1 + + // Disable GCS, we don't want additional faults logging things + mov x0, PR_SET_SHADOW_STACK_STATUS + mov x1, xzr + mov x2, xzr + mov x3, xzr + mov x4, xzr + mov x5, xzr + mov x8, #__NR_prctl + svc #0 + + puts "Got SIGSEGV code " + + ldr x21, [x20, #si_code] + mov x0, x21 + bl putdec + + // GCS faults should have si_code SEGV_CPERR + cmp x21, #SEGV_CPERR + bne 1f + + puts " (GCS violation)" +1: + mov x0, '\n' + bl putc + b abort +endfunction + +// Recurse x20 times +.macro recurse id +function recurse\id + stp x29, x30, [sp, #-16]! + mov x29, sp + + cmp x20, 0 + beq 1f + sub x20, x20, 1 + bl recurse\id + +1: + ldp x29, x30, [sp], #16 + + // Do a syscall immediately prior to returning to try to provoke + // scheduling and migration at a point where coherency issues + // might trigger. + mov x8, #__NR_getpid + svc #0 + + ret +endfunction +.endm + +// Generate and use two copies so we're changing the GCS contents +recurse 1 +recurse 2 + +.globl _start +function _start + // Run with GCS + mov x0, PR_SET_SHADOW_STACK_STATUS + mov x1, PR_SHADOW_STACK_ENABLE + mov x2, xzr + mov x3, xzr + mov x4, xzr + mov x5, xzr + mov x8, #__NR_prctl + svc #0 + cbz x0, 1f + puts "Failed to enable GCS\n" + b abort +1: + + mov w0, #SIGTERM + adr x1, terminate_handler + mov w2, #SA_SIGINFO + bl setsignal + + mov w0, #SIGUSR1 + adr x1, tickle_handler + mov w2, #SA_SIGINFO + orr w2, w2, #SA_NODEFER + bl setsignal + + mov w0, #SIGSEGV + adr x1, segv_handler + mov w2, #SA_SIGINFO + orr w2, w2, #SA_NODEFER + bl setsignal + + puts "Running\n" + +loop: + // Small recursion depth so we're frequently flipping between + // the two recursors and changing what's on the stack + mov x20, #5 + bl recurse1 + mov x20, #5 + bl recurse2 + b loop +endfunction + +abort: + mov x0, #255 + mov x8, #__NR_exit + svc #0 diff --git a/tools/testing/selftests/arm64/gcs/gcs-stress.c b/tools/testing/selftests/arm64/gcs/gcs-stress.c new file mode 100644 index 000000000000..a81417cd6f5c --- /dev/null +++ b/tools/testing/selftests/arm64/gcs/gcs-stress.c @@ -0,0 +1,530 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2022-3 ARM Limited. + */ + +#define _GNU_SOURCE +#define _POSIX_C_SOURCE 199309L + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../kselftest.h" + +struct child_data { + char *name, *output; + pid_t pid; + int stdout; + bool output_seen; + bool exited; + int exit_status; + int exit_signal; +}; + +static int epoll_fd; +static struct child_data *children; +static struct epoll_event *evs; +static int tests; +static int num_children; +static bool terminate; + +static int startup_pipe[2]; + +static int num_processors(void) +{ + long nproc = sysconf(_SC_NPROCESSORS_CONF); + if (nproc < 0) { + perror("Unable to read number of processors\n"); + exit(EXIT_FAILURE); + } + + return nproc; +} + +static void start_thread(struct child_data *child) +{ + int ret, pipefd[2], i; + struct epoll_event ev; + + ret = pipe(pipefd); + if (ret != 0) + ksft_exit_fail_msg("Failed to create stdout pipe: %s (%d)\n", + strerror(errno), errno); + + child->pid = fork(); + if (child->pid == -1) + ksft_exit_fail_msg("fork() failed: %s (%d)\n", + strerror(errno), errno); + + if (!child->pid) { + /* + * In child, replace stdout with the pipe, errors to + * stderr from here as kselftest prints to stdout. + */ + ret = dup2(pipefd[1], 1); + if (ret == -1) { + fprintf(stderr, "dup2() %d\n", errno); + exit(EXIT_FAILURE); + } + + /* + * Duplicate the read side of the startup pipe to + * FD 3 so we can close everything else. + */ + ret = dup2(startup_pipe[0], 3); + if (ret == -1) { + fprintf(stderr, "dup2() %d\n", errno); + exit(EXIT_FAILURE); + } + + /* + * Very dumb mechanism to clean open FDs other than + * stdio. We don't want O_CLOEXEC for the pipes... + */ + for (i = 4; i < 8192; i++) + close(i); + + /* + * Read from the startup pipe, there should be no data + * and we should block until it is closed. We just + * carry on on error since this isn't super critical. + */ + ret = read(3, &i, sizeof(i)); + if (ret < 0) + fprintf(stderr, "read(startp pipe) failed: %s (%d)\n", + strerror(errno), errno); + if (ret > 0) + fprintf(stderr, "%d bytes of data on startup pipe\n", + ret); + close(3); + + ret = execl("gcs-stress-thread", "gcs-stress-thread", NULL); + fprintf(stderr, "execl(gcs-stress-thread) failed: %d (%s)\n", + errno, strerror(errno)); + + exit(EXIT_FAILURE); + } else { + /* + * In parent, remember the child and close our copy of the + * write side of stdout. + */ + close(pipefd[1]); + child->stdout = pipefd[0]; + child->output = NULL; + child->exited = false; + child->output_seen = false; + + ev.events = EPOLLIN | EPOLLHUP; + ev.data.ptr = child; + + ret = asprintf(&child->name, "Thread-%d", child->pid); + if (ret == -1) + ksft_exit_fail_msg("asprintf() failed\n"); + + ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, child->stdout, &ev); + if (ret < 0) { + ksft_exit_fail_msg("%s EPOLL_CTL_ADD failed: %s (%d)\n", + child->name, strerror(errno), errno); + } + } + + ksft_print_msg("Started %s\n", child->name); + num_children++; +} + +static bool child_output_read(struct child_data *child) +{ + char read_data[1024]; + char work[1024]; + int ret, len, cur_work, cur_read; + + ret = read(child->stdout, read_data, sizeof(read_data)); + if (ret < 0) { + if (errno == EINTR) + return true; + + ksft_print_msg("%s: read() failed: %s (%d)\n", + child->name, strerror(errno), + errno); + return false; + } + len = ret; + + child->output_seen = true; + + /* Pick up any partial read */ + if (child->output) { + strncpy(work, child->output, sizeof(work) - 1); + cur_work = strnlen(work, sizeof(work)); + free(child->output); + child->output = NULL; + } else { + cur_work = 0; + } + + cur_read = 0; + while (cur_read < len) { + work[cur_work] = read_data[cur_read++]; + + if (work[cur_work] == '\n') { + work[cur_work] = '\0'; + ksft_print_msg("%s: %s\n", child->name, work); + cur_work = 0; + } else { + cur_work++; + } + } + + if (cur_work) { + work[cur_work] = '\0'; + ret = asprintf(&child->output, "%s", work); + if (ret == -1) + ksft_exit_fail_msg("Out of memory\n"); + } + + return false; +} + +static void child_output(struct child_data *child, uint32_t events, + bool flush) +{ + bool read_more; + + if (events & EPOLLIN) { + do { + read_more = child_output_read(child); + } while (read_more); + } + + if (events & EPOLLHUP) { + close(child->stdout); + child->stdout = -1; + flush = true; + } + + if (flush && child->output) { + ksft_print_msg("%s: %s\n", child->name, child->output); + free(child->output); + child->output = NULL; + } +} + +static void child_tickle(struct child_data *child) +{ + if (child->output_seen && !child->exited) + kill(child->pid, SIGUSR1); +} + +static void child_stop(struct child_data *child) +{ + if (!child->exited) + kill(child->pid, SIGTERM); +} + +static void child_cleanup(struct child_data *child) +{ + pid_t ret; + int status; + bool fail = false; + + if (!child->exited) { + do { + ret = waitpid(child->pid, &status, 0); + if (ret == -1 && errno == EINTR) + continue; + + if (ret == -1) { + ksft_print_msg("waitpid(%d) failed: %s (%d)\n", + child->pid, strerror(errno), + errno); + fail = true; + break; + } + + if (WIFEXITED(status)) { + child->exit_status = WEXITSTATUS(status); + child->exited = true; + } + + if (WIFSIGNALED(status)) { + child->exit_signal = WTERMSIG(status); + ksft_print_msg("%s: Exited due to signal %d\n", + child->name); + fail = true; + child->exited = true; + } + } while (!child->exited); + } + + if (!child->output_seen) { + ksft_print_msg("%s no output seen\n", child->name); + fail = true; + } + + if (child->exit_status != 0) { + ksft_print_msg("%s exited with error code %d\n", + child->name, child->exit_status); + fail = true; + } + + ksft_test_result(!fail, "%s\n", child->name); +} + +static void handle_child_signal(int sig, siginfo_t *info, void *context) +{ + int i; + bool found = false; + + for (i = 0; i < num_children; i++) { + if (children[i].pid == info->si_pid) { + children[i].exited = true; + children[i].exit_status = info->si_status; + found = true; + break; + } + } + + if (!found) + ksft_print_msg("SIGCHLD for unknown PID %d with status %d\n", + info->si_pid, info->si_status); +} + +static void handle_exit_signal(int sig, siginfo_t *info, void *context) +{ + int i; + + /* If we're already exiting then don't signal again */ + if (terminate) + return; + + ksft_print_msg("Got signal, exiting...\n"); + + terminate = true; + + /* + * This should be redundant, the main loop should clean up + * after us, but for safety stop everything we can here. + */ + for (i = 0; i < num_children; i++) + child_stop(&children[i]); +} + +/* Handle any pending output without blocking */ +static void drain_output(bool flush) +{ + int ret = 1; + int i; + + while (ret > 0) { + ret = epoll_wait(epoll_fd, evs, tests, 0); + if (ret < 0) { + if (errno == EINTR) + continue; + ksft_print_msg("epoll_wait() failed: %s (%d)\n", + strerror(errno), errno); + } + + for (i = 0; i < ret; i++) + child_output(evs[i].data.ptr, evs[i].events, flush); + } +} + +static const struct option options[] = { + { "timeout", required_argument, NULL, 't' }, + { } +}; + +int main(int argc, char **argv) +{ + int seen_children; + bool all_children_started = false; + int gcs_threads; + int timeout = 10; + int ret, cpus, i, c; + struct sigaction sa; + + while ((c = getopt_long(argc, argv, "t:", options, NULL)) != -1) { + switch (c) { + case 't': + ret = sscanf(optarg, "%d", &timeout); + if (ret != 1) + ksft_exit_fail_msg("Failed to parse timeout %s\n", + optarg); + break; + default: + ksft_exit_fail_msg("Unknown argument\n"); + } + } + + cpus = num_processors(); + tests = 0; + + if (getauxval(AT_HWCAP2) & HWCAP2_GCS) { + /* One extra thread, trying to trigger migrations */ + gcs_threads = cpus + 1; + tests += gcs_threads; + } else { + gcs_threads = 0; + } + + ksft_print_header(); + ksft_set_plan(tests); + + ksft_print_msg("%d CPUs, %d GCS threads\n", + cpus, gcs_threads); + + if (!tests) + ksft_exit_skip("No tests scheduled\n"); + + if (timeout > 0) + ksft_print_msg("Will run for %ds\n", timeout); + else + ksft_print_msg("Will run until terminated\n"); + + children = calloc(sizeof(*children), tests); + if (!children) + ksft_exit_fail_msg("Unable to allocate child data\n"); + + ret = epoll_create1(EPOLL_CLOEXEC); + if (ret < 0) + ksft_exit_fail_msg("epoll_create1() failed: %s (%d)\n", + strerror(errno), ret); + epoll_fd = ret; + + /* Create a pipe which children will block on before execing */ + ret = pipe(startup_pipe); + if (ret != 0) + ksft_exit_fail_msg("Failed to create startup pipe: %s (%d)\n", + strerror(errno), errno); + + /* Get signal handers ready before we start any children */ + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = handle_exit_signal; + sa.sa_flags = SA_RESTART | SA_SIGINFO; + sigemptyset(&sa.sa_mask); + ret = sigaction(SIGINT, &sa, NULL); + if (ret < 0) + ksft_print_msg("Failed to install SIGINT handler: %s (%d)\n", + strerror(errno), errno); + ret = sigaction(SIGTERM, &sa, NULL); + if (ret < 0) + ksft_print_msg("Failed to install SIGTERM handler: %s (%d)\n", + strerror(errno), errno); + sa.sa_sigaction = handle_child_signal; + ret = sigaction(SIGCHLD, &sa, NULL); + if (ret < 0) + ksft_print_msg("Failed to install SIGCHLD handler: %s (%d)\n", + strerror(errno), errno); + + evs = calloc(tests, sizeof(*evs)); + if (!evs) + ksft_exit_fail_msg("Failed to allocated %d epoll events\n", + tests); + + for (i = 0; i < gcs_threads; i++) + start_thread(&children[i]); + + /* + * All children started, close the startup pipe and let them + * run. + */ + close(startup_pipe[0]); + close(startup_pipe[1]); + + timeout *= 10; + for (;;) { + /* Did we get a signal asking us to exit? */ + if (terminate) + break; + + /* + * Timeout is counted in 100ms with no output, the + * tests print during startup then are silent when + * running so this should ensure they all ran enough + * to install the signal handler, this is especially + * useful in emulation where we will both be slow and + * likely to have a large set of VLs. + */ + ret = epoll_wait(epoll_fd, evs, tests, 100); + if (ret < 0) { + if (errno == EINTR) + continue; + ksft_exit_fail_msg("epoll_wait() failed: %s (%d)\n", + strerror(errno), errno); + } + + /* Output? */ + if (ret > 0) { + for (i = 0; i < ret; i++) { + child_output(evs[i].data.ptr, evs[i].events, + false); + } + continue; + } + + /* Otherwise epoll_wait() timed out */ + + /* + * If the child processes have not produced output they + * aren't actually running the tests yet. + */ + if (!all_children_started) { + seen_children = 0; + + for (i = 0; i < num_children; i++) + if (children[i].output_seen || + children[i].exited) + seen_children++; + + if (seen_children != num_children) { + ksft_print_msg("Waiting for %d children\n", + num_children - seen_children); + continue; + } + + all_children_started = true; + } + + ksft_print_msg("Sending signals, timeout remaining: %d00ms\n", + timeout); + + for (i = 0; i < num_children; i++) + child_tickle(&children[i]); + + /* Negative timeout means run indefinitely */ + if (timeout < 0) + continue; + if (--timeout == 0) + break; + } + + ksft_print_msg("Finishing up...\n"); + terminate = true; + + for (i = 0; i < tests; i++) + child_stop(&children[i]); + + drain_output(false); + + for (i = 0; i < tests; i++) + child_cleanup(&children[i]); + + drain_output(true); + + ksft_finished(); +} From patchwork Thu Aug 1 12:07:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750420 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 67EE5C3DA64 for ; Thu, 1 Aug 2024 13:02:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D64BD6B00DD; Thu, 1 Aug 2024 09:02:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D13F96B00DF; Thu, 1 Aug 2024 09:02:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B66726B00E0; Thu, 1 Aug 2024 09:02:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 978FC6B00DD for ; Thu, 1 Aug 2024 09:02:13 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 570DF140D6F for ; Thu, 1 Aug 2024 13:02:13 +0000 (UTC) X-FDA: 82403689746.08.6237A12 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf17.hostedemail.com (Postfix) with ESMTP id ADC6D4007E for ; Thu, 1 Aug 2024 13:01:57 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vGH+nzw9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517254; 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=x4bRDIg3FZYF4TjRB4Ac3+0Hb2IaTqNwKYJSKp4sACo=; b=Bk5AvI3mwWxAfuMLeCK9HoxpcWFkf+K+W3I7eHgeFrbGv3gHVrSsLa6LAVYefn5dLIzmjO zL6c94JOVZtnFyG+JQd2X7FLyILTy/dYZW6Fhp5nrg1muX8ey9DyeyK+ol4oQIQDxGKxYX vPJBU9oPud90Q8QyJ3Xeek24r90Ti54= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517254; a=rsa-sha256; cv=none; b=0n06cMD3ktxvB7JkutYFWgg32n9Ow/6ePRbNs6z/pMcAE/qilO9mAOdXGl8h9csqNiY+YX Hww9P48Sh+b4Vdgo1RgqI+kZArqicwVvCyzC43vYgItoxd786hv9GPDVlNHxohE6kZ7ayH 3HsuFPKCDADnTWWYxzoeg2rDoekdKcE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vGH+nzw9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9B98FCE19AC; Thu, 1 Aug 2024 13:01:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D64E5C32786; Thu, 1 Aug 2024 13:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517314; bh=YYz6vJzvFivBjzQl/oYVfPbzMadH/24Qr7CyuKANnYA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vGH+nzw9stnDTdcaftUMZ0RSrgKf7OteE0TbDxGrYkVLsG+cDPLHLN65Kv1/N4j/q KkwToUJ8Xg7dKAusreA/2dsthDLf+JuDgtaZ0natBK+eHTXNKOuOihBQfyIBJYCSP8 MhXRdrrJQAJTb4kKrWIhoaaJs1RsdEx6bKTZOcfJgwwublrWEtufqEI09N6a5yI7x8 02keFtwbxiMdw1K8xQwg+xthHk09VaeAUKwjJLry/undGymRfhuJ0YpJIDtZxhC9SC lCJ1JJcsHj6fTKJ9B9nuH7gwaqaGHB8btfldLKKuRK/aDia5C1GRrYerJJ4vMHCs5U JriKtF9UMfzXA== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:06 +0100 Subject: [PATCH v10 39/40] kselftest/arm64: Enable GCS for the FP stress tests MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-39-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=3151; i=broonie@kernel.org; h=from:subject:message-id; bh=YYz6vJzvFivBjzQl/oYVfPbzMadH/24Qr7CyuKANnYA=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4Yk7gWmnGFkGrMdlCnUH3lfdRyPQ26ry/+pIlvh D9NfY9qJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGJAAKCRAk1otyXVSH0J8tB/ 40xcfumCAXaBAwsmdgdRL95dbspFwaxEzgXyO64AaG/C8o9hNZefmAMaq/PxFo0Ni6FHz3yipgiRx6 yrerq119lFtUvd+7lHrcyWo/mdoKZ4cwOzV9Whr1IvDJPZ06uozmIEdF/iyDtvTyAZNvzVO84gBj2M q85Qzze6VxUhpdwJVrF4Yx0EkNNKZ+7qdqNU7EtXNTwNeLIU4xWnyxl8bF0jTJjrO/4QvQKjEjZZUi S4QK5iXMXEUIxq7osw0xYVXGusBdQwBFmxsz0HrOCM0GE2ACUOAJS3pR6gHoJfRsq8XHFUDwdtPwXP t2DXyibXI765vRiG1dNK7vTS4V7Yot X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: ADC6D4007E X-Stat-Signature: ieymx6hx4bzhgfarix6bo7otineyqw8m X-Rspam-User: X-HE-Tag: 1722517317-640682 X-HE-Meta: U2FsdGVkX18BHobGbyWuKWSF210ab5mYVzCIJ7JnovtlQl2/NlRF7XcbkBjZkS4tRp6rxgn8LU/0/k+LdT+Wfk2zrgeXsKKP+PKtYUQhMyzi5flHJSp1zZNQVCyWtIzqtnjEkWOXA7dqWfjUlOI3HaSfw0qfnq4xHcUGMp4c8y4KQvfK3nGft0/TmWtGkQ9SirddKtUTLxrV0jaaSSN9F65omFlzvoLu1y1ttr6F9AqcalzQ6T03QoMA9wPUyEIW0Mi91JIkxG7xgOsJ06lVO187BW+9ghloxCY9/mJ522c3lGQ/NhYCb01ncb5yeWifS220bVYqLSvrNYN0FSVd8QhGgoFSL1bD3h6fjhoYRAgpDAZdvGXG7KSfQ38hMjUGcP63fWrqa1EeTcgkBx6g7u1ZL9bu65g5i2JPBPOvSwx7S3oDRn1eV4wQcfpfmfK/MykFEY6L5uHdVSRcnwxSIZ3PaY9ciNkpix2plvFsxVWlUajBtFjhozG2ofkC4UH5sPgaIch7Ec0STpKouw+bl5WsEOh6SHgV8j8BtXFBntr9dG9Yq65LIY3bgN9F2Q6JutWOozw/sjk9gPbgOeKGSH0GMCz24EcV88z19kjfIxQCeBbNGpniEWyuNCEcagMl7Ze7lC+R1GkD+wi/nD/5V/tRJLzD6GYOoKfSFDAoCLBbUAl6gguxY8XJZUb367Kjp9uOCm/tGXEDPUTVeBn1GR0Su+e1JxcobnM88FB2RY4pIsInW5SWUhBZPZzosU0CZ2CvHaAN4VTBCwhNr0bPe23eaYfwMaM/IT7HhmQZMRJghmXgxjpxjfi+/NjeoyS8l5QcwkA4bHBEIc8oFL/7s4OTpeS+4lp45fJe+wIesMQXBwweoNfKEhFS9N7nsI/+ANC1vVup/CwHC8LbHMJhB+oOzgvTg7Vc5IItNlbfta/io2VPsY8HDGu0a7hPjMhrRVsNlNzc4HtZ5VlUK5F jlWeDfRG Xp2BGA1dGWWVuvr/TLs144L+FDVEvEJp/0w6+TlTAS0xsD222CDVKW+hqIWDMR2m3z/u5MYQU/j/VJouJ55jCMYaidTeMUu1vWsvdAlvJZfTgtwrUGxy2pmA9DmiTUI9u+KJ9IuegLkdqBcIkL0FlxRbRSNeLEgh1bbgq2uuRURMR80kXABijyaBmO8vlfzd5KhZ2C+428vLivozV8AMyM3esaQ2I9VgwmlgW+3nliBbHfbQ5WOiUnMcHiIuGeGCloSpVvLpUGC3YMQaKs6kBQFYBnemIklMtVbpT+X/dZcR+FRMA7iqbvgXYvrPdEPaZ2QcHpg5f2t0MOh2xbJ5Ga3/0Dz3fd50yhdejg3wAq/WuuZoPwtOf4ST/yCUa9iktgnPT 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: While it's a bit off topic for them the floating point stress tests do give us some coverage of context thrashing cases, and also of active signal delivery separate to the relatively complicated framework in the actual signals tests. Have the tests enable GCS on startup, ignoring failures so they continue to work as before on systems without GCS. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/fp/assembler.h | 15 +++++++++++++++ tools/testing/selftests/arm64/fp/fpsimd-test.S | 2 ++ tools/testing/selftests/arm64/fp/sve-test.S | 2 ++ tools/testing/selftests/arm64/fp/za-test.S | 2 ++ tools/testing/selftests/arm64/fp/zt-test.S | 2 ++ 5 files changed, 23 insertions(+) diff --git a/tools/testing/selftests/arm64/fp/assembler.h b/tools/testing/selftests/arm64/fp/assembler.h index 9b38a0da407d..1fc46a5642c2 100644 --- a/tools/testing/selftests/arm64/fp/assembler.h +++ b/tools/testing/selftests/arm64/fp/assembler.h @@ -65,4 +65,19 @@ endfunction bl puts .endm +#define PR_SET_SHADOW_STACK_STATUS 75 +# define PR_SHADOW_STACK_ENABLE (1UL << 0) + +.macro enable_gcs + // Run with GCS + mov x0, PR_SET_SHADOW_STACK_STATUS + mov x1, PR_SHADOW_STACK_ENABLE + mov x2, xzr + mov x3, xzr + mov x4, xzr + mov x5, xzr + mov x8, #__NR_prctl + svc #0 +.endm + #endif /* ! ASSEMBLER_H */ diff --git a/tools/testing/selftests/arm64/fp/fpsimd-test.S b/tools/testing/selftests/arm64/fp/fpsimd-test.S index 8b960d01ed2e..b16fb7f42e3e 100644 --- a/tools/testing/selftests/arm64/fp/fpsimd-test.S +++ b/tools/testing/selftests/arm64/fp/fpsimd-test.S @@ -215,6 +215,8 @@ endfunction // Main program entry point .globl _start function _start + enable_gcs + mov x23, #0 // signal count mov w0, #SIGINT diff --git a/tools/testing/selftests/arm64/fp/sve-test.S b/tools/testing/selftests/arm64/fp/sve-test.S index fff60e2a25ad..2fb4f0b84476 100644 --- a/tools/testing/selftests/arm64/fp/sve-test.S +++ b/tools/testing/selftests/arm64/fp/sve-test.S @@ -378,6 +378,8 @@ endfunction // Main program entry point .globl _start function _start + enable_gcs + mov x23, #0 // Irritation signal count mov w0, #SIGINT diff --git a/tools/testing/selftests/arm64/fp/za-test.S b/tools/testing/selftests/arm64/fp/za-test.S index 095b45531640..b2603aba99de 100644 --- a/tools/testing/selftests/arm64/fp/za-test.S +++ b/tools/testing/selftests/arm64/fp/za-test.S @@ -231,6 +231,8 @@ endfunction // Main program entry point .globl _start function _start + enable_gcs + mov x23, #0 // signal count mov w0, #SIGINT diff --git a/tools/testing/selftests/arm64/fp/zt-test.S b/tools/testing/selftests/arm64/fp/zt-test.S index b5c81e81a379..8d9609a49008 100644 --- a/tools/testing/selftests/arm64/fp/zt-test.S +++ b/tools/testing/selftests/arm64/fp/zt-test.S @@ -200,6 +200,8 @@ endfunction // Main program entry point .globl _start function _start + enable_gcs + mov x23, #0 // signal count mov w0, #SIGINT From patchwork Thu Aug 1 12:07:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750419 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 D17ADC3DA4A for ; Thu, 1 Aug 2024 13:02:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 502346B00DB; Thu, 1 Aug 2024 09:02:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 489AC6B00DD; Thu, 1 Aug 2024 09:02:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 302166B00DE; Thu, 1 Aug 2024 09:02:05 -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 0ED306B00DB for ; Thu, 1 Aug 2024 09:02:05 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BC4A1A0D8F for ; Thu, 1 Aug 2024 13:02:04 +0000 (UTC) X-FDA: 82403689368.30.7684592 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id 55FB5180032 for ; Thu, 1 Aug 2024 13:02:02 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EOypttz1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.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=1722517280; a=rsa-sha256; cv=none; b=TE4yOZr+1tOVx/J/Bn1CA+k/vnu3oZYcBg+a3KoRMQie0ORoDMbxu98YDA73WGUbpO3kDV PSi+4xtxCOQiLBN3c+1Fkk+4tpsCnvZ3yv0veO4H1bu2WnW03kwX4Y0ys245JLNNcF8eeC GjeeW0KUETnOJaD/MygBzH4q5163Fgk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EOypttz1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.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=1722517280; 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=KgFh/BxEiZ/ikilMITQSdKhachKnnW9R3XZwoyVpr3A=; b=qsfGO5IZ8tn4yQEQZ1MSiZu4NWk7XTbsZM/nmjeXbh8mGL4tBSyQoUPfeOxqrJTEQYJRqV nSkZSyvgjAGHG8dyWy+TPndqLvwYxg6UUO/WtTAl6bl1FYc5BNU6xrRACTr3GLCZQCluQ+ BHhChwglBx7bxhHZ9fD+MnWkUJBh/HU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 663806287C; Thu, 1 Aug 2024 13:02:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4528C4AF0A; Thu, 1 Aug 2024 13:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517321; bh=2o7H97U54cEmD5Tv71kF1eEpEycy3n5iAga6TGpYn58=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EOypttz1iUC6Oqt2kwkwmd4hYK/iYBJyUlsSGBCxML2MrAMFnoFqWmEE8yplv/Zf2 g8lM4YlFhj9+fdD1LFcVHcxhbj4wVXGv9AFclgyBJJdQI8TN26iUHLke/PjeQJ6pha qtzIUteV2oxLMg4GPFfIUSHThfXVm5pvBCWlc0/TXAbN+PB65tYEWVsOkGR0/ooeu3 wR3cCoXFofGIvrX3WiieIBTXZzDojnzLlQJTv+YC7WLr+WhDa3+nuZN0FbZnNlAel4 HYAP0fEe7Pdb1UGWHxPOw1/2ocSKJhL8rPBXlAIPbaw2nrLP0p+9aBvD0dE10tKzcX caaPVWssBnNAw== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:07 +0100 Subject: [PATCH v10 40/40] KVM: selftests: arm64: Add GCS registers to get-reg-list MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-40-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=2352; i=broonie@kernel.org; h=from:subject:message-id; bh=2o7H97U54cEmD5Tv71kF1eEpEycy3n5iAga6TGpYn58=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4Yl2GIZXXyTb/zmM1+n2z4UQxnV39+pL7mDiQag cFTi6HGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGJQAKCRAk1otyXVSH0PXDB/ 4j5qGQGsGNdUNY04r8BP8DhGZFseiQkyBLks8Be56HfC2p51Bs37kAiCN7vw5o6FNjV7nHuKordgf8 yw8h5xIw20SOGbtSiJzK+Ytmcij7dKixG3lRNnjLjqaDdEBHYQd36UkkNAQgXrVYEHb3uGUdeSe4Pf bVg2h3X4uA2HXpmx1Re6duBQnFxQkT9rwDaPrUVUJ8O1yGDA6GES8iwokMeuWIm1IuG8kk4/ryxjLS MQuOjZLd4+rfnA99YvtwSC6d7LH3XTe6kZlg8lx4hPJ/2a1XoSi//5g2fntfcaHvPuz/xHErMA3FRH FgQKeE4l1SWZJYN8U5tIpu0CgGk3wq X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 55FB5180032 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bba6gk6uy5jr1uirrxf3wi5177x13ata X-HE-Tag: 1722517322-743481 X-HE-Meta: U2FsdGVkX191X3VopBFYGo6U/BH7F8cioM9Rz+YGrA4qbPbFGM4TYfFwav+QdZNgPQ8+XHpwcVlHlUQcqfhfwMNkT9aRjNcTbZa8+CkdFRBiysUKStjzhAczAuazPKlBhhzHHGfX3x59K/IHj4X7KX0WEL/FLChzGcozTVki/ABdu4gZtevwYidsHEARzDtr9uXAaBuGKGQa7NtoWYDE28SQpbj1gRbSaYHM0P85Y4M2MbBaUoqI8eTwYChHMc3JYicDiOYaZeAWo388RA6FFaTLHU3mtWRpKjNHjkyRI23qCS8QaI/0/WHa59c6bdw9ARI+PxNQPu/+8+VHY6XGZcifgx/MmCBY/fp3TQLpTgr3EtwAPNKu8kwaFjqdriGAG/ZSA3ae1HSUSwcf0mcEiq/ueAnDUSL9qdAG9MOVj7YFplSrPiqRmS8LOciS081mFXcCeWgyyJ6XhhaWIZARgmb+DIBLh4MsD9jZA1op9g8cbRHzQmYyNEpy9phgSBbkWT2xjomdDsLOKdz/DPF1gA5dTQYygpVBbdyYIkteg3GOrQ4iRbvRYoJeZf9Y+EmyJieyruLAbJ1Gw+ZDBzRq6e7C7jk5sTBBYlXXIP3TV3e0Ndvcb27VSxqAm5DYLQQ6XqVZoKBxN0fGjkBlhcvM3Nu8Vrs50i3lhiiSbwUFeihxw4ld1MfyOYzgUzPhYAio2WesgxO0PmLB1xx154QpdXLRrRvuCvfaWdMnrYgYIFwf89hXbipalz538bITZkryofqU8MWWO78N3Z6eFVPWoEbRDbQ/C6G8jVG6rh+uPQM7aLJLL94ULvPHupIWthGeYSItY46bbQginM7JpEnO/Ifkbd8/65HHt/6/VBX8lvt96Q4k4SBEAk7qk8nuHIUEZ0vGgdyWl0UMKEm2BGtd331m5khvmm+NknXdCVknF2CiESYIWHToRABFZ+bAZg/GhdfkrjMRpUisKUoWBUw STqDCMsQ wE8HXt3/c6ngbe/u+xP6uNRDrtc9q17GhZbyHt0uVYC/IHZa7jUDTlaNWFdaXNq0G2YcPMNk/PIR08srsauVH68ffDmqNoi8VoXj/i5ZwfASdPIbD7OcbW7Rqz+b2mlA7EbCK4O1lPlOjAay3fkfbAM13DmfrsRA0eDAgGooS5G1mU2C3ZV+beUtS2tdXMABdgL3fnVUPWylldFLxAUpU3Cin5ocwhMFe4yGw3CLOFUjH5LRN75Rb4hXZyyMKql1G7rsmlCLTOynbEUkYYIspTYyDXB+Kc5bFEjXdsY7vHUvavbuQvKy3qDfljsby69Mtbfuv 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: GCS adds new registers GCSCR_EL1, GCSCRE0_EL1, GCSPR_EL1 and GCSPR_EL0. Add these to those validated by get-reg-list. Signed-off-by: Mark Brown --- tools/testing/selftests/kvm/aarch64/get-reg-list.c | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c index 709d7d721760..9785f41e6042 100644 --- a/tools/testing/selftests/kvm/aarch64/get-reg-list.c +++ b/tools/testing/selftests/kvm/aarch64/get-reg-list.c @@ -29,6 +29,24 @@ static struct feature_id_reg feat_id_regs[] = { 0, 1 }, + { + ARM64_SYS_REG(3, 0, 2, 5, 0), /* GCSCR_EL1 */ + ARM64_SYS_REG(3, 0, 0, 4, 1), /* ID_AA64PFR1_EL1 */ + 44, + 1 + }, + { + ARM64_SYS_REG(3, 0, 2, 5, 1), /* GCSPR_EL1 */ + ARM64_SYS_REG(3, 0, 0, 4, 1), /* ID_AA64PFR1_EL1 */ + 44, + 1 + }, + { + ARM64_SYS_REG(3, 0, 2, 5, 2), /* GCSCRE0_EL1 */ + ARM64_SYS_REG(3, 0, 0, 4, 1), /* ID_AA64PFR1_EL1 */ + 44, + 1 + }, { ARM64_SYS_REG(3, 0, 10, 2, 2), /* PIRE0_EL1 */ ARM64_SYS_REG(3, 0, 0, 7, 3), /* ID_AA64MMFR3_EL1 */ @@ -40,6 +58,12 @@ static struct feature_id_reg feat_id_regs[] = { ARM64_SYS_REG(3, 0, 0, 7, 3), /* ID_AA64MMFR3_EL1 */ 4, 1 + }, + { + ARM64_SYS_REG(3, 3, 2, 5, 1), /* GCSPR_EL0 */ + ARM64_SYS_REG(3, 0, 0, 4, 1), /* ID_AA64PFR1_EL1 */ + 44, + 1 } }; @@ -460,6 +484,9 @@ static __u64 base_regs[] = { ARM64_SYS_REG(3, 0, 2, 0, 1), /* TTBR1_EL1 */ ARM64_SYS_REG(3, 0, 2, 0, 2), /* TCR_EL1 */ ARM64_SYS_REG(3, 0, 2, 0, 3), /* TCR2_EL1 */ + ARM64_SYS_REG(3, 0, 2, 5, 0), /* GCSCR_EL1 */ + ARM64_SYS_REG(3, 0, 2, 5, 1), /* GCSPR_EL1 */ + ARM64_SYS_REG(3, 0, 2, 5, 2), /* GCSCRE0_EL1 */ ARM64_SYS_REG(3, 0, 5, 1, 0), /* AFSR0_EL1 */ ARM64_SYS_REG(3, 0, 5, 1, 1), /* AFSR1_EL1 */ ARM64_SYS_REG(3, 0, 5, 2, 0), /* ESR_EL1 */ @@ -475,6 +502,7 @@ static __u64 base_regs[] = { ARM64_SYS_REG(3, 0, 13, 0, 4), /* TPIDR_EL1 */ ARM64_SYS_REG(3, 0, 14, 1, 0), /* CNTKCTL_EL1 */ ARM64_SYS_REG(3, 2, 0, 0, 0), /* CSSELR_EL1 */ + ARM64_SYS_REG(3, 3, 2, 5, 1), /* GCSPR_EL0 */ ARM64_SYS_REG(3, 3, 13, 0, 2), /* TPIDR_EL0 */ ARM64_SYS_REG(3, 3, 13, 0, 3), /* TPIDRRO_EL0 */ ARM64_SYS_REG(3, 3, 14, 0, 1), /* CNTPCT_EL0 */