From patchwork Fri Jul 12 05:27:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 168867 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp394531ilk; Thu, 11 Jul 2019 22:29:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyc74PXQ56ViofrpzgukHzNwbodVorHzmnsxEDMPX2yAJI25jVW7o3zVUIbw7UhXYdASeSS X-Received: by 2002:a17:90a:3344:: with SMTP id m62mr9397433pjb.135.1562909362914; Thu, 11 Jul 2019 22:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562909362; cv=none; d=google.com; s=arc-20160816; b=dJhAYK4r8QqBIA73QFV0pghD8Mn94moqeAEkyd4i+Bb2A4PeHZ6+t7LLm1Qr41txMJ ziBcrbK7ERfFVTeTHtvz7gdrgmC06MB2qgn95U2aecshBGxy4kzTW1gi1O6gb0PsmmGV o4BZE0egkleVEX4Pk/DaIl084Xw1L69tRBWr9sL7tAZ8eqBAcE6b7u3m3q2fWuU0LHxR 0k2I3jwPrMtrPiH4SgDB/KLMOBk/WgsEKMni8tVp/ugT7dji6Y5XodgI4kTp6KKBzoJP xGK5EcvyVzixiKgSxWNH2Q5PGLnRVJla53NH3Mn7a7QuGdaxx7kDMXUFydsMq+0kQiKe JnBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Lt3w372XAiP2T5A3AE8p2nBAFVuCKsgxbI6J0UJSdP8=; b=o42z/fkHOom+QzummlrULx2fpGrxRLpDsyi6yCN5w22HdxYPHHOiGz5g1vK2fM9IWk qRjzXIjAdPN3yx95RFnSikzjy8VMLPNaCd9/oJUDZUmr6BoVsCGQanCfIpBidrdkqVw3 xS1fhKhM4sPXm5WU5Eco3PUmGo/4SnTe4ihwRiEANXmfFjgOTj5g5l5YB+fOhzObVdSF I9dUssgKai8GM7AWW9mFbNUad/Gc7b8R6DhiGz7DRgm20wPqeLt97gwMBVpDStjfCnQx R5qS5kCv09LWDvoFFcJxpC3QWrCAuEf04ND6lBjByQzz8QfkIKpz/rGuJ7+q9y3m1nu4 BmSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="LaE/Kno7"; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 e36si5303191pgm.17.2019.07.11.22.29.22; Thu, 11 Jul 2019 22:29:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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="LaE/Kno7"; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1726050AbfGLF3W (ORCPT + 13 others); Fri, 12 Jul 2019 01:29:22 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42447 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725791AbfGLF3W (ORCPT ); Fri, 12 Jul 2019 01:29:22 -0400 Received: by mail-pl1-f196.google.com with SMTP id ay6so4195749plb.9 for ; Thu, 11 Jul 2019 22:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lt3w372XAiP2T5A3AE8p2nBAFVuCKsgxbI6J0UJSdP8=; b=LaE/Kno7nEObxeBKxYf9ds5SR/CXNWhXinMc3wcULfDJoYCm/+NNy5aliYFycyp/Pd xQjNCTX3R2Lq+L+RC/SMO5qnlzYoPN7ZrN0vVtlR6eZ+5ScFKAuQmQ3TO7j8mSsmt4Xd YlVHx3iK1DZkTJj5xP/b+JuDVFC6zP4989JLcd7xMAHJNgpFr3BPj89s9hC2xYMMV8up Aa7U2CtFy3VMya7CPReBDeY64SUW9PmXWPcFPrYDtu8vg5DZYAHcIBmCQyWoU3HVghK3 cMB2NDUennZ7lH8fyvKlDMyuCzU87oRy6E6zBmLCUtu5VqBlG9PrA3ZfPYCxqfgtFQwy qZAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lt3w372XAiP2T5A3AE8p2nBAFVuCKsgxbI6J0UJSdP8=; b=HrPt6lo+NFUohSAosWXfwTzQ4PQf7dSfDWdfPch2P2zqSIq/EPCE8p6U9EO1R4yhPs 4l8a19m700r242cwTvPRC/lYH0dtNp6wQOOgRyLBGDeft5WWXfXSGt51xFxJmtGU67x5 WoIZRRIr1Rx7fpEMfQzQ09HQgvnlbRVZB5GGZnsZLXRFTt4ThbVoma9Lram3KtNSd/F8 F7Tm0ZpSsDMWg5Is69207BUluTtLV1ILD2bdx3lSF1AF/tS64FpsYQcjdac7Cn6qvn4w 6UZ0TM3MbCWvHGr6LEIjPJZlK5vW80oLZmtr2RaYOTgodm6sxbh6LoiJJL9WaJI7yFh+ ddnQ== X-Gm-Message-State: APjAAAVBC+qeMoRh3sXaKb9uR7rwW/eXoNiWu9ObX3SNtT1mNHBkWU+X uiNpd8qYG15qWls2x16tKDk70t30Vso= X-Received: by 2002:a17:902:8509:: with SMTP id bj9mr9229479plb.79.1562909360992; Thu, 11 Jul 2019 22:29:20 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id 196sm7991977pfy.167.2019.07.11.22.29.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2019 22:29:20 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Julien Thierry Cc: Viresh Kumar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Marc Zyngier , Mark Rutland , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH v4.4 V2 08/43] arm64: uaccess: Don't bother eliding access_ok checks in __{get, put}_user Date: Fri, 12 Jul 2019 10:57:56 +0530 Message-Id: <61ec4192da912ef3c49e2e40670ddc76d9583683.1562908075.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Will Deacon commit 84624087dd7e3b482b7b11c170ebc1f329b3a218 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 [ v4.4: Fixed conflicts around {__get_user|__put_user}_unaligned macros ] Signed-off-by: Viresh Kumar --- arch/arm64/include/asm/uaccess.h | 62 ++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 26 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index fc11c50af558..a34324436ce1 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -200,30 +200,35 @@ do { \ CONFIG_ARM64_PAN)); \ } 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_unaligned __get_user + +#define get_user __get_user + #define __put_user_asm(instr, reg, x, addr, err) \ asm volatile( \ "1: " instr " " reg "1, [%2]\n" \ @@ -266,30 +271,35 @@ do { \ CONFIG_ARM64_PAN)); \ } 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_unaligned __put_user + +#define put_user __put_user + extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n); extern unsigned long __must_check __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);