From patchwork Thu Aug 1 12:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750413 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 C7387C3DA4A for ; Thu, 1 Aug 2024 13:01:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54C246B00CE; Thu, 1 Aug 2024 09:01:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D5726B00CF; Thu, 1 Aug 2024 09:01:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34ED76B00D0; Thu, 1 Aug 2024 09:01:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 168676B00CE for ; Thu, 1 Aug 2024 09:01:20 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C36EA140D6F for ; Thu, 1 Aug 2024 13:01:19 +0000 (UTC) X-FDA: 82403687478.15.CA474E5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id ABB2D4004E for ; Thu, 1 Aug 2024 13:01:13 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eiQC9tfE; spf=pass (imf04.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 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=1722517229; 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=zhvHto6xlC0sMVxu+XR+6Lq09w3eTjsAAShqJEMtBLaWwVzrz16zKvY1xSqk/lCZwGcu09 CC8uL/3tolD0ZS2Z8xvWl/VYewrLdcAV5u1rEu+W8+vqi31QYcaiZGQoA02WGz698DVWmg KgI8vgG2+2Wz1KnftGqRPvbW6yCN510= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eiQC9tfE; spf=pass (imf04.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 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=1722517229; a=rsa-sha256; cv=none; b=gXU/MOKIdaV47oKlPeyFdvoW4wE1zqBc3lgcNwmjNoc8tUKLUaYZaoOH53rOqIHOiAgYPI zS9qlprKlc/Me35u8zBQBt+YyV009UyZRs3jXKZEJ2c5uemwMxPVqqCPDDm4KETWfPuTc3 b0b4OBAw6A0fI4lnQzwCvq3HsmDnny0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BB67E62862; Thu, 1 Aug 2024 13:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 760D5C4AF09; Thu, 1 Aug 2024 13:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517272; bh=LmUMQLV4QzyWbEviejJtcrr2Je4DeKbVGxPr/Gcjy80=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eiQC9tfEj2yzbkQUVXuEHA5FOCUQHlZsCNGDpYBeDhIZahyslRfPpjWdlSGLz6loU S4s88Lq5J29Pt50M3T98bU6+aWK7vhZwQgr3yZ3Y7UsrlpN5arpGSPNb5Rk99niNo/ TgsAQutH5c759cE6VN50T/zDAEZwjnkXlQWXW6N8AZRTv1i0lVUaPYG7bnMjaD/AXJ 0dv7guXmbq8WvESmD5D3celWtH45rjAsGVMPjiHlxN/IJUvQKYAQsJrv/XWHTRNgNH Kw3X9fCFajCuE/P7ul7zOiyesfJYpFAl3j/nUk4Ji/lEVLP+EYu+9URKrgefd5yVn6 Ui0PXtb0gB6gQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:07:00 +0100 Subject: [PATCH v10 33/40] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-33-699e2bd2190b@kernel.org> References: <20240801-arm64-gcs-v10-0-699e2bd2190b@kernel.org> In-Reply-To: <20240801-arm64-gcs-v10-0-699e2bd2190b@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 , 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/pANAwAKASTWi3JdVIfQAcsmYgBmq4YfZHSTRLe1W0pE6ZV+ChRvx8M1mI3slzwhZw3O nR/3G/6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGHwAKCRAk1otyXVSH0Da/B/ kBN10pM9iQ0M7RJ7DnXB/XtakgurlZID9xXfbmSA521fi6o3bzBiw7Aib7wVwjLCx7C7kZevZNYB0D gUkpZv4ysXJ78OKkGw3ePtUD+gbK/YXk+qfsu6aqiNBo/6kIPlInroTz76OU30v5XYBRtv0qGjr8z4 HKl65vUzC/F7YW5uYWYbJg5qIroL3CNndMIbnKDTDBg/YYNpY993oea/y8Y3HxOCrMESy0p4Yhv+hi o4cUmtfZidJsNsh8Eu7WMIaoGJosFAcaEAgp/x6nFlkooNF89WsuySwLaR+t2/ZDSMyAcbBL8OKKR1 /7etPpNbJS7ZWvNxQ6rNYNZ2bSQUvo X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: bt39ck4hrzgikj9ewf93o8strkqread8 X-Rspam-User: X-Rspamd-Queue-Id: ABB2D4004E X-Rspamd-Server: rspam02 X-HE-Tag: 1722517273-103507 X-HE-Meta: U2FsdGVkX19zb+s5JB40+XSrwHFvqVezfi9rGCn9VO/zDCxUEWHnZd9KGMRyaL1FmayKdRX/WfNNH2Y3RlwNM+MM18ps1YvcWqCPUk7gk9dVHac1eE/4uUrM03f672Ajy1bBWXojp01H+MgSmoevxpcqpofc8pVlj/ThuvwdwWnD/k5PedZdCCIDqfuHADPVW+1xbPL7U6ivsfWgZsEgOJKLTwvFc9tRcu3qMvt2jHsdezzK2Cl6IVNLFzb2nPhsErwL65KJ9lOpkL0PbMjuf5kufcgZB1YJe0OhQ7YekPo7jLeJIaOmxvkTNS8fH+t7HddrbNP9w/WdqZJuV8FJKTY0vilZUfW+BTrQO3C5yx9JiKZX/7eWfsl0J3dfi+jRp+ZHGuYSct2+QqbDCbNx+YGsOU1FzAMXfIA134rErejvbA1MuZ4/NUozz32chB4W38YVxqU9FUWgKbXHhNj8hidmciIh5GRpvza4uJwY/xFMjOsFyp+4GjKW4QRcmMPZkibwlT9KZxfWn2Vwn22tmO1dUV6efRx2SjMGgwD7ntN6401sRxSHXkS4761X5Y+dX1isQZBfOoncWvJXaWXcgvCd8rRS/YhMayMmN40XVAMBqbLGpg53Wl0KcBiB1HmwJFSIRHlRuePlXFaaX2uw06kX2A/eExJkJTb85ZnmYxkJ3512kJiIm6KkzObCzNQZsoYdOlouwjfyBJiNldsDS3F4Vq2famp3EhRIIxJo7K1ry2fsWblZlQdVfown5doQBs6LB1sUtb/IcQdo3ysKsuOBWqnwPv75wCs+oAUt+WOrrTzTRm0WmCysJzW1QWPBSsrXj6iEpmbsHfv6R2OL7cYwdUT5ZLCrjJavGM91IOUc7iKYuv3kUmXHq51JFNoZ+yH6MfEC8pawURKB4yxf/HlAhF2wiH+z9fMmXpatMzW/ihHbL3GzacBr609RyTMr5s+FCo1IhlXCtGwBwgm rAPWK2YX fRGE2W5VFCb0aHHx4NjfM2LjIa6+qTw4It0ucPFn1O42ldpFwNU58Eo4SoAKYBwMDtnFl8jsqMvX1F2icN5r5ReLMIGEqSx0N0Lny+A93w5YRAyc33od+9t/inknpqJdqqAI7kLMNGN+OaQE8kSOLc9LTWn5H0DaFJ//cpku1ORzBdFd2ST2zmErpUKRkPBUDe5K2q0VDlfNoxdj4pZ2sy1d7nDRQXbEH8BbNvYUlgf/YSxMcp96SW9+Ka9WTFBRJ6SKTFuOUWxqp/D7C1jqZyPTzY45DJ7HuE+yrbSQYrtPcFbfn6DceAnTrZ/PXABvzLkLcgOhL94wABE+hJY8q2JgRBniSDxN2SDjI7K+3EciprDUIq+Em/hZ5YRaxMvu3NYOk 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..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)