Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1321923pxk; Thu, 10 Sep 2020 12:27:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh9zay8ASeWAOO7DsKrv/1OWmdr28ISgyhQP6CxySmfXd8fzTRr9oNN+4KVGmOT0163JwY X-Received: by 2002:a17:906:b285:: with SMTP id q5mr10252483ejz.545.1599766038077; Thu, 10 Sep 2020 12:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599766038; cv=none; d=google.com; s=arc-20160816; b=h3onMjX8N+kLUTAkQVrYokOyMOwkYQNEfhg+D/BFGGVm16mCOwaKFcfvvey5HTvkM/ jnYHZkiuh4N6HZp8ldaxdRytORV9ItMr5yxq0y8LIxyE8Fhe8cYBEdx2RwIwh5CwrPjb VvlLsDYlBAaUu5ZcGgGowudtRa8iz1w3VsPOwfbCoXVPY66apds0in29/8YI2NE9Dlx/ jj6LeZ3X9nUos20RUuDFszI8DF2NbV+eJtHl0YlCJGUQ0ZKZg/M7ckty6+mSQnFpUJ2E v+rSrWPMaDAxTiEbauGKcebsmMac2t5C3arLZFywaFVAs075/XQee5s2Hpog67FRiNwX xK9A== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=tvGp2dFSlnOW2S1ik1GkqcvaK5bxciluW8+nr4qAfqo=; b=YsTLageBkNiaJfrUWcY2Qs4Phtui5cwrcmFb/6+RqUSvSu1ZOHelHG6YjZz+6XR8VS dAloEW+OS316/4PJwZFvyF4QZVAf3Pyc6mK9J7lzjR+umDn9rzmkTsqXVlYcYbtwFlGu /+8m9KlsJwBO3ByBv0dISMYjV7urxXZDgAvij1HBjx5urJmsWp8tPPicw71YkBeMewPr HHkakIH9/3WN8PgsDQMVjcCS3+5Omjo96aM9aZcYQl/N1P/vvdw4+PuVvdI1akakV0oT h8T569wo+ysSvEh4bE/QDskYOxgl+InB3JXWNmlf2ZXCbGiWovw8dVyTuY0kezrhlWH9 gLdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=CeRbx548; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si4182910edr.508.2020.09.10.12.26.55; Thu, 10 Sep 2020 12:27:18 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=CeRbx548; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727001AbgIJT0W (ORCPT + 99 others); Thu, 10 Sep 2020 15:26:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726410AbgIJT0G (ORCPT ); Thu, 10 Sep 2020 15:26:06 -0400 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5969C061573 for ; Thu, 10 Sep 2020 12:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tvGp2dFSlnOW2S1ik1GkqcvaK5bxciluW8+nr4qAfqo=; b=CeRbx548EKw5nH0PU3rgpg1Cf7 rNIldiIxxgEHpcg9nuKheObdqHw5ui2Fn4iOj6GaSIUf1NZ91gmkSWbVm5IhSpwb7TRtS4TEoxVRS t/au6fr4ZK0WjAIFZaxXjAw10A7cv/H0Ew8lwi/MViGg6QRzueXz2rJ/YaAg6QHMdkKzOJIV/bQe0 LOIbCfKeUW76WVZzwBNZ0mccA9Lva45Q33I+Ciii5/8IrxfNQ/mDCr508+31wub8YF1GwSlBVnsCS SKeUbbA+nACEJnOAHD42HDQA2AcCJuMndX1u2kI4+uquW1sYernvLSNYsXEZtedvRgnFTttn2W9mi 4I2GoPCQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGSCY-0005Y9-IZ; Thu, 10 Sep 2020 19:25:46 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 88D5B980D81; Thu, 10 Sep 2020 21:25:44 +0200 (CEST) Date: Thu, 10 Sep 2020 21:25:44 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: x86@kernel.org, Al Viro , linux-kernel@vger.kernel.org, Linus Torvalds , Will Deacon , Dan Williams , Andrea Arcangeli , Waiman Long , 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: <20200910192544.GC7131@worktop.programming.kicks-ass.net> References: <1d06ed6485b66b9f674900368b63d7ef79f666ca.1599756789.git.jpoimboe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1d06ed6485b66b9f674900368b63d7ef79f666ca.1599756789.git.jpoimboe@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 10, 2020 at 12:22:53PM -0500, Josh Poimboeuf wrote: > The x86 uaccess code uses barrier_nospec() in various places to prevent > speculative dereferencing of user-controlled pointers (which might be > combined with further gadgets or CPU bugs to leak data). > > There are some issues with the current implementation: > > - The barrier_nospec() in copy_from_user() was inadvertently removed > with: 4b842e4e25b1 ("x86: get rid of small constant size cases in > raw_copy_{to,from}_user()") > > - copy_to_user() and friends should also have a speculation barrier, > because a speculative write to a user-controlled address can still > populate the cache line with the original data. > > - The LFENCE in barrier_nospec() is overkill, when more lightweight user > pointer masking can be used instead. > > Remove all existing barrier_nospec() usage, and instead do user pointer > masking, throughout the x86 uaccess code. This is similar to what arm64 > is already doing with uaccess_mask_ptr(). > > barrier_nospec() is now unused, and can be removed. > > Fixes: 4b842e4e25b1 ("x86: get rid of small constant size cases in raw_copy_{to,from}_user()") > Suggested-by: Will Deacon > Signed-off-by: Josh Poimboeuf Acked-by: Peter Zijlstra (Intel)