From patchwork Wed Nov 22 09:42:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13464426 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 E3C52C61D9B for ; Wed, 22 Nov 2023 09:47:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 888D26B05CA; Wed, 22 Nov 2023 04:47:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 839286B05CB; Wed, 22 Nov 2023 04:47:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 701416B05CC; Wed, 22 Nov 2023 04:47:13 -0500 (EST) 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 60CEE6B05CA for ; Wed, 22 Nov 2023 04:47:13 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 47D86B5B00 for ; Wed, 22 Nov 2023 09:47:13 +0000 (UTC) X-FDA: 81485111946.07.6ED838F Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf18.hostedemail.com (Postfix) with ESMTP id 508D11C001B for ; Wed, 22 Nov 2023 09:47:11 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Y9kSWTAV; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 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=1700646431; 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=WdLZmli9vg8t6fe84vUBdKw/nM+D1l+ZQgyfXgsT10E=; b=OhqqU5/LWpdtULel67Ak4J2qp5XZp/nxmYsELjJfSc344jWuSOwdYdnhTVymCLH7BYqTs6 bCXb9Ki1nxdU4Cy5lQ4wCnMiRiulosvgcafVjPZyTfX4DGLlNI7N6YCle6RgZDfJi3F3z0 RfyFcgqRssSlBwP0j7TogThaOfzLfcQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Y9kSWTAV; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700646431; a=rsa-sha256; cv=none; b=dw0FPkeKG3CmQpyQv5FxLRnoJAIpLtBRE4tQJFa4M5ovyXM1LdhdW6xTobjSp7rxTm5NjE BUjP/Zd7IFXpWLBw5Pcf4J6WQxVruytRV0iCtIxVKjFwa6V4QUI7Vwn4dKEcnlo6gdFxf4 6lfe2CRR9y9tcrK96pFREzjD+/lIvWQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id CE428B81674; Wed, 22 Nov 2023 09:47:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88DA2C433CB; Wed, 22 Nov 2023 09:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700646429; bh=b3DUElLZ+Soh0Lccqy2ZSImkcM7zO9jMiCyb9nDJSwQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Y9kSWTAVK98zhtVsyhDnKInGWdD30T07Ake/yR4jhC/+XLRShZE6i/o1V6NRBUhLz Dxrc74iwZWGjxvodTdGkItzPGoLKXLdxFS2Kgf26ynO1y5UO6mFbuGEYFRezPYZ3SN BJ6+Cpt7eYespf4hYmoUEvmoRFweNTPbyCFCCMewFKq5ZNXVlAgNurJYmvFMgcKAoz 6A5VkqVZkQux3aS2rdDhZOMzrDvsDBVF7gmWW8Wtj1s1MwxG9PDWzmbqkEHXCrQaYg nTZt+W8U2etS7jdzyurIciWhdn9ueX+xYQm+Qiv9r0ECdsUBfiYa9tDRxTCLuOOVc8 ssLs3BiYaclDw== From: Mark Brown Date: Wed, 22 Nov 2023 09:42:42 +0000 Subject: [PATCH v7 32/39] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20231122-arm64-gcs-v7-32-201c483bd775@kernel.org> References: <20231122-arm64-gcs-v7-0-201c483bd775@kernel.org> In-Reply-To: <20231122-arm64-gcs-v7-0-201c483bd775@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-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=3590; i=broonie@kernel.org; h=from:subject:message-id; bh=b3DUElLZ+Soh0Lccqy2ZSImkcM7zO9jMiCyb9nDJSwQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlXc0Pq69NiV0DZvuQOBOHTJq4Hskdu8ueWsh0A OXrPDovxWCJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZV3NDwAKCRAk1otyXVSH 0AvKB/4gIm6EQumGj0Sww0FN0GocO/C+BLqTbwD6sziQA+cF0OfObYvSHOKFbMlhgZBDcbxRj+H 28uewK7t1SSYel2V8C+ykywrGEfBsUBjsriI5E5CfKOsPUhqtYwfEvHNoVySVobx5Rc1uodWehE wD4kxoZug4GzX0A1HdT4HPvZzCYUzCDXeyINi68DPqWrwit2CvDnkhjf8gGKqotnS4KnvHmhtcG C29Newlq2zS23qzht35JcPjfcn8Y1kR1IcN6GlS81iqTMkIEXYrjUAOl11+nDynG8e7kSOrapK7 71JfVueE4JJPVZeyyV05a7VJNsMwlN+yEcRjJzeJj1TAN/mD X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 508D11C001B X-Stat-Signature: 6466a5qf4pubirksbc8inaoyq1dm5nu9 X-Rspam-User: X-HE-Tag: 1700646431-286131 X-HE-Meta: U2FsdGVkX180SLhwsj1Ug1TRGrbThn598Imzgg/guTzNCNzQqupskJO7lrpRL5uDC5GIWhqZ17OHl+AliRN8s1etO59jSo9sm7z2VBA3Kg20nGASTQM/9fu4iy9oEDxR73i/98QS9o3Akcum88r7PWpObHZ/ls8TkCgwTizwvt/rbOxjDiRHkmwUQ5Q2nccauILuTu7Dtkj4gqUTPcUvGsDAsQ5TXozE/i2fg7E2mlQy/CqcOm5LzcyDUC45NNbJY169lYJpV0DMWGXNMJ1QbWikGuDXaxy7PBKkHxt6JlBJH06MgK1op7A59rOUVVui2DYRJKo+3kpNRvLdJfCaQ+zAlHPx4beExlrTGSveOcHikSB+qDYsCVB2Y8oeQ1r5oTULP0irPhdtrcnJE512yKMRt9Sv7TfAasZOvczxmJHmM7iqvucH8baYQYeQ/5Uy4xUUdoduc6PjOAQ6GpH0mObqG9Gww5uYFCXKs+7/5Rc7esDJi7ScmRcQY5qn+guHuNemDiUDrb8NlMggsA6OVLH4bcV9vv+Loi9/gU0wIYqgNrNRuaSQfXMtmMlap6RJzymGLeYREFF04ZonaRMXS/guG2rdB3arfydFH2GDwS3Qk6jMh3mtYNUPnVHsP1GThXtEu3EBY7a1iPRqKQDplk2s2OoipsvHZ/N+bozUl0/lGdyNd3B+ox6A5FNCVmkf49+ZBMmgaD56sq+QZ/Y8L3Z1dfv9ebFx1O+AhToPHrR8Bzm7GmNJ+77Irmf0iagRE5SyPhJoXkM+7RzJg6uwfebOm0+ZBIKLLokwY2ysDfDuHA0GrKlrjKh2EJa0StF6rJiepFTxs43r/qGG0Nl/XODH2tg49MaO8EH1kqM7pIod3p2NJZXg1mBGc99tHz5gT/CEqjCTBhQMdOsi9nj9D/8BpbAhN5RVJ3SZL+HN9VWQoQpko3to3RuXF0riz5SdbQdkR45Z0JGxmxDFzLX q4ICUA0s 6TxUlPr4X88X4WlT00hK1tpdsdPDKfTvN0UpyKDlAgbUOsDsINjuYO6Z2BZAo/tHBE8aHChj++1kU04xebAWhFx47bkrBJum91V6XkqyJpJhkwzT9YDA4cJSvajkZkLjPHUJjbKmjx+Fyo4LLYPPcHtT0IZOuGAtK4UHPAiCOUtCfkCJcbUWbojxgmhdwS3Si/dMolrWExhfZuhebKngO9aGEhCsxN2CH5JWvLS/qkXrvfhfFPcf2RHNbgQTiK+eTetFE4B22VlRWMl8jMumjiy/t5uzb6cmTaAqjG/r8dwrHRDHkoh2wggqqSzHY1aKqZ2R2 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)