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: 196278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp995915dyc; Sat, 3 Feb 2024 04:42:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYRNL5K02o2xnDoxhc/yvWbWPqPLBQMcBerOdCKpEwr1rDQTFd4cwjrjnmFNyqVqVleSU7 X-Received: by 2002:aca:d13:0:b0:3bd:c44d:e561 with SMTP id 19-20020aca0d13000000b003bdc44de561mr10219492oin.35.1706964122786; Sat, 03 Feb 2024 04:42:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706964122; cv=pass; d=google.com; s=arc-20160816; b=QjotraEt/AtkdQNDsxgTK37I47qNaT+Olq9yeLXlSBcjqxNj7/xvAyC9m8RiaKyYgO ZpVNb/vMVkg95WRjiNJA7aZ1ABroR6lTyVxYYXsu0FJclb5TSeM+9zYyw6GGrK+6hzZM Fdzp6AkahOlwZ+RNSn801AMMbGGw7cOqwJ/TzYAv58VIuRU2EI6P3Ww+QOhJGFXEXEIA EQoOLYXda1H9nSkZM6rUoBzjjUNvo+aNBlREN1H5rnCGw4UMIAYjNhjuCNW6RMdwopX9 XATnCHXyR5g/jx9DpvomsvhYHyDGgX8T2NbJn297mWHyVl+nM9StdRv/Dh3rpZE4eOef AEVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=txc3X2V7CJ9ZdLUppYIcM2fiWiyeeo4/+q5He8/QHL8=; fh=Mb/VNeBACvGweiaq9w60rNxZKESizG9AkKjLUpijmkI=; b=HgvhnVPgMkAmr3AptM63dtYD5x1hHycwmqTsKfjl37kkRgccDUJ2PO7WQDdxib0K5M vkURt91csMBGDzKUTieGsSfM7Lm8s8BycaErbzDgcl3+RpkKerZZLLClKzH6A+ZHngt1 sVJ8cansYyHI8YDXJeLlicaqBpSqtLevFGM5OX8MsXSQoDmRVFkPICkTYmDPmBF080DB jt9CfSrVBNZB21kplq5SfBhMCfxusF2a/Z816tMhPn0mdky9TRyw3YUUDQEKBHR+uujl BsxmKmIVfx9ru2btSiCFqfJjA0XSX3dWLJixFdAKTYyE+w97ebLM1ZHuSJQrUHy2DKWE KCKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hJjcPh3u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-51073-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51073-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWI98gd64wWHgZqu2y/GEI5cA1ecQO+k6IGQstgU90hFnwHlKxyMerY7F8XbepSg+1yKZ5bCiV11QebRzeCO3T99kVqyQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bz8-20020a056a02060800b005cdb499a9afsi3205468pgb.108.2024.02.03.04.42.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 04:42:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51073-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hJjcPh3u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-51073-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51073-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 817D6285E1E for ; Sat, 3 Feb 2024 12:42:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 556205FBB4; Sat, 3 Feb 2024 12:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hJjcPh3u" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E7F27CF12; Sat, 3 Feb 2024 12:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706963592; cv=none; b=UkCzeTvrJPp2C8jQNb5L+KN5IoaRb34+1Scurn27nekcLi8DK2bsHlfjAornhbDMtuU+blvkGjxTIgZvKAqm+Ut3dfh7s2r+s19y2W1aWHKb3gyXd4mdUPoiE9ray1Lutc8SpKIETkKhiMhfUkQ3KZAZeENtdO2C9xw1wKIl+RU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706963592; c=relaxed/simple; bh=OYaAyRMLSn6kTs6FMYnMtTS8W24+WIO4Ly8HwzP8d7o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DNELQ88EYKjKx5zktklU1bCUDTP5EdK28GhRbLaBShL3hOCAOUgXoqn+6lYsSqvmApdhmqktNha4TiHuitkHIW8KT9HoJq5QR7ABn1V8zRx5jx+l8U/o2sStOxleTjsJkpsrciweam6l25W787N28lEoRiFM+g/hkf1O7Bp9ZRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hJjcPh3u; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789881612179351214 X-GMAIL-MSGID: 1789881612179351214 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)