From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5149FC433DF for ; Fri, 9 Oct 2020 20:14:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C7DAE221FD for ; Fri, 9 Oct 2020 20:14:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7DAE221FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 19935940009; Fri, 9 Oct 2020 16:14:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 121FF900002; Fri, 9 Oct 2020 16:14:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2B66940009; Fri, 9 Oct 2020 16:14:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id BED19900002 for ; Fri, 9 Oct 2020 16:14:46 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 673CF180AD811 for ; Fri, 9 Oct 2020 20:14:46 +0000 (UTC) X-FDA: 77353490172.07.cause61_231004d271e3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 4D72D1803F9A1 for ; Fri, 9 Oct 2020 20:14:46 +0000 (UTC) X-HE-Tag: cause61_231004d271e3 X-Filterd-Recvd-Size: 5785 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 20:14:45 +0000 (UTC) IronPort-SDR: uYNhGL+CAb1mbqcgFmT5YZ2iMRcN5cxwDzV0V5UwjMk8OF+Gs3s7kNLWYSGZ5YXmBxI0bU2OO7 7KDV624t5naw== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="162070300" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="162070300" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 13:14:28 -0700 IronPort-SDR: pR0E5+snVDVvANAvRoPu2vzR9Dkhb+z+d5YuMNBWvSFgArh5bcL4/F9v9jFvdtkO305iwbVsfb Q1T44vID0agg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="462305512" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 13:14:27 -0700 From: ira.weiny@intel.com To: Jonathan Corbet , David Howells , Andrew Morton , James Bottomley , Mike Rapoport Cc: Ira Weiny , Dave Hansen , Dan Williams , Fenghua Yu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-integrity@vger.kernel.org (open list:KEYS-TRUSTED), keyrings@vger.kernel.org (open list:KEYS-TRUSTED), linux-security-module@vger.kernel.org (open list:SECURITY SUBSYSTEM) Subject: [PATCH RFC PKS/Trusted keys 1/2] vmalloc: Add vmalloc_pks() call Date: Fri, 9 Oct 2020 13:14:09 -0700 Message-Id: <20201009201410.3209180-2-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009201410.3209180-1-ira.weiny@intel.com> References: <20201009201410.3209180-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: From: Ira Weiny Add a vmalloc call which allocates and creates a new mapping with the specified pkey in the mapping. This is currently a placeholder for the idea of an interface. This does not attempt to update the direct map and as such leaves access via that map open. Protecting that map would potentially fragment the direct map. Signed-off-by: Ira Weiny --- Documentation/core-api/protection-keys.rst | 4 ++++ include/linux/vmalloc.h | 1 + mm/vmalloc.c | 28 ++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/Documentation/core-api/protection-keys.rst b/Documentation/c= ore-api/protection-keys.rst index 9e8a98653e13..574c88f45830 100644 --- a/Documentation/core-api/protection-keys.rst +++ b/Documentation/core-api/protection-keys.rst @@ -121,6 +121,7 @@ mapping adds that mapping to the protection domain. int pks_key_alloc(const char * const pkey_user); #define PAGE_KERNEL_PKEY(pkey) #define _PAGE_KEY(pkey) + void * vmalloc_pks(unsigned long size, int pkey); void pks_mknoaccess(int pkey, bool global); void pks_mkread(int pkey, bool global); void pks_mkrdwr(int pkey, bool global); @@ -138,6 +139,9 @@ Kernel users must set the PTE permissions in the page= table entries for the mappings they want to protect. This can be done with PAGE_KERNEL_PKEY()= or _PAGE_KEY(). =20 +Alternatively, vmalloc_pks() is provided to allocate memory within the p= key +domain specified. + The pks_mk*() family of calls allows kernel users the ability to change = the protections for the domain identified by the pkey specified. 3 states a= re available pks_mknoaccess(), pks_mkread(), and pks_mkrdwr() which set the= access diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 0221f852a7e1..f5aa1d54b9b7 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -115,6 +115,7 @@ extern void *__vmalloc_node_range(unsigned long size,= unsigned long align, const void *caller); void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_= mask, int node, const void *caller); +extern void *vmalloc_pks(unsigned long size, int pkey); =20 extern void vfree(const void *addr); extern void vfree_atomic(const void *addr); diff --git a/mm/vmalloc.c b/mm/vmalloc.c index be4724b916b3..8cc973a968c4 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2589,6 +2589,34 @@ void *vmalloc(unsigned long size) } EXPORT_SYMBOL(vmalloc); =20 +/** + * vmalloc_pks - allocate virtually contiguous memory within the specifi= ed pkey + * domain + * + * @size: allocation size + * @pkey: the pkey domain to allocate the memory under + * + * Allocate enough pages to cover @size from the page level allocator an= d map + * them into contiguous kernel virtual space with the specific PKS prote= ctions + * if the architecture supports it. + * + * NOTE: This does not change the PKS settings established with other ma= ppings + * such as the direct map. + * + * WARNING: Calling this with an invalid pkey is undefined. + * + * Return: pointer to the allocated memory or %NULL on error + */ +void *vmalloc_pks(unsigned long size, int pkey) +{ + void *ret =3D __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, + GFP_KERNEL, PAGE_KERNEL_PKEY(pkey), 0, + NUMA_NO_NODE, __builtin_return_address(0)); + vm_unmap_aliases(); + return ret; +} +EXPORT_SYMBOL(vmalloc_pks); + /** * vzalloc - allocate virtually contiguous memory with zero fill * @size: allocation size --=20 2.28.0.rc0.12.gb6a658bd00c9