Message ID | 20230807-arm64-gcs-v4-11-68cfa37f9069@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1759375vqr; Mon, 7 Aug 2023 16:03:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjHQn5tFPt9px+bESWsQQ/7gB0LgQfjFCkALieJIfkgBFg1AwvMBY7y45dsnt5XaUqTM4W X-Received: by 2002:a17:902:b682:b0:1bc:3f9b:2d57 with SMTP id c2-20020a170902b68200b001bc3f9b2d57mr10570254pls.37.1691449386322; Mon, 07 Aug 2023 16:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691449386; cv=none; d=google.com; s=arc-20160816; b=j2e5mkohftF16aZ57gsCDmAh0JLmErEsjFVunoskSEUFiBgloKgGB7QITDwxySEqIB iZ3JX9z9FC3Wm295wuRzGqM/eti18TYfsei5EuFE9OV3AlVABaSfy5RCKnGgVBBC2Qcl HRrBlj9yRpKgfQegOirrPc9CNUyWgGf9Tmpq4f+JT4ygYsX3zaoaAMpn2AxgOjMu3Yd7 pRRVDyijJifk3oqxeDEsbO3kZmoUiOR36A8qvOPWcMet+doskBunZ90469Sk4b8nud9q roFL0W0wZVadQq4JKeQrjzGZC0aOXCt1O0E/tmM5Hx2+nJJaqPs9WaJxyt+Atvo46YBo 1+Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=XE0cp/pXkFJO5Epc20SRtvrQrMW2Zd7bcQADyaYtsBc=; fh=EdAFSmIgUzZTC6WCy4Jg1wBZ0/m6m2d/OjiRUJ3BsTI=; b=wpEKBcG/XwsJb76sU2siLCH1RGQQ1JeyJ175C32ob2fnhInC4TExPMTQiu5qqwMfK4 5icgVJfz9Bm9gfFBE4pT9R9ZMSHuhwe2YLUbRONcDCpli81LtmUjDG1ONAvge4RQUx1U fe+r00ISsleizGaAhPemR+8CAHmt/ujJu0qAoLEsKFmuFoOU44x9ph/vVqCFFH35iT/n G+oCIawlZAIzXkKWrYUCY/ByyV6qwHs9JE0LftOwCoFC8iVx04G03PSCJGvI2ZgAJBrs 6Ve9cDdTSWMc6e9NM6N+qTpFZlA9gjeqS8HbnJAZVr9pLCiAjMyNa8SIyIQY2W2232Ag yTLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=B7+8io7J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb12-20020a17090b060c00b002612b8cd1dcsi9595798pjb.162.2023.08.07.16.02.50; Mon, 07 Aug 2023 16:03:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=B7+8io7J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231164AbjHGWEC (ORCPT <rfc822;aaronkmseo@gmail.com> + 99 others); Mon, 7 Aug 2023 18:04:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbjHGWD1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Aug 2023 18:03:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77F75131; Mon, 7 Aug 2023 15:02:40 -0700 (PDT) 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 1019A622A9; Mon, 7 Aug 2023 22:02:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B665AC433CB; Mon, 7 Aug 2023 22:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691445759; bh=aGB9MytFbopKILsUP0kPuxTbIpt9GJuR7uXvXLP6vLo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B7+8io7JEg/LIWoZNhiKlYaOzexSqBArV056/ScJvMpxGs2kYB4Okzkzol5kScHYE 55HMmJFzcyF8LtgXCBJKWR7eLCptLh/oMa3OwoCIW/lmiSswqdleH9vkIljQqqI1NG HLehvcCG393fnl1siFCS/s7UzNZzDQUk8j/IEVppVkDJ+oI6SfDcO/ioLRso4uqmWd 0nFYrpM45VWM6oql/4rbBGH9Bwejm80beYj84++Sz29XVXXPZ08K9bNizQdES4ri9s TnarJsT6SfHg4wd1fb/cH2kV7WdxLpv3PjSjRekkZcxhPwSttByrH0KzubjmRIB62N obTS3NSXeRxEw== From: Mark Brown <broonie@kernel.org> Date: Mon, 07 Aug 2023 23:00:16 +0100 Subject: [PATCH v4 11/36] arm64/mm: Map pages for guarded control stack MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230807-arm64-gcs-v4-11-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 <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, Jonathan Corbet <corbet@lwn.net>, Andrew Morton <akpm@linux-foundation.org>, Marc Zyngier <maz@kernel.org>, Oliver Upton <oliver.upton@linux.dev>, James Morse <james.morse@arm.com>, Suzuki K Poulose <suzuki.poulose@arm.com>, Arnd Bergmann <arnd@arndb.de>, Oleg Nesterov <oleg@redhat.com>, Eric Biederman <ebiederm@xmission.com>, Kees Cook <keescook@chromium.org>, Shuah Khan <shuah@kernel.org>, "Rick P. Edgecombe" <rick.p.edgecombe@intel.com>, Deepak Gupta <debug@rivosinc.com>, Ard Biesheuvel <ardb@kernel.org>, Szabolcs Nagy <Szabolcs.Nagy@arm.com> Cc: "H.J. Lu" <hjl.tools@gmail.com>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, 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 <broonie@kernel.org> X-Mailer: b4 0.13-dev-034f2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1124; i=broonie@kernel.org; h=from:subject:message-id; bh=aGB9MytFbopKILsUP0kPuxTbIpt9GJuR7uXvXLP6vLo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBk0WmgYE5sTjIW0s7MSSUHBmNdoL8mADFajoHMlxxa sLCcTiKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZNFpoAAKCRAk1otyXVSH0CQmB/ 4hCrLHpUMmcfdaL24W2A5mDkcuuBM88bAHrKma9GqNW27peedUqdX7QojJVVcc8Pti+JDlRJQlF6eA QZEKYM3bKTE3mosdO+93NlHTPGn7gi26Pt1S42K8kRxwwm3mJo1gL/HQE1ao9d0KZg9o9LHWjR9UsG hAoZdZeodWYeIhnbOvuyIXIfGKTlRPnEOtzr//cVzV6vxPF3kggLcSNXBGXhBYJxComChKV/1oWfxG tHKcsX37YMulc8njZNNNcc7c79OcVYO4TFDHmUNkosm8ee1zIH4H+rIteZ0Pyhx3nAnQLUDe23kVjg n0K3NwP/ZpHSz6lX1gqzfW1nyN7hWy X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773613231383533205 X-GMAIL-MSGID: 1773613231383533205 |
Series |
arm64/gcs: Provide support for GCS in userspace
|
|
Commit Message
Mark Brown
Aug. 7, 2023, 10 p.m. UTC
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 <broonie@kernel.org>
---
arch/arm64/mm/mmap.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
Comments
On Mon, Aug 07, 2023 at 11:00:16PM +0100, Mark Brown wrote: > diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c > index 8f5b7ce857ed..8f40198cd44e 100644 > --- a/arch/arm64/mm/mmap.c > +++ b/arch/arm64/mm/mmap.c > @@ -79,8 +79,18 @@ 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)]); > + } > > if (vm_flags & VM_ARM64_BTI) > prot |= PTE_GP; Some combinations here don't make sense like GCS + exec or BTI. I think the code above (correctly) ignores exec but it still sets PTE_GP if BTI (the architecture may allow this but you can't execute from the GCS page anyway). I haven't checked the x86 patches to see when VM_SHADOW_STACK is set but if there's no additional check at a higher level, we should add something to arch_validate_flags(), assuming it's called on those paths.
diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 8f5b7ce857ed..8f40198cd44e 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -79,8 +79,18 @@ 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)]); + } if (vm_flags & VM_ARM64_BTI) prot |= PTE_GP;