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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8335FC433EF for ; Wed, 16 Feb 2022 13:16:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CAEB6B0073; Wed, 16 Feb 2022 08:16:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17B4E6B0074; Wed, 16 Feb 2022 08:16:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F100E6B0078; Wed, 16 Feb 2022 08:16:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0009.hostedemail.com [216.40.44.9]) by kanga.kvack.org (Postfix) with ESMTP id E28706B0073 for ; Wed, 16 Feb 2022 08:16:04 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A4E2593D79 for ; Wed, 16 Feb 2022 13:16:04 +0000 (UTC) X-FDA: 79148691048.19.042EF84 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 3948B1A0006 for ; Wed, 16 Feb 2022 13:16:04 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8E6B361687; Wed, 16 Feb 2022 13:16:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7BA1C340F0; Wed, 16 Feb 2022 13:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645017363; bh=pxtLV1Eo2uhzbr/ZGDUi5vmKQTdm70WnLcSn91l2Vi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZpRpPZZ56QuGCzWKWIA8wL+2evDjiPNn22sA3IyfSnxeSs4NljN0bMDriNWZNGwOV kFJGnNtw7i2L/YqdH0OrjhgSlxDXkKvsObNGouNeE3xHH01IQrp9Q7uEH1vPiRAxti M+gWF7dq0Z0OKwNJnW8Pf+DVxIg46RXVw+ghV6JkK7gYKJhkz/FRa+64uk7sJQlkYa grRqHak77628J1lm/iv9sC116oN+V3z5UuU6vHXOuqQW+Attotzf8/GDQdCnI0mVdf zfpxriQqY58hcPAxkXpPjVdrCsL1sAU3QszV1ujsYZtkxZR217/jpmnw0TPF0gjCBh S8i/GRFxP5xLA== From: Arnd Bergmann To: Linus Torvalds , Christoph Hellwig , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, arnd@arndb.de, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: linux@armlinux.org.uk, will@kernel.org, guoren@kernel.org, bcain@codeaurora.org, geert@linux-m68k.org, monstr@monstr.eu, tsbogend@alpha.franken.de, nickhu@andestech.com, green.hu@gmail.com, dinguyen@kernel.org, shorne@gmail.com, deller@gmx.de, mpe@ellerman.id.au, peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, hca@linux.ibm.com, dalias@libc.org, davem@davemloft.net, richard@nod.at, x86@kernel.org, jcmvbkbc@gmail.com, ebiederm@xmission.com, akpm@linux-foundation.org, ardb@kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-xtensa@linux-xtensa.org Subject: [PATCH v2 02/18] uaccess: fix nios2 and microblaze get_user_8() Date: Wed, 16 Feb 2022 14:13:16 +0100 Message-Id: <20220216131332.1489939-3-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220216131332.1489939-1-arnd@kernel.org> References: <20220216131332.1489939-1-arnd@kernel.org> MIME-Version: 1.0 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZpRpPZZ5; spf=pass (imf19.hostedemail.com: domain of arnd@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=arnd@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam07 X-Rspam-User: X-Rspamd-Queue-Id: 3948B1A0006 X-Stat-Signature: zcut7518nghe1ussdzsz157rbz51g7uu X-HE-Tag: 1645017364-602920 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Arnd Bergmann These two architectures implement 8-byte get_user() through a memcpy() into a four-byte variable, which won't fit. Use a temporary 64-bit variable instead here, and use a double cast the way that risc-v and openrisc do to avoid compile-time warnings. Fixes: 6a090e97972d ("arch/microblaze: support get_user() of size 8 bytes= ") Fixes: 5ccc6af5e88e ("nios2: Memory management") Signed-off-by: Arnd Bergmann --- arch/microblaze/include/asm/uaccess.h | 18 +++++++++--------- arch/nios2/include/asm/uaccess.h | 26 ++++++++++++++++---------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/arch/microblaze/include/asm/uaccess.h b/arch/microblaze/incl= ude/asm/uaccess.h index 5b6e0e7788f4..3fe96979d2c6 100644 --- a/arch/microblaze/include/asm/uaccess.h +++ b/arch/microblaze/include/asm/uaccess.h @@ -130,27 +130,27 @@ extern long __user_bad(void); =20 #define __get_user(x, ptr) \ ({ \ - unsigned long __gu_val =3D 0; \ long __gu_err; \ switch (sizeof(*(ptr))) { \ case 1: \ - __get_user_asm("lbu", (ptr), __gu_val, __gu_err); \ + __get_user_asm("lbu", (ptr), x, __gu_err); \ break; \ case 2: \ - __get_user_asm("lhu", (ptr), __gu_val, __gu_err); \ + __get_user_asm("lhu", (ptr), x, __gu_err); \ break; \ case 4: \ - __get_user_asm("lw", (ptr), __gu_val, __gu_err); \ + __get_user_asm("lw", (ptr), x, __gu_err); \ break; \ - case 8: \ - __gu_err =3D __copy_from_user(&__gu_val, ptr, 8); \ - if (__gu_err) \ - __gu_err =3D -EFAULT; \ + case 8: { \ + __u64 __x =3D 0; \ + __gu_err =3D raw_copy_from_user(&__x, ptr, 8) ? \ + -EFAULT : 0; \ + (x) =3D (typeof(x))(typeof((x) - (x)))__x; \ break; \ + } \ default: \ /* __gu_val =3D 0; __gu_err =3D -EINVAL;*/ __gu_err =3D __user_bad();\ } \ - x =3D (__force __typeof__(*(ptr))) __gu_val; \ __gu_err; \ }) =20 diff --git a/arch/nios2/include/asm/uaccess.h b/arch/nios2/include/asm/ua= ccess.h index ba9340e96fd4..ca9285a915ef 100644 --- a/arch/nios2/include/asm/uaccess.h +++ b/arch/nios2/include/asm/uaccess.h @@ -88,6 +88,7 @@ extern __must_check long strnlen_user(const char __user= *s, long n); /* Optimized macros */ #define __get_user_asm(val, insn, addr, err) \ { \ + unsigned long __gu_val; \ __asm__ __volatile__( \ " movi %0, %3\n" \ "1: " insn " %1, 0(%2)\n" \ @@ -96,14 +97,20 @@ extern __must_check long strnlen_user(const char __us= er *s, long n); " .section __ex_table,\"a\"\n" \ " .word 1b, 2b\n" \ " .previous" \ - : "=3D&r" (err), "=3Dr" (val) \ + : "=3D&r" (err), "=3Dr" (__gu_val) \ : "r" (addr), "i" (-EFAULT)); \ + val =3D (__force __typeof__(*(addr)))__gu_val; \ } =20 -#define __get_user_unknown(val, size, ptr, err) do { \ +extern void __get_user_unknown(void); + +#define __get_user_8(val, ptr, err) do { \ + u64 __val =3D 0; \ err =3D 0; \ - if (__copy_from_user(&(val), ptr, size)) { \ + if (raw_copy_from_user(&(__val), ptr, sizeof(val))) { \ err =3D -EFAULT; \ + } else { \ + val =3D (typeof(val))(typeof((val) - (val)))__val; \ } \ } while (0) =20 @@ -119,8 +126,11 @@ do { \ case 4: \ __get_user_asm(val, "ldw", ptr, err); \ break; \ + case 8: \ + __get_user_8(val, ptr, err); \ + break; \ default: \ - __get_user_unknown(val, size, ptr, err); \ + __get_user_unknown(); \ break; \ } \ } while (0) @@ -129,9 +139,7 @@ do { \ ({ \ long __gu_err =3D -EFAULT; \ const __typeof__(*(ptr)) __user *__gu_ptr =3D (ptr); \ - unsigned long __gu_val =3D 0; \ - __get_user_common(__gu_val, sizeof(*(ptr)), __gu_ptr, __gu_err);\ - (x) =3D (__force __typeof__(x))__gu_val; \ + __get_user_common(x, sizeof(*(ptr)), __gu_ptr, __gu_err); \ __gu_err; \ }) =20 @@ -139,11 +147,9 @@ do { \ ({ \ long __gu_err =3D -EFAULT; \ const __typeof__(*(ptr)) __user *__gu_ptr =3D (ptr); \ - unsigned long __gu_val =3D 0; \ if (access_ok( __gu_ptr, sizeof(*__gu_ptr))) \ - __get_user_common(__gu_val, sizeof(*__gu_ptr), \ + __get_user_common(x, sizeof(*__gu_ptr), \ __gu_ptr, __gu_err); \ - (x) =3D (__force __typeof__(x))__gu_val; \ __gu_err; \ }) =20 --=20 2.29.2