Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp228023pxb; Mon, 13 Sep 2021 17:44:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw42bui7qxjwDollwkJhgQIAtbjqRKd1LsE56HVcYi6vz8+n1kfuLymJhLx5CylTw+057u+ X-Received: by 2002:a6b:2c45:: with SMTP id s66mr11592256ios.213.1631580270486; Mon, 13 Sep 2021 17:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631580270; cv=none; d=google.com; s=arc-20160816; b=TIGg4rx4ISe/nsPc8gKSMhrMjY/pP7SxKdKCi62MWfClb2mTsIgTcDo4l/UKDuV84W WbXU0/1W8BIXol60k2yrWTCWmy9qCKgCQwgDsrHhQ1DkSUIsUAnbkrG90WDdRNygsBtU QjWE+dPyPEvNQrVSn+2470vUX0nLbnMig8hxzfdblPsZgLPT8F7s153FJXZ60uNkQwpL Xj34AkaPtyqLXxuZUuKCXBMaaQeJ56Nr+KcAvBJLZn1KNvU/NMgyXzqsL+P5eEr/pOZl Hym2soWPyiVMqZ3vDVjVSU+jujRxH6CGYv1KO/VcjLWl0qiNhMAYzQQGld1zIhXKST9x bTlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=n/SZdzMe8eUdmBuyWWJKgfFRJrbCvNUoHWcTrFXoJDo=; b=uvOtiOvFOuUKTudY004jYjTBfzxmeuYEzuQtQsGLgKX6l9/4wlqQAZQOrFV6ng0BMA 2vEsd2UH8OSr5+b2eOG/BHkrr82f3qSn7ABkBSKfbhi4hhNdTP92GKf8BZk8ber18vV6 eFrqix5W/mDCiZWxmUBtF8Hvithp/FSHnD1CKgxrLQp/vX0xU9FIsdkwUUEM9F/zpQ9W JsJg4cKr09tAkb2x/rrLXlHri1oTyh1aVETjH/49p3dGqLG2825SjOrxIQa/6FEDvdXG 86AGiWhVZ0NJDgGDwBabw8KJT8/rowcVcR77U3Qe0MuKkgERj3MOkZxD2fztzwt2SI1r gZ7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J7krykSz; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si8054251ilm.108.2021.09.13.17.44.19; Mon, 13 Sep 2021 17:44:30 -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=@linuxfoundation.org header.s=korg header.b=J7krykSz; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238804AbhIMQt1 (ORCPT + 99 others); Mon, 13 Sep 2021 12:49:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:42560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238219AbhIMQt1 (ORCPT ); Mon, 13 Sep 2021 12:49:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C657760F26; Mon, 13 Sep 2021 16:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631551691; bh=dgZoCqLRf7yYWTZPvAE8JfsdZ8bcTrri+VeUGd3Iql0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=J7krykSzHQ2oEYzswpeqbkf6gI29sZwJe/8kAJPOfbPnLkn2PamRUl9wC/DzveXLP GhNrMiSeoscNezVWufm1PfIf8FfSYdsQikMUOe1jDqDOpG6rjReQ8BpZBEEcjwAZhn gYlWxk+2izBA93AwNrdz5EcHCLNkjkcVnjHpe4eM= Date: Mon, 13 Sep 2021 18:48:09 +0200 From: Greg Kroah-Hartman To: Will Deacon Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Nick Desaulniers , Bill Wendling , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra Subject: Re: [PATCH] x86/uaccess: Fix 32-bit __get_user_asm_u64() when CC_HAS_ASM_GOTO_OUTPUT=y Message-ID: References: <20210913163547.5156-1-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210913163547.5156-1-will@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 13, 2021 at 05:35:47PM +0100, Will Deacon wrote: > Commit 865c50e1d279 ("x86/uaccess: utilize CONFIG_CC_HAS_ASM_GOTO_OUTPUT") > added an optimised version of __get_user_asm() for x86 using 'asm goto'. > > Like the non-optimised code, the 32-bit implementation of 64-bit get_user() > expands to a pair of 32-bit accesses. Unlike the non-optimised code, the > _original_ pointer is incremented to copy the high word instead of loading > through a new pointer explicitly constructed to point at a 32-bit type. > Consequently, if the pointer points at a 64-bit type then we end up > loading the wrong data for the upper 32-bits. > > This was observed as a mount() failure in Android targetting i686 after > b0cfcdd9b967 ("d_path: make 'prepend()' fill up the buffer exactly on > overflow") because the call to copy_from_kernel_nofault() from > prepend_copy() ends up in __get_kernel_nofault() and casts the source > pointer to a 'u64 __user *'. An attempt to mount at "/debug_ramdisk" > therefore ends up failing trying to mount "/debumdismdisk". > > Use the existing '__gu_ptr' source pointer to unsigned int for 32-bit > __get_user_asm_u64() instead of the original pointer. > > Cc: Nick Desaulniers > Cc: Bill Wendling > Cc: Linus Torvalds > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: Peter Zijlstra > Reported-by: Greg Kroah-Hartman > Fixes: 865c50e1d279 ("x86/uaccess: utilize CONFIG_CC_HAS_ASM_GOTO_OUTPUT") > Signed-off-by: Will Deacon > --- > arch/x86/include/asm/uaccess.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h > index c9fa7be3df82..5c95d242f38d 100644 > --- a/arch/x86/include/asm/uaccess.h > +++ b/arch/x86/include/asm/uaccess.h > @@ -301,8 +301,8 @@ do { \ > unsigned int __gu_low, __gu_high; \ > const unsigned int __user *__gu_ptr; \ > __gu_ptr = (const void __user *)(ptr); \ > - __get_user_asm(__gu_low, ptr, "l", "=r", label); \ > - __get_user_asm(__gu_high, ptr+1, "l", "=r", label); \ > + __get_user_asm(__gu_low, __gu_ptr, "l", "=r", label); \ > + __get_user_asm(__gu_high, __gu_ptr+1, "l", "=r", label); \ > (x) = ((unsigned long long)__gu_high << 32) | __gu_low; \ > } while (0) > #else > -- > 2.33.0.309.g3052b89438-goog > Tested-by: Greg Kroah-Hartman Thanks for finding and fixing this! greg k-h