From patchwork Thu May 3 14:15:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10378443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 136CD60353 for ; Thu, 3 May 2018 14:16:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F389429032 for ; Thu, 3 May 2018 14:16:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E76F72904B; Thu, 3 May 2018 14:16:01 +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 6002B29171 for ; Thu, 3 May 2018 14:16:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 111216B0010; Thu, 3 May 2018 10:15:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0985A6B0011; Thu, 3 May 2018 10:15:56 -0400 (EDT) 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 E7DE96B0012; Thu, 3 May 2018 10:15:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f70.google.com (mail-wm0-f70.google.com [74.125.82.70]) by kanga.kvack.org (Postfix) with ESMTP id 8B8DF6B0010 for ; Thu, 3 May 2018 10:15:55 -0400 (EDT) Received: by mail-wm0-f70.google.com with SMTP id d82so5606159wmd.4 for ; Thu, 03 May 2018 07:15:55 -0700 (PDT) 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:in-reply-to:references; bh=ctyxioGiNTZ7rpdFbKdyZtiNPRmeyeSFA/d5IrA7HX8=; b=ZFzTIqh+eRG+JgbWmgBz0zCuik9QESW9xMXnqfabEsLw7TjzJDgPDD9+uJMSRjDY8+ 7VQVe9ocoyI3FJcCQ2jziTLVjGqQFgvYIu8x+pJz1R1IeM6ZsAUtd99uM4ZJKg7s136b G9D/NvUUlFT8kVpTYkOXd6aS7ANFdlWoWvMyKx+IoOFORrewhphkXQTf4fb00E+HXkvG EyZFB9IUytumFaJUsQleA0XX1z7XCX09i639gh7D1tH1D1aG7jec7luFQshSth4C0jTJ RWPUCWyZH+VFT8UucigVspEyIQXx5ymdL56hxx+Wc01RtWH2n/L9UPq1XlUShCYGrix9 3k9Q== X-Gm-Message-State: ALQs6tBwiCnpOApXir8gkyUurQpO2EoY0S2GtVg55mwUQNx1pJEiYl7j gjIE8G5XJJPSDO+SbrX3KCgCS6PkKDr9XzT0zbiRofWsVZF31MnTN2bmXtDcTbCoxRbvUCENbtN 9mJv+js7JdPfQVwY8VDBRH7U6E9pFK+qE/IxmyAQRWG0ePNXK7ATVHaXBfUhPQ+TgvKWaeX3o5Y s9SDrvEN6ZkVGycYWRmLW9TwpHPtjKbtpZyG7HiXbRl+oHpozMs0Octm4zCd98uXf9vlnwoWlkU 6nesOTSqteNIGGMlhPTdj0mzz6Z8AYxm/ii5rSM4I5sr4oigX3PMzbHePbkpKfx/1b/iVG3VRJ0 QGVxc+pS9kT1q75rdOdqWrCIFyZ4AwU+98H1KFakildhBSlTWh2rMSf67ybX3N5x0hfTQIMQgkU S X-Received: by 2002:adf:db4f:: with SMTP id f15-v6mr17815399wrj.212.1525356955082; Thu, 03 May 2018 07:15:55 -0700 (PDT) X-Received: by 2002:adf:db4f:: with SMTP id f15-v6mr17815363wrj.212.1525356954324; Thu, 03 May 2018 07:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525356954; cv=none; d=google.com; s=arc-20160816; b=FQFiFEzU4T8CWjQBnhZ8xFTwFiaDyR0zDB8bJdKpNJ3gWlKUiO5BKn1S1FpdXqDF9m lpEtI2aCUKxMpUgylnncj+x5vChjCozlQuJTurL0NVQGyG86YNZYU9JniknP1EysucDk VHontiR1UBCXVdMb90ErTCqhg4SVeGW6Tx4I03M6hBdc9ulPRVpx0ZyU/Xq91/IVw8ag GN+GlNSouSPKxqKaofWC9MFpcrKbfNiAJ5ZpJC+Fzv0OvdaiJCXgU68Z1HMfy9P4jR9i 5kz2osyfmDCIIeCIYXMG07ipz2eVwAeIkeLKTJy2TII5QO895TrmgQWeKey30Ua/2LWc Y81g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ctyxioGiNTZ7rpdFbKdyZtiNPRmeyeSFA/d5IrA7HX8=; b=MYxZjc5+UQ+QXwUMvmq4mwDqu2E6BQ6oHEEbIdNulgpDI/KUNiEAsEjG0eAVVxrcoK Nv0xUetccDDva4K3zKJcuQDmg5n54z6I84w5fRqDMMtCwbdadHCZkVGzmwxlpF5rxuWw 7zxX2H9Fxq1TjJj815i2iopZYcITCRBtzk9FOrijZsUqBf2OfUH4pyrrU5kCWLKZkVDy 8ub6pYrLIkOvUeGNmRyBiPgBF7PlMKmS6+rIOWTXA9Wfo2VYAnB0UzWrvSBN9t46WZDL 20XdqY+rRHiOgns7n4V0DX2QoPQMlck0Y5lK1DYz4O4VL3Mvva/BuWOpX/rQfss2Pb3X bwAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hryGsx/y; 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 b9-v6sor1909906wrh.88.2018.05.03.07.15.54 for (Google Transport Security); Thu, 03 May 2018 07:15:54 -0700 (PDT) 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=hryGsx/y; 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 :in-reply-to:references; bh=ctyxioGiNTZ7rpdFbKdyZtiNPRmeyeSFA/d5IrA7HX8=; b=hryGsx/yxTmgjv4bZv8g8mXRkFPYEd6EltiF5RFvZ96FGFw+N+FiaCYSgucX74CTrN Q+UenCZ/98WaZggEUBXp8aEUycrM2o8FNOFNm0oNq8YgJz6N8q8NcEyhnEOw5yT1uxhs yCJLdo7Lm0Z70ZqM4uRbI0jAR2EGbJGI/iJszvGU8bVp+c8BpSqNrSv2yums7mzpPAMv uaPZp9+wUtBsxhuB5+RUDZxzNdnVm50xv3vsddL6fYrqN00cFI7IYe6CtP7d+lFB6S68 LFbUGv2Umtjp0+ObFIzYawnGxdiD2wu97vu5kI3cIquxhPtIY5kS7TAp5mqROWSdXSsP 48Tw== X-Google-Smtp-Source: AB8JxZpawo+iTN3j3wND3dZiwHsLK73Ji/eDYkcylrk4gUPBNiMOM8Uttu/rSNJkfJl7Xbmq767iZw== X-Received: by 2002:adf:9444:: with SMTP id 62-v6mr17792664wrq.264.1525356953516; Thu, 03 May 2018 07:15:53 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id u20-v6sm22090298wru.33.2018.05.03.07.15.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 07:15:52 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Jonathan Corbet , Mark Rutland , Robin Murphy , Al Viro , Andrey Konovalov , James Morse , Kees Cook , Bart Van Assche , Kate Stewart , Greg Kroah-Hartman , Thomas Gleixner , Philippe Ombredanne , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , "Aneesh Kumar K . V" , Zi Yan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya Subject: [PATCH v2 3/6] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Thu, 3 May 2018 16:15:41 +0200 Message-Id: <20bddb7a15984ba05eb1d248162a845af246449b.1525356769.git.andreyknvl@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: References: In-Reply-To: References: 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. 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();