From patchwork Mon Oct 9 12:09:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13413533 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 683BFE95A96 for ; Mon, 9 Oct 2023 12:14:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05ADB8D006B; Mon, 9 Oct 2023 08:14:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F273B8D0031; Mon, 9 Oct 2023 08:14:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9F9E8D006B; Mon, 9 Oct 2023 08:14:24 -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 C3D0F8D0031 for ; Mon, 9 Oct 2023 08:14:24 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 98A0540224 for ; Mon, 9 Oct 2023 12:14:24 +0000 (UTC) X-FDA: 81325815648.23.C986EE3 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf20.hostedemail.com (Postfix) with ESMTP id E452A1C0005 for ; Mon, 9 Oct 2023 12:14:21 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aRNZd3pI; spf=pass (imf20.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 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=1696853662; 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=2p8CTEgPM6t5PCaOK8UwcklXvAajMJ8mc1DG9bmLkXIlDE+xzTFs1hN4pst+bGQdZbz9c9 WzQNJMBXuT1t+B9SbLPqpvKr4BOCgPY+CkV274ibTW7FwxhUFPpNU32NmHDcSZ61vFOlbG iyyV6CaWxU0LbAW2MFgR/C4Ug0CCKbI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aRNZd3pI; spf=pass (imf20.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 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=1696853662; a=rsa-sha256; cv=none; b=U/hjZ3rl0o7MFbzNcwehpn6zex+u1derp0FHyptbIB2vPmxA1pmrde/jVBpPDQKdETG0Ws JORLZdy9fst0WmbFBNIZ0UQ+xgt8XzZzTwTASeBnh8b7pl6opuXxbFJ0mhXDWINNeUyEYx hgEJYydbz2NKKg/rBpB+JVmnrGSegQ0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 977F4B81186; Mon, 9 Oct 2023 12:14:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3630C433CD; Mon, 9 Oct 2023 12:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696853660; bh=OYaAyRMLSn6kTs6FMYnMtTS8W24+WIO4Ly8HwzP8d7o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aRNZd3pInrVeMdKBw7H6QrC9eqFo/kLOrdLcZwp6V+ul7HAC9gLTUyM1GwvLQB1xc 63PWfOonUjUAaZfItFjlrBSYj0C1UcPcMcnTdWr5qP0HwSHUCIy9tFx5enWS0I8iGd wjWnfqGYjjOFM/9uuXGnODB0Zd9KJOmfqfQ/gBUBt2IPK/IELuF8BE8/T0iAWJl0RN mvrxsrT3AkWz/G0c38Ss4zwSuGHoGW3LdHsPvzWcdBrnOND7PG6AsRZFb6C77RTVUz GIOt7HzNDVv+43GI4Uj9im0YHhm9U7UGFLKfwCWJ1Im7sMe7ZhKQk6x5XnqFgvUaas Y9JWtr+JTJzBw== From: Mark Brown Date: Mon, 09 Oct 2023 13:09:06 +0100 Subject: [PATCH v6 32/38] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20231009-arm64-gcs-v6-32-78e55deaa4dd@kernel.org> References: <20231009-arm64-gcs-v6-0-78e55deaa4dd@kernel.org> In-Reply-To: <20231009-arm64-gcs-v6-0-78e55deaa4dd@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 , 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-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=3590; i=broonie@kernel.org; h=from:subject:message-id; bh=OYaAyRMLSn6kTs6FMYnMtTS8W24+WIO4Ly8HwzP8d7o=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlI+2q4BjYkOhejyoKKvxOrxbGdTheXJOcb2eROkLO TpWR1lWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZSPtqgAKCRAk1otyXVSH0JmAB/ sF/bW4NV1xIXh7KwGzExoXmOWHnZry7NDDHROu0qS/35UQvrwfrBi6tTQNyeIn3v23ghEC2izYQe5/ xF4AI4iosNEQXMNfGRX3CemNMDMILSqO4k6FKtNbqu+VFvTfUZwG8xYNORtZ45iW3tBPk3TCpX09M4 XfPi8G9lx+Y0oWjPDQNtH0cOJA2ummMCDEBK2GKpN6raQ0++tWx80btDNgehnvMePinSWSnYZcbrpO 4YNGY4kE3Tbh20tWr65zqBWE7rqLO6TTsxbHF4VghVQs3K5htXUqYipLcCJk3YKHM8IM9rPSG4lWz8 x7N6aOifCEoSoXFiW/0gq1RcqyV0xO X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: E452A1C0005 X-Rspam-User: X-Stat-Signature: eo6gbbkdcjye5bdxcw9634ed5hxyfu9y X-Rspamd-Server: rspam01 X-HE-Tag: 1696853661-808891 X-HE-Meta: U2FsdGVkX19BFnwJ7lsZZKCPAAypOUJPofHASlS78TT/z9bRAGZqxvstcDf8o/b9z2FAs+eMAHDePFRe7SdVYoIFZLiFTgQDNoYf7PgrY8wNFDYfBpb1iKHzwjQOnLDc73WaRmFbv+XPsMuXzm+LljlmiyLtfr7E5EHs2H1fm0NxTy1xun52jGxPYAENBnWiHvCrx9IhBiN1+vqS9FSZkYXqRGoaB3UMw9tlfWlGxcyMJggjNVN2985Aj/nK0hh1TVL9PdMpxIQHHLW/tjKKObQcdV0D3dlMMwxHgXot7JTtanqTiMJv1qe/s/fal22e9Z88J/S3q3ffWXfDnz/LoErabf7jOWmTMliouLgaxqL8mNOGq2bLOCoPnBQYj3jbULaRhpN6xvfsUPzMp2BTYwT2CAo1hEvntEcPA054nGiJbyh4heltpf+fv2EDAVMaUiqoG9Ref7yf0nGRVYvag3LsKWZNKaLT0u4P71gqdHoiFc/8gIU2C+zEdTZfB0SynAcb/WrR7/7i9W66JE3q6XxMxMc2oILhXu3efj8KHSJmWtEmg/I6UoGqKMsm98aLWqNI7Cb0iugPocrpzWswyH7ysqYRLjOQzWtzikVmNJVFaZdd8lE2+FHaTIDIIXKHB2YMzwhsCO18TzRjDejFUIkZ3eHhHhFmPq1qAXJqx8mqo4eVs3Y1BN1PuoIa1GuGXiRwMqdcWckA+LjZ+NHtse/ZKMhAGn0SzqRQA+CWW5yD2Z1QZD+25CYPfJhB1sk4ZOFOcTJ0tOtY5NMZ+k8NeL1nY9invF926P/9rh7X4XyTC8DdMWm/uSZDtaB9fDehf5pnsu+fuRGkpHFlSq0xXv7l5Aesi3NZG4WKDIY0p7tCFfWwBOkl8A/kxX5wiG0ReNUTKFUlZGBvnb6Ogi8hTX8SwVpPFyVXbXBQ2OuAouHCaVjKd/Tl00wCjIZ9GISo3pTaE43Nxkg8dvkmUXx bS2B/VbR UGsvX0piEL2+SVtH62ZLHEEhOn4dowtUV8LSTKMowxTf3wxFA83/e/dR0nsCdN92CzuoPa2+Bjj9FxamT+LP+3bk7AveA8vWRxm4sRdMXzJ3UiK2t3Br4PGr4mDGIDxgKLqcvAAl8Tvaa0aQSvjbS7T+fby5JCZp0omo+g863R/r/g97EG92sN07FaChtYG6y7oQUZDW4WZbsBaUCrj8XzxzBBxIteV69IJqC+DIfoWK8M55cJ/44P8Cn1d0zmVWPWCyFRnBxMzAa/RhLlWTjrXQ44ENxBViafwvclEotaPBpNY8r2OK/wIXev9y4gezpiRgqgOXbbpKjIGw= 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: 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)