From patchwork Fri May 25 17:21:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10428171 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 475BD601D5 for ; Fri, 25 May 2018 18:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4378729751 for ; Fri, 25 May 2018 18:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 360FB2976D; Fri, 25 May 2018 18:06:30 +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=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E326E29751 for ; Fri, 25 May 2018 18:06:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=JoCDD6/dAyHm9T8IU+FHFIMmuXESSQ+kj6m2Rs5uOQg=; b=LXGmWHpGi2IsUQhJjRpRaFJmfa rb8lAV9bh5djBcOREQ8452cVWsem65gSIK8pkVklLXcqWGnZhaXh2BTJenLC05pZsnQ5vBK3SDrlq vFKbz6FCoxkz4+sLHpWpZ5qu2ztYF+nizyoFf2+rV2VNoeYHC0K8FEy3eSC2Sp6mwIfRVZR/gR+Ir bavBWbjBrTf/kO9spolBxlTNC3lRXfF89x0NRDyy+bj24LnGRpFFz3X9VK1VMumJKetslQ7hG73Vw jtwt/AvlbUbA15foVPhV5GMhZeh3HbyYECl6WskiGHlIrqFf9ju4kehFVrU8T+fLkOzexCzaGtD7Q KRvw9e+A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fMH6X-0001L8-6R; Fri, 25 May 2018 18:06:17 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fMH5k-0000WP-8W for linux-arm-kernel@bombadil.infradead.org; Fri, 25 May 2018 18:05:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=soSxvk8tz+HMI+9osTf5bW8A1wo3JVkLgkcX5odLmWA=; b=ETUgfIBlHL0LpsygHN7gz7gP+ hpKGYQKYhOHvjucp8RVA67jJY+uQtFez2L7T//HUccyaLAMeY9TLWvP5fBCj9pKxFQD804eIA8D4v 3tohgL3IHKRWFm5GoXKkpkLbFYqVsuYWYfwNq2v0U51mQ25TGk1T9uhm/N8VqvYsbh8qD7cIZt5EE 6aQ2Z/3SnCj6Jli/ua7HyoqwzkZ8Iq15Kv+2PWQhGKYqweWpL57DwgRIeERluVobtsx4NaxhZRPtp Xi7Osg6ZnRLNEOOtRiX3SqTaRKpB7lUIWk9Hb5QqyzP7oHUyc6KmNYXcmM71awEytx9kVpTaKYQCu NIKWy/VLQ==; Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fMGPI-0006Kp-0J for linux-arm-kernel@lists.infradead.org; Fri, 25 May 2018 17:21:36 +0000 Received: by mail-wr0-x243.google.com with SMTP id u12-v6so10424141wrn.8 for ; Fri, 25 May 2018 10:21:25 -0700 (PDT) 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; bh=soSxvk8tz+HMI+9osTf5bW8A1wo3JVkLgkcX5odLmWA=; b=ddm4tSYv32Ehswqlrf+yGJhke6pId3pIxYmA0VIMwyasJAFP2AQY/YNzyqdYkvsYlU PT9v4uxtoqA/UaKe+ZjrzC06vVDSF39evOrhMiH+aF8bD5oBtf5Nqyb/NF+el2tArnPu i9GvOLHq16wIeyN3Ojb2QR0IjTKaVDT6/PYHx4qBwUNy/VZj0l7srbJsogAMp2VCtszg 4XgDY/iwgnqbeHRWO985XlIz03sxzhjQKW+g7W+Ds9CSh6mtkrBfGv+hoI/Qilw/chE9 3MrQWVJASZJKIQXdS1/RUAcOYnxevnfE+6lmBP8GzaX7hucx++QvJ5uXaPKGFGrO2MH/ XoVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=soSxvk8tz+HMI+9osTf5bW8A1wo3JVkLgkcX5odLmWA=; b=Pze9vldFfJNoXoKfNDgHSL7vpVLdBGDTGveKaPU5+4Nvwf7M8EV4JShbbsknl2LTRY j1ka5+K8DHhTJC1+fMQH/Rdl0dYpYCGIaFM0N2mvh+sHMVPVRYxVMpe3MGgOv7nkVWdi StCH/YTdvs4+J6a+EmNLI/8zw3A3PFPr/tGNOSkdDPioHr5HuPa6bWiTwopMWuN0hcJC OSxz+vg0fQTUKiuz/jm1WHmvqxbLgSdFH7wVDifNJW9tlES4ZtgBy6w1IPbFEgi26V+L pfM5xwDVzMQZsPGS89Z9t/cVWHgMJVhqXp5zaNFS/BcSYwPJx9bESxmmHFzpvFHNj6gO Lxew== X-Gm-Message-State: ALKqPwdnItb/lrOUn7SfTHoZ4zvlMLhgOm3BNamcNJ4lHNaT32k7lP+A sOPlWcxdb3JeQM2LxsRDga3wDg== X-Google-Smtp-Source: AB8JxZqTFpWuWoXOTf7secDy7ByY17hOe2t3oSNMGcuWVSp4mCg2G7wwL8D5VIpq/ET7c74OvQVxGA== X-Received: by 2002:adf:e542:: with SMTP id z2-v6mr3124714wrm.111.1527268883792; Fri, 25 May 2018 10:21:23 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id s5-v6sm26579964wra.48.2018.05.25.10.21.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 10:21:23 -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" , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/6] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Fri, 25 May 2018 19:21:13 +0200 Message-Id: <13e2b2fc8d95fda2441d3ed818451e5b5570bcde.1527268727.git.andreyknvl@google.com> X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180525_132136_093027_F2923507 X-CRM114-Status: GOOD ( 16.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chintan Pandya , Jacob Bramley , Ruben Ayrapetyan , Lee Smith , Kostya Serebryany , Dmitry Vyukov , Ramana Radhakrishnan , Evgeniy Stepanov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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();