From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 354DBC433E6 for ; Mon, 8 Feb 2021 23:03:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E1E4264EA1 for ; Mon, 8 Feb 2021 23:03:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E1E4264EA1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 786F66B006C; Mon, 8 Feb 2021 18:03:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 739566B006E; Mon, 8 Feb 2021 18:03:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64DF46B0070; Mon, 8 Feb 2021 18:03:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 4ED956B006C for ; Mon, 8 Feb 2021 18:03:53 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1C951183594FD for ; Mon, 8 Feb 2021 23:03:53 +0000 (UTC) X-FDA: 77796629946.14.coal07_1a09e5a27602 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 08E7F181563FC for ; Mon, 8 Feb 2021 23:03:53 +0000 (UTC) X-HE-Tag: coal07_1a09e5a27602 X-Filterd-Recvd-Size: 5148 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Mon, 8 Feb 2021 23:03:51 +0000 (UTC) IronPort-SDR: SPekWeueD2mSEIsTC/q8IM0G2u8HEYxCEew0ARUgag3Hl2cXICrpV0ZrTB286hhuEQJBZ2cwxC dCr6Vx4Ukbgg== X-IronPort-AV: E=McAfee;i="6000,8403,9889"; a="266627642" X-IronPort-AV: E=Sophos;i="5.81,163,1610438400"; d="scan'208";a="266627642" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2021 15:03:49 -0800 IronPort-SDR: 6GEVXz/VgALvszVbd0TdqgdmvophOiP8mEI+0QbfRkrsOKkVyCH9sNyQbMCxLLxK5UlgBJvyVo O6/xZ0f0qpKg== X-IronPort-AV: E=Sophos;i="5.81,163,1610438400"; d="scan'208";a="358962658" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.251.11.33]) ([10.251.11.33]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2021 15:03:48 -0800 Subject: Re: [PATCH v19 08/25] x86/mm: Introduce _PAGE_COW From: "Yu, Yu-cheng" To: Dave Hansen , Kees Cook Cc: 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 , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu References: <20210203225547.32221-1-yu-cheng.yu@intel.com> <20210203225547.32221-9-yu-cheng.yu@intel.com> <202102041215.B54FCA552F@keescook> <2e43bf0b-e1a9-99f6-8d5d-d6e6886b4217@intel.com> <7381d8c1-5e1c-2667-7cb8-0a99f2c79b6d@intel.com> Message-ID: Date: Mon, 8 Feb 2021 15:03:47 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <7381d8c1-5e1c-2667-7cb8-0a99f2c79b6d@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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: On 2/5/2021 10:41 AM, Yu, Yu-cheng wrote: > On 2/4/2021 12:27 PM, Dave Hansen wrote: >> On 2/4/21 12:19 PM, Kees Cook wrote: >>>> (e) A page where the processor observed a Write=3D1 PTE, started a=20 >>>> write, set >>>> =C2=A0=C2=A0=C2=A0=C2=A0 Dirty=3D1, but then observed a Write=3D0 PT= E.=C2=A0 That's possible=20 >>>> today, but >>>> =C2=A0=C2=A0=C2=A0=C2=A0 will not happen on processors that support = shadow stack. >>> What happens for "e" with/without CET? It sounds like direct writes t= o >>> such pages will be (correctly) rejected by the MMU? >> >> A page fault would be generated regardless of CET support. >> >> If CET were not around, the fault would be reported as a present, writ= e >> fault. >> >> If this happened and CET were around (which shouldn't happen in >> practice, it means we have a hardware issue) a page fault exception is >> generated.=20 >=20 > Thanks for the clarification.=C2=A0 With or without CET, direct write t= o=20 > Write=3D0, Dirty=3D1 PTE triggers page fault. >=20 >> Yu-cheng, I'm not sure there's enough debugging around to >> tell us if this happens.=C2=A0 Would we even notice? >=20 > That potential hardware issue is, on a CET-capable system, a processor=20 > writes to a Write=3D1, Dirty=3D0 page, and then observes the PTE is Wri= te=3D0,=20 > Dirty=3D1.=C2=A0 Let me think about it... >=20 One way to detect the potential issue is adding a check when a=20 non-shadow stack page's PTE goes from RW=3D0 to RW=3D1, like the followin= g... diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtabl= e.h index 29aa6f07e3c9..241b94a0fa77 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -405,6 +405,8 @@ static inline pte_t pte_mkyoung(pte_t pte) static inline pte_t pte_mkwrite(pte_t pte) { if (cpu_feature_enabled(X86_FEATURE_SHSTK)) { + WARN_ONCE((pte_flags(pte) & (_PAGE_RW | _PAGE_DIRTY)) =3D=3D + _PAGE_DIRTY, "Found transient shadow stack PTE\n"); if (pte_flags(pte) & _PAGE_COW) { pte =3D pte_clear_flags(pte, _PAGE_COW); pte =3D pte_set_flags(pte, _PAGE_DIRTY); I run all my routine stress tests with the changes, and do not see any=20 warning triggered. If this change is desirable, we can probably add=20 #ifdef CONFIG_DEBUG_VM around it and make it a separate patch. -- Yu-cheng