Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp617728img; Mon, 18 Mar 2019 10:21:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwm4PiG0ZrFTopn4artpujocdCx6kFyIdfz5Usm41pEPZ8D2zEJTERXVVqwqq+oDVEwiKIJ X-Received: by 2002:a63:101c:: with SMTP id f28mr18218079pgl.224.1552929670979; Mon, 18 Mar 2019 10:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552929670; cv=none; d=google.com; s=arc-20160816; b=aMYnIq+vp25bUBUOU+w4SOAzs695akT5L1aV37BuV3MGxhlag8r6P1xS55ifQR+0Xm VblmzNZXZFC6p2O0pLHzzjEGY4FeewjZVIxg3e8l9GLeuzLT7oZGlfnevjZo0i2YGRIY VLKn9JaRrTijpRU5sWecA+8sOFTZpY/+IyTXeQWfj47JU97Vt9TmxjwQ7eD+BwuwY8L7 R88+IgvC0bM8FdU10ojDoRQrMEd1mi/YtElwoQkLRdGjy9/IciNDTRQ7EB9j7/ADpJRa LmRrB88nyP27bUehyUvZ666mCwkT7U1Kl0k0Jhoybp+F9q8fVOd7daWDGwBLVCJmM4sV wRCQ== 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=UykDW4hFaDHfzyUH5xSGMBQs4gGYEgUL/nC+SEDYWFU=; b=Q4cNqETPZmCpitIO583k0BgS9+1Qdy+sYoAlo53jrX3/z90x1NkBgQ8W3Lg1TVrC8B e20GDPNNjXFhlv5vU0Gsdqym38Xq8ax7KSs2c8HvNXOQZyUS+a3jLcebkJaT/eB+WkIq BS1qgNA0qX2uiybGbaOYijCIIyKrxDVJc7a5kh7fctWSW5XwM/YJBrUfBUinx0eppPwU aytVK+cn5H4FmHgtusfm9huMGg3sR1kroyxhN4R4fmxNKA7092DTzhdXy3jZBKM2s8oB UexXBWnnH+vm5LvkzjzrX1+C6tL1F70X3J+fuWTK+Kr7lyj2CkqGJxbjb5Ag2WSZTrCr FPWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eTZPglq7; 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 j66si10421599plb.370.2019.03.18.10.20.54; Mon, 18 Mar 2019 10:21:10 -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=eTZPglq7; 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 S1727829AbfCRRTk (ORCPT + 99 others); Mon, 18 Mar 2019 13:19:40 -0400 Received: from mail-vs1-f74.google.com ([209.85.217.74]:35379 "EHLO mail-vs1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727358AbfCRRR4 (ORCPT ); Mon, 18 Mar 2019 13:17:56 -0400 Received: by mail-vs1-f74.google.com with SMTP id e63so3944536vsc.2 for ; Mon, 18 Mar 2019 10:17:55 -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=UykDW4hFaDHfzyUH5xSGMBQs4gGYEgUL/nC+SEDYWFU=; b=eTZPglq7PxVqxdqVAjoMC4HmmCrWD8Td2oOWhHZFu/cW19YPVAKsaJLDurjgd2ljVf XFoitnM7dNKXaO1X3w5n48lJ0Y+z6lMVYoHTi6MyqIKBKDduB9n8l/eQ3eoQ6ApOGJcf g0Ut1Mty7B6R+MM5DXRurd3w783o+tqjI10hk93IissEzK7cyNctMDjvmU3Tdk6WDEwH ffIMuMSLEoDbieTKF2ybjM0vJlmx+cWPNY/uy7bo6luMmancF6Vim1Jp4tv/8hL6d3pb M2HFyE+DxIM6V89Ha75sQlU/Ar8a05rWTSWi6zpfjkxsTGWw3NraARaPUHt9My5Uw9OY 7lHA== 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=UykDW4hFaDHfzyUH5xSGMBQs4gGYEgUL/nC+SEDYWFU=; b=s9jSIDJpk4ME5RcicrAI+zK8npDzAHsrIeeMMQsBNZ3Gxs9UwVFSdbRZJQSBg3La2I dzp0BxAVoUQDSnKtE4wpHQnMQ5Zh6gAJK9mzwu6kcotU3AeRmENHO19KAxYNJqBQn7Nm AEjaHsCC9Qldb8KVcG5eb7kQR03yrRkIWcgA47Oiicbs34wuTukKSek2Ywx3vjFz5ns2 uyFJ6AI8E7dDZOyGU5LLh1RDmnx0i2NyvO0wUeo/MDQDKAUUq4gvQGpoegnhWqJF+n8G ChDgrIKWwSnsfVP/U8togjWdbf27xGmY4NPNOXKyIgnac8sjqP2rTdj7/ybPV+afW+2l euCg== X-Gm-Message-State: APjAAAX0+1i5TDWTncGKm7b/Of402ZTRAE2XUu3KF7QVBB4yX5YPPapi BmoP8WBEf551TXyQiNBm/D/zuKeJrebQfK94 X-Received: by 2002:a1f:1e4a:: with SMTP id e71mr11807432vke.2.1552929475245; Mon, 18 Mar 2019 10:17:55 -0700 (PDT) Date: Mon, 18 Mar 2019 18:17:34 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.21.0.225.g810b269d1ac-goog Subject: [PATCH v12 02/13] 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.225.g810b269d1ac-goog