From patchwork Thu Aug 30 11:41:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10581519 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 098A6139B for ; Thu, 30 Aug 2018 11:41:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED0E12BA60 for ; Thu, 30 Aug 2018 11:41:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFF112BA68; Thu, 30 Aug 2018 11:41:33 +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 791362BA60 for ; Thu, 30 Aug 2018 11:41:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A812E6B5136; Thu, 30 Aug 2018 07:41:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A09286B5137; Thu, 30 Aug 2018 07:41:27 -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 7E5206B5138; Thu, 30 Aug 2018 07:41:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by kanga.kvack.org (Postfix) with ESMTP id 1CDAD6B5136 for ; Thu, 30 Aug 2018 07:41:27 -0400 (EDT) Received: by mail-wm0-f72.google.com with SMTP id s18-v6so1172120wmc.5 for ; Thu, 30 Aug 2018 04:41:27 -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:mime-version :content-transfer-encoding; bh=LhBQZOJZ5CY1iejYHh5r+OO80KOFbC9w+x7Kw+7XH2c=; b=EIQ5i5Ci6dHOTxATrXXZWVE5tV9ZcnL70B6WxiLEG8Cpcz6zWfbLEYAfriZMh14pqk jRbyndykHWItBCvxIfENBzW6x1yY4cP52jY75P5qs5kta+x8RIzMnhH0wMQwIYUHK3iO rm0YGr02MB0LfptjymJenuJGnAWRhlGzt7wz7s3+DleWauUI3Q334aTModNXBUiF57FQ O//D9isOqxQSTphDRRKC0LFue0vUg7Cqv3RYIxvtonawg8PCqMUrzqJhjRfNJW6q5tH8 /YxdX48ffjh27C4WgBFcXuW2yva+LmRaW+HZZsj3m2t32xfFt5LSSYAsZiofYmfMHS2i yELg== X-Gm-Message-State: APzg51D9sjeALmAJpOQEGC2+3TAuN3TaYs8ioJpLqJzq/VU6cibrR4Gw mPHQmxcQQkNp7wFxV5HSVTR/fv7GV8Er5EngClKIDdji2mOp1CwDnH8m5ThOztq1J/N+/MY0lxu b0j98Copols9CxPHIJh+Rzewbr5+PW93M6K+2LTUxExfhuPWgRv+2wB6s6QSfWVqNHib4q/J/l6 zOyx4Ujdaszka5qB4YC7QKu/b/7exjedtoTlkpthsHsnXMXO9rwJ9FiScPkoW8oH0MEmyVeeYA5 P2Q0XxPktNah1t3GtyJQfD8sNTF8IM7tk6AEnOPTwjosLJmlwi0SWxtq7iKvwMqLPU3apibudic uxLLTdOPb4xlCm25fuf50wl1IcMgByboMP+1nSbzWY/kdEPS4MFLHYmpMbDGUS2wS1RBRgCapyv a X-Received: by 2002:a1c:9215:: with SMTP id u21-v6mr1546937wmd.106.1535629286600; Thu, 30 Aug 2018 04:41:26 -0700 (PDT) X-Received: by 2002:a1c:9215:: with SMTP id u21-v6mr1546914wmd.106.1535629285912; Thu, 30 Aug 2018 04:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535629285; cv=none; d=google.com; s=arc-20160816; b=iJxXaqG/ZpXXCjKqdY1UQpCyC7ET8Dmzj+TM9UeP2HrI4XTjWyMIc3ne9pvRjkF29o +Z5kvTqdcrD3MjyBNtkE8qF68dnlcHPrDjVRVjPMQvTSTu/i6eiOmgdrLOzOPm+OWlf0 4OTrxkukhwlJ2fcQ+AhsJiYhF1fyb3FP07KpNtN+NDrsW9r9tbGWY4zk5ppGAQWhtajt kiQ0ZqSRONJmfJZk0aatsBwVqmb1h0+2B8zVMyr4+d2h9mBK8idQMVuhQzRoNKJTP3Cl A4QLDai83DB3ZLU/T4mdKnF9rjk5tcunyWJ2KXqg3C5XUI7KFBhLteKUYGqnUbwipUm2 NhMQ== 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 :arc-authentication-results; bh=LhBQZOJZ5CY1iejYHh5r+OO80KOFbC9w+x7Kw+7XH2c=; b=jUhm0n9vmfbF9K7MyjyP7LCZQ20GASx+FC9ygtlQZGEeQ35Fd82w3zF7VzMPQUNdDi BxOzGzh+ArY66EA6kHUqrv8n3JoM5SGJ8fdVit98CA3FQHBxKmsPUlgFGpB5b5gUGfz2 Jc6SXiBZzZ/lTyh7h+a7Q7cs9oVzmzpBLRkOCK6VJES7yUpeoiYB2frDiIk4m+EEyg6k 6fQ79QQWlAOvvy15kn05epNWy0Xzjq/9DIY5R7Z+1euZqXp/puXfBXHqq3gbw8r3Tg1J E3708+RAZk59Tlj7c7Fj+O3S6Kf5Y162wpwHOxXINg0XYxvSaCA/mOfXZxIcUu5piYky 2aoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qhLN0+Xl; 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 a3-v6sor63003wmh.13.2018.08.30.04.41.25 for (Google Transport Security); Thu, 30 Aug 2018 04:41:25 -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=qhLN0+Xl; 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=LhBQZOJZ5CY1iejYHh5r+OO80KOFbC9w+x7Kw+7XH2c=; b=qhLN0+XlBq6jHDTlSlKfMMmJjUqASaVSiAZ0zywVXpAg+VpUOeqdiJHj/wArfR65XG Ut3JLptVruN/PBv/xjcMUVNG81WIKCO+dMG9qK6HWxTAtR/EtQB8CpaH9QF+IGCW4BWn YSmQMOUq6FSuRhvb8AempV8E+YLZPSUlE4hF2263DyPfege/APAPyWSrGUaOUqwNEiw3 O4IibHRF1/nN9/UDdjKaDCSYnTyG5+kjDhFJC2srV9nASdDLL5E5WdrKISQHKKrQN0eP M8nLl+weFtfn/3yYYPWxYTFB3bviLyYR2P+BrZHk7c4uvaVyPrL5NiMZclTO4/7ZClBg Xtfg== X-Google-Smtp-Source: ANB0Vdb475utvdy0BbImRrjLj8t24oq22bP1K+3VkFe8W8AFPMSWX/v25NfkMksN2tme/fdtdkw3XA== X-Received: by 2002:a1c:7915:: with SMTP id l21-v6mr1693369wme.136.1535629285313; Thu, 30 Aug 2018 04:41:25 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id z184-v6sm2175218wmz.0.2018.08.30.04.41.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 04:41:24 -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 v6 03/11] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Thu, 30 Aug 2018 13:41:08 +0200 Message-Id: <7a37e7363328f4aa10706c0294242eaa5e4e9e89.1535629099.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-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. 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();