From patchwork Mon Feb 27 22:29:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 62166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2682684wrd; Mon, 27 Feb 2023 14:34:32 -0800 (PST) X-Google-Smtp-Source: AK7set8yNiGKvzneivg+KF9uEm7nOFDR+z+vcx1ECeIWJtjL/l1xY8Z/KZALHlkNvlhi2WUQ2HCA X-Received: by 2002:a17:906:36da:b0:8db:4c66:59cf with SMTP id b26-20020a17090636da00b008db4c6659cfmr326231ejc.42.1677537271984; Mon, 27 Feb 2023 14:34:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677537271; cv=none; d=google.com; s=arc-20160816; b=hgZ+4YHZfrD5oiL2lG1o4DkNL0Fo0AKcfy5FI81nUDyVzkzFJjZW1YIapb2Vf+KaTT z3TOUp09nH/uwJS40VAkqEy74+2chF7IURii1TaOGKxJ8duc9jGudcPvEvAnCOT1zAdi 9jpWwsjJeZgFEA7E8FkR2MMPsaPIGuB3QwBycXCCt7md0OXCFsp+4Lo7+dL14mo/T622 atulkwWjIptbAyVYOFbtCYliQKpAZQ6jCSCXJF1inardbNrLLKqrBS40Us6O8GEE/mWF xQwjqv7D+G3wSTjbikGuestcyK2QielBuZ8ffJsnIwqoq+eQDdZp8SZ3RZB2K3E5SO7v +h1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=wceL11ZZ0s1oZMAkJv9xADmkIBB3swH4yWQ/WScjmXo=; b=qJQj92AozZ06elDQrj96ZQJ/uJLDMrw6JKDH7Sh3A4UmVtY3cbCJfibeG/gw3O8/jj KwyeRhAEve1cY/T5g38+4tPsce6n6eOvOsGt+MIMFxPDtzKonUHcBOTGBXbKr0c+OUUK rGhA5s+22n6Hl1N9bwors1RV2KgED1cGXLgDtXQ7btI4z8c4Ga8YF0RnVVklTKKG6zJJ OxGaTgI3RxH40muTSyr8Lv11Q/72RcTs0Mg15L1UlGOYJPVSRb+stFu6O4AS//9fpBt7 GcthzeNkyqdNIb0eGLqcH9rhkvgnLAu4MFHT8F8QcLqYQtHloEZ+Zc1V6c0SNvzqBSd8 0wKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JFvk8NkX; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j18-20020a50ed12000000b004acbd499461si10702397eds.178.2023.02.27.14.34.06; Mon, 27 Feb 2023 14:34:31 -0800 (PST) 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=@intel.com header.s=Intel header.b=JFvk8NkX; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230413AbjB0Wc4 (ORCPT + 99 others); Mon, 27 Feb 2023 17:32:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230257AbjB0Wbs (ORCPT ); Mon, 27 Feb 2023 17:31:48 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B05229E23; Mon, 27 Feb 2023 14:31:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537107; x=1709073107; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=9ua4eoVpPkNNqQnm/7DlucqvtoyDtbjdtgZW9gHkRAo=; b=JFvk8NkX7YXOxVBdhj90YGc48gRXyYjRcPiorJlmm3P/YnPKNV2n90b/ 0LmPl1W6YnpM5kWg+rB0aqCu0ZMSX+rr42291lJIIio/CufXKBZY2fzlz ZLji/eF91srphypS3YLpTtOpCsbhvgyJT/KlCfeRD5VjUOJrwN0Q47Vvr 8GpScEtjNWzHeFgkS9+TRURIDSghRcsjq+3sCz4+GNC2w4jtKy/S3W/Hn THNbetVwIrQINknmjDcSmdZZZDAMqRhKcUXBBfTfRBa5xY6kp5ADyOeU3 n6UDxfQyPv2AXSfzcokkJyJe+5kPmOHWXRrQRjnrnpsidS+0DL+TLN50j w==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313657428" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313657428" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:24 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="848024595" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="848024595" Received: from leonqu-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.72.19]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:20 -0800 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v7 18/41] mm: Introduce VM_SHADOW_STACK for shadow stack memory Date: Mon, 27 Feb 2023 14:29:34 -0800 Message-Id: <20230227222957.24501-19-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230227222957.24501-1-rick.p.edgecombe@intel.com> References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759025322828487608?= X-GMAIL-MSGID: =?utf-8?q?1759025322828487608?= From: Yu-cheng Yu New hardware extensions implement support for shadow stack memory, such as x86 Control-flow Enforcement Technology (CET). Add a new VM flag to identify these areas, for example, to be used to properly indicate shadow stack PTEs to the hardware. Shadow stack VMA creation will be tightly controlled and limited to anonymous memory to make the implementation simpler and since that is all that is required. The solution will rely on pte_mkwrite() to create the shadow stack PTEs, so it will not be required for vm_get_page_prot() to learn how to create shadow stack memory. For this reason document that VM_SHADOW_STACK should not be mixed with VM_SHARED. Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Acked-by: Mike Rapoport (IBM) Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov Signed-off-by: Yu-cheng Yu Signed-off-by: Rick Edgecombe Cc: Kees Cook --- v7: - Use lightly edited commit log verbiage from (David Hildenbrand) - Add explanation for VM_SHARED limitation (David Hildenbrand) v6: - Add comment about VM_SHADOW_STACK not being allowed with VM_SHARED (David Hildenbrand) v3: - Drop arch specific change in arch_vma_name(). The memory can show as anonymous (Kirill) - Change CONFIG_ARCH_HAS_SHADOW_STACK to CONFIG_X86_USER_SHADOW_STACK in show_smap_vma_flags() (Boris) --- Documentation/filesystems/proc.rst | 1 + fs/proc/task_mmu.c | 3 +++ include/linux/mm.h | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 9d5fd9424e8b..8b314df7ccdf 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -564,6 +564,7 @@ encoded manner. The codes are the following: mt arm64 MTE allocation tags are enabled um userfaultfd missing tracking uw userfaultfd wr-protect tracking + ss shadow stack page == ======================================= Note that there is no guarantee that every flag and associated mnemonic will diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 6a96e1713fd5..324b092c2ac9 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -711,6 +711,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR [ilog2(VM_UFFD_MINOR)] = "ui", #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */ +#ifdef CONFIG_X86_USER_SHADOW_STACK + [ilog2(VM_SHADOW_STACK)] = "ss", +#endif }; size_t i; diff --git a/include/linux/mm.h b/include/linux/mm.h index a1b31caae013..097544afb1aa 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -326,11 +326,13 @@ extern unsigned int kobjsize(const void *objp); #define VM_HIGH_ARCH_BIT_2 34 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_3 35 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_4 36 /* bit only usable on 64-bit architectures */ +#define VM_HIGH_ARCH_BIT_5 37 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0) #define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1) #define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2) #define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3) #define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4) +#define VM_HIGH_ARCH_5 BIT(VM_HIGH_ARCH_BIT_5) #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ #ifdef CONFIG_ARCH_HAS_PKEYS @@ -346,6 +348,12 @@ extern unsigned int kobjsize(const void *objp); #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ +#ifdef CONFIG_X86_USER_SHADOW_STACK +# define VM_SHADOW_STACK VM_HIGH_ARCH_5 /* Should not be set with VM_SHARED */ +#else +# define VM_SHADOW_STACK VM_NONE +#endif + #if defined(CONFIG_X86) # define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ #elif defined(CONFIG_PPC)