Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1588492pxb; Thu, 4 Feb 2021 17:47:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzBW0S0sk0ePA/pJVvzQzHHWoq3YcxD4uFT0DyyWHTg2wRJ+qpWAteHA7qYUG9Mi4uYXp6 X-Received: by 2002:a17:906:6096:: with SMTP id t22mr1872935ejj.34.1612489627555; Thu, 04 Feb 2021 17:47:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612489627; cv=none; d=google.com; s=arc-20160816; b=LmobVr1TLT/GXD9rBto+ilXsl+8Qyo3YsDrkcevLIRdfHECZRv6YB5um6OujXhnLaK dQ0hFxNYTQBgM/uxpDr+//4+JwTAcOO54keAoRv/FaSXoSHezCYQ1Rs1vy7tuAJmZ37u P9hcZAd3vurLUUdoSoZxHhVRa1hFJBCvv+A9asHak1y7PE+UFJByLO7GSoDcO3O/G4as SboCW8rdccJS0j2d6GOvjrKNM1+TTyjDOGBMT+R3tgZt302vVSsIrFYRVXJWdf7WcAgZ phuR0m+PtS4YMH6AYneMystRKtE4JVXRLsAXo1oVGKEoF27ZUrO1yGWKnGC/aOtUVAuM bcpQ== 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=l281j3ItWk9H1C+Zr+UKWfAUNh5R5Gnsi8pKJzoTn0Y=; b=T5i4LaNW4G/2kFkeZvckKPbGGD6ZBC5j8X4tzKU3Vrh2ovGxRUMHLwmI7Dz4td7/Rq UgWYly/hX2I4oyDFbCNQ+1rDbdfhUN1sGl1aPY5E1dKl0jDLGfApVDaF5gUyiybD7Bk7 bxfB4vWZ6tqwgknLMC+ZzkXk0oFxkHHJH2XSYsHCuCMVx/ufEbBEwfESwdaA5fRfB7NK V6Oq4QU5VyckbxF25qzPijK0Lm7QytVnYHg1conPBU4YKCqKjL086j4LYP/MJEbfvDaI ZOYSi15hKitEljFzXeaeqNGORfyfk65o15A3hdmJywVjh3DVnNTQ9jcC6cV+2v/uly/w DKQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=m8bNR4kU; 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 j21si2284650ejn.713.2021.02.04.17.46.43; Thu, 04 Feb 2021 17:47:07 -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=m8bNR4kU; 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 S239998AbhBDUVs (ORCPT + 99 others); Thu, 4 Feb 2021 15:21:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239507AbhBDUVn (ORCPT ); Thu, 4 Feb 2021 15:21:43 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56C16C06178A for ; Thu, 4 Feb 2021 12:21:02 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id fa16so1914225pjb.1 for ; Thu, 04 Feb 2021 12:21:02 -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=l281j3ItWk9H1C+Zr+UKWfAUNh5R5Gnsi8pKJzoTn0Y=; b=m8bNR4kU1FTOhjXyaVKDbA4cJ6CUhZEAt/Acj2okLlIxhkSswEUS5rh6/beYKqU5Vv TnBIgnOmsom9UNzPdiRegE73O4iBMPoKye2XicDP5jWBCvmifNLmjKp2S/L72D+Q5hcD QdJgZCK8fwHFv1D4+EtdJ73MaSWkzRtnHxwRA= 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=l281j3ItWk9H1C+Zr+UKWfAUNh5R5Gnsi8pKJzoTn0Y=; b=GZFnkCtgrQJRDgQ6qnEvOXzA6o33tLcaeb5cy+3Fes6SwiVuwSXH9KrK+KN/qxcS6J drF0yUzi+6FMgrQ1VJKEE+E5FOwB4qdkUwltcN2t95+56cY2MBWlQs1C6+9Exn/ZPSb6 PRjuPGvUjGx4cERUIU1S8LJHHCQiGh9lMtlimH2bgmZTrFDT3fRX+Qc4zlNPTTghyVp6 EsPm0paW+WLG6GCIQ2JN/D9FwUHCG4Ik+HqoXoRp8pgCALDq7nRGgoksE+6TrBCC9euO FzygDsXgNUVOOkYfkIWUhfXW16e6gWOmRXMDstmPzDGJwjuzM8QZgurBJ27bRkKBOkea mJVQ== X-Gm-Message-State: AOAM530r1jI15FNwi0n1X6fF+WnMpfV69c/PJnmC4disYfroZGJRut/G JJHzhuMoJSkMoaYWe94pZwaV+A== X-Received: by 2002:a17:902:8604:b029:e2:a249:4474 with SMTP id f4-20020a1709028604b02900e2a2494474mr745841plo.15.1612470061943; Thu, 04 Feb 2021 12:21:01 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 62sm5499904pfg.160.2021.02.04.12.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:21:01 -0800 (PST) Date: Thu, 4 Feb 2021 12:21:00 -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 Subject: Re: [PATCH v19 11/25] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW Message-ID: <202102041220.3F62D2775@keescook> References: <20210203225547.32221-1-yu-cheng.yu@intel.com> <20210203225547.32221-12-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210203225547.32221-12-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:33PM -0800, Yu-cheng Yu wrote: > When Shadow Stack is introduced, [R/O + _PAGE_DIRTY] PTE is reserved for > shadow stack. Copy-on-write PTEs have [R/O + _PAGE_COW]. > > When a PTE goes from [R/W + _PAGE_DIRTY] to [R/O + _PAGE_COW], it could > become a transient shadow stack PTE in two cases: > > The first case is that some processors can start a write but end up seeing > a read-only PTE by the time they get to the Dirty bit, creating a transient > shadow stack PTE. However, this will not occur on processors supporting > Shadow Stack, and a TLB flush is not necessary. > > The second case is that when _PAGE_DIRTY is replaced with _PAGE_COW non- > atomically, a transient shadow stack PTE can be created as a result. > Thus, prevent that with cmpxchg. > > Dave Hansen, Jann Horn, Andy Lutomirski, and Peter Zijlstra provided many > insights to the issue. Jann Horn provided the cmpxchg solution. > > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook