From patchwork Sun Jul 16 21:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13314963 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 66427EB64DD for ; Sun, 16 Jul 2023 21:56:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08691900002; Sun, 16 Jul 2023 17:56:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 036F38D0001; Sun, 16 Jul 2023 17:56:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E246F900002; Sun, 16 Jul 2023 17:56:07 -0400 (EDT) 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 D2AF08D0001 for ; Sun, 16 Jul 2023 17:56:07 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A5C561201C6 for ; Sun, 16 Jul 2023 21:56:07 +0000 (UTC) X-FDA: 81018833574.08.7757B24 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id CE7271C000C for ; Sun, 16 Jul 2023 21:56:05 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P1h9KVdb; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.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=1689544565; 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=nDVR3fn2xd0MNSzIh34zJUX6KbyaSvUYB+1ILixlbyQ=; b=5fKvTR30+kBocDnQCuHv6iRKXuE2Q+RLSKo4YTyljuEMD0ry9n0rhPOy7SY0+L5ws54tqP OACgN3dsqF4FhA8ELgtS5gCzJRS1IYMTfdFqB7X66WXPNj1KmLfSJVdGWUVE9/p71ekdUy GfL8ImVBYgEephXxg1JSx3aIZZH92y0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P1h9KVdb; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.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=1689544565; a=rsa-sha256; cv=none; b=mLX9mR1WLAMOVWT8mW7aR5rXeRDMVzLSNJwgkKyYu9EMLjM3VhE8UJEAn84TUU2qdhgWzZ AoVGfhcWkjsc3ZmpusJCh8YT/sxt+R9q7Ov8VgsJT8Xy14+LgpePPT2znAeVxMl5jZd6MV r/pxe9hHxnQtclKqdgjNIe/75BSwXZA= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BFDD160EDC; Sun, 16 Jul 2023 21:56:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79391C433D9; Sun, 16 Jul 2023 21:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689544564; bh=Nuasx9Ylf/ySuoGV/J7jU7muHvsTQeng/1l4pki2YVk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=P1h9KVdbbAprE9cGnSst8fVG40lH+zlIEa0ULjrrdOGPLgDW4ZLLFEN5ZvPGWvuMa gwFumvj9BBOTlWawxnw/4K3oU/Lx7yaLI8jpeumEkP1wRajuWGl4CNn0PcnQ4fCbKV CN8DSHDH2z1aSTnQsbqAKpaQjDfLYXvHO4x5r+odKnwAdtD5L8GlPXto7ze09j0d7/ facbXKzFyqhBddfWjNd/+oUmRRXmprqLZavow9m1hLr1dACcQuJQmZgJzl0K6Ti/XD KCGb2Ik4YuAZH6f4OVAXQ9VVA9bJtItttNHqhR/A7QU8GcLnra6YSP0t1K5xfmQ2+/ Eyj0qahxmHYwQ== From: Mark Brown Date: Sun, 16 Jul 2023 22:51:27 +0100 Subject: [PATCH 31/35] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20230716-arm64-gcs-v1-31-bf567f93bba6@kernel.org> References: <20230716-arm64-gcs-v1-0-bf567f93bba6@kernel.org> In-Reply-To: <20230716-arm64-gcs-v1-0-bf567f93bba6@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 , 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-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=3590; i=broonie@kernel.org; h=from:subject:message-id; bh=Nuasx9Ylf/ySuoGV/J7jU7muHvsTQeng/1l4pki2YVk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBktGan2iFZRR56liRBNgBrNa8Q9jM0eX1IYZHjq6q7 hHCAKcaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZLRmpwAKCRAk1otyXVSH0NcQB/ 9J49ekWpVX8qtcugCCDHGBMz9he4/VOu9aJ5NstPp1veTJmUV3yzY3JsDEPe24a923q6CqdQgcnzA6 RomVBFbK42eFR/gYU4dXyyGnrtStUF9uj09jC/gDfRgkT/PD/PR9hFgn4oTwlVX6hwWJyeKFTicWKU VOqcNSm+8D3R4cdhbVMqYWEOW7Vok3SwbcBa6X3UEVoqSed9j2MPxW+iYYyZfF8HiggQErBUqMKk7e 9Cf8LbFP6DgjzMI5DTg4Qc5zcRTZ+IxsBv8KNdFJOhxdymzByoF05oqQXaf+xJ/IdpkWIeCqWhWYqd 6tR4dDTM9BacjC7TIEH5zv3ob5DiSp X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CE7271C000C X-Stat-Signature: bjme3agiykb9oh3jfq6pix7ywkr5oykh X-HE-Tag: 1689544565-290135 X-HE-Meta: U2FsdGVkX1/XlBka+vt9Gs41Y/z8NrcRSw/Dk0fJwDnGE0LxibHmNSHR6rT6q4ET7KWv+NRiLtm/hrk7y/OtHjv+c+eGIZNLy2InERNz0s9etsdZOu+DmDTPrBEOjukKgA7jFzqIfJpCccIik65RB/ypvA1PicBTjqBVJ/k6fo5WX/zD+QHzonDL1ay/NayIV6FJJWGA+wT39gvhwOnpdnWiJT7sLDKY++xAoPSd5XAj44XKa8OLZENUGfPcAhTnuVGvin1ThYZivMR1W2p/UcNBQU89mpQ/yWNRCtnxPuQBQ43ML+0yila3FbhlISWIDctzibdRsHwWG86EEM9u4+Nu+mjm5heRM6rDqKp8T+l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000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 222093f51b67..1cea64986baa 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.h +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h @@ -16,6 +16,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)