From patchwork Tue Mar 27 16:57:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10311129 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 9D4C9600F6 for ; Tue, 27 Mar 2018 17:00:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84F3629D94 for ; Tue, 27 Mar 2018 17:00:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 791B029D8B; Tue, 27 Mar 2018 17:00:39 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID 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 12D6529D8B for ; Tue, 27 Mar 2018 17:00:38 +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=Nk7Q0e4m3zn9RjmMJ6iD1qvLFByRw8lR0Pb2VbPnEJs=; b=D2+1SwSMl6WXyasx2l0qH/+lfq 9rH9B65xX8xJt0E5D8yUMJdfKchqlFjgJxtv54B2h/BdqDOnokKEpqRb/Njzerh+ivLxIoUyUyPn+ 2WaTJ06YMLhKt/5xYM5PEUWIPZ44HQs5MVbeMX/pEuo1iY26zS6BPp/CicsqgO8Mlyt9RgtrKCPOd yHV65GxnSnPARRVCI2RK46GSamnuN+/lfEW1k0dIhc5IkuEuULo1dHTW+iL6Idz3zTYVipyEoo44T lCl0atHcET7WVUw32mWJB+usTSBgMLus+PGDMgK6pg7fnmLMXf/Ths+mQSMpKjW2Hb7p/U3OuARLK gFslPZmw==; 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 1f0rxW-0002l5-3O; Tue, 27 Mar 2018 17:00:30 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0rv9-0007zj-IA for linux-arm-kernel@lists.infradead.org; Tue, 27 Mar 2018 16:58:05 +0000 Received: by mail-wm0-x241.google.com with SMTP id t7so95295wmh.5 for ; Tue, 27 Mar 2018 09:57:53 -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 :in-reply-to:references; bh=PQDvPwpCCj++tEzmkEClg/xNExzGMoMf+mTY7ONA9sM=; b=ADn0rmiuJ9XMM6PYDzfTZVuW5CPYnKWZBN/2cGETCgpoqcygh9M5u3blB9njWr8Re+ Ut+uFZmTsK60HI1Jcl6sLhzGhaTNCal3v1v31Uw1yLenf4qO1bduAucD9HAo+XI1WVpp vvATKMr+BXh3qUgY2ja3gImPbJpWvsf9XdLPep6eVNyEOD4VehwyH0vASDitWzdKi8jI RYMrKQyKpgHfH0xnORC4RZwf7UU2E3EN5wwujgEijY0vzEHO3O4sXAXYaZy/eK730CKW uc7VAhsT1Lt5vkZkYhfWdXjnNDJaVfTSyR10wD1nqo+XpLmTmgfOy8db9Rjpe69AnI6K vSCw== 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:in-reply-to:references; bh=PQDvPwpCCj++tEzmkEClg/xNExzGMoMf+mTY7ONA9sM=; b=SvEJ3CODyzr5fZE94vHgPPRa42vNa6HzN/i/ZL6XUCi3oMKFtc9kw2vvkF41rawRYf dVSxmTImhb3A3uiyROMJWrFeEpeeENCZ3amS1BpTcYfF9qDZBRZIv3qwJejZ50Ko70Fa Yh1heT69BAv+kdIZfEdDdKnc8z9ce2EGO+9IarudiznSdErVb8ZLGCZdwQG28fWB2HLx S4NF7X/AVCkqUES7uWfrCJD2CX63wZlErfPw0+lzqkblIec5jkPQ4qzRcX1YxwBMsrtx +kqZV/qmBwXIhNJMEOcv5/X7VJbE2U0OvU1RA8lfdrMGvmYYfNlszO/Xroyq33MeZaHL wpMg== X-Gm-Message-State: AElRT7FPY3+YRpKGolSvkyGfEW71SnjQkwMq6ZaZ3MBi6DA/olBssxam sEaCSp9P+MtnMpul8YEWUkPhwA== X-Google-Smtp-Source: AIpwx4/r7QqaBNv+zh63HY6pUE+6nXfgV70QA44S2r+rRUeb7OeXVCpu+eEC5+uPaXYYZWHThL86gA== X-Received: by 10.28.5.145 with SMTP id 139mr35642wmf.31.1522169871428; Tue, 27 Mar 2018 09:57:51 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id 93sm1622992wrh.46.2018.03.27.09.57.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 09:57:50 -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 Subject: [RFC PATCH v2 3/6] arm64: untag user addresses in copy_from_user and others Date: Tue, 27 Mar 2018 18:57:39 +0200 Message-Id: <22d41e0e1439ed0d13b2a2ca4b7c8317131f7ea9.1522169685.git.andreyknvl@google.com> X-Mailer: git-send-email 2.17.0.rc0.231.g781580f067-goog In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180327_095803_610723_0286F3AF X-CRM114-Status: GOOD ( 15.83 ) 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: 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. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 2d6451cbaa86..24a221678fe3 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) \ @@ -238,12 +239,15 @@ static inline void uaccess_enable_not_uao(void) /* * Sanitise a uaccess pointer such that it becomes NULL if above the * current addr_limit. + * Also untag user pointers that have the top byte tag set. */ #define uaccess_mask_ptr(ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr) static inline void __user *__uaccess_mask_ptr(const void __user *ptr) { void __user *safe_ptr; + ptr = untagged_addr(ptr); + asm volatile( " bics xzr, %1, %2\n" " csel %0, %1, xzr, eq\n"