Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp673749pxb; Wed, 3 Feb 2021 15:01:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMuvWagmSLPHrhdd8F5rX7E1orJzeTgew+DiUImV9ztVKVtgk7SCf1K97cibJ8ObVWjLRU X-Received: by 2002:aa7:dc17:: with SMTP id b23mr5534691edu.139.1612393304666; Wed, 03 Feb 2021 15:01:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612393304; cv=none; d=google.com; s=arc-20160816; b=HComB85M/zApdZi3x+zz/x4w76254wtm6VhE3BoG88JXlgddap/SHfEj++ZIwNz3kS n5WQNdLxziTzbMjfcqLrnfBBVe9emZ2fx5Y5D1wEi6NfpBz+5vX432wmlu/RrjU79jqW UUJv+QowjcNlLAHxnNkF/tga/XA9rZhhfJ6fKRhkuA0VlSIvwY/84BR//01cG7qg8y6F kuctJrvGjroJsft1dukDOo7R/98KD5MTO3CAA+fPl/qB+c2J0bHn9noTYJlyBjgJdnG3 9A47rfYggsbK1QlUv1mtOjxTeE6UtL+U5ZgVMtuxzdyQl6ShCeuVRe/9gbRVki4FrwMV RQ3w== 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=bxiutzrtjfq6SPnwIWXYimf0q1A9D87cnrv/P9SzROc=; b=SJzrUwx3j3/goht7+/huM0XNoze1bCQYlr9rBbcnxKncoZHtQs20N+CI5fFuVwydyr BC9qJxudVBphDRBtzabvwpPyniYJnO4gjASikIfydv3YZnRhKM3AikoVOZ8lx2bBcK+V mEBn5+/JyKIEM1Epyr5gMTUNgqNW5hiQ2OiMubrIk2Rrakcgio9yyNdcQ2PAMVYtKgon ygOxyK8K//6ukFqXvkwRH3dF3b6XiKVQMSCo/iEsgcUGCLnwij0Dk2LKFcM9im9i3w60 iIoedI23FM66KMBkLU2KLS8NvXgJf9NzauEeVuH+OR1FTsil7yzB9XkQAVx0OBKNPGZ+ P7cA== 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 bx21si2136942edb.354.2021.02.03.15.01.19; Wed, 03 Feb 2021 15:01:44 -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 S233238AbhBCW7g (ORCPT + 99 others); Wed, 3 Feb 2021 17:59:36 -0500 Received: from mga06.intel.com ([134.134.136.31]:30209 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233234AbhBCW6A (ORCPT ); Wed, 3 Feb 2021 17:58:00 -0500 IronPort-SDR: M370wfm+y0ffpPWBZEKTg+DDmK/90lma1RqiBBAV7IQdhrgksSiAH8av7HBkxnmnQ+1FqfSawx tsCZXY7cewFQ== X-IronPort-AV: E=McAfee;i="6000,8403,9884"; a="242642361" X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="242642361" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 14:56:27 -0800 IronPort-SDR: SCq0rYLGCTlnoX4DLRB9aYCg54EYLToAa2tWmDC4ME3ZhgHwiXx3C5LkdsxOUec5Q5s7B28U62 2X0n9b4JgX1A== X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="507921113" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 14:56:26 -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 v19 12/25] mm: Introduce VM_SHSTK for shadow stack memory Date: Wed, 3 Feb 2021 14:55:34 -0800 Message-Id: <20210203225547.32221-13-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210203225547.32221-1-yu-cheng.yu@intel.com> References: <20210203225547.32221-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 602e3a52884d..59623dcd92bb 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_CET + [ilog2(VM_SHSTK)] = "ss", +#endif }; size_t i; diff --git a/include/linux/mm.h b/include/linux/mm.h index ecdf8a8cd6ae..7be5f8b874aa 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_CET +# 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