Message ID | 168694302063.404.5940870188283668995.tip-bot2@tip-bot2 |
---|---|
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 k13csp1570336vqr; Fri, 16 Jun 2023 12:34:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6xXz3t8oHSZnQr5U0cxcpFRsJTswdh2I7TzXoVqU9+4dQ2dCwGHHigXmPAgR6ijW87ijVI X-Received: by 2002:aca:2307:0:b0:39a:c1ea:6c32 with SMTP id e7-20020aca2307000000b0039ac1ea6c32mr3132331oie.31.1686944066791; Fri, 16 Jun 2023 12:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686944066; cv=none; d=google.com; s=arc-20160816; b=IgeglHVtT402vweV5bgYekzKkfKIlNGa56XSgWALdplO5+WvKWTW0lhAH5YKQv4dI8 AdVokpv+M5fPkvgr7ZmBTCdJ1IN2sDfe/osPko7RccScKnljiA0wi9hY4aVfyPhrt6us qlJxn9Sur4Oy7wXsvdzJkHLRqXEM8wkxaFxZ/oCKAyksVUbFqfCd1LgvyRPYR1an7DAE HL3diI93cbIxaGHUWJQl5Tni33LNvsJq9j8zNwde3gW75wB6yJV9zIa95aXBV8fg2u4E svBOgcI33fvDFsxUAWE+0TQJ4I7SQY6H7+jRdQAmdBe0hl5xC//ESm+6OGZWjNogkTLQ mTZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=ha6EPbpdA+l2JvEFyPXLUG/lmSuPF5IVCR6oMWi+6aE=; b=wVs6xkLtlZav2Ko33ljUyvxi+LrYBIwTi2uK6XaA0JWuWC2kGeiB7iSijEMRr8fivt fILezr1A2nAYioIzLCpRjS8d8Rc94XpZbImuq1iCcvhq0SgA87Ryz2Q8+LiQT82Zg3lX sHHxPiT8lvREdOXWWmQz30bNQRHKV687gdVjlq8vZiKwUqio8dcp2Z3L9mJ62t0IfVXF f7BTp94XxyHjRbjihL+86HC6MRScifO5CgapYIlpUoK1uTv8vc7CVFNPQEiGXXv75zoM l1Vk2wkUeDBM9reqB91RYr11zazDMqxPu3drejxERU126Pg2UVNlto9JydM156dbjemf 7Ahw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AzMxja+4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=aUO0pCWI; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e9-20020a17090a804900b0024e16a5935bsi2196897pjw.54.2023.06.16.12.34.11; Fri, 16 Jun 2023 12:34:26 -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=@linutronix.de header.s=2020 header.b=AzMxja+4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=aUO0pCWI; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345897AbjFPTSm (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Fri, 16 Jun 2023 15:18:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345964AbjFPTRF (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 16 Jun 2023 15:17:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773BA3AA8; Fri, 16 Jun 2023 12:17:02 -0700 (PDT) Date: Fri, 16 Jun 2023 19:17:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686943021; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ha6EPbpdA+l2JvEFyPXLUG/lmSuPF5IVCR6oMWi+6aE=; b=AzMxja+4zsMRcfC4Uct3im7qjKUzVlbhKhmpkve29Na1OOY2JgQCxGDUnRd7xqgT11P50m WpoSnrhboOcLG1nsSQsn4m2kHIOawKtZbon3y4mPkjTEAHOXBy2onCsWg3bDITrtUM1qcS bEHABDyCd2/zpjtypOvPrkiPzk9rKDOkX49VA9xmmmgr7hR1XBZc0LEzShX8RGlUs2wnDB 8kozN8yQGmniMwmkIoqAYIXFhMhM7LQiCQLPTR149O2sFdCjhqb6Fm3to8BqFu7m8N6UZ6 8xtzl/wUUX8zYo5klwuezQN7ewzRHpwiB/MWU3xY/Ur8w7Zqi+VMQqQg+CuQ1w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686943021; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ha6EPbpdA+l2JvEFyPXLUG/lmSuPF5IVCR6oMWi+6aE=; b=aUO0pCWI9NuzL2r4PvnTFeLDF+VcpKJQsszr3aT/qmH6+FTfzyHdR81V4drJves9SAsQe1 Mvfw0uHP46BeGZAQ== From: "tip-bot2 for Rick Edgecombe" <tip-bot2@linutronix.de> Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] x86/mm: Warn if create Write=0,Dirty=1 with raw prot Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>, Dave Hansen <dave.hansen@linux.intel.com>, Pengfei Xu <pengfei.xu@intel.com>, John Allen <john.allen@amd.com>, Kees Cook <keescook@chromium.org>, x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168694302063.404.5940870188283668995.tip-bot2@tip-bot2> Robot-ID: <tip-bot2@linutronix.de> Robot-Unsubscribe: Contact <mailto:tglx@linutronix.de> to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,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?1768889061745093480?= X-GMAIL-MSGID: =?utf-8?q?1768889061745093480?= |
Series |
[tip:,x86/shstk] x86/mm: Warn if create Write=0,Dirty=1 with raw prot
|
|
Commit Message
tip-bot2 for Thomas Gleixner
June 16, 2023, 7:17 p.m. UTC
The following commit has been merged into the x86/shstk branch of tip: Commit-ID: ea7e66f02cbf4f025b95cd724e2159dfdec16464 Gitweb: https://git.kernel.org/tip/ea7e66f02cbf4f025b95cd724e2159dfdec16464 Author: Rick Edgecombe <rick.p.edgecombe@intel.com> AuthorDate: Mon, 12 Jun 2023 17:10:44 -07:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Thu, 15 Jun 2023 16:31:33 -07:00 x86/mm: Warn if create Write=0,Dirty=1 with raw prot When user shadow stack is in use, Write=0,Dirty=1 is treated by the CPU as shadow stack memory. So for shadow stack memory this bit combination is valid, but when Dirty=1,Write=1 (conventionally writable) memory is being write protected, the kernel has been taught to transition the Dirty=1 bit to SavedDirty=1, to avoid inadvertently creating shadow stack memory. It does this inside pte_wrprotect() because it knows the PTE is not intended to be a writable shadow stack entry, it is supposed to be write protected. However, when a PTE is created by a raw prot using mk_pte(), mk_pte() can't know whether to adjust Dirty=1 to SavedDirty=1. It can't distinguish between the caller intending to create a shadow stack PTE or needing the SavedDirty shift. The kernel has been updated to not do this, and so Write=0,Dirty=1 memory should only be created by the pte_mkfoo() helpers. Add a warning to make sure no new mk_pte() start doing this, like, for example, set_memory_rox() did. Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Tested-by: Pengfei Xu <pengfei.xu@intel.com> Tested-by: John Allen <john.allen@amd.com> Tested-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/all/20230613001108.3040476-19-rick.p.edgecombe%40intel.com --- arch/x86/include/asm/pgtable.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 3fbddf6..e846f0c 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1032,7 +1032,14 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) * (Currently stuck as a macro because of indirect forward reference * to linux/mm.h:page_to_nid()) */ -#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) +#define mk_pte(page, pgprot) \ +({ \ + pgprot_t __pgprot = pgprot; \ + \ + WARN_ON_ONCE((pgprot_val(__pgprot) & (_PAGE_DIRTY | _PAGE_RW)) == \ + _PAGE_DIRTY); \ + pfn_pte(page_to_pfn(page), __pgprot); \ +}) static inline int pmd_bad(pmd_t pmd) {