Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2307703pxb; Fri, 5 Feb 2021 14:34:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJ2vUTIauWEYokJDNZ7H/TONqL+f06TZq+QYDYEWMFFXwxdwbL7J7f5nkFYGlfTq1ocgG6 X-Received: by 2002:a17:906:b351:: with SMTP id cd17mr6157314ejb.110.1612564487330; Fri, 05 Feb 2021 14:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612564487; cv=none; d=google.com; s=arc-20160816; b=Pi4Kj59EU4w/ykvdz6gpBInT3oLllI934oAEpebp0dC1R+XITA1ZsGyj8R1+91CMx6 aemct4x9ixLIQ8oUR0+cRft/2TT0lTDmpjz2E155Ho80QO+UrNgK1CmweVla3hnxC7KR dGlD6OmPrqaJ5WAsN2OieL18A4yweupxKdVw8W2ej5f6rrR8qSoo8zWN7SjAbreyXJGC RiNOi9D6x2MGnAUlS9fjqJ/AGR/l7POxpk90NeBWQNbGD/pLGRpL7DaBV4lV0Q4hFOmK CSeLgpUiD5BYZIFMgbC/BaFNjOp1si+YqM9sAvs66MguSriP8P8F+lMs2GdjsC60+FA8 KyCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=A+mvL37jQjubzcB3c42Dk2DlI3OOm0tKl5O+cIy2hiI=; b=jJ8VeQpGGr2u3GiXD9W6NgAn2wsNmEgnXWRMynyyFSSbl0IyYHNy2VYyRtW/exqopI 8kk2CHStsqIAdlqNPfZpiwJdwSnef6we8s3NQIWCCO//19BYEsDyIgJev2+gO2wPYi3l PbRtKgW16stAJxmiDzmkSgakkG+/Dau3hoZW70L8cmCTkxr8iQSbc2rqW/z8ImsdhEnx DuM4BdBy7VI78dzn5GiAatTXCl1choaaF9S0qDcHs6Hl/QRf6sW6l08kDU3n54G17WiG UahaYNL+z/x/AmxSFdKz+fJT+UsbaqG4Vd9qcDMEYzbl5J8Kd5xBcc3omdUPlY/EN2o1 TlJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f23si6167123edj.313.2021.02.05.14.34.23; Fri, 05 Feb 2021 14:34:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231709AbhBEWdi (ORCPT + 99 others); Fri, 5 Feb 2021 17:33:38 -0500 Received: from mga02.intel.com ([134.134.136.20]:12377 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232884AbhBEO4T (ORCPT ); Fri, 5 Feb 2021 09:56:19 -0500 IronPort-SDR: bD8V6DYZcyHn5IgTzAk8ZPKHsFStGaBPUt51CiZLVVkCfklvVmhyzALzmz9RfZM95eHVAj4Yn/ NC8ZieZZSwIg== X-IronPort-AV: E=McAfee;i="6000,8403,9885"; a="168561533" X-IronPort-AV: E=Sophos;i="5.81,155,1610438400"; d="scan'208";a="168561533" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.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: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/uaccess.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 = 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,ptr); }) +#define get_user(x,ptr) \ +({ \ + __typeof__(*(ptr)) *__ptr_clean = untagged_ptr(ptr); \ + might_fault(); \ + do_get_user_call(get_user,x,__ptr_clean); \ +}) /** * __get_user - Get a simple variable from user space, with less checking. @@ -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,ptr); }) +#define put_user(x, ptr) ({ \ + __typeof__(*(ptr)) *__ptr_clean = untagged_ptr(ptr); \ + might_fault(); \ + do_put_user_call(put_user,x,__ptr_clean); \ +}) /** * __put_user - Write a simple value into user space, with less checking. -- 2.26.2