Message ID | 167933036405.5837.15340188207531246966.tip-bot2@tip-bot2 |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1326052wrt; Mon, 20 Mar 2023 10:02:24 -0700 (PDT) X-Google-Smtp-Source: AK7set/RkkSTY/LvlHFjsjKhazQSmpBNQptI+fASs2W3dPqBT59epbDW6kLVIFtJ7WPJgx5KK2lJ X-Received: by 2002:a05:6a20:b703:b0:d9:2818:441 with SMTP id fg3-20020a056a20b70300b000d928180441mr6967080pzb.5.1679331744070; Mon, 20 Mar 2023 10:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679331744; cv=none; d=google.com; s=arc-20160816; b=PiQl5dKKHVn8VttalCbEPp51aSxv7XVdsbALaPF9V64UQ4PKro3UijvcK/JEHeuhad K5lhayCAA8zJXxG8aB4w3IBiHgF49vNYhKJ4wXGKXRQiLoDE7owFNZp4ZEWzN/4vWaN4 /G9l7z4OijSSB159U5eyoHXG0plv8kyWEFMiHv+p09SpK6tEBFV7/d95Cy71kuT7I8hH Gk4OSAd/Axgp740tQHmE+HPlcBi49NAPrXBAL4FyX2NgdY0QIwv12KuD7AtPtd7c+fDY PN6Ttokw0b87Ai5lbOH41iqYvZ2NlavSexsu70LijevXZf7zW5eDRrPw9e9B5hSJOSFb SIJg== 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=mMq0WQr0hq8wDvTsZ+f3hHbrwqrKiCvC+eM50M6jNR8=; b=Wv+YztnownIvGwc4fewDxMNHyH/VGjroqmkpqo5PL8ES0ssnLDrXl8KCXWQl08R8Ku Aldh78S3b5iqDehfuLABcni6R5m/bkUSeEda0itZcF6Ish/FeC9O7gtSzwAE2u7efjU2 z/bQBY/aMyE/ipORl5wPRDoaTneAfZofpwl7RMAOg6DEHQzHQzNV8p1Sl3OvzkH0u6Hm 3KiKXnDzAvTw1gHK3vunmkY1cl8C81MroaS0NqBTWYF+wS8GcVlWe3vNJGXxO/SJFjPp CBiCteSaIil/I6TMO+QuUZ8GrDUi8ZdNdfhPSovJzvlAk6zp+gZC33h2flIB9ZEre7+z UbPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ljZlztWf; dkim=neutral (no key) header.i=@linutronix.de; 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 p9-20020a654bc9000000b00502d5c32148si10777999pgr.248.2023.03.20.10.02.10; Mon, 20 Mar 2023 10:02:24 -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=ljZlztWf; dkim=neutral (no key) header.i=@linutronix.de; 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 S231918AbjCTQs6 (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Mon, 20 Mar 2023 12:48:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231925AbjCTQrl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Mar 2023 12:47:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AEC9360B9; Mon, 20 Mar 2023 09:41:12 -0700 (PDT) Date: Mon, 20 Mar 2023 16:39:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1679330364; 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=mMq0WQr0hq8wDvTsZ+f3hHbrwqrKiCvC+eM50M6jNR8=; b=ljZlztWfPAfQ7tQ801qIxZdeaSaUIzjH7U/e3GKtaRKxUT+rGN4CDImQ2b91lDwMYvonmr fvIDMdXB6hRuEkullqBSeTNOTEsVXAHDxMvgnz/Kn0SuDK7qcmBEnng+QilCeTKLNhlcg2 IfEWn16q6dFYMZ+snMRfXEu4pxM4c/e8V0NsjAaG1C2+xmClhhQPBSkQnRXVaym2Trh1/Q /HJ0QMcSRVWYxm3UHEgO6N1Tl8q92d3LqYRRmvXqE/W2P00UvNIuoawh0bP3I+7zpvo5SM 39UDsIg1Cms0zwo0KNqxX/Ltun/UDJvFyetnVXEdBXK46kjBG9yFVD3k3SYpEA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1679330364; 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=mMq0WQr0hq8wDvTsZ+f3hHbrwqrKiCvC+eM50M6jNR8=; b=RwQ6Ayjsd0HkKvNIRJWbV1zcDgVUoJ/5tg21LJx3z1sQ1EAtVLRCn019BO7dHCmXTSiw2q 9TsRokrfMDobemDg== 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>, "Borislav Petkov (AMD)" <bp@alien8.de>, "Mike Rapoport (IBM)" <rppt@kernel.org>, 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: <167933036405.5837.15340188207531246966.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 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?1760906963024063457?= X-GMAIL-MSGID: =?utf-8?q?1760906963024063457?= |
Series |
[tip:,x86/shstk] x86/mm: Warn if create Write=0,Dirty=1 with raw prot
|
|
Commit Message
tip-bot2 for Thomas Gleixner
March 20, 2023, 4:39 p.m. UTC
The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 6ad563c4b42f64038456f838f3bd712acc95cbcb Gitweb: https://git.kernel.org/tip/6ad563c4b42f64038456f838f3bd712acc95cbcb Author: Rick Edgecombe <rick.p.edgecombe@intel.com> AuthorDate: Sat, 18 Mar 2023 17:15:22 -07:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Mon, 20 Mar 2023 09:01:11 -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> Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de> Acked-by: Mike Rapoport (IBM) <rppt@kernel.org> 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/20230319001535.23210-28-rick.p.edgecombe%40intel.com --- arch/x86/include/asm/pgtable.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index e5b3dce..7142f99 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1032,7 +1032,15 @@ 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(cpu_feature_enabled(X86_FEATURE_USER_SHSTK) && \ + (pgprot_val(__pgprot) & (_PAGE_DIRTY | _PAGE_RW)) == \ + _PAGE_DIRTY); \ + pfn_pte(page_to_pfn(page), __pgprot); \ +}) static inline int pmd_bad(pmd_t pmd) {