Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1716617ybp; Wed, 9 Oct 2019 19:23:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJnoEsEpHAjfKqO3oBJbtH+NeIjR3KWnIPkFp+XIoJ1Y3y948nFjmUJgjNVLoeNTbBQfNH X-Received: by 2002:a05:6402:1507:: with SMTP id f7mr5942396edw.68.1570674206388; Wed, 09 Oct 2019 19:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570674206; cv=none; d=google.com; s=arc-20160816; b=r6Tgq5gnEsAk9s0PPd3nSkNIRZdTtI3SGSz+WmRLBACp2X2cMuMaZLUwlTZwJwaLBk /zDy13SvHapwzKOslF6gmT0ANmBHWM+XSSRneLpjoYFzrF6VcKiUKpTtgvpLmNgY1aRV s+3zfDBzNvagrr2fGUG9L4Nrp8/4KhBxcn7Cb883b0GEohs7xhQRDy5OjJioN7mpXEpY w1RbAFXN997CAOzlY7H5gD9h5sBysFGpufzLTFGgic6S9n1PVws+c7vPJjoG9M4QQCUY pu2vGyS1+BwGXd5zQzohGTLFLTxcWK1OsSqxQ0bVucsw566P4wOctTKaYOMgYEBCr+Nm BmzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=woyaIkIQv6Xs21ozbrL0GY7iKCTuq76f+v68JretALk=; b=sOuREC7ZBkNeo4RlPfAkDNxtmIxc2h0AE9G1bse0hsoxxHJZLaLO77CQWvhj7eTyyH jUSl/uR9B0bdvRIpRoxOhMsbW0Mtz38dC+sUXMN7zu5I0+bP+z4xtelHhDAj9HXc4+em DBrpGmMmXaOQwaVmFilO00OQpXpucGBg0HRDfzJ86/7KPPAYkD1kDyT/MjX/j5nUesvH U41hi0Qq569YNrA4HXDBURIlHEkbTNc59WAKSQlAyBWRI5BEjI2CYjfq9OOyglgn8yuA J51LizhCGtV9fIbn+uChLRAFU60BrACnsEqeMfpmm7DX1EnhC+OUAHWUQSSvpMsPQ/al v9dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="dSK/3UR3"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6si2332732edq.228.2019.10.09.19.23.02; Wed, 09 Oct 2019 19:23:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="dSK/3UR3"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732332AbfJJCVC (ORCPT + 99 others); Wed, 9 Oct 2019 22:21:02 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:46278 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726469AbfJJCLw (ORCPT ); Wed, 9 Oct 2019 22:11:52 -0400 Received: by mail-yw1-f66.google.com with SMTP id l64so1469014ywe.13 for ; Wed, 09 Oct 2019 19:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=woyaIkIQv6Xs21ozbrL0GY7iKCTuq76f+v68JretALk=; b=dSK/3UR3/ac63/FVph2mecjCuuCfPMnqYKYexzIGXFHLESmymGyJvuEOkNJxmopgLf 5xrb/JWTOx3bD1bIQTBrrkOa6GrKrJt1Mcnwrrz2GG5XB59jgbYMVCJf1wDWXFn3NNj1 kkSiaomXd8DWEQe6AePVRU47qYr4Nst8PBIv3QVxcCp5RPOHk8JOXsB0rzEVO3wTPtKT eL8RzJgX5Av2Jc0ZJBR50ttog9yzygYjYrEtDm+BpEWEz7el2WE08oF9KSfgINM/QKwK otJ35OkhiqPAhB22Hnq1b2ZIsDIbX1ugGOMFdDCxERwi1Jx7K8YvjslVMFDun/cDyymv G0qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=woyaIkIQv6Xs21ozbrL0GY7iKCTuq76f+v68JretALk=; b=fiE7tegCEP5o1yXxY8dN3xsuqM9Q1550UQoohgF+Ccatnt1WlJdsRctNFK0B4kPA7T Mlk6JSNoB12a1/CViy0KHmuq/+pxh9RefjQxSfcUrurb/X5z2yAMyJKaCNvVT+ncatUr hog/bbJOdj2P51nSJroi2bGmVOShuJK3P5nZcDy2teWehlZ629tPY8ey+4vbd9iJAJ5m DvBPZn4XXXkYu+5+Tutqlw88aLhUOhiNdOQ0zho1cm4H+4bTlFfQpWwDSPs8MrPh+QjW djajidCrhVWKhSfqU3CeVU5jp4Igh9T/QijFn2KvlLKJAF7FvCaalxCTBACqpjn11ZIM scMA== X-Gm-Message-State: APjAAAURQkyZIWo7T9S1XcjUwJ0qQMk7HRvHVMZFZWmXaLA77rhmyb0C g16f70UKFmdCXzhJ1B++K8Iz98D3AL6GyMqDReIGl4gtLFE= X-Received: by 2002:a81:254d:: with SMTP id l74mr5160055ywl.409.1570673511796; Wed, 09 Oct 2019 19:11:51 -0700 (PDT) MIME-Version: 1.0 References: <20191009192105.GC26530@ZenIV.linux.org.uk> <20191010015606.GD26530@ZenIV.linux.org.uk> In-Reply-To: <20191010015606.GD26530@ZenIV.linux.org.uk> From: Max Filippov Date: Wed, 9 Oct 2019 19:11:40 -0700 Message-ID: Subject: Re: [PATCH] xtensa: fix {get,put}_user() for 64bit values To: Al Viro Cc: "open list:TENSILICA XTENSA PORT (xtensa)" , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 9, 2019 at 6:56 PM Al Viro wrote: > > On Wed, Oct 09, 2019 at 06:38:12PM -0700, Max Filippov wrote: > > > There's also the following code in the callers of this macro, e.g. in > > __get_user_nocheck: > > > > long __gu_err, __gu_val; \ > > __get_user_size(__gu_val, (ptr), (size), __gu_err); \ > > (x) = (__force __typeof__(*(ptr)))__gu_val; \ > > > > the last line is important for sizes 1..4, because it takes care of > > sign extension of the value loaded by the assembly. > > At the same time the first line doesn't make sense for the size 8 > > as it will result in value truncation. > > Right you are... > > > + long __gu_err; \ > > + __typeof__(*(ptr) + 0) __gu_val; \ > > What would __u64 __gu_val; end up with for smaller sizes? It does good job with little endian cores, i.e. the generated code is the same in both cases, but on big endian it looks into wrong register of the register pair that represents __gu_val. E.g.: foo_in_s8_out_s8: entry sp, 32 # mov.n a7, sp # a5, # /home/jcmvbkbc/ws/tensilica/linux/linux-xtensa/arch/xtensa/kernel/signal.c:518: gen_outs(8) movi.n a8, 0 # __gu_err, #APP # 518 "/home/jcmvbkbc/ws/tensilica/linux/linux-xtensa/arch/xtensa/kernel/signal.c" 1 1: l8ui a10, a2, 0 # __gu_val, p 2: .section .fixup,"ax" .align 4 .literal_position 5: movi a2, 2b # __cb movi a10, 0 # __gu_val movi a8, -14 # __gu_err, jx a2 # __cb .previous .section __ex_table,"a" .long 1b, 5b .previous # 0 "" 2 #NO_APP extui a2, a11, 0, 8 #, __gu_val retw.n > I don't have > xtensa cross-toolchain at the moment, so I can't check it easily; > what does =r constraint generate in such case? Lower register of the register pair. > Another thing is, you want to zero it on failure, to avoid an uninitialized > value ending up someplace interesting.... Ok, this? diff --git a/arch/xtensa/include/asm/uaccess.h b/arch/xtensa/include/asm/uaccess.h index 6792928ba84a..0bdaadf1636e 100644 --- a/arch/xtensa/include/asm/uaccess.h +++ b/arch/xtensa/include/asm/uaccess.h @@ -100,7 +100,7 @@ do { \ case 4: __put_user_asm(x, ptr, retval, 4, "s32i", __cb); break; \ case 8: { \ __typeof__(*ptr) __v64 = x; \ - retval = __copy_to_user(ptr, &__v64, 8); \ + retval = __copy_to_user(ptr, &__v64, 8) ? -EFAULT : 0; \ break; \ } \ default: __put_user_bad(); \ @@ -172,7 +172,8 @@ __asm__ __volatile__( \ #define __get_user_nocheck(x, ptr, size) \ ({ \ - long __gu_err, __gu_val; \ + long __gu_err; \ + __typeof__(*(ptr) + 0) __gu_val = 0; \ __get_user_size(__gu_val, (ptr), (size), __gu_err); \ (x) = (__force __typeof__(*(ptr)))__gu_val; \ __gu_err; \ @@ -180,7 +181,8 @@ __asm__ __volatile__( \ #define __get_user_check(x, ptr, size) \ ({ \ - long __gu_err = -EFAULT, __gu_val = 0; \ + long __gu_err = -EFAULT; \ + __typeof__(*(ptr) + 0) __gu_val = 0; \ const __typeof__(*(ptr)) *__gu_addr = (ptr); \ if (access_ok(__gu_addr, size)) \ __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ @@ -198,7 +200,7 @@ do { \ case 1: __get_user_asm(x, ptr, retval, 1, "l8ui", __cb); break;\ case 2: __get_user_asm(x, ptr, retval, 2, "l16ui", __cb); break;\ case 4: __get_user_asm(x, ptr, retval, 4, "l32i", __cb); break;\ - case 8: retval = __copy_from_user(&x, ptr, 8); break; \ + case 8: retval = __copy_from_user(&x, ptr, 8) ? -EFAULT : 0; break; \ default: (x) = __get_user_bad(); \ } \ } while (0) -- Thanks. -- Max