Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2837003rwb; Thu, 29 Sep 2022 16:06:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM64hA2i4luBhdOvRO06bjGrihE7UKTx/fPX8V3NgpwZzxXB5muRvuwP20HkdcFkIif/dGnt X-Received: by 2002:a17:90b:224e:b0:203:fb9:6d6 with SMTP id hk14-20020a17090b224e00b002030fb906d6mr18185705pjb.208.1664492798504; Thu, 29 Sep 2022 16:06:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664492798; cv=none; d=google.com; s=arc-20160816; b=nKy2InlzHVNb6tM2J7luEllBttVKV0XorC5Elj3kW7ZCitE2nInGBVemXM4gSUX6m/ sctZfUztyavaedZmdqMuXTHtlOupoRcoVTbPvRlswY4W0/E73Tz8l1AiNmVsdj+9UJbL PEZGdPfMrYgdNfiy7fX6LsGdTv/rgmLd9lxSh0+UGYy+wQc+F+yOczyNuGxs/c1wltaE 28tz3kPVxpaMnCqbdtP3+n5ssacNrFDBi5S3N4HRIZ+AcfS400Fo5yMSmWBklmi/LrTD x2/IsdoYIEu08aHi/Re6vsBgQWaSxkdpSOLU1D5saHrkGvezr0Pi7EaFmgtSkDWknk/E BCvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=d5kHpuIJ8ZUHtrfp7IeYufKnRiW/rKo24qE8EgfXHsU=; b=n6Vh/GNN6Kkl6ONI0hp9tloIe5xJpB3BaoWQroOMKgvjBQfEj5eIa9SrGRCzDVoYfF GQVrJpA4x9/S9OD8pAgIts55U+6PSHgfJm2yd4dJwbxe3MYEKsv2t98uWHSq43Q+w7qV zydH8zzIU9OYoz2+vf3WHXeRi8LgneYZI0KWcYPEQf0YrSS+4ftsxZV3Wf8v3pR2NjJX Z6et5eF2a1U1ATJdphwru0P5TNN7ND86uO3bgGiCrUTz/m6mgSPonUDuFtGVEQWtXPQS NfnabNwFXoo5DxsMAFPJ6DM23XFBo2qfiAwp4iZmnJAvV5PMMl+ny/gpl3oiJ+piKZUD C0Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NV7aP9IR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a639d0d000000b0043966935b33si1127003pgd.166.2022.09.29.16.06.27; Thu, 29 Sep 2022 16:06:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NV7aP9IR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbiI2We2 (ORCPT + 99 others); Thu, 29 Sep 2022 18:34:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbiI2WdR (ORCPT ); Thu, 29 Sep 2022 18:33:17 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E155732058; Thu, 29 Sep 2022 15:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664490672; x=1696026672; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=eA3IOTEvlbESNVd0B9n9A/9HGJD20AxSfeCoBdQ1OOM=; b=NV7aP9IRrFVlkoXIV8UH66S9f6rll49OtVehpD4nK8sXCyMZYdTGwfdj gvdMlCMuAEQHcUjAyfvs14JVwXN8+Go3IAhHgJ2f17KFxwcaKp/WQrygQ AMvuUs07V9Jz5wNH+VfuAJfCbZ21ZR00o4gqqvCQcbX/TRxK/u1BT1+Bi IJb4MJYvycT7oI1ZQp8Zye5NOmI2kRSPhgGOZQBuHLxT3h5OF2mUGaCRv 9DgaNAjTQwly90Jr5VV8PZ8iNRQuklEzGIjYtnQ2Y6QOTJdVt8bdpOmIx SN8IZQcFUOyIo8Q5Cf1GBXuCca+YtO0acYso4YufP7gSc0ogMyo255UOm g==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="303531431" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="303531431" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:30:14 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="691016205" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="691016205" Received: from sergungo-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.251.25.88]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:30:12 -0700 From: Rick Edgecombe 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" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v2 14/39] mm: Introduce VM_SHADOW_STACK for shadow stack memory Date: Thu, 29 Sep 2022 15:29:11 -0700 Message-Id: <20220929222936.14584-15-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929222936.14584-1-rick.p.edgecombe@intel.com> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu-cheng Yu 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_SHADOW_STACK to track shadow stack VMAs. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Signed-off-by: Rick Edgecombe Cc: Kees Cook --- Documentation/filesystems/proc.rst | 1 + arch/x86/mm/mmap.c | 2 ++ fs/proc/task_mmu.c | 3 +++ include/linux/mm.h | 8 ++++++++ 4 files changed, 14 insertions(+) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index e7aafc82be99..d54ff397947a 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -560,6 +560,7 @@ encoded manner. The codes are the following: mt arm64 MTE allocation tags are enabled um userfaultfd missing tracking uw userfaultfd wr-protect tracking + ss shadow stack page == ======================================= Note that there is no guarantee that every flag and associated mnemonic will diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c index c90c20904a60..f3f52c5e2fd6 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_SHADOW_STACK) + return "[shadow stack]"; return NULL; } diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 4e0023643f8b..a20899392c8d 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -700,6 +700,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR [ilog2(VM_UFFD_MINOR)] = "ui", #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */ +#ifdef CONFIG_ARCH_HAS_SHADOW_STACK + [ilog2(VM_SHADOW_STACK)] = "ss", +#endif }; size_t i; diff --git a/include/linux/mm.h b/include/linux/mm.h index be80fc827212..8cd413c5a329 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -314,11 +314,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 @@ -334,6 +336,12 @@ extern unsigned int kobjsize(const void *objp); #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ +#ifdef CONFIG_X86_SHADOW_STACK +# define VM_SHADOW_STACK VM_HIGH_ARCH_5 +#else +# define VM_SHADOW_STACK 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.17.1