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: 10428095 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 B273D602D6 for ; Fri, 25 May 2018 17:21:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 977E32972B for ; Fri, 25 May 2018 17:21:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BD4829730; Fri, 25 May 2018 17:21: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=-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 216172972B for ; Fri, 25 May 2018 17:21:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77CE96B000E; Fri, 25 May 2018 13:21:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7044B6B0010; Fri, 25 May 2018 13:21:26 -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 57E6F6B0266; Fri, 25 May 2018 13:21:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f199.google.com (mail-wr0-f199.google.com [209.85.128.199]) by kanga.kvack.org (Postfix) with ESMTP id E82126B000E for ; Fri, 25 May 2018 13:21:25 -0400 (EDT) Received: by mail-wr0-f199.google.com with SMTP id j8-v6so4259441wrh.18 for ; Fri, 25 May 2018 10:21:25 -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; bh=soSxvk8tz+HMI+9osTf5bW8A1wo3JVkLgkcX5odLmWA=; b=ssLi6SRdB7THMFC7/xBVTjOZJgQxo4qFxtF+oP3T6BWsl01SVCaVXWETIbDXsMniO5 C9D1Q0MSpI4AcHZE7BhFxDSIlLfQ1+1/Qq/6Jy7RQ1Gz0yECsSauK0hv8ppNTUXxgsat 35bQWZG2PBiFkNb5ZOiTgEkLGFRvQTF3t31tHnkwpG8uKluMgBbZ+cytig3n7y6ogt/f bWuQ1vcioettH5jchH5eC8H85wDd4ry4QYzjIi76v5wouOjAOG4xFyD/Y6oDRmV17yDP PwUcdso2PZX1l7ECh7SPqGG9jArspCTyscHrW637oMS6XFWcTCXJEydmJ+QVarbc8All xOrQ== X-Gm-Message-State: ALKqPwffXPHA72CXfDLChEi4Ko+pK7v9rAJf7Qlhyq7b5C5OXeUtoaLM NS6JCyBuKx8Cfe3h7/Ie7jINS4COyCdCJqSry5oOWZ2IEQ3FqL45wE3fhYNCWCUKh1LbcrIaUcx tBMwTR0+3VTFqeC9gQKv0iTJFVX7dfPUn3dWXZjfO3Ft8ZvPFXZSHeEwCsAJLnWA1C92+DjSeUK OJiiwtvl9PlFMrQkRdHQvSNQDpHQGy6NVHi7rtjc8D0O75yEpdvFgmylNZ7jdu5/bQnXHbQ2MPo Gfb86WNEhwgLLX1K+ebC1PCqPiR7CUbnFLGTxQ8z2l60z6hntR/tk+2q0SjNGUgZw0Ix5I5d4s2 j5GrPiz3lciyCiLoyLceoqEk9DZFfgh1Mk6Ltn/g/VX2U6Y36bEDIK0nvF75QXmj9sMTzVEZt7Y p X-Received: by 2002:a1c:3b87:: with SMTP id i129-v6mr2675525wma.51.1527268885521; Fri, 25 May 2018 10:21:25 -0700 (PDT) X-Received: by 2002:a1c:3b87:: with SMTP id i129-v6mr2675476wma.51.1527268884361; Fri, 25 May 2018 10:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527268884; cv=none; d=google.com; s=arc-20160816; b=VP8LmL1xclKoPuSA0admDZSN+m7lGVy/P1kV0ZCNIYint+V7vl0KdKmpQfaRul+yXE G2bT+xzuuTQlGKG3PFfsAliKMF3VHB9SmlxBZSKmNtvP1qGIIdk7HE09kvLFnKoqKaWw 2MeEni6LiCprBAkAgQYW3eweEDNG7LoCHFTDsFfSGIYcG4/Vxg9nZvHd66HIuh9gEFiY y2k6NLe9rGqNV/VngdciZWMnqrm+fE1Q4ETv4Ibap/srKI1qAtGCkLNlv7NdEei+W8oq 9RAVSL7iJeyK+lobAEyB/RC4EyPQfuAQ3nmMbJESnXnm9RsQLZ0cgZEDghe1rVmM7pql UJIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=soSxvk8tz+HMI+9osTf5bW8A1wo3JVkLgkcX5odLmWA=; b=TbU1pF7pJkq9sg7PAW+tUBLIn/sJ75xclUJTkWxQc7Gza4e8c8VIUW2Bl2e2zdO7bt UUFa7YNqGR4ldBfOaTaBi7vpjuc2i66bbfTDWSSZhGFHx4+za2ds8RrOyyPifqZ2Wxgn e1YRjpOZx4o3aQOCcB19fVJMdJENRdScIvJV5nJwfeGdZ0QHK4VruVeOcjOD4ztS07zn w4KdPf06N4ggd+PifP6+7rAQSxe5loIqlbORvf9DGOhVWl7N5jwObQd2opUjU1wLe2Mv 2oRvde4lr1ifI4JvEcz6s5dxJthDM7blkN44jK/+m3ULkuOzJketBdn98Ix0PzoV7rmH a53Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ddm4tSYv; 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 d7-v6sor4941170wrq.34.2018.05.25.10.21.24 for (Google Transport Security); Fri, 25 May 2018 10:21:24 -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=ddm4tSYv; 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; 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-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 Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya 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-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();