From patchwork Thu Jun 7 14:36:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-cheng Yu X-Patchwork-Id: 10452275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E02FE60146 for ; Thu, 7 Jun 2018 14:41:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D02F429545 for ; Thu, 7 Jun 2018 14:41:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB3E129586; Thu, 7 Jun 2018 14:41:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BD34295F7 for ; Thu, 7 Jun 2018 14:40:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 108C16B026B; Thu, 7 Jun 2018 10:40:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0B6BB6B026F; Thu, 7 Jun 2018 10:40:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0E726B0270; Thu, 7 Jun 2018 10:40:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id ACD206B026B for ; Thu, 7 Jun 2018 10:40:43 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id e7-v6so4626550pfi.8 for ; Thu, 07 Jun 2018 07:40:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=uykaDMcpqeoA5WJe89EKlnsNTr7InlN+MhMLbfxaFQM=; b=d6JdHVpm3Iy6CdeZD5AKz9ctcv7CilgGxiEDjF0LORWACUprzvnlfdWIv5jL5VYi7g tgwgXevn0HBbFCoeGDj5xBbZpV4HErVXE5rwJVYW8dShdZ3wuaK4gA8cAYF9shNHa4Td ZXPmIe9y2Zjo+UiqoGFwmsoMuwQ7AWa3qP2yztbGI4OxN7PFNd6UkOxgRY4vwlMgwTH9 luh2uJsG1oovwMlq+c4zzLZIig9Oh1Nj4jxmGPmf3e8SqpNH7esDOauSsn+uVWYvkO0h weU678f33Jw5k34HSH3YTcVGUJcEJKFj7niZYTnePQjknukwFHSDkE7D5H7v8hVqoome ohyw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APt69E2ylhxo2c0tTX7D/ZolR72YNuiWilPHNq684LU5cDcSIYeQcIBy B7SKzt+g/Phcrd1MFu/7JsvOTTdP9AdzDE/r96M6cnkNeORbzGpfhHYEtcAxrQgh1RHO2bI4wUT fvccbhj6/1ehyLZr5qNB59SZNWYoWMVkdvQ7Tt+aA3RYZ6I/A92N6U5dSWnN2T/ltiw== X-Received: by 2002:a17:902:6046:: with SMTP id a6-v6mr2316210plt.59.1528382443148; Thu, 07 Jun 2018 07:40:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLAjoug5NkXgR00OLVmcu444bj0iKBGFK0jvfMdwz7xq5jicIe/NmtFZyJprGRZO1OePFpT X-Received: by 2002:a17:902:6046:: with SMTP id a6-v6mr2316168plt.59.1528382442490; Thu, 07 Jun 2018 07:40:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528382442; cv=none; d=google.com; s=arc-20160816; b=fw8KPA4YO096mmyjLhBIcfiGAT7umKhS1sk+7HrYmOWop0xVUltfeti3LJIT7JdlNu GdWXZAdjpWf4FEagN1KuHl40LBTuIqWdPDPmoxFnP0q+sSAWua9MZg9Jf8GkajjWvBsK bGl+AEVkzEA3QQSGHd/mIXn1XReYJ2/SfakMTozcMHoPWhzSR3dlCCsjqC8OJW1zzPD6 kxd6gVCiCgYN5iVwiQmQUbFVE5atjW1jvyWCXG82jw99mUMjI+I2qXcl/jGM7CI958rn 5gRTHgCpQZyhK4RQf1QkHXGUmyK0E1DXtEp37NB2ptBHZW7+Q44540SNGij9vLNvv4O2 ty4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=uykaDMcpqeoA5WJe89EKlnsNTr7InlN+MhMLbfxaFQM=; b=pOY9o9jKotG4GgxwPizoPuc0YU0ttMyd9XfIHufj0Ak4aTTpeHAs3Lhqoq8OfynZow nAJPkqCEtmqvubeLTBKztSJdl5bw2Wmal8lgqWjjUnqdtcUUyQv+bYTvUMEvfom4h+3V eWvhmyaBMT2KlpmgxBhoDxXz2LPdekNNwYwlWpfaDUcMeq6H+5rLBZMIEvmXGNgc1dNZ JFPMlVaESVOBqNf3xTBWQRfLeDwgGJGSFvrRmfWKlgzMPngusdHPFfv372jV6PRUPahb 52m4CXXQa5HDYtMiE+fjCMbOHyUuBVyuQHUVU5qpCJBaOIaFQhV7SHoJpK6TzZ0VcGUy NoJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id b60-v6si54342625plc.270.2018.06.07.07.40.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 07:40:42 -0700 (PDT) Received-SPF: pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2018 07:40:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,486,1520924400"; d="scan'208";a="47542292" Received: from 2b52.sc.intel.com ([143.183.136.51]) by orsmga008.jf.intel.com with ESMTP; 07 Jun 2018 07:40:32 -0700 From: Yu-cheng Yu To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H.J. Lu" , Vedvyas Shanbhogue , "Ravi V. Shankar" , Dave Hansen , Andy Lutomirski , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , Mike Kravetz Cc: Yu-cheng Yu Subject: [PATCH 3/9] mm: Introduce VM_SHSTK for shadow stack memory Date: Thu, 7 Jun 2018 07:36:59 -0700 Message-Id: <20180607143705.3531-4-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180607143705.3531-1-yu-cheng.yu@intel.com> References: <20180607143705.3531-1-yu-cheng.yu@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 02a616e2f17d..bf4388a8cc41 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -221,11 +221,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 */ #if defined(CONFIG_X86) @@ -257,6 +259,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 502d14189794..44c64711a309 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);