From patchwork Wed Apr 18 18:53:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10348809 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 3A959601D7 for ; Wed, 18 Apr 2018 18:55:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A4D3287F2 for ; Wed, 18 Apr 2018 18:55:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D3D7287F4; Wed, 18 Apr 2018 18:55:48 +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 5C735287F2 for ; Wed, 18 Apr 2018 18:55:47 +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=TvdI6PVbrlKPDZ1JAwIC6qeUHCsmEHFVaYOG2mR46ZA=; b=NH+w/dxW6zvMqZGS0v0m7vIewT PnsbnvNr9NvVAB8NvfozZbzxTyW94X9UfCwED77n6LTIfy7lLSBSRvtMtZuzDI4iSjdi8vwwG2F+P H4O2Vz9n5rnZGUVOaSiYEzXGolFyTiqnjuXFtZlsL3upC0MOi1PjkyZWY2sp+nd/+0cDFBhPJU4IZ l0+Apw5NWB2X7nbz0eEgVGqiQaDZkmAskpQDXZ8fvXu50Re1dVpNWtaQs2nbPmE74eNlkNpYRbTDf dzuajHvTwz4wMQOBEfYA4Qbu5HxgGYB6gXoFdUsWXZhfh6FMagQwZFKKkFKH7dODA2SZLXfU9OuZu QS+7fCkw==; 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 1f8sEu-0004eS-2H; Wed, 18 Apr 2018 18:55:32 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f8sCw-0002ur-Vd for linux-arm-kernel@lists.infradead.org; Wed, 18 Apr 2018 18:53:37 +0000 Received: by mail-wr0-x243.google.com with SMTP id f14-v6so7537085wre.4 for ; Wed, 18 Apr 2018 11:53:24 -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=QMF8XDyX8uZ/Zov9SXCN5rgufNs9uhqTRQTKwFRg5lw=; b=qegfrnN0cCtdmFWqXkd90xJKq1gbjC8qNHtX3IHunpIIynqrx2W/uivKsgTea4Y1fM BhQG9auXFDq622f2XQh5bRE3A3Kforf0aEdykQ3VJSfyFSZgUEKC2IAHyqv0CV1uW5jw DwXvlQKDQF9NL6PrtUTUqvXBHlVJ/CnbtmKQL40MDJGQ9DqoXYNJjz5A267tmGPJL6op 17Fk1pBsQ37OWfdW0p25gHfwSMtOVmqNwvRzGV87SK/ooQNPEnVbj6MYJs6TkgFOnYA/ mmE3HxrqLnoBv5IetibPqvEBAH9jkhI1TzpH2CP8z4lr2ODSutrXLINC1RkLZmcjAnAd 50dw== 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=QMF8XDyX8uZ/Zov9SXCN5rgufNs9uhqTRQTKwFRg5lw=; b=JRDThGRi5HXJtc/8MxGOHq4ilRYGyEO/5mH89BnmjBhga4oL1R44KFZt6iwWfccVbH j3mGP8sNoA8PS+KHtpFvBwIRNlibrt6iqlsTsP19xA9pG26gb4ODfcCl1cpxLYHHnlPV n9+RvLZvWdkPsT4YL9tFzgVdXRbuj10YXE1QKztZkSCI3B8fS2t82nHDAjG8or1bBcYR /s4edfEnRO1g+VZaomJW2hx5jsHSvb337DM0hWMs0/aU7lwrUNsjuXcEdS8Bjs5VY+kR eoWmhugEetHn2wBvvPRNs1887m4FyvtxYKr/PJG5yvd9ihJEcGzb9UfdpxZeJvlyoFgZ WNpA== X-Gm-Message-State: ALQs6tD1KQ71wIhmRlve5N8JX93glveFPtUeNrG165DPwyoUSuSHfAqJ TRR2r7dV+iPM9wNZ0MaO/LxIBw== X-Google-Smtp-Source: AIpwx492GvuhPEjMG2W8I64jHz+nZayfp/4zSvo+ArBaT/Wb6JPZpMMwmnLtMw3uOBQMOx8/SrQWJQ== X-Received: by 2002:adf:a98f:: with SMTP id b15-v6mr2440629wrd.48.1524077603355; Wed, 18 Apr 2018 11:53: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 k79sm2616735wmg.39.2018.04.18.11.53.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Apr 2018 11:53:22 -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: [PATCH 3/6] arm64: untag user addresses in copy_from_user and others Date: Wed, 18 Apr 2018 20:53:12 +0200 Message-Id: <949c343a4b02b41b80f324c2b7cd56b75e6a04f3.1524077494.git.andreyknvl@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-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-20180418_115332_924358_6E4C2C68 X-CRM114-Status: GOOD ( 15.77 ) 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"