Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1688949pxb; Fri, 20 Aug 2021 11:22:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1vLrErCxhlOJXG67sIJ7Tp2rLKWgAlactGGXPApo5dWdo/oWB9U/nJBpJlUKKjnMkz2p5 X-Received: by 2002:a05:6e02:20c3:: with SMTP id 3mr9488043ilq.139.1629483777463; Fri, 20 Aug 2021 11:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629483777; cv=none; d=google.com; s=arc-20160816; b=a1Yu1CnpCbcSyol3SsCqPsSHekemFIkddW42kW4zhid21zZjRLEcpFa+Szp5nkRKNq 7J2oYAIu+yN1dzfn8FBZkrq6v6ZNXNJJ5/Jabz2EKu0xStebriZWsb++JaKOfyMMUogK NbxGfIU7Vynq6cEZQbjRRXqJYwBBVxQDJyOA2L4MY9rhlUatI6g+8S7YmWDUX2+RWxPf 7NRiPB3QCzS2aNudc8/EeB7n1axsRfb74ST1Le0GFgvJY1SZ3741hjLcxES8lNc6EcBy IWjA3W0ALmPpL9yVSweue6UD8FzrxH+7LcKis+VwQvTGhdwySMZA8G1LcuQa9FDoZjhJ cCJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qWI5q9qf57jzV6OYVXs7/Y71ZAI/jUa9DmsMy34g+Yk=; b=N0ccF+Fj1USB9TORcI1/95hw32bH31PRNDMG3SBxWe9+lB5SO3u3De/eDp8zneIciJ vrgjnvtbx3I+sGVjujAvcJ/kzH6hHLdlZImvHjZ0jEXoWyecOpSlgIbuJDbfa3Xtcj3H C71hTeTX/fr8m1W/pbPl0ia7oJgW2Fbs8yH2n6PfZAcPg8onZnwtalRFSaLd79ttL0kK 2yNMW0mxNc5vMes0FL+Ait21ZzeMi2Bi/dL+QdEZVxHYHBekOakFo/kwC+3GxI9mSBIq 6t7S4mgbrrBDtA5/lWCU7JloRNESAH/0DJ+HfSFtKBFrN9h0YcgXpzmhVAXdORuj6sS2 sYiQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 i23si6910367jam.111.2021.08.20.11.22.45; Fri, 20 Aug 2021 11:22:57 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236644AbhHTSUp (ORCPT + 99 others); Fri, 20 Aug 2021 14:20:45 -0400 Received: from mga05.intel.com ([192.55.52.43]:22429 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237848AbhHTSUO (ORCPT ); Fri, 20 Aug 2021 14:20:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10082"; a="302407813" X-IronPort-AV: E=Sophos;i="5.84,338,1620716400"; d="scan'208";a="302407813" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 11:18:47 -0700 X-IronPort-AV: E=Sophos;i="5.84,338,1620716400"; d="scan'208";a="533074715" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 11:18:47 -0700 From: Yu-cheng Yu 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 , Pengfei Xu , Haitao Huang , Rick P Edgecombe Cc: Yu-cheng Yu , "Kirill A . Shutemov" Subject: [PATCH v29 14/32] mm: Introduce VM_SHADOW_STACK for shadow stack memory Date: Fri, 20 Aug 2021 11:11:43 -0700 Message-Id: <20210820181201.31490-15-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210820181201.31490-1-yu-cheng.yu@intel.com> References: <20210820181201.31490-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 042c418f4090..3473f1aa7e89 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -553,6 +553,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 eb97468dfe4c..d8b2414e47ee 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -662,6 +662,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 1d4e5012c27d..4a9985e50819 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -319,11 +319,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 @@ -339,6 +341,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.21.0