Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp619705pxb; Tue, 1 Feb 2022 07:08:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7f5rx9htb1WolsisVSlHNDLmjxh/uyL54lsayCTcpiKG/qY+Y2MMwhRTjZ54VFsgs9XS3 X-Received: by 2002:a05:6402:3514:: with SMTP id b20mr25680087edd.65.1643728086032; Tue, 01 Feb 2022 07:08:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643728086; cv=none; d=google.com; s=arc-20160816; b=phyTuUwSCtOloO6IVL3N2V8Y0SkzzWRLDgx4jtU2WcoilJVYG3mhOMp0k2Wn2+DElb q27kB7+UwJve1e+b9ib+PAO8MNiPVC2OBO1cWmwe5ZjjblKpkfdXAFNvOD6/CPMA34st by/x6AiU5AbSFO/qXrYTPLOT5hnPz+sl8dnQa5Sc+ep5AF8ztYRh9bDGlM5rgmNKiyAr qiYXNmqBElzihz+YdfdczjKX9Fv+ngv6dDOXKqZvMs5tyVMJB+LMi0oqRcuBpwfTd5Gw yYZohdo1281jG2dTn86Kxv6UFRXbiLlMVyIubJw+SWlmkDt7GtKaq6bcC5esUordgenF Y59g== 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=4YtEaYaHvB0v8/Dn3HEDugbFO5VR22IbjiiMybRYQqk=; b=CF4Zh4WJlTDHtc+Q+LM0KE8Jl6QgkpFtFW35YgNx6+oQ8+8FDxDAlvegOgveQ1U377 5/L4vUU89vEQaxHPWng6ykl0aA2jkNUx7VOOH9VExLP1o0k6QY75duumDJFprQra3CvM GvEpZ2b2VmS4c0Nx189umGUiQnTGe/o//DWqJjIlsI7NURKl9LL6PRXO8c7qirOLImX+ dIw/fttM6OfDmGSVGhe4S/Bt/46eLZGPz+oTdBkXp6lQ6jYvUf2vn0kedQlMJcDEEJPa CTodByXOnbPx+BSihnS1inBnA+RaeicXKFDhYVZ3AygLWOckG7LRJffuSt3zNSAs2VU0 Jecg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g23OBzhb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si9424109ejl.181.2022.02.01.07.07.39; Tue, 01 Feb 2022 07:08:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g23OBzhb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1356495AbiA3VWN (ORCPT + 99 others); Sun, 30 Jan 2022 16:22:13 -0500 Received: from mga06.intel.com ([134.134.136.31]:52019 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356475AbiA3VV4 (ORCPT ); Sun, 30 Jan 2022 16:21:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643577716; x=1675113716; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=HlWo8OKNThkqHwQn3Dphtl6Opo3L/i/03JpsJVaIZ2A=; b=g23OBzhbAjNLI4HpENBuTWPqnMFujE1MB7oDuq9Zlk6Y5e2V83S29uLt QXbMH7fOyFPTQScz4sK+4nfvptHt/VuCpl2PqIHJg2Y6ph3+UkWnsxya8 FulV1DrtkeFYtP/XZep21myGdudorw3ckLLlAzoRX/UdTE5O6ojcvix8+ H9/W/nT44d+2mK+Dx5gJrLe0wDaM3x7MUW3adU5QMdhAAFbP1LvaM0WlF 5Z1PnCevP4UPvuFjm3a9BI7pB3jP5NXczYomjB2op1QlxSsRDT6o0c4Rq 9EOgELM9ohx2Fwqbl6L8zz4HH7/xlNZoyKpSY77OJH0H6rN8YX9J/FJi3 Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10243"; a="308104904" X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="308104904" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:21:52 -0800 X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="536856715" Received: from avmallar-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.123.171]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:21:51 -0800 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" , Dave Martin , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu , Christoph Hellwig Subject: [PATCH 07/35] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Date: Sun, 30 Jan 2022 13:18:10 -0800 Message-Id: <20220130211838.8382-8-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220130211838.8382-1-rick.p.edgecombe@intel.com> References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu-cheng Yu The x86 family of processors do not directly create read-only and Dirty PTEs. These PTEs are created by software. One such case is that kernel read-only pages are historically setup as Dirty. New processors that support Shadow Stack regard read-only and Dirty PTEs as shadow stack pages. This results in ambiguity between shadow stack and kernel read-only pages. To resolve this, removed Dirty from kernel read- only pages. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Signed-off-by: Rick Edgecombe Cc: "H. Peter Anvin" Cc: Kees Cook Cc: Thomas Gleixner Cc: Dave Hansen Cc: Christoph Hellwig Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Borislav Petkov Cc: Peter Zijlstra --- arch/x86/include/asm/pgtable_types.h | 6 +++--- arch/x86/mm/pat/set_memory.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 40497a9020c6..3781a79b6388 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -190,10 +190,10 @@ enum page_cache_mode { #define _KERNPG_TABLE (__PP|__RW| 0|___A| 0|___D| 0| 0| _ENC) #define _PAGE_TABLE_NOENC (__PP|__RW|_USR|___A| 0|___D| 0| 0) #define _PAGE_TABLE (__PP|__RW|_USR|___A| 0|___D| 0| 0| _ENC) -#define __PAGE_KERNEL_RO (__PP| 0| 0|___A|__NX|___D| 0|___G) -#define __PAGE_KERNEL_ROX (__PP| 0| 0|___A| 0|___D| 0|___G) +#define __PAGE_KERNEL_RO (__PP| 0| 0|___A|__NX| 0| 0|___G) +#define __PAGE_KERNEL_ROX (__PP| 0| 0|___A| 0| 0| 0|___G) #define __PAGE_KERNEL_NOCACHE (__PP|__RW| 0|___A|__NX|___D| 0|___G| __NC) -#define __PAGE_KERNEL_VVAR (__PP| 0|_USR|___A|__NX|___D| 0|___G) +#define __PAGE_KERNEL_VVAR (__PP| 0|_USR|___A|__NX| 0| 0|___G) #define __PAGE_KERNEL_LARGE (__PP|__RW| 0|___A|__NX|___D|_PSE|___G) #define __PAGE_KERNEL_LARGE_EXEC (__PP|__RW| 0|___A| 0|___D|_PSE|___G) #define __PAGE_KERNEL_WP (__PP|__RW| 0|___A|__NX|___D| 0|___G| __WP) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index b4072115c8ef..844bb30280b7 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -1943,7 +1943,7 @@ int set_memory_nx(unsigned long addr, int numpages) int set_memory_ro(unsigned long addr, int numpages) { - return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_RW), 0); + return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_RW | _PAGE_DIRTY), 0); } int set_memory_rw(unsigned long addr, int numpages) -- 2.17.1