From patchwork Mon Aug 7 22:00:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13345152 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 ED97BC001B0 for ; Mon, 7 Aug 2023 22:04:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CF7E8D0007; Mon, 7 Aug 2023 18:04:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87F0F8D0001; Mon, 7 Aug 2023 18:04:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7207B8D0007; Mon, 7 Aug 2023 18:04:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 625ED8D0001 for ; Mon, 7 Aug 2023 18:04:42 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3E9D780B1E for ; Mon, 7 Aug 2023 22:04:42 +0000 (UTC) X-FDA: 81098688804.21.99D7DBE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id 58C731C001A for ; Mon, 7 Aug 2023 22:04:40 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oqomdH85; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf20.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=1691445880; 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=jZo23Uq9vZkJZCA+NADqo4cI+zl43lS/5/oz1F9fG54X6hUi9D636eIuIdjIoUmIRbifwo TEGludfc3XPpE9uj7dq2Zxcrr0OFbxNqM5aCzVsltMefyrw+Phza1DyfgHnxHKdIoh6hj6 s39xQCstlYfW/Mo3hwN80pzgK4Fl43Q= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oqomdH85; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf20.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=1691445880; a=rsa-sha256; cv=none; b=p+BpRL1tx43vssm9m+Fjk6K7KqjZN/Sa7TAt/AlDogdXRgkster9bvJfhRORDZQ9Iyka/9 iGng4dm+SumcCUtlf9rYnaH87/0JwE9pp9/PEt/iPwwfN5/FnxICRPnWFF1g04jJ2ZtszZ vYxAmpQDOcF8d+BLnLN/m1wqNh0X75c= 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 A3D56622BA; Mon, 7 Aug 2023 22:04:39 +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 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-Rspamd-Queue-Id: 58C731C001A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: zmbkdor5o53c8dk1wwjko8hw85xh7yt5 X-HE-Tag: 1691445880-170521 X-HE-Meta: U2FsdGVkX1/iQFKnczxC2HRruMG/eWqv84toIamo90UmIzd/BmJ4LN+5COase5WoHQPH6aS4OtNDVpgX6hz8nh0LiFejKAaLkLWyORSmuX3kea8BJrio9F1Eab/lUbRZ59wgt/rHdK46vxvLKFfkiZeRXNihF+9eR06G1D+zl+KuOjbtyDuAomXl34HmFABUieKljsVR104EUKZa/pnQWGYrZuh/pil07TCSuodn24wPc079Tc9cvTJHzkJmSmMCZjTPI3tgbZ0HW38T6WVjg3dM1CfzBC4lkxxBIFMUtdDTg/WyYgIOpn7RfW/vr3eDAVyhKE0PJAaH8bDMFdZgHL+f9F9c4+Z8ICL5AVYqccphuhEGxvZPigv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V7bMYu96S6q/LJH05UJ8H9SKk+Mb/yhw== 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: 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)