Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp672744pxb; Wed, 3 Feb 2021 15:00:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGb4U9z8XFDInlh5XgMG4j4BWjIJNuFzL5Z5PKGJxKqwg0Q7ckxUwnCZoiO8ifXUBgu5RV X-Received: by 2002:a17:906:5043:: with SMTP id e3mr5452507ejk.260.1612393200378; Wed, 03 Feb 2021 15:00:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612393200; cv=none; d=google.com; s=arc-20160816; b=kIZvDfbYZXgYQlI46EaWEk8hiQwqPdifCNwMKenYUjJXONSj1Pt/c243KCQm+afBzo ABrErhjpGUfEKxvMNzn39RZ8fupORydFTCvwExc4ia77toRg9AOo34iiIjsxpVe5iuI1 0UY8vdu7QzEPCVh0hAnYBMRG6CY7nzDEGKXh2m+kPkvUrveYzUu344cu5xe7P3CNjMNj ryI3L6uU6iYRgT1V3VV+HgTIk4Lv3mxzHFzImkjLN7gP1OXGCgeYB7WmHKFEbLTgTdiE 4gmyoO4Ex9lmDz/gd0xnIGKgiJyNVMpLO7PhQwa16qO1HAyOsMU90VpOz1CE+jcRmlTb 5LRg== 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 :ironport-sdr:ironport-sdr; bh=v03F6bX8MCKgPKMEjjrJKnnVciuw58pofmtgYEDiDKE=; b=UEPRWP/NCfL9YoWhn+6OyC0cvuQ3Gig8YelJsDiwLiX15Tgijw51spNc/ceEvwounA oAXSgBpIlB7P2BchiTcv4c/TUXqeoHG9LFRVz8GPTwM7UmtXdTFE5v1uKb0NASqCbLkg tylqrr1Ik/CGKEZQ6F6OJ7umtfHlu8wJ5fReZdv6HcGRR4W/M0TH5e55rFYEtWpYd4Yk 4AGIaT2U5pigNe8RMPw6fXFjaW3sBZpqDkSvom7Nl1tK0azHKHSbigrPreqtTRpdllvp iW9pcZVkeRxZXEFFTia6CNQZ5TmNw+Yr4a76/QM+4Bh9Ufp/uUzvS1nPnLxOz80EFYZy rPKA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 d26si64354edv.47.2021.02.03.14.59.35; Wed, 03 Feb 2021 15:00:00 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233244AbhBCW6G (ORCPT + 99 others); Wed, 3 Feb 2021 17:58:06 -0500 Received: from mga06.intel.com ([134.134.136.31]:30220 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233178AbhBCW5f (ORCPT ); Wed, 3 Feb 2021 17:57:35 -0500 IronPort-SDR: uk78OMyp+iYY3whYO/tlDw+ItmgLuTiomwO9rLLS8wIgwQbvd83Rk4HomMjTWOJ8zno5mg3Zj/ z9jhJbr9eQZg== X-IronPort-AV: E=McAfee;i="6000,8403,9884"; a="242642354" X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="242642354" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 14:56:24 -0800 IronPort-SDR: 3nbaox0jKZgUilk5EPXMgHPCPR+iHDIeo8rlYyu5ss2eUYSTBriBUNZu17ePHFDLdg2HptICDc I6QZckegouKg== X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="507921091" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 14:56:23 -0800 From: Yu-cheng Yu 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" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu Cc: Yu-cheng Yu , Christoph Hellwig Subject: [PATCH v19 07/25] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Date: Wed, 3 Feb 2021 14:55:29 -0800 Message-Id: <20210203225547.32221-8-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210203225547.32221-1-yu-cheng.yu@intel.com> References: <20210203225547.32221-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 394757ee030a..b8b79d618bbc 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -194,10 +194,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 16f878c26667..6bebb95a6988 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -1932,7 +1932,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.21.0