From patchwork Fri Jun 14 03:07:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 166750 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1505517ilk; Thu, 13 Jun 2019 20:12:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUO5NDlHViedxw5DZ3K+lXeANyjhBi6ff9rgBX/fnyK3hoyhpgUVGwuWpAsKphjkAe8lzn X-Received: by 2002:a17:902:b102:: with SMTP id q2mr4232150plr.149.1560481947622; Thu, 13 Jun 2019 20:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560481947; cv=none; d=google.com; s=arc-20160816; b=ZgKv7xub8MsNPRjan+ENYcX1tvfLkl7ZtxosDiBW91Odd8B/cVebTDXHYr24mVqS0R HhrNqKlk6bD8PT4S1mqwVKOkv8KorUX0tvqE1IQpc6qVm7LKI6vzvxxkXmAb2ilY02Xq 2zkHOgBnFcTVg8lqsF+JIS5m5+qFDEUV71No+f2HtlQn7Y9P9GoIo4aT3l4G+x1eWkaa x//hErdY4HtjNeWDR4N6lzD8M9MK0SHzlv9XBg+o602KN0fE1MnrxaSmY2Lpv3wcpd5N MDHsihbgV8i3tEBhd0B/kpUCeD3Ltkii8qd3wOYf6iD5MHq3MzPMnQWsAdLBGvLXh3Sx eFqQ== 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=Zvf6a5n0b57m5571dEwc9PlwLEZ1HE7kAfPBhGFdWe4=; b=FJAbNWsE75fMH0MTco2DlR0HS7xSPKIGiDMMmhnsm63xMSBFF5rLCXseUeuXc2MMJi 36uNfkW0oHW36Zv+/FsPphl6lzrVspjOB8oeZN+nuIZVotP9VvtOMpsyTRZULz7SPgKn xW+hry78OqXIFQc3+0xWGZW33GE8NLhlngiqLWsUfB47MhguWtKi5uFxEhiHdFHevHMn 6EFuU9ErHZuVGcyJeGkcsn8AY/K9pM4RTnRDDi8uvUu0RhPkG1F6B4PlgGqbLOzwY11o oX/5bCacEyATRYXfwXYXT1jDsfEMkS2DJ7SjqMASEKIqPjj50+nRcx8ctKRb/oZwgzSa q/Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ztvXyBjE; 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 e8si1073936plb.420.2019.06.13.20.12.27; Thu, 13 Jun 2019 20:12:27 -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=ztvXyBjE; 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 S1726327AbfFNDM1 (ORCPT + 14 others); Thu, 13 Jun 2019 23:12:27 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37669 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725819AbfFNDM0 (ORCPT ); Thu, 13 Jun 2019 23:12:26 -0400 Received: by mail-pl1-f195.google.com with SMTP id bh12so377469plb.4 for ; Thu, 13 Jun 2019 20:12:26 -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=Zvf6a5n0b57m5571dEwc9PlwLEZ1HE7kAfPBhGFdWe4=; b=ztvXyBjEuIE8pRhNLIo38p951l7799Fiu7539y9i4bXyR/9SLopeN0wi3Hg5qaRSLa ontrmxklVAi69ytzxsCIlhosEi5TQM5i0ZbphTZ/PIieeXhXmLnu8OQwxBRxsWL7eTtU 0AkgT9ikRbzufBmBfhyY+cJRiMEILdWX8f4H5pt0EzsfgqUHMS3vRN8YOsXwTAHnmQpW jcczzZglVslkF2CFIjncy2tZjLVuZ3MWdhv9UhkGE5Pyl3au4XwJ16LowVI6BhB2+tGZ 20kj/YxMMXGaRx6L56183shTe7LoBdu+DjE2eJ8CY2Q17zp4Rrq6ktyXeAn5orsiyZF+ n9WA== 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=Zvf6a5n0b57m5571dEwc9PlwLEZ1HE7kAfPBhGFdWe4=; b=jzE8l2DJxie71/W6w1ZkE+fTPG0o4jsNPZRpVptT61AmjD0L61ssiRirOYVv8f+NUT d9OBdQE+Z6ZgjiA7cvextee5018bZZ851eQjWpAGo21v2DET94iaoMIh4kk2bgL3m/Ki 7cNs2l0LrMVSM5cRnCnF0g5uhaaZ3gH/t71pPw+cotsP78KL1UlqZDgWhwHCBfWZDnxc 23y6lx0Wg72zBmVLK6Ly2g6+v87O6WTfbh2HWE/fOAJmOY8QRqxsbZjPNae100vYg5Eq ZT1RmgjcufBlGTgJ4JUQYzFhviTMS7SvqO7o3VpzUoPpUUNrx6AgIjESFLkRCWlaZ7rs VPSA== X-Gm-Message-State: APjAAAWUeG7I7lmFK2C1bazSxL11wjaAMlXbWbuWeIC9MrEaWOCXjVaw gNhBL/P+1AMQ8LIGzbdnb8YLeQ== X-Received: by 2002:a17:902:6ac6:: with SMTP id i6mr77136100plt.233.1560481945949; Thu, 13 Jun 2019 20:12:25 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id m6sm1217413pgr.18.2019.06.13.20.12.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 20:12:25 -0700 (PDT) From: Viresh Kumar To: linux-arm-kernel@lists.infradead.org, Julien Thierry Cc: Viresh Kumar , stable@vger.kernel.org, Catalin Marinas , Marc Zyngier , Mark Rutland , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH v4.4 12/45] arm64: uaccess: Mask __user pointers for __arch_{clear, copy_*}_user Date: Fri, 14 Jun 2019 08:37:55 +0530 Message-Id: <9f68161e012c5942720575377cffd4e445446acf.1560480942.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 f71c2ffcb20dd8626880747557014bb9a61eb90e upstream. Like we've done for get_user and put_user, ensure that user pointers are masked before invoking the underlying __arch_{clear,copy_*}_user operations. Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas [ v4.4: fixup for v4.4 style uaccess primitives ] Signed-off-by: Viresh Kumar --- arch/arm64/include/asm/uaccess.h | 20 ++++++++++++-------- arch/arm64/kernel/arm64ksyms.c | 4 ++-- arch/arm64/lib/clear_user.S | 6 +++--- arch/arm64/lib/copy_in_user.S | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 693a0d784534..a25b8726ffa9 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -303,19 +303,20 @@ do { \ 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); -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n); +extern unsigned long __must_check __arch_copy_in_user(void __user *to, const void __user *from, unsigned long n); static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n) { kasan_check_write(to, n); - return __arch_copy_from_user(to, from, n); + return __arch_copy_from_user(to, __uaccess_mask_ptr(from), n); + } static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n) { kasan_check_read(from, n); - return __arch_copy_to_user(to, from, n); + return __arch_copy_to_user(__uaccess_mask_ptr(to), from, n); + } static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n) @@ -338,22 +339,25 @@ static inline unsigned long __must_check copy_to_user(void __user *to, const voi return n; } -static inline unsigned long __must_check copy_in_user(void __user *to, const void __user *from, unsigned long n) +static inline unsigned long __must_check __copy_in_user(void __user *to, const void __user *from, unsigned long n) { if (access_ok(VERIFY_READ, from, n) && access_ok(VERIFY_WRITE, to, n)) - n = __copy_in_user(to, from, n); + n = __arch_copy_in_user(__uaccess_mask_ptr(to), __uaccess_mask_ptr(from), n); return n; } +#define copy_in_user __copy_in_user #define __copy_to_user_inatomic __copy_to_user #define __copy_from_user_inatomic __copy_from_user -static inline unsigned long __must_check clear_user(void __user *to, unsigned long n) +extern unsigned long __must_check __arch_clear_user(void __user *to, unsigned long n); +static inline unsigned long __must_check __clear_user(void __user *to, unsigned long n) { if (access_ok(VERIFY_WRITE, to, n)) - n = __clear_user(__uaccess_mask_ptr(to), n); + n = __arch_clear_user(__uaccess_mask_ptr(to), n); return n; } +#define clear_user __clear_user extern long strncpy_from_user(char *dest, const char __user *src, long count); diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c index c654df05b7d7..abe4e0984dbb 100644 --- a/arch/arm64/kernel/arm64ksyms.c +++ b/arch/arm64/kernel/arm64ksyms.c @@ -35,8 +35,8 @@ EXPORT_SYMBOL(clear_page); /* user mem (segment) */ EXPORT_SYMBOL(__arch_copy_from_user); EXPORT_SYMBOL(__arch_copy_to_user); -EXPORT_SYMBOL(__clear_user); -EXPORT_SYMBOL(__copy_in_user); +EXPORT_SYMBOL(__arch_clear_user); +EXPORT_SYMBOL(__arch_copy_in_user); /* physical memory */ EXPORT_SYMBOL(memstart_addr); diff --git a/arch/arm64/lib/clear_user.S b/arch/arm64/lib/clear_user.S index a9723c71c52b..fc6bb0f83511 100644 --- a/arch/arm64/lib/clear_user.S +++ b/arch/arm64/lib/clear_user.S @@ -24,7 +24,7 @@ .text -/* Prototype: int __clear_user(void *addr, size_t sz) +/* Prototype: int __arch_clear_user(void *addr, size_t sz) * Purpose : clear some user memory * Params : addr - user memory address to clear * : sz - number of bytes to clear @@ -32,7 +32,7 @@ * * Alignment fixed up by hardware. */ -ENTRY(__clear_user) +ENTRY(__arch_clear_user) ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) mov x2, x1 // save the size for fixup return @@ -57,7 +57,7 @@ USER(9f, strb wzr, [x0] ) ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) ret -ENDPROC(__clear_user) +ENDPROC(__arch_clear_user) .section .fixup,"ax" .align 2 diff --git a/arch/arm64/lib/copy_in_user.S b/arch/arm64/lib/copy_in_user.S index 81c8fc93c100..0219aa85b3cc 100644 --- a/arch/arm64/lib/copy_in_user.S +++ b/arch/arm64/lib/copy_in_user.S @@ -67,7 +67,7 @@ .endm end .req x5 -ENTRY(__copy_in_user) +ENTRY(__arch_copy_in_user) ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) add end, x0, x2 @@ -76,7 +76,7 @@ ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) mov x0, #0 ret -ENDPROC(__copy_in_user) +ENDPROC(__arch_copy_in_user) .section .fixup,"ax" .align 2