Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp906751imm; Wed, 20 Jun 2018 08:27:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJy1CcVUcCKJM6grbxY/zAXlXtIAkzShAjeWTkg5La8F96nD4cTaY8hnKBQNSGzWV5HAIlz X-Received: by 2002:a62:b50f:: with SMTP id y15-v6mr23087784pfe.22.1529508465558; Wed, 20 Jun 2018 08:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529508465; cv=none; d=google.com; s=arc-20160816; b=cMgh2jieakng6eMzd3hNVqnYqcVDvqiprziIxkd67uhJPOZZHLjAp5TPLAMFoCj/Fw E6WGVJY+mKPBrbCIYxmaXrC746Xc6rGKeQXpLxb8O+G/H62nvZHVaH1uBnenu12EcCaD q5r6REDXLPPv18+QHm7mis3qhN31XlwxXAtr3YKgXuIvLWQujHgP9+MrKc7xyDFTXwSm GEnMkE5uObsGMMxhKD/0hS4d8+5bkWdiGh1O751ytr6VY/VHOEITDrgCxD3Ds7dF3Be3 8cYxPA4OGHA3x8Bmz+sHwKpH5XRQ8CtMRhdUC+wLI/Ynfz6l1wwfz8YStq7Mo6HMS36G yF5w== 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:cc:to:from:dkim-signature:arc-authentication-results; bh=m9bM2usci+57xc3zRMgpKMd80JVfANdAQuqRMxrSXbE=; b=IDC5RGEGlMRr4C+Dx4lX2kB8ltySTZFFzlVICKW8y08jrqmUIXDycXg7xNlRqQUTkL yWTbg7mB5MnBJRGX0V+3knyRxAfCBN//03wvXPEMbDMjPBxhjQytlK7f4TJfOZfq/HEw EyZizipCY2yhsSqRrHZbjjsuI3f8ljLf/it7YkqWqDuonCGWEefc1ViWLqafqkE8sUfx j8e+ru8oFReb3bzc8dJMEOuZl6DvNVPtNz4+jDP1u6Hb+wWCWjqLU6Nep2JVoFEIynWb aljOlOzrjg4NGYSkVIxmoIGUVMdAlDnB9rLgGoCqLgfy9xDm0xjQ/6qHkay8/p/2VVrN D/VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=P4QMe9eU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si2771291plf.133.2018.06.20.08.27.31; Wed, 20 Jun 2018 08:27:45 -0700 (PDT) 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=@google.com header.s=20161025 header.b=P4QMe9eU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754269AbeFTP0f (ORCPT + 99 others); Wed, 20 Jun 2018 11:26:35 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:52236 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754142AbeFTPYf (ORCPT ); Wed, 20 Jun 2018 11:24:35 -0400 Received: by mail-wm0-f68.google.com with SMTP id p126-v6so207714wmb.2 for ; Wed, 20 Jun 2018 08:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=m9bM2usci+57xc3zRMgpKMd80JVfANdAQuqRMxrSXbE=; b=P4QMe9eUNQNmUEDFBBlBegREw9qogy95KBK5zhWridJ7KAYuu4P4qoJ4RSKpU9A9uj 5fca0DIDVpiHr/mfdFgE3ofA/Enl3ijcfpPqVwDoidv/ZBmJd3UfR+UiNCeMZof4XCST 4C/1T1Yp+k36uWBvPwnzfbw0QykFayqOyUY5ncoD2eTJsW/QASmCkGs/GutEvLYzNuJj 869lLy8dgvSAUBlgEVAbePvzExXpPUkKx6xwcWa6d2c6HPYOArGLmbtV9voMXMuXOIDR Yv0PUDda2BBkNvrXOwhUkwNT0fQrGVD3726M/2PMhCspWsSHXdrSHi0Ge+6EaYp8cb5d tjdg== 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; bh=m9bM2usci+57xc3zRMgpKMd80JVfANdAQuqRMxrSXbE=; b=R7jyMC+dI+9EZbMnk8WZm5lHHKsws60+sYJd7XPPwunXbEUySyM3h/El1zagDQUg1X jg5J4lQo9kPAe7XP3ALuy+OEg+zohX3dh7D5OiQ2jS5Gih3JtDKFwqZY6cuxBNXaEQjZ EPbQWPTBfi1wfbFphSvR2fBDD56Qz5YX2V3grhBaicCxluvgyCtAQQbJnu+WljorpqXx SebYuXE76sNpqyJWKCCDSr3LaV6tUGBDaCIHqyhG9mfWXseVREXHSwkG5W0QVIu/KT+5 6CqdrpA4XHqLfcYv3dC2Kz7vjMRM4JR3LgeLwWMAdIsRnMQ6Y0FyrfsWwbWR21nWVdDO CYjA== X-Gm-Message-State: APt69E1MUiT1hrnPjm+4iTei7Xe9nTMUVhzPoYqiJmaYrfdhrheJq+lB 2rVqV8WDHXEv94PqU4SkD2F2og== X-Received: by 2002:a1c:9015:: with SMTP id s21-v6mr2104314wmd.20.1529508274166; Wed, 20 Jun 2018 08:24:34 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id c11-v6sm3959244wrm.65.2018.06.20.08.24.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 08:24:33 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Al Viro , Andrey Konovalov , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya Subject: [PATCH v4 3/7] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Wed, 20 Jun 2018 17:24:22 +0200 Message-Id: <69573b1f821c5068be21fdff556cef11f03a09b4.1529507994.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org copy_from_user (and a few other similar functions) are used to copy data from user memory into the kernel memory or vice versa. Since a user can provided a tagged pointer to one of the syscalls that use copy_from_user, we need to correctly handle such pointers. Do this by untagging user pointers in access_ok and in __uaccess_mask_ptr, before performing access validity checks. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 2d6451cbaa86..fa7318d3d7d5 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -105,7 +105,8 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si #define untagged_addr(addr) \ ((__typeof__(addr))sign_extend64((__u64)(addr), 55)) -#define access_ok(type, addr, size) __range_ok(addr, size) +#define access_ok(type, addr, size) \ + __range_ok(untagged_addr(addr), size) #define user_addr_max get_fs #define _ASM_EXTABLE(from, to) \ @@ -237,7 +238,8 @@ static inline void uaccess_enable_not_uao(void) /* * Sanitise a uaccess pointer such that it becomes NULL if above the - * current addr_limit. + * current addr_limit. In case the pointer is tagged (has the top byte set), + * untag the pointer before checking. */ #define uaccess_mask_ptr(ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr) static inline void __user *__uaccess_mask_ptr(const void __user *ptr) @@ -245,10 +247,11 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr) void __user *safe_ptr; asm volatile( - " bics xzr, %1, %2\n" + " bics xzr, %3, %2\n" " csel %0, %1, xzr, eq\n" : "=&r" (safe_ptr) - : "r" (ptr), "r" (current_thread_info()->addr_limit) + : "r" (ptr), "r" (current_thread_info()->addr_limit), + "r" (untagged_addr(ptr)) : "cc"); csdb(); -- 2.18.0.rc1.244.gcf134e6275-goog