Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4124118pxb; Tue, 10 Nov 2020 08:29:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzz/+aZu4XJq6kCro/F0NBv1kc99OURDgdsSPynYqRgYzDL/Ld7byabJKGNfIc+cAbJKFu9 X-Received: by 2002:a17:906:6453:: with SMTP id l19mr20690714ejn.366.1605025771849; Tue, 10 Nov 2020 08:29:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605025771; cv=none; d=google.com; s=arc-20160816; b=lScFWWSKUjaEU5bKRNQspCdfYHnI1jwibrtuZhf0W20D2taQW6jk/4c0JkpJ5MVk8z Klo5xKQONX2GrHOj8A+t/nyCt/Fz4S9DmJuois6upIAIs4/Lx/yMK7rf0Fx7kUXX16N5 J70pKZVYz1VFqWFs0VaagvXs+1KOsikHa1Pjo9oZoHXGR1SXBhRfuZaQedILSC3TsAbd oBwaw3YFh+F++K++n2blCmRDCdoL498/ZEx1k2PVXb0w9Z5mBsFkPYxSWqfbG3OxLf0w lOF6w/uZiheqelPTCkqZL7YIOx2T4++NwYY6go1N/M8wIpXEN87q9+faKb4SzRbh3yS1 XhqA== 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=SUyZ9yy6v0j7g0nV3DQez+xq5YqQODsjjqf1sd4EBIc=; b=G6aRzdJFDk9E2vXjT67vhOYUo8KHgL+EqKhBNgpwM48K1A/vq3VdFuxGz/ekH7/cvc SS2zkZCZownAShoCyql+i5hosFBgWba5yPuUn2T9lmZyGrg6HhWJri+aGnAPB9kYc+7O ws8b31Ajk0PuPr0Ks19cYbUgonaHXsYvfOdms8irNT9a4dZ0VCnfVRts2sMPhuionMdP rXrrFhcMrAmuBl8NfRCM+0XzNDP1LcOKYWe47DfLLqs/pCNwmre+TiKx0tAf4nEAw9e5 kEiepRSYMNziE7NAUY0njMa/3KDv+0LT108clzg8CSytkr50RUGlZtGmG4ZEu/1n3ZhE d3aQ== 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 k9si9364758ejx.605.2020.11.10.08.29.08; Tue, 10 Nov 2020 08:29:31 -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; 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 S1732773AbgKJQYp (ORCPT + 99 others); Tue, 10 Nov 2020 11:24:45 -0500 Received: from mga02.intel.com ([134.134.136.20]:25988 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730285AbgKJQWy (ORCPT ); Tue, 10 Nov 2020 11:22:54 -0500 IronPort-SDR: afA7vCTZ45w3iRHpxEthrlT55Wv9DDm05oAodJEjiwZ4saIJYi49bnCxKVa7Zfiy81RJv4v+aT nEHsXrU1lLGA== X-IronPort-AV: E=McAfee;i="6000,8403,9801"; a="157008720" X-IronPort-AV: E=Sophos;i="5.77,466,1596524400"; d="scan'208";a="157008720" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2020 08:22:53 -0800 IronPort-SDR: X4ZGIXYr72OoqjMRdcb2KyYOrHFdaxGQUCrbrs3fyfXGApp6XDRiaLux66jcXM+tUX9weRoVLv roxMnFNfg1gg== X-IronPort-AV: E=Sophos;i="5.77,466,1596524400"; d="scan'208";a="365572853" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2020 08:22:51 -0800 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 Cc: Yu-cheng Yu Subject: [PATCH v15 12/26] mm: Introduce VM_SHSTK for shadow stack memory Date: Tue, 10 Nov 2020 08:21:57 -0800 Message-Id: <20201110162211.9207-13-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20201110162211.9207-1-yu-cheng.yu@intel.com> References: <20201110162211.9207-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_SHSTK to track shadow stack VMAs. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook --- arch/x86/mm/mmap.c | 2 ++ fs/proc/task_mmu.c | 3 +++ include/linux/mm.h | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c index c90c20904a60..a22c6b6fc607 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_SHSTK) + return "[shadow stack]"; return NULL; } diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 217aa2705d5d..c72143cdbb5d 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_X86_SHADOW_STACK_USER + [ilog2(VM_SHSTK)] = "ss", +#endif }; size_t i; diff --git a/include/linux/mm.h b/include/linux/mm.h index db6ae4d3fb4e..c7f527bd21fb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -304,11 +304,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 @@ -324,6 +326,12 @@ extern unsigned int kobjsize(const void *objp); #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ +#ifdef CONFIG_X86_SHADOW_STACK_USER +# define VM_SHSTK VM_HIGH_ARCH_5 +#else +# define VM_SHSTK 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