Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4832330pxy; Tue, 27 Apr 2021 13:47:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVot92O1oNpzgBxq/Rw3cxDrTdQ4Mm33fdsDm+WCiOuOTo79km05pcKsoXhcpvUU/wsyyz X-Received: by 2002:a17:90a:6582:: with SMTP id k2mr151552pjj.11.1619556448229; Tue, 27 Apr 2021 13:47:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619556448; cv=none; d=google.com; s=arc-20160816; b=RZb1Z0V4oHFolB+h8vX+AwXbInforoPS7JGJZVOB05aDFrVOPbfyXAJ4WQr3nptO9p LmkN9Fwtd286f1Z7H+DvujKynn4rj1ZcsD4yD0ZGjdCenSyvxiqjJzp6hwIfFTY+jenl POpTSzj4qMzFwXzNjYVPHqCkHhnIg12NAaFSP5UZrzNrCKW/zwWRJLkDx3Y1yGS/fgkl 11yMcRiDOAhAgc255DCDykx66atd2ceuFtiDM8ViuuZJdfM7Q8P6h2dDKw3YKXa7Axjv MG1aRhUl7pJgiE02XbKxFQYhj/PGZ89h8h5gV0b9uiON0UlixhnA84lf4LA9VRNhu+Mx Hd/w== 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 :ironport-sdr:ironport-sdr; bh=I5xaVb2FlnlxIN1pg1sIM+dgD2kl33L5NW+B2s2LnHo=; b=oCB5QbAGxn0u8Rz/eFFrdJAv/qr2g7EKHlpsxD8qv0SadO/V0ifbnXmUrjSPlcERhl aUJQWvvheMaVFsdEk2h/ZvEY6EnqGzAjszOIUUSjWTIQ7JUbXsQRD3ODe3R1qT74gzrX 6RIY5dnflKBVJrAPMZyDyOYKsr02YBpi51Ac8QpvANajoGXGEe5i372P1D/EZ6i0BsnW Pa1v/TAaokTAYHGsZARyLByPFIKiBG+Ke3kGoxOuY/1yYNmMdKy0+ioCFMVBvNhYvXB7 it20MsZV6xcPKHBp/yUJMcPCGzObDK9yPO6kF2W7aBfcsH14Gyt8og14NHuY2b1WxgDO W/aQ== 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 3si5402997pfh.72.2021.04.27.13.47.14; Tue, 27 Apr 2021 13:47:28 -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 S239159AbhD0Upn (ORCPT + 99 others); Tue, 27 Apr 2021 16:45:43 -0400 Received: from mga05.intel.com ([192.55.52.43]:31798 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239149AbhD0UpU (ORCPT ); Tue, 27 Apr 2021 16:45:20 -0400 IronPort-SDR: LcD5KnT8q60rsqfk0mfI3Enihw2LyWNcJQlqXMYypwwXCBHk36RhYPYKpt8by+bpIFYFkSkb8O R/gnbtIvkyRA== X-IronPort-AV: E=McAfee;i="6200,9189,9967"; a="281922473" X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="281922473" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2021 13:44:14 -0700 IronPort-SDR: fPQDCgww/rvIQCz4XzmmPJ6YWN3uFmotycfnhwhLnt+5VNk5846wUueDBHbfJE6q5HYKmwekrj uerC1/LhuDFw== X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="465623499" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2021 13:44:14 -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" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang Cc: Yu-cheng Yu , "Kirill A . Shutemov" Subject: [PATCH v26 13/30] mm: Introduce VM_SHADOW_STACK for shadow stack memory Date: Tue, 27 Apr 2021 13:42:58 -0700 Message-Id: <20210427204315.24153-14-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210427204315.24153-1-yu-cheng.yu@intel.com> References: <20210427204315.24153-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 --- v24: - Change VM_SHSTK to VM_SHADOW_STACK. - Change CONFIG_X86_CET to CONFIG_X86_SHADOW_STACK to reflect Kconfig changes. 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 48fbfc336ebf..5d8a2d75c799 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -549,6 +549,7 @@ encoded manner. The codes are the following: mg mergable advise flag bt arm64 BTI guarded page mt arm64 MTE allocation tags are enabled + 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 e862cab69583..0aa57de9dfab 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -661,6 +661,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) [ilog2(VM_PKEY_BIT4)] = "", #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ +#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 8ba434287387..08282eb2f195 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -312,11 +312,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 @@ -332,6 +334,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