Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2415983pxk; Mon, 14 Sep 2020 12:44:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz90E8ZoNNo2F8EM6YafLp+H2WG8S4TT6QgLay6zbkEADrjxrbH8/pdNN+vhXPA3SqZOIFm X-Received: by 2002:a17:906:f897:: with SMTP id lg23mr17274858ejb.89.1600112653804; Mon, 14 Sep 2020 12:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600112653; cv=none; d=google.com; s=arc-20160816; b=vYErDFwlZ+1eM+0oegsONADWzc4hZdzZzepEYVEABU2e+KDcvo3vOekchaiokVgyvf J5uDQzrILGMJ5EbggY/EO1l0Vmxk+LcVvymLJFKtHTkEr7wFCivUKwOPp2BoQ5WHm+cK 5yRE5H+dcihvK95btPO4Sbqg4QJSm29yc9nCO42NOH6aAXJ6DQ5Y6Gv8GhjrlpbaLLVu FgCilnqOl4vRURhgJzG3H4SgIcJrqKzbxwJFYMYYTu7bsA2yVmSnh5XcSVW/06XxvQ/R PjV+2PaDY9qNNgKAHeSX2sz3Yxpjk9fTrBSa7dMSjLPKAjiKcDp9WRZpcxSOiOEMjiwr ar4A== 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=7+il9ewnFZ2ENEAK6uzc623uGpDq5p/EzxFKHkMAKSY=; b=KBr+2VGhyEcXU/qIfGHDfGw4h24iMJIB7O69v0t//TnFgIfHIXeN7L0FFJqjnOZZrU x3gFWWxNoTEXp8x/sfAypW4mePe5v1luTVN0j3ECyxYR4yb9nbsjxklt+ab2GEkyvDe5 rhwkoZTD/FXqRsYrgte4JDXvrRhZyxK2RTSaGBZnnNE2slGNlvTvaNTXkEI9F8kk0c06 i4Jn3Lu8nLYw4jeKfa1uKFHhcNZJjba4HLwQU3qFbGRH9euLqv8kOBkYUxZak8xLTE4I BY5Q/gVspMwchTu8d3Q1hLoJ3uWs9+eWeavfwwqh73Rap2xOFK7MgTxQHtOEVpt35dFj jfBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=mV2MRCsE; 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=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j15si7060321ejf.18.2020.09.14.12.43.51; Mon, 14 Sep 2020 12:44:13 -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=@alien8.de header.s=dkim header.b=mV2MRCsE; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726007AbgINTnA (ORCPT + 99 others); Mon, 14 Sep 2020 15:43:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgINTm7 (ORCPT ); Mon, 14 Sep 2020 15:42:59 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D0E4C06174A for ; Mon, 14 Sep 2020 12:42:59 -0700 (PDT) Received: from zn.tnic (p200300ec2f09260089ebb5f4b84dd95c.dip0.t-ipconnect.de [IPv6:2003:ec:2f09:2600:89eb:b5f4:b84d:d95c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id B68301EC0593; Mon, 14 Sep 2020 21:42:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1600112577; 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: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=7+il9ewnFZ2ENEAK6uzc623uGpDq5p/EzxFKHkMAKSY=; b=mV2MRCsEd1YXoM8ckud4LXcoK95PfB2mpHDsuuvR1/6ljTMqPoMTP6kYj7/itWBSt4obNz hlaolnb0Syae9c22mY0OmKPClpclZB8WoOp6LC74qy3ci9eWXX0zF8Pe60uJ3kl8YXdEqq Y+3WWfumnUQUcOYBjnsz57Sy7/M12w4= Date: Mon, 14 Sep 2020 21:42:52 +0200 From: Borislav Petkov To: Josh Poimboeuf Cc: x86@kernel.org, Al Viro , linux-kernel@vger.kernel.org, Linus Torvalds , Will Deacon , Dan Williams , 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: <20200914194252.GI680@zn.tnic> References: <1d06ed6485b66b9f674900368b63d7ef79f666ca.1599756789.git.jpoimboe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1d06ed6485b66b9f674900368b63d7ef79f666ca.1599756789.git.jpoimboe@redhat.com> 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 > --- > v3: > > - Rebased on vfs#for-next, using TASK_SIZE_MAX now that set_fs() is > gone. I considered just clearing the most significant bit, but that > only works for 64-bit, so in the interest of common code I went with > the more straightforward enforcement of the TASK_SIZE_MAX limit. > > - Rename the macro to force_user_ptr(), which is more descriptive, and > also more distinguishable from a planned future macro for sanitizing > __user pointers on syscall entry. > > Documentation/admin-guide/hw-vuln/spectre.rst | 6 ++-- > arch/x86/include/asm/barrier.h | 3 -- > arch/x86/include/asm/checksum_32.h | 6 ++-- > arch/x86/include/asm/futex.h | 5 +++ > arch/x86/include/asm/uaccess.h | 35 ++++++++++++------- > arch/x86/include/asm/uaccess_64.h | 16 ++++----- > arch/x86/lib/csum-wrappers_64.c | 5 +-- > arch/x86/lib/getuser.S | 10 +++--- > arch/x86/lib/putuser.S | 8 +++++ > arch/x86/lib/usercopy_32.c | 6 ++-- > arch/x86/lib/usercopy_64.c | 7 ++-- > lib/iov_iter.c | 2 +- > 12 files changed, 65 insertions(+), 44 deletions(-) After clarifying some stuff on IRC: Acked-by: Borislav Petkov -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette