Received: by 10.223.185.116 with SMTP id b49csp436926wrg; Fri, 16 Feb 2018 01:20:45 -0800 (PST) X-Google-Smtp-Source: AH8x2258kJ46CZARUB8ZjyW+jxyrmTmoXSdxMokRjyCDXqMkU3UBsl0vjJVhmJZMQsGmOXJwiiWV X-Received: by 2002:a17:902:bd08:: with SMTP id p8-v6mr5192724pls.78.1518772845485; Fri, 16 Feb 2018 01:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518772845; cv=none; d=google.com; s=arc-20160816; b=JCZeuAPdhGwgMIZN5nKPyS2R00ChYPXlUDz75gBskVM0EcRV0yIMdD1x9im0FBzxPP 4PudpnvbvlwPwoa9LHDRNzgsSSbKMlUEIWdpxhaYU9tTwh0IyuVcdcMhZUNpeNSzaqRF jQ/v9RHgBcGOlFA7SECQlIhb+um+W8ItrQRbftQwSMyLNExE5F+tM5SaH2DNd6MWzfTu DkqcNnet8BZUJraIVb5Uqps0jUrT70ufbD9ZuPP8ZJwrsne8G4ke+DWOqs6LrrcDOmzH hLeBBNPqBco4/GJBXosWmmoT+bwxSbRcffcEG08ZhEENGibjuDv9ZtIcO9xDSgROv6Il YG/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=VH6j2WsWglFT11NEg7ucCSKh/yiTy3I570y3oezcFkk=; b=OyVo+pvDjGMzFi9XWBtdPEyfVeiK6FZcVvRsS+x5j9PO+8eY5Io/MRduom/ddmUrVG V5BRaDK+znVSWrBtHJJW3I/40GNmuj6hQT4oN8m4Kz5Uu499qZ4RLN3zluLRRI4ka+3I 7JJYfeBRs/knH4paafKJnosGvjZjYZ4cP/fGveI/ChY/f5aFnrNJyvDCp0XVkDaaKG4s qMwMnWRbT5gatORWhdHd/gtu0gyg2i7D3kQAQLVPn8x+Ki4iPFU4rhYw3rUjGqTEdkPm 2dujG8+IPYPqf+aVcGG6JqJ28zsNLE/pZcDFlqHltHHglAIqoIIxaZOtqIqfkS27xGvb FFGw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i66si8878056pgc.445.2018.02.16.01.20.30; Fri, 16 Feb 2018 01:20:45 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426441AbeBOQq2 (ORCPT + 99 others); Thu, 15 Feb 2018 11:46:28 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60302 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423834AbeBOPk6 (ORCPT ); Thu, 15 Feb 2018 10:40:58 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A5A37116E; Thu, 15 Feb 2018 15:40:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Murphy , Will Deacon , Catalin Marinas Subject: [PATCH 4.15 055/202] [Variant 1/Spectre-v1] arm64: uaccess: Dont bother eliding access_ok checks in __{get, put}_user Date: Thu, 15 Feb 2018 16:15:55 +0100 Message-Id: <20180215151716.130434875@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 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 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon Commit 84624087dd7e upstream. access_ok isn't an expensive operation once the addr_limit for the current thread has been loaded into the cache. Given that the initial access_ok check preceding a sequence of __{get,put}_user operations will take the brunt of the miss, we can make the __* variants identical to the full-fat versions, which brings with it the benefits of address masking. The likely cost in these sequences will be from toggling PAN/UAO, which we can address later by implementing the *_unsafe versions. Reviewed-by: Robin Murphy Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/uaccess.h | 54 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 22 deletions(-) --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -294,28 +294,33 @@ do { \ (x) = (__force __typeof__(*(ptr)))__gu_val; \ } while (0) -#define __get_user(x, ptr) \ +#define __get_user_check(x, ptr, err) \ ({ \ - int __gu_err = 0; \ - __get_user_err((x), (ptr), __gu_err); \ - __gu_err; \ + __typeof__(*(ptr)) __user *__p = (ptr); \ + might_fault(); \ + if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \ + __p = uaccess_mask_ptr(__p); \ + __get_user_err((x), __p, (err)); \ + } else { \ + (x) = 0; (err) = -EFAULT; \ + } \ }) #define __get_user_error(x, ptr, err) \ ({ \ - __get_user_err((x), (ptr), (err)); \ + __get_user_check((x), (ptr), (err)); \ (void)0; \ }) -#define get_user(x, ptr) \ +#define __get_user(x, ptr) \ ({ \ - __typeof__(*(ptr)) __user *__p = (ptr); \ - might_fault(); \ - access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \ - __p = uaccess_mask_ptr(__p), __get_user((x), __p) : \ - ((x) = 0, -EFAULT); \ + int __gu_err = 0; \ + __get_user_check((x), (ptr), __gu_err); \ + __gu_err; \ }) +#define get_user __get_user + #define __put_user_asm(instr, alt_instr, reg, x, addr, err, feature) \ asm volatile( \ "1:"ALTERNATIVE(instr " " reg "1, [%2]\n", \ @@ -358,28 +363,33 @@ do { \ uaccess_disable_not_uao(); \ } while (0) -#define __put_user(x, ptr) \ +#define __put_user_check(x, ptr, err) \ ({ \ - int __pu_err = 0; \ - __put_user_err((x), (ptr), __pu_err); \ - __pu_err; \ + __typeof__(*(ptr)) __user *__p = (ptr); \ + might_fault(); \ + if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \ + __p = uaccess_mask_ptr(__p); \ + __put_user_err((x), __p, (err)); \ + } else { \ + (err) = -EFAULT; \ + } \ }) #define __put_user_error(x, ptr, err) \ ({ \ - __put_user_err((x), (ptr), (err)); \ + __put_user_check((x), (ptr), (err)); \ (void)0; \ }) -#define put_user(x, ptr) \ +#define __put_user(x, ptr) \ ({ \ - __typeof__(*(ptr)) __user *__p = (ptr); \ - might_fault(); \ - access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \ - __p = uaccess_mask_ptr(__p), __put_user((x), __p) : \ - -EFAULT; \ + int __pu_err = 0; \ + __put_user_check((x), (ptr), __pu_err); \ + __pu_err; \ }) +#define put_user __put_user + extern unsigned long __must_check __arch_copy_from_user(void *to, const void __user *from, unsigned long n); #define raw_copy_from_user __arch_copy_from_user extern unsigned long __must_check __arch_copy_to_user(void __user *to, const void *from, unsigned long n);