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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1562C004D4 for ; Fri, 20 Jan 2023 00:57:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbjATA51 (ORCPT ); Thu, 19 Jan 2023 19:57:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbjATA50 (ORCPT ); Thu, 19 Jan 2023 19:57:26 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 927129F06A for ; Thu, 19 Jan 2023 16:57:25 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id s13-20020a17090a6e4d00b0022900843652so7613769pjm.1 for ; Thu, 19 Jan 2023 16:57:25 -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=lEHXslOior1iC36oZl8rvCBEJjihHqep9sJwUDMqsEg=; b=f3y4Qq2kjIJ57POmydv+v0X2WmxwQwjCJNO+IzVXLoV2114lAMl6Ch00VZy9aIEyBd oilRLW1fxHa2Ex9xwuimXDFKNwIjlloI72Kl1kNyAIT+zMOSEFmfLcV8/zKlxRqJ+YKW 3Z+JnxVbm1Lhnb6pdZm0/iDTmL4b2OBJDWeY0= 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=lEHXslOior1iC36oZl8rvCBEJjihHqep9sJwUDMqsEg=; b=ihYM0gJfGlCLigDc1nN0LqxhHqiroM9OoUobBkvVJ1eLeoXvbVTeXmfz7rBSwy9S3L 18SGOF9vzIxuZMEw0Qd3LrlFstVgqFM+Rn77TwhGoRcnXQR5UT4QCx6SeWQPmb/oKALj muHmwW1qmVv5nE6TW1A1BwoUZcKRRm3FT/VjaJTtJDb/3oDfjym/PPkqQ+9wHHoeoNU4 7fio0Tv5/YtnAvAkgA2XMaY4u3es/tK9CxOEuUeEkQ5oBGaDVDbND9F8MHCd/+iZfjyu mv29XbcLHvFWSULZjM7Yggn3iJmcuJXQZBonQ3UPwdjAX8bxRC1JVcrMZYAYJDW2yY3X oM2Q== X-Gm-Message-State: AFqh2krEJ4LtYlkypAIX1W7LitKQY0rsVeJX/HpmRw37t/E4ZbWBf1Y4 4lub0F3/GXwaTl2cmIWS64xbvw== X-Google-Smtp-Source: AMrXdXuzvSuvcNQXbjmD67x6eCKVyFgfIP6jDqIDZgYrd6B5X7omXzC+CDMYarBYrLg2yENuyJffyg== X-Received: by 2002:a05:6a21:151a:b0:b8:927a:6a9d with SMTP id nq26-20020a056a21151a00b000b8927a6a9dmr14012280pzb.9.1674176245077; Thu, 19 Jan 2023 16:57:25 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u11-20020a6540cb000000b0046ff3634a78sm21576083pgp.71.2023.01.19.16.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 16:57:24 -0800 (PST) Date: Thu, 19 Jan 2023 16:57:23 -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 Subject: Re: [PATCH v5 11/39] x86/mm: Update pte_modify for _PAGE_COW Message-ID: <202301191657.3B81D1C589@keescook> References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> <20230119212317.8324-12-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230119212317.8324-12-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Thu, Jan 19, 2023 at 01:22:49PM -0800, Rick Edgecombe wrote: > From: Yu-cheng Yu > > The Write=0,Dirty=1 PTE has been used to indicate copy-on-write pages. > However, newer x86 processors also regard a Write=0,Dirty=1 PTE as a > shadow stack page. In order to separate the two, the software-defined > _PAGE_DIRTY is changed to _PAGE_COW for the copy-on-write case, and > pte_*() are updated to do this. > > pte_modify() takes a "raw" pgprot_t which was not necessarily created > with any of the existing PTE bit helpers. That means that it can return a > pte_t with Write=0,Dirty=1, a shadow stack PTE, when it did not intend to > create one. > > However pte_modify() changes a PTE to 'newprot', but it doesn't use the > pte_*(). Modify it to also move _PAGE_DIRTY to _PAGE_COW. Do this by > using the pte_mkdirty() helper. Since pte_mkdirty() also sets the soft > dirty bit, extract a helper that optionally doesn't set > _PAGE_SOFT_DIRTY. This helper will allow future logic for deciding when to > move _PAGE_DIRTY to _PAGE_COW can live in one place. > > Apply the same changes to pmd_modify(). > > Tested-by: Pengfei Xu > Tested-by: John Allen > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook