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 X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBF6EC433E2 for ; Thu, 10 Sep 2020 19:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 772AE20882 for ; Thu, 10 Sep 2020 19:26:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CeRbx548" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727870AbgIJT00 (ORCPT ); Thu, 10 Sep 2020 15:26:26 -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)