Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1413715pxb; Thu, 4 Feb 2021 12:17:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9d/7JUZ6OMORV+WwYlHAc/Fy/wG+Nq4530Wlp3dkkVW0DEd4WPSR/+6DtgMmG3fZMhpAy X-Received: by 2002:aa7:cdcd:: with SMTP id h13mr311221edw.11.1612469833160; Thu, 04 Feb 2021 12:17:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612469833; cv=none; d=google.com; s=arc-20160816; b=nfCEn5EzS1VN0ORXgrfx5tlmDHpnyD0dFohxOJbWkgjs46OIc8bYzlz3EllV/6ojDq B8L793JLyPAyd05OXnLKb7rUwQLY9Ss5rli5Pz2KNsQn6lD5WyMBUzdRYZiby/Pj0qEB lSYbJ9xzA2enPhr1I01VsFKUKwoMc+bbCXxOlpzEIP4TaTy2y9v91ojQObenJOLwtbGy EGLeb78kxdVUmgvdrL7HuQkdQmq2h6pEdclPMqWOwOcXh8PPoSH10yoSJdviws5QkdhA dZ3/8vy9Azw+DS9KDeuKhhjdeMQFVM3c32RtAl+V/sFCadTOkR5nnmkO5eivfbTmFs21 Zu8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fX9wt//YV7HFh+TVdRSpEAtZyx53HBAsOKvt4WgJ1Yo=; b=Z6jcSxf7txzisdOUUeRiAGjVEggqc6Oxic4ZW5BKlgAy8bX1NUOyNJYSgQGdVv4yrc WLh2a/oNlDiee7Xdj9ND4u6SRn2i6/BLBPwDmontdkR13/+MAZMkbPZHRRm4Ox27YxK1 rKW0Pm8wKDZQlII6leBxKa3aeYIJkBGk9BLokn9/S+ezJKq3i9L7MXkmowiZMPIEqIbY jTv4UyX3N8hEITg8NA1UWZS6nuPNxh7aDNq2tIHFKjs52On/eH6NHsJtQKLNzGxg8tkq qO02e7J2P23UeOzwL2DupNjCQS50kWXd3HOD4hYY4E5opxE/1Fv4c9cADs4S6VB2EiHZ 5WWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YhJdPmg1; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o26si3938689edw.74.2021.02.04.12.16.48; Thu, 04 Feb 2021 12:17:13 -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=@chromium.org header.s=google header.b=YhJdPmg1; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238649AbhBDUOg (ORCPT + 99 others); Thu, 4 Feb 2021 15:14:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237973AbhBDUNz (ORCPT ); Thu, 4 Feb 2021 15:13:55 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE3A1C06121D for ; Thu, 4 Feb 2021 12:10:17 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id o63so2893639pgo.6 for ; Thu, 04 Feb 2021 12:10:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fX9wt//YV7HFh+TVdRSpEAtZyx53HBAsOKvt4WgJ1Yo=; b=YhJdPmg114YYnBjPK56CdbPVOocSGUyd5YcpH2lUejbpSb8ZonyhNOWwaQ5ULTIMZe T4rUfyImzEk3QwZ8qqLMepFEgoV3QdcC5Ji6AoJgtbWLHd7Wauiit5qqBpMgUzRN5YLz VO3JCGV1FKBKLBmmwah7xbCtIWEqnZjquY9T0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fX9wt//YV7HFh+TVdRSpEAtZyx53HBAsOKvt4WgJ1Yo=; b=S4hvxAYVnsm7/Ix8dcAFtl7zkO9amYwtNxTep9fiKrsAl7P2HClQmhe0RXTk7WF34v xRqvslNu4zLRC5CVP9/Xs1Wc5e4PDXY80ghFpCM751VcM+cwnZTV7+2DDJYxnQ2nKHDl 0wWGKw/8YNFfEehmTBDZ0pzA2afD+gBoQCyaiox80fbrUgAkTnzCx2ZP4/+HF89+MT3B HwgkWD5T5loWWV/kfdF4IFxXv637ocvqUn4XAS8/9Wc4aewZ1ZrrGT7TpSyH8tsutlXv RHgVMFRV+dTrilRBR2vYKvMPB+WSLlAcjP7pubCSZ4PK+UX8xTpPJpxDh5ppKdUz0px9 h7qw== X-Gm-Message-State: AOAM530W1bTzN1MMSHp+Gi1uHqzM+Bxam486CzvgbtTQxB5RCCKissQn 0rWzi8vvc05p8Q8QxH/B8zn0Xg== X-Received: by 2002:a63:cf06:: with SMTP id j6mr650745pgg.195.1612469417277; Thu, 04 Feb 2021 12:10:17 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id bv21sm6698862pjb.15.2021.02.04.12.10.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:10:16 -0800 (PST) Date: Thu, 4 Feb 2021 12:10:15 -0800 From: Kees Cook To: Yu-cheng Yu 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 , Christoph Hellwig Subject: Re: [PATCH v19 07/25] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Message-ID: <202102041209.B1A0FF3D@keescook> References: <20210203225547.32221-1-yu-cheng.yu@intel.com> <20210203225547.32221-8-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210203225547.32221-8-yu-cheng.yu@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 03, 2021 at 02:55:29PM -0800, Yu-cheng Yu wrote: > 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. Does this have any other side-effects? Otherwise, sure: Reviewed-by: Kees Cook -Kees > > 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 > -- Kees Cook