Received: by 10.223.185.116 with SMTP id b49csp3489074wrg; Mon, 26 Feb 2018 00:25:25 -0800 (PST) X-Google-Smtp-Source: AH8x225bkn7IMynQ8KxbftvqfXudwNtTGNV/B6BUHA0Y1OBzfpGaDwTnYjg6dioduPO0/zzc7AZ4 X-Received: by 10.99.152.10 with SMTP id q10mr8031310pgd.212.1519633524930; Mon, 26 Feb 2018 00:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633524; cv=none; d=google.com; s=arc-20160816; b=s++JVutHUgg81RlebnF+PBqiiWpfKUer7hdH4fQUKX+criA2aTo3kwqrW1mXXHMjQc 0CJhL6EUoANYxJV+uERrd3LqY5Gw9o09F7UmoSO3PWrGAC43buTCpAnauX3Ubo+u7GmO uk8TlJuuDSng8W2xGX5yx1VNbCyzEdJPDDoDuu2YNyAWYZ0tUr6Pz7N766p12Bml3O2j b9unZXADdnD1Hd3zmcs0IBnf3U5jjCATVyfGxQvw/5YR4K1SiqFK6FQskDkXPJzWYUf/ SgaSHFxxYY3D/47vfr7PjYTgD2doD8wTBOp3YCw6rMnZbBCaWBSdZU+NLNMeBFWGM8c0 uSMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=JeYitV85vYUZHZtgTIJwAzhhdYjQpmFJh73a4N4z6FM=; b=KAhg1LG9txbSU1MVQmdtmqD6ke1kAiC8O8o+qRjXxzEfaCOo3sQHab0zxz2f0yibCl qWpYp9fGAFjRpDtotlYWOQ3n2Hvx3hJxZGpdqtYambUAsy5UpbycUY/1NwO8fR7bD6x8 gIdq4nXnTjkdDqZ6mLrv6l21xyn15ln6mHsngmKhhLjgodNo8x3bEAVtR5YVHAe94+Cg CtcXQtLhShOlxBAhTVNoLzAo2DwGOwEbJQioC1q0eV6zQw2TqFwgrBrU4i8MW5KfW4hb LuNgcSgfSVsbuR1JSZPeyeepWtTieOY3/x++uPXxx7oyJKjzoqlmddnGbuLShpurPhiD 8ozQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WuEnGHaW; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z100-v6si6452025plh.415.2018.02.26.00.25.10; Mon, 26 Feb 2018 00:25:24 -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; dkim=pass header.i=@linaro.org header.s=google header.b=WuEnGHaW; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752480AbeBZIW7 (ORCPT + 99 others); Mon, 26 Feb 2018 03:22:59 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:38034 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752460AbeBZIWv (ORCPT ); Mon, 26 Feb 2018 03:22:51 -0500 Received: by mail-pl0-f68.google.com with SMTP id d4so8862490pll.5 for ; Mon, 26 Feb 2018 00:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=JeYitV85vYUZHZtgTIJwAzhhdYjQpmFJh73a4N4z6FM=; b=WuEnGHaWFEDfKx3hNgfDxwVUV612UXDp7O3vkuvzzYqTTTrRDssZ4a0LQ5AbaWbII2 hzmuQlibDWAxkE6coVIxiK06vBbRzCmkQ2mfCW0sEhnlQG+lR4WUzlEmRlj1dMSBCngG q5Sd4quYSTPM2z5cEOKOj/QcT793ca0IgWZtQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=JeYitV85vYUZHZtgTIJwAzhhdYjQpmFJh73a4N4z6FM=; b=lvdT2/DSrFnfTpSKBAi2M/qDxxBLMSBSgOOwsMbduAMa3Cd4lgsWmy4l5bSqbDzTod z098iuJJ5zI67RF+6YXC46nuVXROwDy9DybFRh75FNRCr/u8ZNcZ2SoEkqvl14bEX+0n WQ7vrJpYZhs4nGKH0DBOjk1goPS4YhsfEmi3KE8MJ1USnJNN9Gjt5uxWFbCEe6Nhq2Jb sj0SiMcVCFaSxP+rIf4y49aY4LIBBl6Fa90zd63M/KP+fuhSKxQjm/F6+4wRrnwoDVKM p+G4+96PkBlQ7J4TvGR6KyPZNtaBMs68ihEAQW0iAuqLPGTWl1Z+EhBnh9OF4JYrtEHZ gnQA== X-Gm-Message-State: APf1xPAr2bXfcVGeLH9f5o+QDgxNd8PAAbqPoOtIF9VHYWKA/5HjcJ7r IgNbTnflPZgzFU1Xq+aztCcLQA== X-Received: by 2002:a17:902:34f:: with SMTP id 73-v6mr9561276pld.55.1519633370036; Mon, 26 Feb 2018 00:22:50 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.22.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:22:49 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 14/52] arm64: uaccess: Don't bother eliding access_ok checks in __{get, put}_user Date: Mon, 26 Feb 2018 16:19:48 +0800 Message-Id: <1519633227-29832-15-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Alex Shi Conflicts: keep __{get/put}_user_unaligned in arch/arm64/include/asm/uaccess.h --- arch/arm64/include/asm/uaccess.h | 54 ++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 00025c5..ffa4e39 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -248,30 +248,35 @@ 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_unaligned __get_user -#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", \ @@ -314,30 +319,35 @@ 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_unaligned __put_user -#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); extern unsigned long __must_check __arch_copy_to_user(void __user *to, const void *from, unsigned long n); extern unsigned long __must_check __copy_in_user(void __user *to, const void __user *from, unsigned long n); -- 2.7.4