Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2953452rwb; Fri, 2 Dec 2022 18:39:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf5F5ow0gqn1DQJuqAxh3E3GtgRPd7iRolX75fpkxmKLrvej7HH3h+WAiLoIz38ygQhx0/V5 X-Received: by 2002:a17:90a:de93:b0:219:4139:7589 with SMTP id n19-20020a17090ade9300b0021941397589mr26680820pjv.188.1670035146746; Fri, 02 Dec 2022 18:39:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670035146; cv=none; d=google.com; s=arc-20160816; b=QAwAxrxJMfmj/DJzzc76xEt/ejc4JLGLH6YuOR1erCxyYpz/ty1bN5WpmoVaOndm/4 dm9Oibehd3mi0GoAFty+DfBM4H7dj1NkWoMuvCY+f5Syk/YLedXYxYYWjUZvcUyETE1w WxFFodeTqR7ij9E7XEQ6bDsgd22fe+XTAJq9wGcdnew8S8aFYVjehkZ0/z2PXB89WdUo DmROtq6FmYJ5cVBb/qSnbYaO9pvmKYJCBa2lc8Ytlx2dWCyKXFMDvvlVgO9DGGszHCcu mGNPDJ+GD5m8bG+kQXBHihiC4CbKJfRo/+AUlLu2Me1AJySVKBTHpaS8X1qc1igl1ISx 0cEQ== 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=7cAXYlQ5VaMQ5BLk1aXMB0oGCT+qSAsSmGT0reRflQc=; b=BN2djcNTdYSDqt31i/14201igcH9GG1uOp4cJdo61cvYZjBfybj7rdE0qfunkv+SG0 e7WD1xzJLYnTHhXImaCPTtAIFGLdDojrJ4elH1W9NieUQ4z5fzGtKZ1VKVw5gB3/hAVy yNfCwSIG4G6zpu0Expzdehbk8Y7KA/7y3A98jlAO3D0axZdz3iIvTcsnpYjg3vn1TmhL 1OHfppL8P+ihzKSnxDG3+Mw4fkQ3ZFN9CIu9HQUbVkYjZm7ue4vUHXn2RINrO1DSnZo6 ePfyTmMIo4M3kUVJ1XqfuHYPvM5v54a8JCf6T87SGL91wGBNI0EeZoGGWVmaqk+SpnRF u6Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cw0UHv0K; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 7-20020a17090a034700b0021306464b66si8407790pjf.28.2022.12.02.18.38.56; Fri, 02 Dec 2022 18:39:06 -0800 (PST) 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=@chromium.org header.s=google header.b=Cw0UHv0K; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235006AbiLCC3L (ORCPT + 82 others); Fri, 2 Dec 2022 21:29:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234949AbiLCC3I (ORCPT ); Fri, 2 Dec 2022 21:29:08 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA53AE0761 for ; Fri, 2 Dec 2022 18:29:07 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id h193so5815118pgc.10 for ; Fri, 02 Dec 2022 18:29:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7cAXYlQ5VaMQ5BLk1aXMB0oGCT+qSAsSmGT0reRflQc=; b=Cw0UHv0K60H2AUe/OHjHGbe1/PIv2QHijwO47pCLQnR0Nr3P2+bbC8LJsVDbY+XouK NFoPxlyc2jdU2VQ+juROPfFypj8Jq05Y+bxXUKPbXsSeUNyBt5F1Bsw9gKeXm4yh9imA AV8acjj2rcjHaPGj3e4k1akRPlxsWHNY2D/M4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7cAXYlQ5VaMQ5BLk1aXMB0oGCT+qSAsSmGT0reRflQc=; b=iU4fERC/scFbo0f6FwQ12UfPYjbhnD7gJ5Vp2DxteAOcreThZKRBYHkjWslknNLC8E jEQrYZzG6QSRMwnxsFUoYTOZelI3VQ+NGnFc8GuuUiDLGs2o3cA/xmbU9E9lqXrHzc8O kPR7l9jz+zleS+YenLuQX11bIutnHUo29J1iRLRqBYPo/x/yOjVB8A4tlkaopg2UCEml LRxEz8Kk6VYVHLqF4KZ0PLkhlgOEvxNqVMiHseK3PyPwpiWUhZZzpCZXFFge7pwKOX/c xoEAZ+Alk0CCSskVaDufSwFmrHYP05g31/vIxf6SPP6aaLj1F/bZN5R95csVx9ZOdnmm HFtA== X-Gm-Message-State: ANoB5pnOcbVv3e2bYxe8vvOcn/Y+JxE2ysnT0zVfGoVw33CG4tvNB9PS PUmij238hrE5ZYq5hprX8BLIDA== X-Received: by 2002:a63:4908:0:b0:477:e0b4:3f5 with SMTP id w8-20020a634908000000b00477e0b403f5mr34621298pga.265.1670034547107; Fri, 02 Dec 2022 18:29:07 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x27-20020aa7957b000000b0057534fcd895sm5716573pfq.108.2022.12.02.18.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:29:06 -0800 (PST) Date: Fri, 2 Dec 2022 18:29:05 -0800 From: Kees Cook To: Rick Edgecombe 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 , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, Yu-cheng Yu , Christoph Hellwig Subject: Re: [PATCH v4 08/39] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Message-ID: <202212021829.6BC87357@keescook> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-9-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221203003606.6838-9-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 02, 2022 at 04:35:35PM -0800, Rick Edgecombe wrote: > From: Yu-cheng Yu > > New processors that support Shadow Stack regard Write=0,Dirty=1 PTEs as > shadow stack pages. > > In normal cases, it can be helpful to create Write=1 PTEs as also Dirty=1 > if HW dirty tracking is not needed, because if the Dirty bit is not already > set the CPU has to set Dirty=1 when it the memory gets written to. This > creates addiontal work for the CPU. So tradional wisdom was to simply set > the Dirty bit whenever you didn't care about it. However, it was never > really very helpful for read only kernel memory. > > When CR4.CET=1 and IA32_S_CET.SH_STK_EN=1, some instructions can write to > such supervisor memory. The kernel does not set IA32_S_CET.SH_STK_EN, so > avoiding kernel Write=0,Dirty=1 memory is not strictly needed for any > functional reason. But having Write=0,Dirty=1 kernel memory doesn't have > any functional benefit either, so to reduce ambiguity between shadow stack > and regular Write=0 pages, removed Dirty=1 from any kernel Write=0 PTEs. > > Tested-by: Pengfei Xu > Tested-by: John Allen > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook