From patchwork Wed Nov 22 09:42:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13464407 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 F144DC61D9B for ; Wed, 22 Nov 2023 09:44:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FB596B05A4; Wed, 22 Nov 2023 04:44:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8ABC06B05A5; Wed, 22 Nov 2023 04:44:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79AD96B05A6; Wed, 22 Nov 2023 04:44:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6A0B66B05A4 for ; Wed, 22 Nov 2023 04:44:36 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 36958A0228 for ; Wed, 22 Nov 2023 09:44:36 +0000 (UTC) X-FDA: 81485105352.27.F981C16 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf21.hostedemail.com (Postfix) with ESMTP id CF7B31C0007 for ; Wed, 22 Nov 2023 09:44:33 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rTp3IgyI; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1700646274; 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=Arbjk0aSXvp932aR/l2/MuAVze6JtdDBpxWCzpTeg2M=; b=azviwIrRkKlZJ49RhV9TmP75w889xge6uia2GqJNA51dbqwxp1IoE3Zy43Q4g/3d7ryNGK DOKk9dxOOhKxT98PW95t67r4xk6QUJ6hbNk1PipaZ1NPg8+oXOjZkT6eZp0E6Z292bgPtM FWidzuUeDKx5mQ0yJGgYvYMDEG+nYtA= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rTp3IgyI; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700646274; a=rsa-sha256; cv=none; b=jJtOnOBrQsbjit87JdEcAmoIqoXVdzP5wR/42xpI8Jr8tvzCGnC5oPfJ/T6Chg2XgX1wNw IQrzbS9GaYGJh8SkgHL+Iu+XGvgjA4lkveJLng6ydRLetiY3jiMUXt+AowM171at/hHhH0 0jBbEVQal83VmKuKaLathB0M7FneHtk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id F0A42CE1ED6; Wed, 22 Nov 2023 09:44:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50C67C433C7; Wed, 22 Nov 2023 09:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700646270; bh=qEFrCNf3UEgHGW1T9wtS9jRJz/KS9KwPB3lxI2GEsTI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rTp3IgyIvQfGD4I+L4TFOAbCJv9NbsiNeIDD4RtpVFyB4VfP3fsoai+tC4z4rivNB 8csRCTYL8ZxeIFyOEnSQA4auqXLMjPB0TV4q9PD4M8mgIYeKJidyttb6RB1TqgN3n/ 7KFCMpd6Y97LNcgEUgDa3TuB2NG38oyO3WYbYyT4ZlzJStWJg4OpYtI1zx1GNbFLcQ EqvGVx0LQC1NgAEZKJhwgqD7BpUehJeQAuBogQ81mPWkWennLwbFNmzi6M9MU9ePt7 EfPhNaYflYB6bWpv0JVKbnZGesMDPr2M3n8dHIwjEE+6mu+EB7/vi4iVvbD9/uCSfp qfBU5xs5TJplw== From: Mark Brown Date: Wed, 22 Nov 2023 09:42:23 +0000 Subject: [PATCH v7 13/39] arm64/mm: Map pages for guarded control stack MIME-Version: 1.0 Message-Id: <20231122-arm64-gcs-v7-13-201c483bd775@kernel.org> References: <20231122-arm64-gcs-v7-0-201c483bd775@kernel.org> In-Reply-To: <20231122-arm64-gcs-v7-0-201c483bd775@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 , Thiago Jung Bauermann , 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=qEFrCNf3UEgHGW1T9wtS9jRJz/KS9KwPB3lxI2GEsTI=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlXc0A24D56zutL8bLQvd52fo0wC43SRULlWAh1 +rU/4PE4q6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZV3NAAAKCRAk1otyXVSH 0HxeB/wMjuD6MVRsjymmm5q0PFo3mPpIDfrsn5bfPM93xyIkhexzp3o8MKMLZJR6AyWc5SU9ANA 9VNb9/Gq2SqulwM+T75NERQoIaX5QN0rnERoUsbZEovn2OVcl1rKgSR9V3pSg6Qe7bTHQI1RXba 52pV6lnw7K6QWG67Rs68SOCjwuPipie41cnu7hHYrKAVPUJgJ3xAaTF3zvDCHGppy2hPtemSDue xvPJt2OEUG/I7wwXpBQXAIdu64425sWrMATEdrAKaBbTDiRIX3QHYitwt4URVvOPC092qkbtgUq ocdLzNoIZ+MRZVauVM6J+z8pX5L1QoZViXQ6EXKLKo+5igsQ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Stat-Signature: 6gxf8riecusznit161mun663zo48zn87 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CF7B31C0007 X-HE-Tag: 1700646273-196334 X-HE-Meta: U2FsdGVkX1/WZDdqBmJTc7XYy1ye9iDjrBjQytWlFYW0pddZSzHTLjs0kAsMu+QNrcMCotG7ZZpw0jWRyuJMRpzWZp0wSCvPt4IAu1Bi7arhzND+vfXUjPdusBLi1S1OvsaFR5rmJuqlDjBfbe7ShYDEAOfmJ+ku2FOrOVcNWJO/83UH8qvlEX/HMqT1kAVm19Ndyv5N+Xm1jutxLHA3/3MArLopQI+S0zG6TrqkuZ9qvxuuMGGGvWIplcGW1MvhT/Pt33gwnXuMi0gfgMcO2pY0pgY4fbQaC8AztGbhd//yQey6UJp+sTCfk0wpmfoiwWA72BZ6c7+e6nwzHqv0BRXa2JfcelX4Ja/3ppjt1qvkfPRQyENwAQeXp+Vnh+RZqBBRwxykl0LtB8ZbASdpd95wXpg1/D1c5YHZSsu1LUS4qptcDEt52+QaTc4WsCu43SRJAJPFm5ZcT+/QhhXX8cfCg8e4wqDLLOxthmYat0q6k1OcXyVrPvwcLnMjEmci63/o7bVfZ2+3+b/2g8IZulkQeVJFtajvAYzkSgcTUb5HivU6PuWLqk1LxaIf74ieYY3iIDZsJUAFjLQhuIWVI0nr974mR1gQCQK3z5eo0MjFsS2LbxGS3xy90GPTLLNJtv65aoj9AH5wDesShou1xKhhEA39ttGWulKlWLSw6I63IFFComSpp+hIsFaRLw/EvU/Sn071R8lr3aSHdh4y9/94SdJu9rremFvycvcIO3gdkHrnlZ9UsU94nzmAYUWqusAR5RjYcj2U/fEZnX8bVxr7O/qeMaet6bWLFEQcc1w86VNGg24fvLZtxM8j8hnI8KdSbnzIq9LPjqLGH2j+RtvXSKEOkRGjTZnuG8a3i3DZXfKO6jX8wmlvO7RPzi7KHmnn64yWg0Nmc5g/dzwyC4d3nD+qNnPf1cQoGtnHBmyaabhFw5qSS2wpEIu+el95qHLqAg8mZcPwJcNOAdR Lp64NMoe qCxw4SxIfg3wNRxnGI4wj4CqxOCEQndHH6t4NtO1SukwXmnriSkw4+h6O2NrMWVIej/nthRInKsid0s3GVWJWOTzYV+/C+ZYrZ3XZiEhKIWQBWhSHQpIVy8jUTFncwIrsRnpKUliaNto12xtPwmn6/06GHqi3XkY4iziQF5imO+ZI3C/f+5YA4I69ZzJtcYVpbJ3m/R6+Frje5MfZ/UDH9TMh7d+vCmJqx/qhyI0EU3RPP5Kt2pZt7VngqG4sdtdYvPiQApBAYLQlwnu55dipo/DqcWc7E5/SFLOk8IljoKmdFZyN9srRKzgBi8XOVvZYPnL7 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. 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 645fe60d000f..605d4e6edc1d 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;