Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4069417pxu; Mon, 12 Oct 2020 08:43:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtiI+HSwY1iP4rwsoyvx7IEDKyJF+ENnSK1T7JxCt2U9DroMuke30OBfoWVUP6M2ojWCtQ X-Received: by 2002:aa7:dcc7:: with SMTP id w7mr15117085edu.80.1602517404365; Mon, 12 Oct 2020 08:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602517404; cv=none; d=google.com; s=arc-20160816; b=diWTXgGwZUITfJWYU3w3EX59LWBKRn2PB1kk4fzxmeAdfO2ITPyaBGWjRe3lW214rn iUryBWOCntt7LijjublG3nB0M2pjS50/UmmflXKzlA0eGBV3RlgsNUGnGZebFywcr9sy LghM3RblIqvA7dIEvnfU1HZh4Q4lRurCCV39TyNak7wpiU+cez8n/v/ksxL9FcYkN0uE jOCOH6Wfu6o0eeNoGyC49f2wOL95orpjhapQh4wPNA/M0zjF+CHRv0bAIBnw3v7clC+c fBFpM7xTQrqrMSxVcv6QGf8aESqrFwioNjzAp+vfnkMKTsxU8a5bZt2ej2hS4EbrYbHK eeIw== 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=1Qar1YU9T2Wn9bekGgPR1CDG+QT3mTfdsbE569lU2ZU=; b=Be+PaDsNql6K/VvUBfg/+jKzQZ4tBvKTLyyWBobidPP5Z8VO2hhAxS+jPbHkjpYgPC quYkPPf9D/i6hWrZ6qrpe09nvW+5eeCHzyMLHgiv4b0ZERDc2X9OTpQr2oUrjRSyL1gV cbK0oZpf1iV16e35bZTy1W1ZK7yyNoEayuA5aFUjB4NycrW4WdsxytSlUvFEATyJGn9g HmV+goKTjHRtfPbF8Ddv/cTewlzkkqz5eQq/0u+/ld3dOvQgT29acID7IQrX0+IfIjhe Lb6jsGWr2v7MCMRgV0wrJWMaTxyyiCbBzZgvQ3CfCLRa0KG26BT8WmU4jutAjCCHS5DW a3sw== 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 y6si12657401edu.43.2020.10.12.08.43.01; Mon, 12 Oct 2020 08:43:24 -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 S2390761AbgJLPl0 (ORCPT + 99 others); Mon, 12 Oct 2020 11:41:26 -0400 Received: from mga05.intel.com ([192.55.52.43]:1310 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390310AbgJLPkH (ORCPT ); Mon, 12 Oct 2020 11:40:07 -0400 IronPort-SDR: ZhcJR5or1Pid1b2Y8Gs3aL5uA72U0oml+GrRNgobV8bj0pe8pJPRKurVJxa9ZDSDyfH/NOoD10 t+GjzP0Cab6g== X-IronPort-AV: E=McAfee;i="6000,8403,9772"; a="250452679" X-IronPort-AV: E=Sophos;i="5.77,367,1596524400"; d="scan'208";a="250452679" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 08:39:52 -0700 IronPort-SDR: H83apuW97TYnz5qJujaFhyiJphQUrX0JfE5i4d6NfcHnCcy6SHaI5mzME20D2J+NAbTYjrd0Pe tO9z3lW206aw== X-IronPort-AV: E=Sophos;i="5.77,367,1596524400"; d="scan'208";a="530010853" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 08:39:51 -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 Cc: Yu-cheng Yu Subject: [PATCH v14 12/26] mm: Introduce VM_SHSTK for shadow stack memory Date: Mon, 12 Oct 2020 08:38:36 -0700 Message-Id: <20201012153850.26996-13-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20201012153850.26996-1-yu-cheng.yu@intel.com> References: <20201012153850.26996-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 5066b0251ed8..436dd37f2d4c 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -663,6 +663,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 16b799a0522c..12be96b061c7 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