Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp619930pxb; Tue, 1 Feb 2022 07:08:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJybJOEYo4lOz8wBtzhxYWnAaPWF4Jdfi1dm1rxnje5Z8GXFi4baYgzosakvNRJ+ZhIzBJVO X-Received: by 2002:a17:906:6d82:: with SMTP id h2mr21341565ejt.487.1643728099026; Tue, 01 Feb 2022 07:08:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643728099; cv=none; d=google.com; s=arc-20160816; b=AttVWYGdjZPO4kZi73qFjmCoUr4K96D1W5G6mE7+2uaAkBZxih70RPVyvWHfCtcr71 EU4kkeUWlgLWN7/mwotxwbYzYR/T47aLuiW+ZBqhG6jcuyTUbBI+UzZF95OCodwyVHuy mSPRWP9R3vhQyWhTuahWO8KsQUAeja3wF22fdQr9bTLb2aGW4A849HEQjWg+sdH/MDeo S4PZ59hVidKO5lJFQ5ZD5r9m1skC/vpBjwNfqmeRhOQcyhyn7Mag1zT/ATqgS813VVbR EwN2S53MbZfX89kZv2QjUVtfwsFHTAu2p0U4oSX0gBLd/27VVM/5/RfPy/wVlk8OpEsZ hGzA== 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=XqtARnzfruLDiu0AkuwbmK+FJTc8m1DM0C4m6q9oGf8=; b=Mn1KasTvnQx73cIKf0IdacGnxn8V75Gp+aUlTpjEee3a0oI42nmZlj1Pr/MFEPymPu Rm3JIYfpo25kFnpX6PU6jWRCyLE6pS9LWhUDUDzFgvzx6Z59wmFJ2IvQQoSCWHuea7lX e45BHQ5uUCmWYtkCqhadyHNNiC71zbckWfYXOykmRk4NTQTQ5rL+YecD6bbwVWj+oyXg YW/s8walZ+4xaZHN9gkThpThzuY+vKwbkMKqjJRKtWoUjcwFklJsb+lHNEadYxr12x4h 1uqE66T4IpYpn1FFcUz6yV8wrzES3E2FNc3JQ1XlV3kuMAqdn+h8rArRoAG1+44HVgcr G5CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cum+Pm8e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb35si8425191ejc.356.2022.02.01.07.07.52; Tue, 01 Feb 2022 07:08:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cum+Pm8e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1356729AbiA3VWk (ORCPT + 99 others); Sun, 30 Jan 2022 16:22:40 -0500 Received: from mga06.intel.com ([134.134.136.31]:52015 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356500AbiA3VV6 (ORCPT ); Sun, 30 Jan 2022 16:21:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643577718; x=1675113718; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=jMzw65MKfqq52oVnmq5qfAZv3M9YR8fJMyeeTLiS5eo=; b=cum+Pm8eXAKvWbw1zCV4gZjc5rUHQnB21mFBAyv11K7mm8g63WjH2nj5 Hotbv+5IJkjszH1keB6OIZ14var2V1TSuvZxgunDQ2BHK6aJeDViQzxoL opXRyGZb8kWaPd33HDFItnsYwrgN8QuGKMdHsNXTHUzQFfu3VFvQPcNG5 ENv95JXnySwRMhtAhjoDO2dBkXiUgOR15Pggwlcpt1Pfg6MSBCVB73DLm Y8kqck1wReR7sUCGqEZBbEK4EgNJphc9GP5n/BglUZ7vcU7mmcyosAr1Q vthH9uuBHTZdR4EDjiiCo9FVm7nVRIvfIvIGwwUfOzZhYim7JlWjAx5Cv A==; X-IronPort-AV: E=McAfee;i="6200,9189,10243"; a="308104930" X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="308104930" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:21:57 -0800 X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="536856781" Received: from avmallar-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.123.171]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:21:56 -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 , "Ravi V . Shankar" , Dave Martin , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH 14/35] mm: Introduce VM_SHADOW_STACK for shadow stack memory Date: Sun, 30 Jan 2022 13:18:17 -0800 Message-Id: <20220130211838.8382-15-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220130211838.8382-1-rick.p.edgecombe@intel.com> References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu-cheng Yu A shadow stack PTE must be read-only and have _PAGE_DIRTY set. However, read-only and Dirty PTEs also exist for copy-on-write (COW) pages. These two cases are handled differently for page faults. Introduce VM_SHADOW_STACK to track shadow stack VMAs. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Signed-off-by: Rick Edgecombe Cc: Kees Cook --- Documentation/filesystems/proc.rst | 1 + arch/x86/mm/mmap.c | 2 ++ fs/proc/task_mmu.c | 3 +++ include/linux/mm.h | 8 ++++++++ 4 files changed, 14 insertions(+) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 061744c436d9..3f8c0fbb9cb3 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -555,6 +555,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/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c index c90c20904a60..f3f52c5e2fd6 100644 --- a/arch/x86/mm/mmap.c +++ b/arch/x86/mm/mmap.c @@ -165,6 +165,8 @@ unsigned long get_mmap_base(int is_legacy) const char *arch_vma_name(struct vm_area_struct *vma) { + if (vma->vm_flags & VM_SHADOW_STACK) + return "[shadow stack]"; return NULL; } diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 18f8c3acbb85..78d9b0fd2aee 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -679,6 +679,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_ARCH_HAS_SHADOW_STACK + [ilog2(VM_SHADOW_STACK)] = "ss", +#endif }; size_t i; diff --git a/include/linux/mm.h b/include/linux/mm.h index 2e74c0ab6d25..311c6018d503 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -308,11 +308,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 @@ -328,6 +330,12 @@ extern unsigned int kobjsize(const void *objp); #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ +#ifdef CONFIG_X86_SHADOW_STACK +# define VM_SHADOW_STACK VM_HIGH_ARCH_5 +#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) -- 2.17.1