Message ID | 20230613001108.3040476-22-rick.p.edgecombe@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp223271vqr; Mon, 12 Jun 2023 17:47:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7TN6GpV5GOAQ6QdL27CKdpj05dYwr4IrItW1+jjLF/njzkLrJFvUTeZHRVSf4i8bVOmOKY X-Received: by 2002:a05:6402:1258:b0:518:7902:d244 with SMTP id l24-20020a056402125800b005187902d244mr36100edw.6.1686617240144; Mon, 12 Jun 2023 17:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686617240; cv=none; d=google.com; s=arc-20160816; b=fQFYu8wWKUXEz6i1Abhq9xq68pbdTJXx7CJXw2gM3opwMZ1VA+cowWDyx0UBAPSsHK YsRU0pyamkzNkOXvMJJJE7GrBuGX4uvJTAlKzC2Tvk2NnDqHRDXkJUOnF2TovDATJmCL 8azMVEIuhcN/fYZ1WmDix3wQzMOs+Nfwj0MazBdowZUU7p3F+mFtgWivniqJ9s2mtDt0 6PUCyuHt30rN0Khe5AX5LfE2FYFXmYOFePjMWkJsdsjETZE7vzcnIaqXO0vcc5PLHca+ pgLIjUnSJeM2H2aH1ADCtJvoQK6GYqzkAJemwhwWMlc+5tySIDZlNZPW+NkSuj3wZqSV nJ1A== 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 :dkim-signature; bh=PXl5GqZ7V0Lo7jE7kAx6s21MXFeCFmlgpAurMlsy448=; b=LgcW3RzquP8lTfQG8TB0PLi/Y8da4wcCGeTqva2lxCp8BMOzEGgc/2rPiTZH+MYje5 t9vuwMAIydW9F9hORrgQ1qOfvAf3FdGb43mGpaKgly/5urk/eeM+rfHd9IEM9UmwscQg AH1z+PKmkGCD5Pc5lqk3aS5d8mhioV+8sdCD37+o7xF8FY8k16euNHPSZEEXLkVXMMb+ YGc0aH9K3pmuwxpeO0QzvH4UXhmKPZ59F0u38ZdsQMzpEAEsvU3JMrq3qNhK+QFToZtK q/V66jfR1H/4keSJ5F1SLEH5FDOeQZD927o8W/hYApfhKOSh+xF0e6dxCSSJIe8ze3/a aj+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G03JU2S0; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a056402180400b00510d91f80aesi6645614edy.73.2023.06.12.17.46.56; Mon, 12 Jun 2023 17:47:20 -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=G03JU2S0; 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 S238924AbjFMAPt (ORCPT <rfc822;rust.linux@gmail.com> + 99 others); Mon, 12 Jun 2023 20:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233336AbjFMAOY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 12 Jun 2023 20:14:24 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17AA41FD4; Mon, 12 Jun 2023 17:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686615176; x=1718151176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c7sunRbrNdSwt/1KmOuIzzKZkXv73NcNzDYIVaoBldo=; b=G03JU2S0Evi/fePKI8tofmFf6jCfbNuseYNk3pBFLsEjtODG0wjoLGX+ fTtSibEDt9OAP17er1I4Y2zOUV+gLWqXTiu7hsS6hUTYyhxkDSadT8Ihk C5CDBUZgCNPaY5h5CR/sbJg/4LKePeZkxee12wEJJxmjKh4tipSR+a9Qc w5tc+YhEQtoNcTjqPXbqzwshaVvGDWwcJzqPt9OrfXmTvLLO3tyz384MH 2E5LkLl5e2e07zNSx8KSt4z1kHIfUHdPl8zbXgCZdRIuKlsGxnubCYOtY P3ghlZM2+r1GM7YyFY84GurNIdlWtTMvT2smfRg87Qwe8bKcd9xoMsz4a w==; X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="361557144" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="361557144" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 17:12:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="835671052" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="835671052" Received: from almeisch-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.amr.corp.intel.com) ([10.209.42.242]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 17:12:25 -0700 From: Rick Edgecombe <rick.p.edgecombe@intel.com> To: x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, 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 <arnd@arndb.de>, Andy Lutomirski <luto@kernel.org>, Balbir Singh <bsingharora@gmail.com>, Borislav Petkov <bp@alien8.de>, Cyrill Gorcunov <gorcunov@gmail.com>, Dave Hansen <dave.hansen@linux.intel.com>, Eugene Syromiatnikov <esyr@redhat.com>, Florian Weimer <fweimer@redhat.com>, "H . J . Lu" <hjl.tools@gmail.com>, Jann Horn <jannh@google.com>, Jonathan Corbet <corbet@lwn.net>, Kees Cook <keescook@chromium.org>, Mike Kravetz <mike.kravetz@oracle.com>, Nadav Amit <nadav.amit@gmail.com>, Oleg Nesterov <oleg@redhat.com>, Pavel Machek <pavel@ucw.cz>, Peter Zijlstra <peterz@infradead.org>, Randy Dunlap <rdunlap@infradead.org>, Weijiang Yang <weijiang.yang@intel.com>, "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>, John Allen <john.allen@amd.com>, kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com, szabolcs.nagy@arm.com, torvalds@linux-foundation.org, broonie@kernel.org Cc: rick.p.edgecombe@intel.com, Pengfei Xu <pengfei.xu@intel.com> Subject: [PATCH v9 21/42] x86/mm: Teach pte_mkwrite() about stack memory Date: Mon, 12 Jun 2023 17:10:47 -0700 Message-Id: <20230613001108.3040476-22-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230613001108.3040476-1-rick.p.edgecombe@intel.com> References: <20230613001108.3040476-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768546359251974006?= X-GMAIL-MSGID: =?utf-8?q?1768546359251974006?= |
Series |
Shadow stacks for userspace
|
|
Commit Message
Edgecombe, Rick P
June 13, 2023, 12:10 a.m. UTC
If a VMA has the VM_SHADOW_STACK flag, it is shadow stack memory. So when it is made writable with pte_mkwrite(), it should create shadow stack memory, not conventionally writable memory. Now that all the places where shadow stack memory might be created pass a VMA into pte_mkwrite(), it can know when it should do this. So make pte_mkwrite() create shadow stack memory when the VMA has the VM_SHADOW_STACK flag. Do the same thing for pmd_mkwrite(). This requires referencing VM_SHADOW_STACK in these functions, which are currently defined in pgtable.h, however mm.h (where VM_SHADOW_STACK is located) can't be pulled in without causing problems for files that reference pgtable.h. So also move pte/pmd_mkwrite() into pgtable.c, where they can safely reference VM_SHADOW_STACK. Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Kees Cook <keescook@chromium.org> Acked-by: Mike Rapoport (IBM) <rppt@kernel.org> Acked-by: Deepak Gupta <debug@rivosinc.com> Tested-by: Pengfei Xu <pengfei.xu@intel.com> Tested-by: John Allen <john.allen@amd.com> Tested-by: Kees Cook <keescook@chromium.org> --- arch/x86/mm/pgtable.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 101e721d74aa..c4b222d3b1b4 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -883,6 +883,9 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma) { + if (vma->vm_flags & VM_SHADOW_STACK) + return pte_mkwrite_shstk(pte); + pte = pte_mkwrite_novma(pte); return pte_clear_saveddirty(pte); @@ -890,6 +893,9 @@ pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma) pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) { + if (vma->vm_flags & VM_SHADOW_STACK) + return pmd_mkwrite_shstk(pmd); + pmd = pmd_mkwrite_novma(pmd); return pmd_clear_saveddirty(pmd);