From patchwork Thu Aug 1 12:06:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750392 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 EED0EC3DA4A for ; Thu, 1 Aug 2024 12:58:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BBA46B00AF; Thu, 1 Aug 2024 08:58:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 722196B00B0; Thu, 1 Aug 2024 08:58:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FF2D6B00B1; Thu, 1 Aug 2024 08:58:52 -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 209246B00AF for ; Thu, 1 Aug 2024 08:58:52 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D270CA0D6D for ; Thu, 1 Aug 2024 12:58:51 +0000 (UTC) X-FDA: 82403681262.13.4A95784 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 0CC9280012 for ; Thu, 1 Aug 2024 12:58:49 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dyQayV0f; spf=pass (imf30.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=1722517125; 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=avsILOT3E2XKHkvtmgvPkA3e9X+XY1/RIVi+DZAo1PA=; b=tBdoj0zah8nKZt9RaRR3WAVJqMBu8gGjazyj2Ft8+Bl8/DT5x1NhTqUezM+wpLQac7uQyQ bFX1OzX/+pWZ2expGWaMGsrNFTdGe2J2GLpRsA1NtqtDbAxwNeVfTpIeq65iGZhRLdy5m2 irB2ttH0Yvqn6y6sA/Mt0kdLzLgXHu4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dyQayV0f; spf=pass (imf30.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=1722517125; a=rsa-sha256; cv=none; b=CLt4FNjwMKpOBdbPXZulpy5IeQGe1fRJRFkhi8pKlTU9CppLu9YsKaA25eTr0ImKeUhbLZ TWYdGXmMYKqAwYfN2qT5lIR3PaIuIXgnDOK3K6RlKBFUjYfMWk5gMUSZ/0LYbPWOfUaThm 7Tpr33xqEH4AWsVsz+Uks2mhIkZk9zU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 33B4B6289F; Thu, 1 Aug 2024 12:58:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CF41C4AF0B; Thu, 1 Aug 2024 12:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517128; bh=iKC2Iasck77jV+Uk+oAXshC4xI2+EzWFpjmjkamUboo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dyQayV0fQPSZH8iBt3r920gWMR8PRqUKHxVxDgPQjyeJut555M3l4cDwsz+/L5qQS As1Fxhi/6bCXuwjr9NdjvBX6wDqf/Fxi3a8wGAE/qWUiZL5LYBhtTcPbxCWz/QML29 60npbjduYtAn0JzFHAUE8zwm6Q1kOxEoiKce7sC4wvjTflnDQ0DF9MalXGTrLYgS8F gXhhRz+nBXf6sqzaCfAlsMkL7do3RzBVthp97yDax4qvCcZ3OHQ8g2VY2PSqMAZLNd IxRDzjVoRVEX+F42dHQhDdgLvph86KDdI1LnkW1mniZkz3+zak2yx9Ro6Xt7xlGQRb XzXuKvipxoNHQ== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:40 +0100 Subject: [PATCH v10 13/40] arm64/mm: Map pages for guarded control stack MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-13-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=1838; i=broonie@kernel.org; h=from:subject:message-id; bh=iKC2Iasck77jV+Uk+oAXshC4xI2+EzWFpjmjkamUboo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YQi3D2wTTUJjuQQY3F7F1CBBVgw8rRNdzwjqNE tB9JpyaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGEAAKCRAk1otyXVSH0LglB/ 9TWv0MHUp/MwJEjSWgKUaa9AI9T9ei3Yo/iBGwhTkm2lo8TZTWMdtH0ztI+7/sV7Bv2+cOXKDxO8Wn xdLbDBsr/gw3zkkssfqjmj3brMAAxPZsleH+Lznr+NV+/0NRHmSZxbVAVa0JsJVu2db+gWre42Wu2T lPKPmT9WC8gLVXsjaY6dzYqMNV662wcZ41nyv8oPea28bIjpwZZNSJspMdUGqpSQdGnjZp/yxu68w5 Y//Qbhz9rxsr1xOKKwh14tKc+nbFMdl2zKPVWbv5yGUS5EZEVUxqENG9eNNKup/HT0n8dZcq3Yep9V Z6RDFNJfx4fCy4UAAQiNxjCf+kO5rX X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Stat-Signature: 7y1499cu4pyexf8fbjrpxfbr7rrrfdhz X-Rspamd-Queue-Id: 0CC9280012 X-Rspamd-Server: rspam11 X-HE-Tag: 1722517129-82857 X-HE-Meta: U2FsdGVkX197IpqoNlhn/zipe21d50f9stSaeHOWhpmnd6VYs8sAowqY+yj5yLXrbIFFTuSWbgt1YEHhss58A6TvbECIP4eFSfn77YGMvdr7hVJcLM/MMxV5sC8Fou/PcaKL5D2k+7NAwfecQWmyoK0MKJS/5u/TlAhp9J3M8Qu7Mqx0difE/sU6bSRz3do0fOs6+lHi97qk8dmZQIzm2dLCzvE1EiETiCvYlmh6qtv2HqU5epppu/BdPBCk3ADYnt38Y+CpXdDA+jymMtaH7f9IpkA2AmBUa5jiVamB65E6p3qm11hBzXNTkwwOS9QnHTT3aAhiM0yZI5+m6fxw56n2ftADhy38mpBKiNdW6mHX9ow0jAKWJTx2oLHxIHp4UodBHlvK/XqrpNVpAFmc7t6Vx3b6yrwKmx5HKNP2j53XmIE7+MgDToRe8bsTmYog3poG3GV7ghA7Pz8x7RIEn1pc2IrhZXluyrsC7pV/wwD2J6M5HItUxzCTix5xL01HRDEhwrvzaMKNLZb2SYifkWCimbui/L/1CwpHsd9BV8dFmJgiYOzb1luUii8tMRFuzw5v5k40IHG9CzLxUXYkB0dWt84+XJNFkJINKpzil5rvjS2S8IbZOkA2t8GHpQ5CxCNJG1JPfB6Dg+HNCKGtbmu95B3+At4XeawgSFzRZvTm3S2V8sR6UykvIWhcpvsaQBzVZGPryFe3zyhXb5rB7JA1uznPYNaYeVKc+kQzbNZtIqsDCas3RgqaNLjcvoYOUChcIqBYldTmWxud5flgBbnvOVqngm/kbiXmrbJfpHvNAu1ATVZkvIrB1d4h9pZtsSrRvRjmjLmYk1XHN/So8zexPC1+/ZEdArCB/I+PG7EjFq7AJcFQexl3dlP23qqf9fBIrNKzyY5KO4XzfxZrKWX2YZbWqYy57WmZNUFqXBYBcQ955UpvibIoHKGDdkfKloTvEiz2NdI+jpgpPAB A8gzGLhw UVQFRYMyFaRUgj7VItZt9I+jltZ6wzrHU6/vp1qMGfo1wGCNrfpEb5BPix/9faMfh0pPDgWWsjG9pgiz84V3yID648xtF8SIqaMazUPNtiahyOIbzLjI2KGxPqVMtVsUlGaZNnMMwANXx5ri1CvIBvxBUWNNILnOWhGNHCK97c9X3MrhxXjc6m7OoVTJedx35pTMNUpnRe+YpfcaohgQcAc0KI/ycZNgPa3V5658V+lm7BPX5gbNKSrMEnjx2d/fZx7UoHgFl6xEd5mMgrimnXHhVxugCnYvfgvECO5TC/PoDO4KwUoHKKlK3sXT+BR6lSI9gcDLtGRAQ8khriIhMJC5t7aWSiQC+FcXbFPgYSaCqO4qFpU+m7DTfxflPNAn37qaq 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: Map pages flagged as being part of a GCS as such rather than using the full set of generic VM flags. This is done using a conditional rather than extending the size of protection_map since that would make for a very sparse array. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/mman.h | 9 +++++++++ arch/arm64/mm/mmap.c | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h index c21849ffdd88..6d3fe6433a62 100644 --- a/arch/arm64/include/asm/mman.h +++ b/arch/arm64/include/asm/mman.h @@ -61,6 +61,15 @@ static inline bool arch_validate_flags(unsigned long vm_flags) return false; } + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { + /* + * An executable GCS isn't a good idea, and the mm + * core can't cope with a shared GCS. + */ + if (vm_flags & (VM_EXEC | VM_ARM64_BTI | VM_SHARED)) + return false; + } + return true; } diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 642bdf908b22..3ed63fc8cd0a 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -83,9 +83,17 @@ arch_initcall(adjust_protection_map); pgprot_t vm_get_page_prot(unsigned long vm_flags) { - pteval_t prot = pgprot_val(protection_map[vm_flags & + pteval_t prot; + + /* Short circuit GCS to avoid bloating the table. */ + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { + prot = _PAGE_GCS_RO; + } else { + prot = pgprot_val(protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]); + } + /* VM_ARM64_BTI on a GCS is rejected in arch_validate_flags() */ if (vm_flags & VM_ARM64_BTI) prot |= PTE_GP;