Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2408602pxk; Mon, 14 Sep 2020 12:30:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyA+fReHpwBXz2hkBL994LeTqMPT8VM/I8U+AFGyXeWmrNJ0Y98L27IRSjl1S9e0XvuHjru X-Received: by 2002:a50:8062:: with SMTP id 89mr18444567eda.241.1600111845445; Mon, 14 Sep 2020 12:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600111845; cv=none; d=google.com; s=arc-20160816; b=gmO6J3CGt2pSOWK4F9kLT00UU1OiShkfz/iwtGKEM6URlNKvFQAkzolHUX2zgBk66n AO9XTumZQ1tIccvfZkMj73tZt4jMNO1IOHgDL4nFsA8WPf+kE4PIoajbxYDsV/NPKg17 gu4eZ6pjmPTuFeLswcC0zsh2jDiNMgwUE8DyNRITVMT2wSqvvGotgCOXTE0703pZwJsT +I5SCsdAeEkEpcaGes3jRlRR9c3ERmGNCcJ5XKAzGLybWLBHGTRmmJCqLwzXQSZJzrib tfT2OKWzNdIQTTpEHYijZ06gefLzAdOoQ2xRO3t211eJ16IddxYGjwOMJymU08y5c9rr hcuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=FCNGaTB2XTlKwuW28Ajr6nro1HFL/b6q2oKuURy+WoM=; b=NG4P7rb+1/BYadV0wmnffL0qX3cDYCKy/W/3bo5o/q2f1cC9k7mbZRjT0vJTkQo0bu Y36arr58ZiMRZMYa/JB9hJ8ZSFSIcDTJzcwswRKd7IY/TDcVfufklz5ntU2vPBXNpoAf iiaS9jhezh4CKQ5uei+pg7ya30Gj3kUR9NDfbGWkzzk3TC+iDkgFiWLvxd5eFznMDIyO eQ7SQBDg+qPDOHtKel3Nzf2okJAWmaPcMCGTXj9ZQJhrHhbHAmNMHqOAlh60UkpYh1c6 ApzKn/2Tp6YXRrUhC7chsRctBoKTd1HXJqq6Hbwm78CFXkYUuYbGVT6NSS+pjpklCxqg qGig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NdMgJwM3; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pj11si7336788ejb.191.2020.09.14.12.30.21; Mon, 14 Sep 2020 12:30:45 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=NdMgJwM3; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726011AbgINT1n (ORCPT + 99 others); Mon, 14 Sep 2020 15:27:43 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:24384 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725914AbgINT1l (ORCPT ); Mon, 14 Sep 2020 15:27:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600111660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FCNGaTB2XTlKwuW28Ajr6nro1HFL/b6q2oKuURy+WoM=; b=NdMgJwM3F9WSt3qK5gb255nuC5RhL2+tcy5kUatD/0iNCZBipuYWTviEwTMTJBPDToFwyI DZkzaFGGwsxiZrbdo0iu7R3HTxvZmksnCvfTUhrlZL5YfY4OtMNEEGRaueemKF5nhivDAL 8zNqHSM2WFeSoVlQd5a8UkNttSjS4y0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-298-heMWj_LSM02Qa5NoAQQtnQ-1; Mon, 14 Sep 2020 15:27:36 -0400 X-MC-Unique: heMWj_LSM02Qa5NoAQQtnQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E039B107465E; Mon, 14 Sep 2020 19:27:33 +0000 (UTC) Received: from treble (ovpn-115-26.rdu2.redhat.com [10.10.115.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D85C35DA60; Mon, 14 Sep 2020 19:27:27 +0000 (UTC) Date: Mon, 14 Sep 2020 14:27:25 -0500 From: Josh Poimboeuf To: Borislav Petkov Cc: Dan Williams , X86 ML , Al Viro , Linux Kernel Mailing List , Linus Torvalds , Will Deacon , Andrea Arcangeli , Waiman Long , Peter Zijlstra , Thomas Gleixner , Andrew Cooper , Andy Lutomirski , Christoph Hellwig , David Laight , Mark Rutland Subject: Re: [PATCH v3] x86/uaccess: Use pointer masking to limit uaccess speculation Message-ID: <20200914192725.cqja3icshjemvcxw@treble> References: <1d06ed6485b66b9f674900368b63d7ef79f666ca.1599756789.git.jpoimboe@redhat.com> <20200914175604.GF680@zn.tnic> <20200914192156.GG680@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200914192156.GG680@zn.tnic> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 14, 2020 at 09:21:56PM +0200, Borislav Petkov wrote: > On Mon, Sep 14, 2020 at 11:48:55AM -0700, Dan Williams wrote: > > > Err, stupid question: can this macro then be folded into access_ok() so > > > that you don't have to touch so many places and the check can happen > > > automatically? > > > > I think that ends up with more changes because it changes the flow of > > access_ok() from returning a boolean to returning a modified user > > address that can be used in the speculative path. > > I mean something like the totally untested, only to show intent hunk > below? (It is late here so I could very well be missing an aspect): > > diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h > index 2bffba2a1b23..c94e1589682c 100644 > --- a/arch/x86/include/asm/uaccess.h > +++ b/arch/x86/include/asm/uaccess.h > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -92,8 +93,15 @@ static inline bool pagefault_disabled(void); > */ > #define access_ok(addr, size) \ > ({ \ > + bool range; \ > + typeof(addr) a = addr, b; \ > + \ > WARN_ON_IN_IRQ(); \ > - likely(!__range_not_ok(addr, size, user_addr_max())); \ > + \ > + range = __range_not_ok(addr, size, user_addr_max()); \ > + b = (typeof(addr)) array_index_nospec((__force unsigned long)addr, TASK_SIZE_MAX); \ > + \ > + likely(!range && a == b); \ That's not going to work because 'a == b' can (and will) be misspeculated. -- Josh