From patchwork Thu Aug 22 01:15:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13772385 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 55A45C52D7C for ; Thu, 22 Aug 2024 01:22:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D192A6B01A7; Wed, 21 Aug 2024 21:22:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA2256B01A9; Wed, 21 Aug 2024 21:22:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF4F86B01AA; Wed, 21 Aug 2024 21:22:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8FD5F6B01A7 for ; Wed, 21 Aug 2024 21:22:36 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 49B98140441 for ; Thu, 22 Aug 2024 01:22:36 +0000 (UTC) X-FDA: 82478131512.26.760F771 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id 74E10A0004 for ; Thu, 22 Aug 2024 01:22:34 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sgddyPw7; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724289689; a=rsa-sha256; cv=none; b=Fg8vsJkwx87OycrZbOI+ZRIGIumJ8vetPYlHdHX9CVB8qU6NbNNoXDIrk2YHXQNrrlyDKf bzOpPlBe63UInf+rCoEoMOGb/x/2McuSSajf6WPDLIGySZQdlaNMZFcJ+lnATalKrUxxHW AtIne/YOgyJ+Tf0ic9RLUfPa383j6tw= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sgddyPw7; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 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=1724289689; 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=hj3WhFaOCpjNcMMrW6j26CW97t/N+Ei51YtOEHgyON4=; b=5M81RxjCTmiyLYgl0sc8uyS8J6Pa9U92YaYqP6OZRy/lz/Pf2CmJdezkDflBwhEkvIoZpG Fiiwt9xKheQWK6t52wwJhpGih0peEMxjyAnYUTzn3QhkEKly5qG6KgRyCg+0bKDodYe2kj tXv1HnA+Q8JDjPSfRTi3Lehc3CvVvyo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AFFC2611B2; Thu, 22 Aug 2024 01:22:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03340C4AF0E; Thu, 22 Aug 2024 01:22:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724289753; bh=LmUMQLV4QzyWbEviejJtcrr2Je4DeKbVGxPr/Gcjy80=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sgddyPw7Z1foicBj1+Dwd0OVNyhela1sRkgvd3uEiArL8VEW02N/0TJdNFvw5V++4 /C/7otwd93MVymcpj46C8z5q50O4SDZws2C4OSqRd/jB49qKtNZBXWHghJlFUk1XzL ApHk1/XZ4srDxP0zoqO+/fE7UgbCRYDbnn+cvKODdG82BPDMs0taP5EF1uVsU1LdKg uxtr1i5SwMVGLYAYX19DRpPBLJ2x8iAXiFiwrImE/RKfn0n59P1lpLyzp2SKjUqK0t j6Tb7GDHfQmrpWQ/vKMt6Qo5e8ppKHyYWnOM47X6QVJYna9NI2XR9B/39w1AJdPyJZ tI6pcfPMd0TDQ== From: Mark Brown Date: Thu, 22 Aug 2024 02:15:35 +0100 Subject: [PATCH v11 32/39] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20240822-arm64-gcs-v11-32-41b81947ecb5@kernel.org> References: <20240822-arm64-gcs-v11-0-41b81947ecb5@kernel.org> In-Reply-To: <20240822-arm64-gcs-v11-0-41b81947ecb5@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 , 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-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=3656; i=broonie@kernel.org; h=from:subject:message-id; bh=LmUMQLV4QzyWbEviejJtcrr2Je4DeKbVGxPr/Gcjy80=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmxpE8A014o1ba8ECObt1pIIsJp6VtKyu0PKBnUq+q NuIjOzyJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZsaRPAAKCRAk1otyXVSH0BKfB/ 0SvpXRC4OAPHo+1ekhhDIAHk1LSJDcopbR3+m03cJg/4wl8sXxY8f5K5zb7Elff5CJn+Jhx/X1LqE4 kwFWiwcmB/pu9ysEraZZ8MjHTgjbJggAMbNKdID/sc8TqWPoqIrx7LXsVzmJX4XQys7y4T3p0bt/jw syN9O717x3qCB8Z/YBvrmqTL6igoXI7ObcyFFJ8gyTeYeOJHPzVLql5ZJ6AnL9p7Vha67asKSinhTP HDF/twrCkZzY+U/ehgwhIBjwIeHIXCxbrnnz5iicCTYdy46HUVb2yOfD+Meg9JMLBwpX9QTykIA/Jn PGkSue2AVnT+69HRVxr41eBvzI9hI2 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 74E10A0004 X-Stat-Signature: quctjaoe58teas4pybn5eh4rk4wy9nyt X-Rspam-User: X-HE-Tag: 1724289754-930574 X-HE-Meta: U2FsdGVkX1/8WLzUrquzcw3WzzqIC0GBq5rcQAPYEAD70NhmNO71Yn3cHwIaEqHJXxkonWbsQLn/Bthb+9U9lGf/2xn/SMwpY/lopjcV16k7c3Wo0/cHeynv1XCsyT49b28NR1DieLN+fM8ctZX6QhIhRKjvb9iOeF+UTRjqxp6Y0RVxTJhF9/XR0n+Zysuaf0O6yRDYbO0kLtFCkxhAPuU+XDgV1gwwCPfZodu6kM20fMEtf87MTzG1V9JbJwCyyjBYCpmDnU2SUMwZ9N53l9ZgvS/YmTKG+ItA6dThU/HsUN0SyVBRZDpApG7q+RU5o1ULuRthUR2rIQqxIJs6LXhhdmmK9/dhv1izxh0jMDdpQ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-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..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)