From patchwork Tue Jun 25 14:58:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13711461 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 E31B5C30659 for ; Tue, 25 Jun 2024 15:05:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4C8B6B00CC; Tue, 25 Jun 2024 11:05:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CFBED6B00CD; Tue, 25 Jun 2024 11:05:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B746D6B00CF; Tue, 25 Jun 2024 11:05:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 80B306B00CD for ; Tue, 25 Jun 2024 11:05:05 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3669DA01D4 for ; Tue, 25 Jun 2024 15:05:05 +0000 (UTC) X-FDA: 82269733770.21.51FE92B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf12.hostedemail.com (Postfix) with ESMTP id 9FB8B4001F for ; Tue, 25 Jun 2024 15:04:44 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=du6vaexO; spf=pass (imf12.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1719327870; 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=DBaG3IHZnzpUoHLCcX2knildpWOqiOyI3JZ/7XXryQasCh/C12tKQyNe4x+XzrzOKiLQRX NsG8zGdC9eYY2qgiv/LizlIbB4SrIx361/hAXq5eHlagvaJUZEB6SXE7lRo5vdk/UYPt0r gfjD2BquqWlV8sh9OavaQtFFR44Frjk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719327870; a=rsa-sha256; cv=none; b=ysLZ64ftmI7xvT48WwdLcoY9fzqbBZcmkpAKUWJprqQuSoGEbf07CdsxT0fo6MxgHkOdA5 YAT4fb4uDlta0TSVz/IL7tfgG8l1E2RJwcECiNWiDwfhgiLyqNi0eyOm6zRhZQU39/CBfK 3v+KOIvJSpp+JNrvRWwg2MUfbIDeqyo= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=du6vaexO; spf=pass (imf12.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A1245CE19D7; Tue, 25 Jun 2024 15:04:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFBA6C4AF0A; Tue, 25 Jun 2024 15:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719327880; bh=LmUMQLV4QzyWbEviejJtcrr2Je4DeKbVGxPr/Gcjy80=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=du6vaexO1e9KK9PBCwvYTpxcVwePxCaXdSUymitdkY2yGi3OSvzt93iasqBU5USJL Os3xr2P02ObG0fL+ZHRIELyG0Ey0MaUl/ka7TIszprjmsRHLPqjGLHWsF0AKTWepq5 +cJ6Yc0uyrKVQWzzBNbf6P12IsfdDXnQ0dEvfXskWqj2RJRsfHSsV74q+1VikPOssK 7K7fNpCc0rnJNIOuk8l6DLh6mlxszcslo3E+QCl+EEf9N65fyyednMT+3xVCwZ8DSN h0LK0chSBv6Mt/xDGWyL7/kbXsWBl/FAHKC/+TIALyF+9MmGv4G7aIy8vlwp6RLGDz RBe21pgE8cSpg== From: Mark Brown Date: Tue, 25 Jun 2024 15:58:01 +0100 Subject: [PATCH v9 33/39] kselftest/arm64: Always run signals tests with GCS enabled MIME-Version: 1.0 Message-Id: <20240625-arm64-gcs-v9-33-0f634469b8f0@kernel.org> References: <20240625-arm64-gcs-v9-0-0f634469b8f0@kernel.org> In-Reply-To: <20240625-arm64-gcs-v9-0-0f634469b8f0@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.14-dev-d4707 X-Developer-Signature: v=1; a=openpgp-sha256; l=3656; i=broonie@kernel.org; h=from:subject:message-id; bh=LmUMQLV4QzyWbEviejJtcrr2Je4DeKbVGxPr/Gcjy80=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmetuMBBzEr/5fPxdn4M1kqYgyqYIDV9xPj9y1gpdq Dasxi4mJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZnrbjAAKCRAk1otyXVSH0NeqB/ 0eu00yVrdM0nkJRE7E10o+fE9zBjQ8yuBbBz40rjowd9RiICT6y6kzUWPLkkw5hZJ+nHhXz6wVEskQ iBk+cdeqVhuG80/i43LtKouhIPOB/pUPVCqOIYEG5J3pL1mVqXfMa6z+PftgDFrA50rtWgyU33qHae NwA17vdSsKBUmTWqD5tWpiXfJ+9BB1HbQozGKbEod8+WGNi55D9isLwEuSjA/UDUW7D5XsYg7IinXN FY6WXb4ZKhRlLIBj+Wp6/gOyh+Zb18GdvOjXgLqtJlRUWeEDRZ6yntwd6FzocmZYzJuFXiWYs+Foiu wWaVUKbXTVDAjk5bPe6wc93gzDa4WL X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: ujifeagwyywymut7j7xftxa1688eszdt X-Rspamd-Queue-Id: 9FB8B4001F X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1719327884-893304 X-HE-Meta: U2FsdGVkX19dOhW9Wi3YkgjR3xRx+jkfo0cwLAN2RiFKj5XcGW+jcdtWGk42H/GhzM16HrXe3EOZjYgPRdcv/wsM3LuSDXMb9fZ4AQi6dy21yrJEoNMtA2eSRBvIeSje8zEW4TJqscAtpYWRsdqEeZCNz+iE/WbzvhA1YI5Gc/2rRO71+Crzgn2l1EZOHXR1SvawrDTtb8YwSZ/so3HSqBFQekW6b4BcWBe+hyroS4vwZlUso3kdn8S6bcF4DFVeW11uKPJ6y11JjfCFooWRWoUmrUo6vH78wlb3bSHm0MXc1magdk92JsxgeS+bmaARYS19RRiHh1oMAhS5OggTBvxLTcQfQDLUdgJkc++KKrjrEREayFd4gNIyxxP65FBsPcRLOXDw17JDjHQrgHL01jXXMxKVklokOqMbIytmQcWGtM//vBxVgeTkdrPKHhaSFIn7vU6ZX+kg/9O7i2yxwcvdhuKG/14qYa9dWy8UzfKS67P67DVb59fS6bZtdiUK2ik8uPFU+wMNSN4yIfdFm8FRjfOC+7ZOK+F8QmkgJG9Euy9YaCL6AEG7DhWYR9G8UF5JD5bQCiW0Zw1M5TqjF3yOgwHnbheUq+aEzwoEZqtcR//aD3UavRC7kCTcUBooC2Tc7LVPcfedgqPFf8VPebj+zP9leqrJaEbJzHRT33rTicx4kg6naRDkpdEBrjbmOE6R5dfMn7pycl4K3YURDhcaqCTK4aFVMxPJwveccu1lvysDumz+9cagqLSqy51qAVEqSvmjPEy32ssO0KOOwPq16HF5tYyir2i/cAam+ArDrpSIUCx5HyW3sUzgPSIhy4GzUx2eItPr2sb5czWYnIiIfUGd8tHedadb8xGnLtsSAh5iKfC8PJobaBygPa8I8FHK6J56ir224SZ0/cE+X8BO8mpso+fdtXYJd28ni+l5+2l0tYle3hN6+QnagMsPRSMESCxwltVbNl0ZYjh knHikuXv reHakt9feB8q50ZIkYrqHMkyGvCJkonR0mjarc9iYqzYCxRdValB6OgtvcjSscBV2UDTjjVXN+csiMHm/7wAmNneVZLKSlOcnuwDvvT99QW/gXPOS4NFsZX+cyt3pIVhb4HhkkrZDPNl+dinhn1bMBC84K8wmxMx6eVhpkgv1Tlg/hnDSDj8mmyH9qp0FF5hg6tkzyf8IM1e0HC+1BDkmSWq8JWY0Vql6jL+te10Kg8UvQKVnkC7VnUrFpW4epwZztJw0yiOCRNCoqsepZCx1IYaD09ujBFd3C7AwlQw7KDUGvwTH3BdpHmBglO2HZ7Kv3WK/yAPrF70WejA0ZYzJrWitxcPrl7YRxlKD1hGkeLVwK4aRWIRGe1DsdiKWMujmLK0m 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)