Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp595716pxb; Thu, 25 Feb 2021 10:01:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0IoBenZKgTa38ux0C+rjBE95fMbqQnpy0esUlVAR5kAw9CcHfoO18+ZltYyQTgocOHL+U X-Received: by 2002:aa7:d74e:: with SMTP id a14mr4174237eds.287.1614276088741; Thu, 25 Feb 2021 10:01:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614276088; cv=none; d=google.com; s=arc-20160816; b=d5pHr7qEaGo6h/DaS0da1Hwov9CeLo4XwDkZ9MnU7KlqG6qda/mtxmynF6+3+0VBRO +QfccET77hR7Dr4tgUSe1wp6iWK7kR3a/Fe0HshasADV8kdgysZIxD8F0SUz+GH6C0Aa YaA4RY10f/wKEOsa91llps1QrBUm65aFq5ofaNNDzr6v0J2aVvBMFd/9F9Heg7YoPuRd e5eItTHJMKUzF3kVSsYRyRwAif6UapIPPKYD6balvwwjMeiW2cz/na+6mfuimXkJvdRB DA2nafwyFoZ4shd1MkQMmUM1IGAZT9+Az1AHMtL6bg583Xsb4RI9f/YEViaMFvwSpFU8 6Ddw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:cc:to:subject:from:references:in-reply-to :message-id; bh=5fbyco8PReBrz5MZLZsbB3/HI6PBnX8CQlCusjNK7Jo=; b=02DSeLidREZ58kc92lVnrcbWMTRXOdiJcspE2gBbcQ0stVxGKiMg3IoZakEFV4dNy1 ll60YsM1XBngcaIpxG3eMquLUcS9wcyro9+f6SmkUPBMSg+rgw1+zYf6M/MUthNq+E36 AbKCe5AfSc/TIgWehfBj+IY20KnfClqzMhT8/IbCgKr9CMUIMRPwQJKsWA/J4aY3coDW //5gvocuhhUt6As56IlN9D1vT4OiiInTKxEOT1m1gOytspm6/lRSx9Pn76O3yU+6tBZ4 wogkBk2i8vWPzUhyWKcTesBCzY1U4Vi0pfDNJP/QUZD3ehSY/qJvCVHErMT4PcufMVQh JLWg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f27si3898962ejf.555.2021.02.25.10.01.05; Thu, 25 Feb 2021 10:01:28 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232081AbhBYR6W (ORCPT + 99 others); Thu, 25 Feb 2021 12:58:22 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:7751 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232923AbhBYRw0 (ORCPT ); Thu, 25 Feb 2021 12:52:26 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DmgLT08sBz9v1BD; Thu, 25 Feb 2021 18:50:41 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id H2LwkeRtkeT5; Thu, 25 Feb 2021 18:50:40 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DmgLS6RpVz9v19y; Thu, 25 Feb 2021 18:50:40 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B1DE68B895; Thu, 25 Feb 2021 18:50:42 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id rmmEhHZ5srwC; Thu, 25 Feb 2021 18:50:42 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5EA648B88B; Thu, 25 Feb 2021 18:50:42 +0100 (CET) Received: by po16121vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 36B5967442; Thu, 25 Feb 2021 17:50:42 +0000 (UTC) Message-Id: <3c174edb80d2d37af6b08c637b09268f675e5371.1614275314.git.christophe.leroy@csgroup.eu> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v1 12/15] powerpc/uaccess: Refactor get/put_user() and __get/put_user() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Thu, 25 Feb 2021 17:50:42 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make get_user() do the access_ok() check then call __get_user(). Make put_user() do the access_ok() check then call __put_user(). Then embed __get_user_size() and __put_user_size() in __get_user() and __put_user(). Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/uaccess.h | 66 +++++++++++------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h index 616a3a7928c2..671c083f2f2f 100644 --- a/arch/powerpc/include/asm/uaccess.h +++ b/arch/powerpc/include/asm/uaccess.h @@ -43,21 +43,6 @@ static inline bool __access_ok(unsigned long addr, unsigned long size) * exception handling means that it's no longer "just"...) * */ -#define __put_user_size(x, ptr, size, retval) \ -do { \ - __label__ __pu_failed; \ - \ - retval = 0; \ - allow_write_to_user(ptr, size); \ - __put_user_size_goto(x, ptr, size, __pu_failed); \ - prevent_write_to_user(ptr, size); \ - break; \ - \ -__pu_failed: \ - retval = -EFAULT; \ - prevent_write_to_user(ptr, size); \ -} while (0) - #define __put_user(x, ptr) \ ({ \ long __pu_err; \ @@ -66,23 +51,29 @@ __pu_failed: \ __typeof__(sizeof(*(ptr))) __pu_size = sizeof(*(ptr)); \ \ might_fault(); \ - __put_user_size(__pu_val, __pu_addr, __pu_size, __pu_err); \ + do { \ + __label__ __pu_failed; \ + \ + allow_write_to_user(__pu_addr, __pu_size); \ + __put_user_size_goto(__pu_val, __pu_addr, __pu_size, __pu_failed); \ + prevent_write_to_user(__pu_addr, __pu_size); \ + __pu_err = 0; \ + break; \ + \ +__pu_failed: \ + prevent_write_to_user(__pu_addr, __pu_size); \ + __pu_err = -EFAULT; \ + } while (0); \ \ __pu_err; \ }) #define put_user(x, ptr) \ ({ \ - long __pu_err = -EFAULT; \ - __typeof__(*(ptr)) __user *__pu_addr = (ptr); \ - __typeof__(*(ptr)) __pu_val = (__typeof__(*(ptr)))(x); \ - __typeof__(sizeof(*(ptr))) __pu_size = sizeof(*(ptr)); \ + __typeof__(*(ptr)) __user *_pu_addr = (ptr); \ \ - might_fault(); \ - if (access_ok(__pu_addr, __pu_size)) \ - __put_user_size(__pu_val, __pu_addr, __pu_size, __pu_err); \ - \ - __pu_err; \ + access_ok(_pu_addr, sizeof(*(ptr))) ? \ + __put_user(x, _pu_addr) : -EFAULT; \ }) /* @@ -192,13 +183,6 @@ do { \ } \ } while (0) -#define __get_user_size(x, ptr, size, retval) \ -do { \ - allow_read_from_user(ptr, size); \ - __get_user_size_allowed(x, ptr, size, retval); \ - prevent_read_from_user(ptr, size); \ -} while (0) - /* * This is a type: either unsigned long, if the argument fits into * that type, or otherwise unsigned long long. @@ -214,7 +198,9 @@ do { \ __typeof__(sizeof(*(ptr))) __gu_size = sizeof(*(ptr)); \ \ might_fault(); \ - __get_user_size(__gu_val, __gu_addr, __gu_size, __gu_err); \ + allow_read_from_user(__gu_addr, __gu_size); \ + __get_user_size_allowed(__gu_val, __gu_addr, __gu_size, __gu_err); \ + prevent_read_from_user(__gu_addr, __gu_size); \ (x) = (__typeof__(*(ptr)))__gu_val; \ \ __gu_err; \ @@ -222,17 +208,11 @@ do { \ #define get_user(x, ptr) \ ({ \ - long __gu_err = -EFAULT; \ - __long_type(*(ptr)) __gu_val = 0; \ - __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ - __typeof__(sizeof(*(ptr))) __gu_size = sizeof(*(ptr)); \ - \ - might_fault(); \ - if (access_ok(__gu_addr, __gu_size)) \ - __get_user_size(__gu_val, __gu_addr, __gu_size, __gu_err); \ - (x) = (__force __typeof__(*(ptr)))__gu_val; \ + __typeof__(*(ptr)) __user *_gu_addr = (ptr); \ \ - __gu_err; \ + access_ok(_gu_addr, sizeof(*(ptr))) ? \ + __get_user(x, _gu_addr) : \ + ((x) = (__force __typeof__(*(ptr)))0, -EFAULT); \ }) /* more complex routines */ -- 2.25.0