Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2212221imm; Tue, 10 Jul 2018 15:34:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdSsKquOE/frjRWKcDf33dC0UHTVswZK3Y34WU/RYFmkxdz2LSE3tq6o/R4OKrO9JebjgCq X-Received: by 2002:a17:902:6b86:: with SMTP id p6-v6mr26510989plk.75.1531262065757; Tue, 10 Jul 2018 15:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531262065; cv=none; d=google.com; s=arc-20160816; b=wXoPuMwcni6lGdnlqC8uVK+YBflGvcJY4Kru1Jvqc5vSfiFfC0DyqvGUXurCgmuMWO HV36ZYYvdZY51XxcmB57J6E6VQXgqS5xM5ohsCwdWu4xXcpX8eYBsEVSeeyLg+sE9+mO sHOBmMp/F0lV9iJIJH/DLLFT9AYp9es8NWVQnwRstuSyWk8ahgo497bcUNUyrKsG7wA3 5F+VLSneOjUVs7wtriY0sLVR0cnoxHYLnhcydZwgIxIjTBcp0kKT15fbSpd/DKij8C1L +0eokzE3KY89s2djgKT6qcPkBuCWquOpOqBK5LbMEZx/VzZM4BBAKAoQe+FbE5GNGdgd Z8iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=EeaDLMQwOELis6Fck36HQv0R/Ho0f34b6bUyk01xJAA=; b=wtysoWiXHVT7t1vsnmFVzGZDQBwP6NdrAloljBVIibPPMZ3U8ksq71yTiN35i7dFSw azjGCHWwF6/rGRmHygsfjoD+HR4kZXSeqzlMXAOfeetY3j670mSt4fJZITnwovN5vCX7 9jfgKG0JupA58ec31Z/9PNNfghorBNQXwhKkDKP/4aktc5kU+Nweq+fBlMiQM2amnC/z 3AWKSvt5p/YTA5O3eM1VsQFsuj7zMgSzCM9bgwcbrTvCyJu0B3nFdRG9vUg/ijw3Gk3d KLyHXj8WkANiQBe5HQFWIqEMgP9To067CLo1ziMRb7Toe8oUO0M5QPSywdziV6kc5Xe2 +Bhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id q9-v6si17245088pll.370.2018.07.10.15.34.10; Tue, 10 Jul 2018 15:34:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1732503AbeGJWc1 (ORCPT + 99 others); Tue, 10 Jul 2018 18:32:27 -0400 Received: from mga09.intel.com ([134.134.136.24]:16477 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732469AbeGJWc0 (ORCPT ); Tue, 10 Jul 2018 18:32:26 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2018 15:31:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,335,1526367600"; d="scan'208";a="70305388" Received: from 2b52.sc.intel.com ([143.183.136.52]) by fmsmga004.fm.intel.com with ESMTP; 10 Jul 2018 15:31:11 -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 , Cyrill Gorcunov , Dave Hansen , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [RFC PATCH v2 08/27] mm: Introduce VM_SHSTK for shadow stack memory Date: Tue, 10 Jul 2018 15:26:20 -0700 Message-Id: <20180710222639.8241-9-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180710222639.8241-1-yu-cheng.yu@intel.com> References: <20180710222639.8241-1-yu-cheng.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org VM_SHSTK indicates a shadow stack memory area. A shadow stack PTE must be read-only and dirty. For non shadow stack, we use a spare bit of the 64-bit PTE for dirty. The PTE changes are in the next patch. There is no more spare bit in the 32-bit PTE (except for PAE) and the shadow stack is not implemented for the 32-bit kernel. Signed-off-by: Yu-cheng Yu --- include/linux/mm.h | 8 ++++++++ mm/internal.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index a0fbb9ffe380..d7b338b41593 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -222,11 +222,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 @@ -264,6 +266,12 @@ extern unsigned int kobjsize(const void *objp); # define VM_MPX VM_NONE #endif +#ifdef CONFIG_X86_INTEL_SHADOW_STACK_USER +# define VM_SHSTK VM_HIGH_ARCH_5 +#else +# define VM_SHSTK VM_NONE +#endif + #ifndef VM_GROWSUP # define VM_GROWSUP VM_NONE #endif diff --git a/mm/internal.h b/mm/internal.h index 9e3654d70289..b09c29762d85 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -280,6 +280,14 @@ static inline bool is_data_mapping(vm_flags_t flags) return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE; } +/* + * Shadow stack area + */ +static inline bool is_shstk_mapping(vm_flags_t flags) +{ + return (flags & VM_SHSTK); +} + /* mm/util.c */ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma, struct vm_area_struct *prev, struct rb_node *rb_parent); -- 2.17.1