Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3562842rwb; Mon, 7 Aug 2023 16:06:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETMYm2lDnWi27NHkcyMGKo7gntmAdwp/wQOfILHKFFbOUZwyxd2LE3BG6xRtv38YBbaJs2 X-Received: by 2002:a17:903:1103:b0:1b8:5a32:2345 with SMTP id n3-20020a170903110300b001b85a322345mr10152025plh.22.1691449604502; Mon, 07 Aug 2023 16:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691449604; cv=none; d=google.com; s=arc-20160816; b=BnID1HbyZUjz/u8RnYZvBOpdn/qFPq01qUOZ6dKq8msGeRWNhVdTbX/4yHlb0rLIsU /advgo8gkwMm9aKPpF9PmDK9jUNWzMeCwbf1G5+tjm4NBwedtgqVyEC2g9xG3iE+1wfo ugxcNQo0sFnQwbt2VI8uyUbSdvdRbuBDoZzZJb8JxeqkPtodUV7A4aO8J2FM36Dj8BLi aKtDqFIMm212/sAfxhY0dCutWy1k2N92N42hc27iyl4+u0us96M8jAhQCpPOJMMOfRly i7I5+NROBWTIQoB3xzpPFN3IK2lP7g6O7ZCQ6rUSBVNWb52xEqt1iZT8x58GY/JNnpjH RLDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=nDVR3fn2xd0MNSzIh34zJUX6KbyaSvUYB+1ILixlbyQ=; fh=EdAFSmIgUzZTC6WCy4Jg1wBZ0/m6m2d/OjiRUJ3BsTI=; b=Qga+V3JObXETwLRisuVIaUxb4VeW7H2z7aoLB7+FXbWpYyH1rzNRMDY7LPpIjyGK2h KJilRYDEusn5lu2zaLpAMjRD6i/gUHz0yZhseudyw6IztC8pGdtKoo/ZjmI3xyDGnAZt t2M9bj1OMRk5FInj3Uta9/WnplnuuI8pYH/iEo8HeVT8TdNPuqjplPKfma5IOeh9R9NG Clh2eheFMFqzud48yY2P1NLRaErlgpHLRWygcVtPM0O9/9qqEWzvRZnw6Rsr9X9QAX8S eg6XmlBmIxdR4m1DW4giSyFJKxv2mdwbcbxIoeofcccdSDaQjVQMUkjgKHcpK37Pjl7/ 9Z8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oqomdH85; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a170902e34500b001b9e8482700si6113735plc.246.2023.08.07.16.06.32; Mon, 07 Aug 2023 16:06:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oqomdH85; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231718AbjHGWJK (ORCPT + 99 others); Mon, 7 Aug 2023 18:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231719AbjHGWIj (ORCPT ); Mon, 7 Aug 2023 18:08:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 827DB448C; Mon, 7 Aug 2023 15:05:53 -0700 (PDT) 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 0D96B62291; Mon, 7 Aug 2023 22:04:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A85DCC433C9; Mon, 7 Aug 2023 22:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691445879; bh=Nuasx9Ylf/ySuoGV/J7jU7muHvsTQeng/1l4pki2YVk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oqomdH85xVI6BmcDXTpgHh4UlnNkfgbBqDewczWS1Nny0bLCpqHLQMZ2yVHmelPyJ DOXHTAFajwNq9EOW/SccMyYrcWr3XkxSVtiNpAjDzEeNT1ACFrPSlpQlWVrAx7sJaQ QgrepD73UZaXrOsnk/dnttsFkGUxtl988T1WSQC9X6O4mNZdLE4Zyxdqu67WSssa1R 0vonamwAx+mrCYAzaCHAIVI/vrmawbET6I7BoDY2GLFVwTHbDFSRaY6/SzIh7zQ/vP bgTZ/eW7Fb43SVWuk1VAv1pyD2vV9GZl/kOfOjyCJlLnKvcq8WUJDlSssM0uarz90B xrQBZnzbfEDmw== From: Mark Brown Date: Mon, 07 Aug 2023 23:00:35 +0100 Subject: [PATCH v4 30/36] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230807-arm64-gcs-v4-30-68cfa37f9069@kernel.org> References: <20230807-arm64-gcs-v4-0-68cfa37f9069@kernel.org> In-Reply-To: <20230807-arm64-gcs-v4-0-68cfa37f9069@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-034f2 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=owEBbAGT/pANAwAKASTWi3JdVIfQAcsmYgBk0WmvLXsYxqKRGRlefxeZBqhl+PK999pZ4YsuCUid ++xJ7IWJATIEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZNFprwAKCRAk1otyXVSH0GduB/ iX6rAEGPgUi4hoQidaZeyfLL/SAuncTAhDLiJc/dN+37eF2A/eLomNoOwnXVaMbkfTh/HOZs7RbOaS Bf3YsuKitPDNaiL6pvJOBA4yU/0JTtG1nBy+55u7Jnmq7nPA09WektTZMH9xGQ7+7ROwjUD24qlZpm tGM/4QTQTT3XyIJrAcUsW9SN2wozrrMk80KWbc8ICQgTVDiOn9u4NFhJnFfFBG7vKs12nZFri272q2 F/xUuvA0cGTixwRUDkGPwBoFFuYvFgwT6G5cL4ECG7eBKoa+o63n+5Nq/G+c/9Y/M214+dR3CdyIZM n6Ext4XFToBJniT3MCC6DkP2ofgtU= X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.30.2