From patchwork Sat Feb 3 12:25: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: 13544157 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 5FFB2C4828F for ; Sat, 3 Feb 2024 12:33:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D13476B00A3; Sat, 3 Feb 2024 07:33:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA0216B00C1; Sat, 3 Feb 2024 07:33:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B17136B00C2; Sat, 3 Feb 2024 07:33:19 -0500 (EST) 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 9D3E56B00A3 for ; Sat, 3 Feb 2024 07:33:19 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6EDBD1206EA for ; Sat, 3 Feb 2024 12:33:19 +0000 (UTC) X-FDA: 81750432918.14.C225E8A Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf14.hostedemail.com (Postfix) with ESMTP id 0859710001A for ; Sat, 3 Feb 2024 12:33:16 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hJjcPh3u; spf=pass (imf14.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=1706963597; 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=txc3X2V7CJ9ZdLUppYIcM2fiWiyeeo4/+q5He8/QHL8=; b=YtP4Wub+pMBYEQ27cC+Fv7je1oyqzVyapGHQuq+1GdhXeOdSLg5Ye6Zz/uMae8UktRc+B8 b9hAxwDxldbGCNLUoLb/OBnGI+n1XJOjUd/59dJxocn3HQhHM6/U7hXb8KkS186vx4IrtZ dNev+oA601OjvA1zg5PR/mYDNq/9Jq8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706963597; a=rsa-sha256; cv=none; b=VzV9GxJYPKkZeJyEuphBxQKb4gaG5RbyssiLqTcf6wbyTEZ0lQ8ssN75NPfXedNGS4NAmv 8QmZTz49jKLBc42D847ufHMmxShBAGRZrbVd5FtMXaWN3+6r3Jm1UCt/z7D/IgB9P3H45i c12ZPoN/Hxs8aSlryWGP1JFD0mIsAzc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hJjcPh3u; spf=pass (imf14.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 961ECCE1F0C; Sat, 3 Feb 2024 12:33:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF954C43601; Sat, 3 Feb 2024 12:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706963592; bh=OYaAyRMLSn6kTs6FMYnMtTS8W24+WIO4Ly8HwzP8d7o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hJjcPh3up4HsDZeZdZrX84RsssLo8XHcibpiV1YYg5swoZV7KuU0a3Ji6qmRxlqdK KpDz2r7cOtyULAMhEqcSBNmjSIFe20d1wwmaFV3mpzGkVJ+e9l8CV4kCrTADGyImUl e/AJPrvxbIBclb9fP5qip4riNVuFxwcOvLSVQS5qMi5Lsa+M+pQ1AWIBTY4x8+JRRP xOLW5BL0CYOS0Agni/T3QBOlIDn0KLyphHOPDdlkRcqLcE+nEQbGpQ3DA45lB5cu2X Zh15cDH5VEWdYtGHAJxQBzXigtBSEQK5zoyUbHgKSIIzJ4axd7yoHCoATcMzq4pdZR rxcvtOaJx6FrQ== From: Mark Brown Date: Sat, 03 Feb 2024 12:25:57 +0000 Subject: [PATCH v8 31/38] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20240203-arm64-gcs-v8-31-c9fec77673ef@kernel.org> References: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> In-Reply-To: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> To: Catalin Marinas , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , Thiago Jung Bauermann , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Brown X-Mailer: b4 0.13-dev-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=3590; i=broonie@kernel.org; h=from:subject:message-id; bh=OYaAyRMLSn6kTs6FMYnMtTS8W24+WIO4Ly8HwzP8d7o=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlvjDpE03vPx+2Pd9LxDq0QKtQO89e99y0kE09Rllr fmbRSv6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZb4w6QAKCRAk1otyXVSH0IW0B/ 4gWE9kc5oX8BOOeLRppL7+i6OUXVRASufGbun+oroqFRKPKT2m/bUgRvBF0DaXYGnvceLQZ8guplbg phtTjyQUG+o5r6ln4cRGCKr17qkiOiDDFRL3K69dvv2zkPwY6URF3rT5N9L3d73Ns1XjoNXlkcqxL4 elVsHMFR6mfG2RbNxdMgN8UipZRDTHNuDksPeio4HFN7c4NT+G+YZxdLTW02A79uOpRUqW1ve5+Ewt +3xXdhBnydiJmr2UwxSlp+6qiuQZV6qfMIe6nFtS92pdjrRCMF1whN5IQpH5hT9EooZg2n1hduVsV3 nGCvXnWeBNRHpLZDmmLL85F5MPAOnH X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 0859710001A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zisg88rko7od18mtgrgordkxpsiasc6i X-HE-Tag: 1706963596-342156 X-HE-Meta: U2FsdGVkX19qexu8CVAQQs619j+OIuKLiuat6ZJMaZ/BGuPVmMuTmxjAuxVAhaXWGE+pyFr4dvZVChYxA5X928QsvST7uVqFcihCqcZTUARPNdDzrskpeLUMW8K/FJRoklX6URsaoN+zb95gbNdY/xnlcPI4nKYLQ70RRNMBcasllC8e+LLTfsz1Pcvv/NYIT8bda6PYECDahItYNix3r9HG6i4LW4ji77kWoNo6Cfhe7eev+bwQeUlISg0kioDkCd5qzflvfa/XZYQomjz2eeLedEm+XZhE3dnuzFgjXcO3hDciEjMadsTD3doRp4JAP5tQECmREtF3BtG3EczL7Td4nsqulzeUBAgj1S2XWXcGoraKrqY6qSvHkkA12euv+d6olRHhAIiz6rmrU2vHd3FojuDbiYbEUPGZqJlgz/g8SmdSomVOZUFHJlXMVnubsELaSweXz4LRB9bHsElZOfRUFexE0xZFI3H/NfCldpcGkL6tQ7VjvI4VE1OOWmyGUeJCIsOLjB/BnqLiDrtRHr2eNgP3RgznxKIPGW7t/Al2bI+pQ3CEvhhtOTGeNJBdZzvxoiHlgkn66KnthARWcJdw2spNNf6VyG1aPgjum8C68LHRSFcMn34Krt8HcvPZv56fnKj1EfpwLKT/4S4ll+3ZcmUG5fquHHUWlJa2dSQvwHtRqk7GD6ztA2yM7yRh1nz1VvxpfU4infi6Z04Y1Qbws//raafcH3X6brMkVWNds6bH9K7rzsoadcLGOl+UTUsa5AAYo7BiZ7RaSTY7njYMjA2MYoM74z1swjAW9ns27i1v8gEfgzzoqpMdLQbbJY2/eX1DlYhE/M4+jkoF2TQC93oIc6mfbuAEvyggR0jIf+vUudOvGzwHceJT3bUHKexkgtg57NY9EZrVbA/8PJ5FKSwabZMbe4TiAlqyqfOsR4PaiCGUyW9hMO4Zk3sZXvdD7dEv00SzLNUfNmG lpg7DSHw mtNUi8/7TxqDSfiIihxltljLKgMzqQYX6X5WD+XM8z7/iE3z+4sjCMtbGc29D4HJAMGk5VBMyGiEPYQFmva98AG27iXN6GWfTr1NMxg/5Y2VBVrV7qGo81b64y8WltJX53C93iPXP+n3qGbdMofOJc5bgpMCGy0GM5rkvI2DNzN7zxi08wMjxzIieRZJE+5dmzfdeeApmQ3k2vNaQHYPFvrod9DQKa2F44/uT1DVnOMQUyLi+ebqJkUhiw3iH/RG15uFo/ydU0+N7aCzMrOULG5DHF4ei2ITGpcJSzxQFSbOHyX8FlGv3t3MswsJqddajd9Xv 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(). 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)