Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1044116imm; Thu, 6 Sep 2018 14:26:25 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYRm4bLk9RzlZ0KcWZtROYhqbei7i7JC//gWFlDkUb8dF7j2BSyhQsOsoSNeNVgazRp5yYp X-Received: by 2002:a62:9402:: with SMTP id m2-v6mr5014768pfe.3.1536269185335; Thu, 06 Sep 2018 14:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536269185; cv=none; d=google.com; s=arc-20160816; b=OwvW/+ciCxLdIw6Sqjl2NcR1hysglOkTq4SBUY4E6WbToK1bM/x6LZhzuZIqYE/7Ft XBjJHEPsXGGUKggd+3U20KqOD5RP6uazMKbF2m2p+QV46CM0QOk1AVkdwPegbaN33fJp z8C0FBuHMTlHnbsFaTIK70RoFpAy6FFcgJn9xh7YFjx+Aulb6zgKduwTYK3EydLSIryI TU8XBBhPg2P6uOsNq+WOxL46AQJdRXmc0+wSfMaQ+JhBzgiwjPSU0h+/pLRAkk5R65lC LCo9sy2L5wE/7jS+PaYAw1q884+k7Nch4pWWJMx09LZ6ead1LLTPifvv92aQnffyOtCx 8gpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VYRxey2F2SF2w6DYxw+ashBEESMxJqIHgALGpyOpbOo=; b=Qu/3RXN/EUqU+pOqUFRB5LlktZ/y/iiljk7DHnQ+o3sV0nuoMbeVRWSZqekk9adDLP 1lxxWQLzLtT7t8YveZz8spYfchRO1SSftNExiz2lrqr0V7npEPfHb7asFXaGkuX/SQDi Hso+jZFvNXu3EPJ9S4AxqlHJm3mFm62isNXecCUF23DYETcmAkiW02e6191wDLIBHoE5 6nR58FFxpGn9UYOYHu4zJRaJHd5zZSJLMZ1eeviwHJZZDYppKAi7MKuTTyNYvMvDYcAx FOQndi0tp9osKUCZbKn2KtjebuCjG1ioQIuiPAJwXaZjCYXmp2C5iZrWq/KjH2HyW411 G9cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ViuEr3Zk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15-v6si6161825pli.194.2018.09.06.14.26.10; Thu, 06 Sep 2018 14:26:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ViuEr3Zk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729788AbeIGBFC (ORCPT + 99 others); Thu, 6 Sep 2018 21:05:02 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:42880 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729765AbeIGBFC (ORCPT ); Thu, 6 Sep 2018 21:05:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VYRxey2F2SF2w6DYxw+ashBEESMxJqIHgALGpyOpbOo=; b=ViuEr3ZkDSPKk1r7AqMin/Sbc9 hgTucbA8Bt2/IGtGlvvv1Ffys9TnG/sAwqqtXAWxYEQiOtyH1K5Sl0/sQcR2qqiCQ4rudbo9Irvvc a9vgGp11WdfZvKuVcG8643ITG8EoUgq0fUeD4N4CBq3IUUCuC60jOf1+gs8dJn906csLUZr52FrN/ Ro4L3DHIVluyIvFiNVTmXlnpkDBn1epvcVNg8oGX+H0E3O6k1rcHtNB5uGW6M1wZ3ga3ms7fXuEjn ughUpwB085H/fKUEIAgDfWyi/iY4YdaDxQPcF4UAQ3IZmuZtyW2hdF9G3wbxN7jWStkzbFoGsVu6o GXbv/Dhg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fy0sV-0002hq-Rl; Thu, 06 Sep 2018 20:27:48 +0000 Received: by worktop (Postfix, from userid 1000) id E93676E0AA9; Thu, 6 Sep 2018 22:27:46 +0200 (CEST) Date: Thu, 6 Sep 2018 22:27:46 +0200 From: Peter Zijlstra To: Nadav Amit Cc: Nadav Amit , Thomas Gleixner , LKML , Ingo Molnar , X86 ML , Dave Hansen , Andi Kleen , Josh Poimboeuf , Michal Hocko , Vlastimil Babka , Dave Hansen , Sean Christopherson , Andy Lutomirski Subject: Re: [PATCH] x86: use WRITE_ONCE() when setting PTEs Message-ID: <20180906202746.GD9358@worktop.programming.kicks-ass.net> References: <20180902181451.80520-1-namit@vmware.com> <20180906195731.GE4816@worktop.programming.kicks-ass.net> <10030BE1-FE29-4C60-9963-4BE932EF09BA@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <10030BE1-FE29-4C60-9963-4BE932EF09BA@gmail.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 06, 2018 at 01:12:14PM -0700, Nadav Amit wrote: > at 12:57 PM, Peter Zijlstra wrote: > > > On Sun, Sep 02, 2018 at 11:14:50AM -0700, Nadav Amit wrote: > >> When page-table entries are set, the compiler might optimize their > >> assignment by using multiple instructions to set the PTE. This might > >> turn into a security hazard if the user somehow manages to use the > >> interim PTE. L1TF does not make our lives easier, making even an interim > >> non-present PTE a security hazard. > >> > >> Using WRITE_ONCE() to set PTEs and friends should prevent this potential > >> security hazard. > >> > >> I skimmed the differences in the binary with and without this patch. The > >> differences are (obviously) greater when CONFIG_PARAVIRT=n as more > >> code optimizations are possible. For better and worse, the impact on the > >> binary with this patch is pretty small. Skimming the code did not cause > >> anything to jump out as a security hazard, but it seems that at least > >> move_soft_dirty_pte() caused set_pte_at() to use multiple writes. > > > > Acked-by: Peter Zijlstra (Intel) > > > > Also, its corollary would also make sense/be required, use READ_ONCE() > > when reading these. > > I don’t know. This would obviously be much more intrusive. I can add a > get_pte() and write a Coccinelle script to use it instead of reading the > PTE, but in most cases, I presume, it would be an overkill. > > The reason for that is that the PTEs are supposed to be accessed while > holding the page-table lock, and the hardware can only change dirty & access > bits. I think that any code that assumes that these bits do not change while > holding the lock is already broken in more ways. There are lockless readers, but I just checked, mm/gup.c already uses READ_ONCE(), so that should be fine.