From patchwork Tue Oct 1 22:59:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13818971 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 8FD7DCF3189 for ; Tue, 1 Oct 2024 23:06:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21D3468003A; Tue, 1 Oct 2024 19:06:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CF1B68002B; Tue, 1 Oct 2024 19:06:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06DDA68003A; Tue, 1 Oct 2024 19:06:07 -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 D73BF68002B for ; Tue, 1 Oct 2024 19:06:07 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 926641A05DF for ; Tue, 1 Oct 2024 23:06:07 +0000 (UTC) X-FDA: 82626568374.16.D196E47 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id BEC7540014 for ; Tue, 1 Oct 2024 23:06:05 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KV82DSy+; 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=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727823926; 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=GEiNLGIiMXg/p6vgOFqkZ8cwyaFCDmtOtstx+RWKpTI=; b=Z6dMPi6WTwSCysvwAiFsgio5pVETQosF/9WaEf71gzbxjcKPFQivilWbjO+zgnUJCDX1o4 AVeu+7c3ViziKnrqKfHmMHBHLKrvMszNUsWjyNbvDMF5JNu5aOibHxmP5QirbHYYkWhEOp 3HYimC5jNO1aVzjY9WPOKkgdVRV+a+4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KV82DSy+; 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=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727823926; a=rsa-sha256; cv=none; b=X8asLsxzyU++JAydIeRW2GKxwjBAl9VVusA8avzTdJWUv6rnMThmprDkwSkOHb1Kj/tjpK NW7a2ws/gX6oUDZNo9vW39zsKn+79B57k8lsZj/riJrkUIp4eU+6eAPxK2XeNBTS+Cyfvd 29cLXo6XB7paXfTl/tRadNMvFW02jUc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BE7925C05AF; Tue, 1 Oct 2024 23:06:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCF33C4CEC6; Tue, 1 Oct 2024 23:05:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727823964; bh=19z3q1N+rcWG0DFUf6My/1AgzJOufQ/JNcKyEmN/p3Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KV82DSy+ohyCor80Y95ssnPy9/5R3+2W7ZiIGHy2LQHI6Qf9BKg8XMS1rPgzsWRQ0 Edh1B3qMwJYXXNeP7VutuQW0zLERpKCpf/wtsDgrsHhY+h5dkmwOiBJFlm0uf9JIh+ hjq8BSsizzypVeePrI96IRQA1zzWmp+si/1bWCfLrobtQjK2dWwPWfuufQBDKMlsmV i4U5ASjpODqfmZ81DURKpo9lHxoSF1hTeoZkVHB5+Nd7TAMuXbx1Ntu7CqwGcd15QH u32ryEa7cvLG+XK+aYa0ohKnI2KqIE3yjYxTVUHdi6ZhxfVTpFsjbNfaV1IwpcnWbe zIBOba17Y7QIg== From: Mark Brown Date: Tue, 01 Oct 2024 23:59:12 +0100 Subject: [PATCH v13 33/40] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20241001-arm64-gcs-v13-33-222b78d87eee@kernel.org> References: <20241001-arm64-gcs-v13-0-222b78d87eee@kernel.org> In-Reply-To: <20241001-arm64-gcs-v13-0-222b78d87eee@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 , David Spickett , Yury Khrustalev , Wilco Dijkstra , 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-99b12 X-Developer-Signature: v=1; a=openpgp-sha256; l=3654; i=broonie@kernel.org; h=from:subject:message-id; bh=19z3q1N+rcWG0DFUf6My/1AgzJOufQ/JNcKyEmN/p3Y=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBm/H7dLuslwYJAZsSlXEDHT3DZwfgYSUphJG7e7vub cxzbxKeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZvx+3QAKCRAk1otyXVSH0O5DB/ 44EHOBqEPw1qRb3OoYtvOUL4xA5H8ccsJm+p0AzKoVipAm4tchEtuDLsOdMHxqSDnIH/dwx2sV0/Tk Gbk80LlT1IooEVt16p1ksKqFYmF8zUmAJTigMph/o7VpMiZKS5FN4PXkjOGJM6h9sR53MnMjnu16He ApbNTjd0Rh3p7TyWmY3HbQkkrK+N98HfLtmVD9drsinBMvPuPe8Gpn6mi7C8BrSzzCZD9SmHMDtTci ctnUDPkgIRb0UubC5hzm4/faVEH7voFALnLFwIHwcysr01kl1zKHOGaFzDfa2iQoAy4Aj5dVrulfkn 2Epdx2z2EiYyemXE99DH7AhEO3braT X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Stat-Signature: b4fhb7jjgyt7fehmnrt1akt6ydaujjs5 X-Rspamd-Queue-Id: BEC7540014 X-Rspamd-Server: rspam11 X-HE-Tag: 1727823965-973942 X-HE-Meta: U2FsdGVkX1+lPCotl8QglmRZv+5hzdMc1MZLA26l6Gai/KuUQk1NJtYEYNPT7ZKyOwszJiSsobFpp2bHa7CchcaGKJGyeWPRaXhUvMlQaM26bjnz1V1Lu3GyNzBIxm6/6rBHH/tp6j41tuugmYH74NX605Hav6mqv43LwgheYs0kyeQpcmauZAwqtbdQF2hD3oDSMhoNvdkkfsGf9o46mR7uKSygtbxCPEZs/0Da2oweX1rB5PXJg4/UisCfmdpE0gw6MXM3JpiKVarY/diD3MnPaN+HCrSYx/ZvIAj0JY3wAmcagBHtHfjOODLQNL4CB8G3MX8pgrnrd/i+nCQIb29WwzODqdCQvOTrxU5g1KWuYrwTMdoR2Bu2qqzI+pcaFxwCQOlCUCBx5iJafDR6urQGJC4tSjR0o0aySC4+deuVhm12K8ZW8gasIc+pEnzO392X84NDWsh6x+aUy6yYx87V0aKO5qL87mzyRV91N2lWBTspFvD5i6JLfyVY32zjmciL1UVWx3eVdU53d2+kinxJetfmg8SYAc5/DDRRBiYTsjNgOvcDnUhXSRig+kX/lcux+HYsh0p6qpq9tR79P/7zrS8eIW5n0QuLzqpLU/ynRBMwC2S87+dXTYcb6uWN6aRtLk5n0FrlPOHV4bETH+rFtW9/14NXimyfyEwimfhYMAbpwm2CyjJ11Wt7c06zUA+YmCh4lrybNb1K+l328laFWqxTsjq2l8M6OdsgFn811CNpUH+b13Xs8M8CmPYLLOEpNPusvq07eM/p8rohaZSPUA74OXqLtkiahU1seA0HkonQEWH4CcR8BABTuJMXof7nsJz6d1dpH5S5Qd3l+530giZwi3639+Ce2ap+cHXZdBQ4Kf+NdjnCy81gqMVGD9XUwxUy1rYwl7yAsiMsX9b5aQMBE9ePJ6Kdu0/Umes/mat4BzmnI2b2OMwhjbFDN4ak8WsrDpYNWSsjE0S FT0T1Ved 1ttgnVYSTc7YeG/eU/GqPhmVVjzEZExx/HpfbZiURq/+3ZR26mOA27gpvCCvDX9ewoDXeAhfEazCPtq1pIKDBGGe6rkY137/gCXTgq5w6bbaaPf6diiKGGJShcS8bjKmXHcPqh/eTtErnp8GF7KtX2mB9EVy7sdPf2JsgxB22dRQ+x0kCSfNyUs/wF3gg3O3r0i6SKgzplgdf0K+QNF6yclVQlTG/jhe24LtjHfoUvefp2Vb6FK4f5ZDnYDiLyXk5StB+rdgGN6kzx7CX2o72TdVZn2GYWCxwch7qfryWmH8WjWh409FX5fK9kxX74DLT2n7CrB+kSrzeHF5Z0d3M1HCyhyOirgPsoY9VsB3utSREJ0+au/CwalwobDrQkZc8ZwZj 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..1304c8ec0f2f 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_HWCAP) & HWCAP_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)