From patchwork Mon Dec 10 12:51:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10721219 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1961F17FE for ; Mon, 10 Dec 2018 12:51:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 069BF2A1E5 for ; Mon, 10 Dec 2018 12:51:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE6C92A285; Mon, 10 Dec 2018 12:51:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80B452A2AE for ; Mon, 10 Dec 2018 12:51:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E08E8E000C; Mon, 10 Dec 2018 07:51:16 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 76CB88E0001; Mon, 10 Dec 2018 07:51:16 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5491A8E000C; Mon, 10 Dec 2018 07:51:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id EE93A8E0001 for ; Mon, 10 Dec 2018 07:51:15 -0500 (EST) Received: by mail-wr1-f71.google.com with SMTP id q7so3393984wrw.8 for ; Mon, 10 Dec 2018 04:51:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=spp1yx5uWvAgxErNR01vKeP4ipxAKNr5cbWijdqL/NI=; b=PLhf2GDEmrPYIIy1KtdaQhefagV3H1nfj2XgklNXOHHamZaZPu29ztAQ+hprV3mFSG vkPm8XIPFTuHK8nWwy66gq/QqPEmx6aeuBmvvgd6zBrVlvZA+5GD/xxe0N2OZgGgUOVJ EGk2Mwt8quk20g90h4DfqJekrmpO68506vi5SKDv8zoA/XaHdLyomEZNBwLspboBo8i4 b7+LyO4918bqqOdYP8CYGli4xSWCyg3txDPNnmgq8zjHR8tRpcMErtmgviRceqnnovHw Q2yP6/zADox4hH8KBrfU2Szr0gCfVOHO7QqNC9jU+ndy6el+T+wsMpnCYWq7J/sXKQqj arqA== X-Gm-Message-State: AA+aEWYDQ/8lxCNR74DSbNnqo4oCBRFyBYPl+yH6BQhoVwjGJEIt0uDY Kk0tivGK+D6Que+YrV1wA4o2Jd2MHDVezBa0VwlJ8xtwEwRh6OpS4A7m/MjsRN/VHmn/cq+DYmj 13YkpLukymdUtJ5iFBvOPFuGRJ8hEV+t1AsFlMWyemKAf+VaoU3ZF7IAe+mbjsk2bk5KzZAGELa yyd3BlIEQpcYqVS+TjKmvJ+5RNE1gIi92lvN+mCRj13KdTiDuyqXzIOxfUMLoEMMqQNNCSOFz2U Hx6ubrC0e6qZDNGwyk1bXi8Aygp6c4M/ZOSPds78nVtMSKcqj3iDXBpdVAkjLsR8JEOyLVT/lP3 DeBA+LiZHBD+Cl7M0B3sqWjT1F+5MlQjniW7SiRDf982r6TYZ1Cuuvv8RrprJbAS150hLznCdt9 T X-Received: by 2002:adf:c711:: with SMTP id k17mr9269106wrg.197.1544446275438; Mon, 10 Dec 2018 04:51:15 -0800 (PST) X-Received: by 2002:adf:c711:: with SMTP id k17mr9269057wrg.197.1544446274566; Mon, 10 Dec 2018 04:51:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544446274; cv=none; d=google.com; s=arc-20160816; b=pbzy+89ZxLUx8J78ciC8jGTBBZvdHKhsuwV+9OqtRmb4iyU2S3GI5okNoIVukq04Ct RcpJpT6ZjBLN6tDYgtLQrnddno1As0icklzxVAzZweNWDil74XMLhg5oOBacJVaeB16i J4UMuxJqOWJztIfOzpui1nb98Z7BvYE1qdp3cGHQBIozOafH1WrmoYqiYZ0FyxsUIGrA X2w/yZb0SJxDRsUb+Zhv/coqvZF3dA0SIXuAC/VuRjg2SNJH0HttR8k649rn1wW4FMPW cIYvni9MujLban5+HanDgeNZ4xMre+y7FYlU4epDDv5i3hHh77Fp7Wdmhny7uYZVaYGr Smig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=spp1yx5uWvAgxErNR01vKeP4ipxAKNr5cbWijdqL/NI=; b=IaXYkM0xDLDR/M/2foGnW1qgGRlotKLG7ivgHp9N4/uXtHHdTiP+6C9ViXadCr70ww YCB8AGNhlt/TxP7ijEXuQtdnl7NgRAIf9BmwGxhe+5q6y4yQBWb7l3QGuKrMc+uMU86G MiyiytzTq7QAisdpU4crafbRnw9RrWY++pytVEVnzG1yivZhlKmUiplqGhRgyi9vYB/L IqdjxQYbRJWd5pTQjMU7gPnVXMZq9ctR16YYGSY/Ch9Uy3pLo5E8z2D/V1utX5SdZrkC iphf4xa3ldpZUoPrcttI7DeQOP2aB5pTN3h8iG5gRhDjW/r3taUYFuy7ouSMFKWLr4kL xODw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tvsXwVCK; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b17sor7133162wrt.48.2018.12.10.04.51.14 for (Google Transport Security); Mon, 10 Dec 2018 04:51:14 -0800 (PST) Received-SPF: pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tvsXwVCK; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 :mime-version:content-transfer-encoding; bh=spp1yx5uWvAgxErNR01vKeP4ipxAKNr5cbWijdqL/NI=; b=tvsXwVCKLmRdJsM+euD1t0rVUHOOn+/ZTTi3MnnQ9yebryAkbI4hvbPXubAR8j9xbT rSzx3Kyplc8mI1Q5cCWawts1mVwnbRT/UG0tp4Xvt5MDVVu5AjP34+MyjU+t6RTFt/1F GtjCSp16Bsb0olrw8ju4ga21oFPvQHFAjGiXj06kBSulY2fBvH1/8yimSxJdEzM0IjDe S2UHXqy/PlTnElD5PvCE/Ei8NOK6WhW4AzfjK1G4NAKHmzILpvArpdT0x23Ci7QVw1Jf siaqLTUGCqHPMIili1iJlbBGd6qfhARL0xDVAgzKR2wFfvkvY0Mi96XrFZLLMJ9KfrPg c6gA== X-Google-Smtp-Source: AFSGD/WK6voMtzDjeOrD0p0dIVtqA5GSBJDXWoYR6ofaTs6wbsSMRcTZb/d4/4QZpcv/PkUOjr5HNQ== X-Received: by 2002:a5d:684b:: with SMTP id o11mr9182121wrw.316.1544446274117; Mon, 10 Dec 2018 04:51:14 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id l197sm36893363wma.44.2018.12.10.04.51.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Dec 2018 04:51:13 -0800 (PST) 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 , 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 , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v9 3/8] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Mon, 10 Dec 2018 13:51:00 +0100 Message-Id: <674252952827b57f4259876cd4ddf802f3539356.1544445454.git.andreyknvl@google.com> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog In-Reply-To: References: MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP 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. Reviewed-by: Catalin Marinas 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 3c3864ba3cc1..d28c3b1314ce 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -104,7 +104,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) \ @@ -236,7 +237,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) @@ -244,10 +246,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();