From patchwork Mon Oct 9 12:08:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13413514 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 0B240E95A8E for ; Mon, 9 Oct 2023 12:12:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95AAA6B0111; Mon, 9 Oct 2023 08:12:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 909BA6B0113; Mon, 9 Oct 2023 08:12:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AAE06B0114; Mon, 9 Oct 2023 08:12:10 -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 64E8D6B0111 for ; Mon, 9 Oct 2023 08:12:10 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3BCA7C0237 for ; Mon, 9 Oct 2023 12:12:10 +0000 (UTC) X-FDA: 81325810020.20.3E898E0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 5BBC740007 for ; Mon, 9 Oct 2023 12:12:08 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cZGxWSXv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.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=1696853528; 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=5/94qsXxPiDesWnHBcESbMaV8t4xzhpc57K4atm/SE8=; b=POAnfqDN2onAHIhNl5A1Jjm4MI/rpi/sowbW2aKtVFVJtcfwojpT39SyFA9A+vxbEKp3i/ DAft2o3cO5VpRpZe5iUgzM/flF8WnwnEXonwTzKT9Q7mD557YF85HcYU5rqmdKYPCe3+pC EddCg306ZHJjBciriabXDVSm0dS/iBo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cZGxWSXv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.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=1696853528; a=rsa-sha256; cv=none; b=yZouGZmCm9yR7vtdxkO2S82g/iETDDz7B1BP4zIrTJhHDZ3QxPydCs9x1HijqvPYICKPta p/E4hwfAzUZ3sEqUn8/IF3RF5ZSoDTOJk/6JzpRGZwV5OsMfPHFOAPpdzRDNr5nkkjdIY7 IMKfJ4bzC2fv8wkA1rIkCXE18So7bdw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 57D1A6111F; Mon, 9 Oct 2023 12:12:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17B99C433C8; Mon, 9 Oct 2023 12:11:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696853527; bh=nFe19RrcDm61i+JVIJSNKwCFAGBQlI1oN8c03/2+1zo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cZGxWSXvQ9p+yKwDzwrWzB8K+WHJgYHI1Erz8lZPQZUjIVKP+bVL6Xl9GUFpktBxe hxdvoPWujKNy0cokSw4VRdpvpwrCR38nw0uDO8tdhtSCc2Gf3hqYoN5AVuGG+dtFXl B0oqdGcPg90/Pll34H0J2fLgA8jEabIHpRHztOFrhc8NklEPwg2oOIPH+N8m486WUw 4lTIaRy++XwgJJdJGGOxXbGqck3GBhTXmKln9du8EN9QggrY+v5LSuXXJ9JPUe35OL 9A2hH/x+I3R/FaCj1jk9DBSfuO83Q9lo++fe4hpLmO6s62YW1iuQmdEM1f7jfEcvxY DFhl7UE1FYSYw== From: Mark Brown Date: Mon, 09 Oct 2023 13:08:47 +0100 Subject: [PATCH v6 13/38] arm64/mm: Map pages for guarded control stack MIME-Version: 1.0 Message-Id: <20231009-arm64-gcs-v6-13-78e55deaa4dd@kernel.org> References: <20231009-arm64-gcs-v6-0-78e55deaa4dd@kernel.org> In-Reply-To: <20231009-arm64-gcs-v6-0-78e55deaa4dd@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 , Florian Weimer , Christian Brauner , 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-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=1837; i=broonie@kernel.org; h=from:subject:message-id; bh=nFe19RrcDm61i+JVIJSNKwCFAGBQlI1oN8c03/2+1zo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlI+2bTh8bFfyd2r4ErvGH3ueKxYkR2qokJvrjYIHe d3kV+mSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZSPtmwAKCRAk1otyXVSH0GQlB/ 9cpjBNO3Hkf17J4ctj7mZ/0x9xYzjeURnc3L7chNJsl7kVZCHJwsK3oGMSJuzBGHmA8bm5zbKxGdHv cIzNzCvwKKPP+GpZ4iV98ewuyU2DUhLI68aHjVxzw1a5ilduYukZQVlSaOEhzaMWfa3JrWfON37j17 U0ypx1Dn/X62XIv6vRrnZn0kGsmi1oyQ8xGTxxuW9KankfsQ68FXGsqRGt62v5teQZoIs5VHY3mdD2 MyBLR7qTYazUymR623R0tIYIiOqlfKTrt8pcRb2punJmcVyjApsuS5jnzIRiB2CsNrWsSAbIJO2Jug J/T3ncAFQKv5EOKNpQTGTowHJvMb4F X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 5BBC740007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: qjc9ma5d8fr3iuky7j95twkuh87fdrpw X-HE-Tag: 1696853528-103622 X-HE-Meta: U2FsdGVkX18x4X14xB4Hi12XfaoND/+JefOoLH6sedvtvLKaU6POmC/T9F9DxsBPrjAjDlo0Ic0yH+usmwdCLnIx4zYL8Fy+u0XT12vRfKcotdDRlbOxpTFEXtGSkeznZHqSJqqQxcoB+z5itaiYWQ27zIUDXPUCcvsOm5rOOOHE51E6lqIOCwoNBSOlKKKIR1pzD4QKi7z8WtxvXCBf4U7o+K3jCT6Bqk+jh961ckaAxu+DzX4GPPI5UtBMK7kyEnmTCppi/wYrGijyBT96KbDsf03ssEqxvLkfSehFMbIeqmeVWlz0VOuOEMIJXd1pJpxaU8buggLsmcqcdRnR7sFRH8eN9RiFodtEDaeVufuP1dFa0dG8P0rrHe2/NOpCVoDr6VfAtk0WUja9Tp0utVVguK0bEBvnKHhqcL355A91mJRJxrOl0JCFN+t74vCDQpQmXLW3diS0Kp9RbAnjYLKlsJVRyomd6kTrgbnCvXLFE2D3WwH1+5j5c1aZf0gxE1uxwmnulTk4J9WLKa5i0bAt53UpHSTtE+7wG/AOrmy/6SgFmRf9F8wD2nNzZo6P3Hk+uhKI4D77BUc8/KxJpHijKTcQTBYHsmRgh/4SJD5OqYA0YZbQPI428MAe27Mr9sfz0fjvAKDZ6mtGrpXb0i/h4pbvaFwLUGPVdg66OduW2nYJxtbC1VarLbGcZzn+hmMK0cdDOFTwRWEj+Y7j7/eOz49WG1oFmRL5d3eiIWT0dVinmD6ejLkCUA3J8k9jcMWDR3vWX7XUpEonIwaNTioLqzUCrfacMQ4wE0f8OrbBtRvMSEiOKVoO6YYnwGPnjjdS3zjGAdwJKJAri1b4jb8I99gGMpP+fS+uuy+/N7938Opzmdrimdiwe1B8Jwvu52elsN7DoEZKzVAaIAyoIPloVPwgPuxdyc8iDaD36UyNxdlO3Z97mxTVeL4mfvGAGhppELTrZA43K1tT9j7 b0Yz2IJu dxMmjhmuHcypUIrqhdYVFWHfeDmdevt4bj+0dcVxwzR93xC3hISRNCS7nv3g27Jts+RJjzzMZbVcGU+KtxzhpXViaGPD4WQWvUw2h5wJw7aT3Z7fykQUVvPRtWcrv4/VCbQNv47uHQfSWC3SC2ME0PEux9lgEE0Y5XX4m28sQb3eIxjqtSr65Be0I0tVw1MHofKirVyjrQKQ/SJNbnvlkjIU+c3KN+OoOcFFvh+BWi/kk6zwVKJMQZm0FUHqjKAJ0AiI2iICEfTrNYAJIE4KxhEth7rQfcGjpIxrxTMauB0KkFKC3Syk0Km1RZ/WjUICJ5ac/bNl4Ve8pURU= 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: 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. Signed-off-by: Mark Brown --- arch/arm64/include/asm/mman.h | 9 +++++++++ arch/arm64/mm/mmap.c | 13 ++++++++++++- 2 files changed, 21 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 8f5b7ce857ed..e6fc7ef83ea1 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -79,9 +79,20 @@ 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; + + /* If this is a GCS then only interpret VM_WRITE. */ + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { + if (vm_flags & VM_WRITE) + prot = _PAGE_GCS; + else + 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_valdiate_flags() */ if (vm_flags & VM_ARM64_BTI) prot |= PTE_GP;