From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-co1nam03on0115.outbound.protection.outlook.com ([104.47.40.115]:2846 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387653AbeIXUwO (ORCPT ); Mon, 24 Sep 2018 16:52:14 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Zong Li , Greentime Hu , Sasha Levin Subject: [PATCH AUTOSEL 4.18 69/76] nds32: Fix get_user/put_user macro expand pointer problem Date: Mon, 24 Sep 2018 14:48:42 +0000 Message-ID: <20180924144751.164410-68-alexander.levin@microsoft.com> References: <20180924144751.164410-1-alexander.levin@microsoft.com> In-Reply-To: <20180924144751.164410-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Zong Li [ Upstream commit 6cce95a6c7d288ac2126eee4b95df448b9015b84 ] The pointer argument of macro need to be taken out once first, and then use the new pointer in the macro body. In kernel/trace/trace.c, get_user(ch, ubuf++) causes the unexpected increment after expand the macro. Signed-off-by: Zong Li Acked-by: Greentime Hu Signed-off-by: Greentime Hu Signed-off-by: Sasha Levin --- arch/nds32/include/asm/uaccess.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/nds32/include/asm/uaccess.h b/arch/nds32/include/asm/uacc= ess.h index 18a009f3804d..3f771e0595e8 100644 --- a/arch/nds32/include/asm/uaccess.h +++ b/arch/nds32/include/asm/uaccess.h @@ -78,8 +78,9 @@ static inline void set_fs(mm_segment_t fs) #define get_user(x,p) \ ({ \ long __e =3D -EFAULT; \ - if(likely(access_ok(VERIFY_READ, p, sizeof(*p)))) { \ - __e =3D __get_user(x,p); \ + const __typeof__(*(p)) __user *__p =3D (p); \ + if(likely(access_ok(VERIFY_READ, __p, sizeof(*__p)))) { \ + __e =3D __get_user(x, __p); \ } else \ x =3D 0; \ __e; \ @@ -99,10 +100,10 @@ static inline void set_fs(mm_segment_t fs) =20 #define __get_user_err(x,ptr,err) \ do { \ - unsigned long __gu_addr =3D (unsigned long)(ptr); \ + const __typeof__(*(ptr)) __user *__gu_addr =3D (ptr); \ unsigned long __gu_val; \ - __chk_user_ptr(ptr); \ - switch (sizeof(*(ptr))) { \ + __chk_user_ptr(__gu_addr); \ + switch (sizeof(*(__gu_addr))) { \ case 1: \ __get_user_asm("lbi",__gu_val,__gu_addr,err); \ break; \ @@ -119,7 +120,7 @@ do { \ BUILD_BUG(); \ break; \ } \ - (x) =3D (__typeof__(*(ptr)))__gu_val; \ + (x) =3D (__typeof__(*(__gu_addr)))__gu_val; \ } while (0) =20 #define __get_user_asm(inst,x,addr,err) \ @@ -169,8 +170,9 @@ do { \ #define put_user(x,p) \ ({ \ long __e =3D -EFAULT; \ - if(likely(access_ok(VERIFY_WRITE, p, sizeof(*p)))) { \ - __e =3D __put_user(x,p); \ + __typeof__(*(p)) __user *__p =3D (p); \ + if(likely(access_ok(VERIFY_WRITE, __p, sizeof(*__p)))) { \ + __e =3D __put_user(x, __p); \ } \ __e; \ }) @@ -189,10 +191,10 @@ do { \ =20 #define __put_user_err(x,ptr,err) \ do { \ - unsigned long __pu_addr =3D (unsigned long)(ptr); \ - __typeof__(*(ptr)) __pu_val =3D (x); \ - __chk_user_ptr(ptr); \ - switch (sizeof(*(ptr))) { \ + __typeof__(*(ptr)) __user *__pu_addr =3D (ptr); \ + __typeof__(*(__pu_addr)) __pu_val =3D (x); \ + __chk_user_ptr(__pu_addr); \ + switch (sizeof(*(__pu_addr))) { \ case 1: \ __put_user_asm("sbi",__pu_val,__pu_addr,err); \ break; \ --=20 2.17.1