From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8101C433E6 for ; Fri, 5 Feb 2021 15:16:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 435B2650E7 for ; Fri, 5 Feb 2021 15:16:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 435B2650E7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A8A826B0075; Fri, 5 Feb 2021 10:16:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EA2F6B0078; Fri, 5 Feb 2021 10:16:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 865116B007B; Fri, 5 Feb 2021 10:16:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id 5F68A6B0075 for ; Fri, 5 Feb 2021 10:16:51 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2206A249C for ; Fri, 5 Feb 2021 15:16:51 +0000 (UTC) X-FDA: 77784566622.26.loss72_2f157c7275e5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id EE6281804B65C for ; Fri, 5 Feb 2021 15:16:50 +0000 (UTC) X-HE-Tag: loss72_2f157c7275e5 X-Filterd-Recvd-Size: 4089 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Feb 2021 15:16:50 +0000 (UTC) IronPort-SDR: ANDdJJVU+ibswq/sAJIXvBXa2PIAMBeSalvTS5+2ZXDBieRSYV2cC/d3oZEwNd/GYxPiT0D03G WTHdvrC1aqlw== X-IronPort-AV: E=McAfee;i="6000,8403,9885"; a="181592757" X-IronPort-AV: E=Sophos;i="5.81,155,1610438400"; d="scan'208";a="181592757" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2021 07:16:48 -0800 IronPort-SDR: iduseYam2qoeOo3j6NdDBWiD0Fn1gcerCd0wPAzSQUrrbq4J5dm7Azk3wNhvGbImTcW8SrkrnQ p9knQzBdFYTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,155,1610438400"; d="scan'208";a="373422224" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 05 Feb 2021 07:16:45 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id F057E314; Fri, 5 Feb 2021 17:16:40 +0200 (EET) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: x86@kernel.org, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , "H . J . Lu" , Andi Kleen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [RFC 6/9] x86/uaccess: Remove tags from the address before checking Date: Fri, 5 Feb 2021 18:16:27 +0300 Message-Id: <20210205151631.43511-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205151631.43511-1-kirill.shutemov@linux.intel.com> References: <20210205151631.43511-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The tags must not be included into check whether it's okay to access the userspace address. __chk_range_not_ok() is at the core or access_ok() and it's handly to strip tags there. get_user() and put_user() don't use access_ok(), but check access against TASK_SIZE direcly in assembly. Strip tags, before calling into the assembly helper. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/uaccess.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uacces= s.h index c9fa7be3df82..ee0a482b2f1f 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -18,6 +18,9 @@ */ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long = size, unsigned long limit) { + /* Remove tags from the address before comparing to the limit */ + addr =3D untagged_addr(addr); + /* * If we have used "sizeof()" for the size, * we know it won't overflow the limit (but @@ -152,7 +155,12 @@ extern int __get_user_bad(void); * Return: zero on success, or -EFAULT on error. * On error, the variable @x is set to zero. */ -#define get_user(x,ptr) ({ might_fault(); do_get_user_call(get_user,x,pt= r); }) +#define get_user(x,ptr) \ +({ \ + __typeof__(*(ptr)) *__ptr_clean =3D untagged_ptr(ptr); \ + might_fault(); \ + do_get_user_call(get_user,x,__ptr_clean); \ +}) =20 /** * __get_user - Get a simple variable from user space, with less checkin= g. @@ -249,7 +257,11 @@ extern void __put_user_nocheck_8(void); * * Return: zero on success, or -EFAULT on error. */ -#define put_user(x, ptr) ({ might_fault(); do_put_user_call(put_user,x,p= tr); }) +#define put_user(x, ptr) ({ \ + __typeof__(*(ptr)) *__ptr_clean =3D untagged_ptr(ptr); \ + might_fault(); \ + do_put_user_call(put_user,x,__ptr_clean); \ +}) =20 /** * __put_user - Write a simple value into user space, with less checking= . --=20 2.26.2