Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp733983ima; Fri, 15 Mar 2019 12:55:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKB4jnS0bdfiWxCPUpz0SHVGWUsajDf0NJtxaSanOtMCeleT2Os63csADhzjOmURUGduFh X-Received: by 2002:a17:902:7289:: with SMTP id d9mr6056784pll.314.1552679712408; Fri, 15 Mar 2019 12:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552679712; cv=none; d=google.com; s=arc-20160816; b=v/86PxCnkqpMQ96srBndOh2EbpyU1OU7flQyzEeXbLC+F3QJPnnZQ37P0VQzChsjuC yq4kVVlzv0CFqmhHlTyA5cVuxwZqAYsgm/E0iwFNlHOr4QWZEsPBeGgd0sQvM6EixMgZ 8XZ+TyVAQ2sRArFjonS5ucBJ6vHCrub7qcqROPZeN/PxBzu4gykHPHUxRSCBRK7bnTY8 qBrgoeODIxia4wSN0p4Fi0CF0GTsreqR3R5XMMQUrvqxcV1jkublVYyl3A7cSA6M8svB DWam6kHy0HFQNifAOCcncf+gM/33WxtvFyb654P6qJEyOYrpMWEftKfPb26pMmhetrPU Hz4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=HBqdcrrZbnaUQvnw2SuV9xpSHs4pKIOHqIC9BZ3VFKg=; b=WWG2ycDExGuLXdpvYm42qTsXB20XIUKsKHoYr5TdDereECyYZzsSUA3cI7d29/BvId 4zZL4e/XFOVuWYA2aDTIbxv+OlDRbyOCLhX3UJc/OEdWxvqDdxQFnA7vN8tafTRZo9Ne oOthJXraY2Gnwi4tJENwj2LBTHqnv3hRKKdd59OZazvfy9yz2ErLRzODkzRF98gv7zgR F+ybskSyOlZfWlKieUwvFPtmqDAiNDGyk76UDoFJXbC+E8efCL+WEAbfFG6eaqJCLAsR H+b1vuF1/5GNZC8ngukz1TUY+dRJXpYgQ5Kd05lxwI6ThJiqkJkdB/NPb7cXcvILcNmX RGGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bMyL6O7m; 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 g59si2569361plb.281.2019.03.15.12.54.57; Fri, 15 Mar 2019 12:55:12 -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=bMyL6O7m; 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 S1726654AbfCOTx7 (ORCPT + 99 others); Fri, 15 Mar 2019 15:53:59 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:33091 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727262AbfCOTvv (ORCPT ); Fri, 15 Mar 2019 15:51:51 -0400 Received: by mail-pf1-f202.google.com with SMTP id x23so11481000pfm.0 for ; Fri, 15 Mar 2019 12:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=HBqdcrrZbnaUQvnw2SuV9xpSHs4pKIOHqIC9BZ3VFKg=; b=bMyL6O7mL3v0PpvhcraOwU0+T0KPIFPV/p7nmVTvmipE51X/RVpxp6XgCeUgtieP7G ixioELJzjz0dEoQWCYr0YK3/FbXsJYHqdPSXpUIsBdn1yDDXj6QnCZ35FOYA8i9HT63C 4NxOaja1Vj1CohRqNK5BDjm+Ej2ZsDeLIYnjGIPj/aDrjQ9HbzCW01i4AWSy9c6BCqBH VOneIHkae9V1wBY19FpITt5gyzE2kQ3GzB4IuuJ9g8/ByewueOS2EyupEZ9Fn2xI7TMs eSLl2rv00PucX+Qh3Q1GWwU/1iBbczPrTond0HrvoOUHVc5VY5X1umF2QYAhZzj9B3zd L8hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HBqdcrrZbnaUQvnw2SuV9xpSHs4pKIOHqIC9BZ3VFKg=; b=nh9sO2Ub8uDZ2yo+nUkgAqpP39kVEJ18ddVo9rEQPG5Wja7pPWkGS0cD4AalsJRaEY 77wAh6ntFtWejf80XYrA8c4pOTnhyKLsv6TFkysGxygcu8npl9ANmZVAIwTwlOPmiuc9 OpM6CkvmGpO8WXK/Cl6JCw4RqK7+qTz+r43FyExoK35SY/71j7HYDwUlOldexSxJGyOp z5rWnj2vl4+lTOFEreWdKAI9TGjJwYjrQV1hWxHhbCrqGjrtDP7znDc8qpabKiI9eCHq UNMVvcbZb2JpZ7c9v6SeNylk79pF86ekRWAwaDvfIAVjysvmU6TjoBluohcSHRDyAx9o 4Kyg== X-Gm-Message-State: APjAAAXkL809TrnuND7vLwMuE1D3sPNdIACG2/NsGAqeGtZLaSPzkj9l dY38wRLJyevgrk6bPIMHu5JSna5SIkjsVjxY X-Received: by 2002:a65:52c5:: with SMTP id z5mr2165417pgp.71.1552679510299; Fri, 15 Mar 2019 12:51:50 -0700 (PDT) Date: Fri, 15 Mar 2019 20:51:26 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog Subject: [PATCH v11 02/14] arm64: untag user pointers in access_ok and __uaccess_mask_ptr From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , Vincenzo Frascino , Eric Dumazet , "David S. Miller" , Alexei Starovoitov , Daniel Borkmann , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Arnaldo Carvalho de Melo , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, bpf@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 , Luc Van Oostenryck , Dave Martin , Kevin Brodsky , Szabolcs Nagy , Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch is a part of a series that extends arm64 kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. 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. Note, that this patch only temporarily untags the pointers to perform the checks, but then passes them as is into the kernel internals. Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index e5d5f31c6d36..9164ecb5feca 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -94,7 +94,7 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si return ret; } -#define access_ok(addr, size) __range_ok(addr, size) +#define access_ok(addr, size) __range_ok(untagged_addr(addr), size) #define user_addr_max get_fs #define _ASM_EXTABLE(from, to) \ @@ -226,7 +226,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) @@ -234,10 +235,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.21.0.360.g471c308f928-goog