From patchwork Thu May 3 14:15:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10378463 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 210E2603B4 for ; Thu, 3 May 2018 14:17:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A84929032 for ; Thu, 3 May 2018 14:17:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F31DE29171; Thu, 3 May 2018 14:17:45 +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 7EB3529032 for ; Thu, 3 May 2018 14:17:45 +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=aeEBw0MdhhlexL+g6/MuzZkEUqUdG/1jRj8SYi3GfLw=; b=CBaLrsJsL+PcYVXnqRXWc2hV/U 8BdzCPoduk+w4gPqljuVdfqdtfQrgveCt20N2xITbJOcP4U9G07+zR55kDyfi8gAwI8X/gQCNaKCJ r2quTaI5pj7IyHH5U851IwZcW9UBCZCet8He3Fy2iMOQVnU+2qqHBgHdUj+Ly3piAvNl+7KzuhY9p Bh7jtUh2vwZJgjPCAJbb4PRns2HeKfuvLGsMRbC4rDYI4iYtuommIeYqRNpU9fRv8oTCuqoQlqWLT +hXmTukmleWJjfBHRlKH5KeNcQjiSd8TYmhYUWmiXYDOi9breeIinT1dvHFaBx1dPQEPO/4S/wXUW nWjm9tdQ==; 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 1fEF36-0004FE-Tn; Thu, 03 May 2018 14:17:32 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEF1h-0003Ut-Qf for linux-arm-kernel@lists.infradead.org; Thu, 03 May 2018 14:16:07 +0000 Received: by mail-wr0-x244.google.com with SMTP id i14-v6so14628042wre.2 for ; Thu, 03 May 2018 07:15:55 -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=ctyxioGiNTZ7rpdFbKdyZtiNPRmeyeSFA/d5IrA7HX8=; b=hryGsx/yxTmgjv4bZv8g8mXRkFPYEd6EltiF5RFvZ96FGFw+N+FiaCYSgucX74CTrN Q+UenCZ/98WaZggEUBXp8aEUycrM2o8FNOFNm0oNq8YgJz6N8q8NcEyhnEOw5yT1uxhs yCJLdo7Lm0Z70ZqM4uRbI0jAR2EGbJGI/iJszvGU8bVp+c8BpSqNrSv2yums7mzpPAMv uaPZp9+wUtBsxhuB5+RUDZxzNdnVm50xv3vsddL6fYrqN00cFI7IYe6CtP7d+lFB6S68 LFbUGv2Umtjp0+ObFIzYawnGxdiD2wu97vu5kI3cIquxhPtIY5kS7TAp5mqROWSdXSsP 48Tw== 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=ctyxioGiNTZ7rpdFbKdyZtiNPRmeyeSFA/d5IrA7HX8=; b=mkShUclH3NFJL3rBM2bF9ROLofd2QNWFX+DViZ9FVcs6V0z1fJbR6wgWMS332MrzAP gbuV0M5E7CXEzPDkcfOXvE3KFR600QdGJzjvQUOwCqLQ9t7kuSvUXvMWbvBQfkqQfKiE jViIhv84N+gLeBwJWGrBkl/2nyf/xUqoQECygc2Q8gA1Hxm73ogKPcRgRp6DFS3zVkWw PH3H8cs3fMqrCbmV6u7gYo54WGjpvXy+QTgQUHI/95gOZpQT2b28bxUEiRcO/u6dNJwJ MwAFY2+AmEWob0wcz6x6qOpZWGj+wwSYnjM/acvX24SSmebIXTdMEp1f1noSZd63x3/v gSBw== X-Gm-Message-State: ALQs6tBUyW6Yo5KayAxoHC+i8Wk7G4xRoO6UErYQ1GOlo6DfnFIPGUgH KJS+CJGdNZaLZElNHF1iZeRwXQ== X-Google-Smtp-Source: AB8JxZpawo+iTN3j3wND3dZiwHsLK73Ji/eDYkcylrk4gUPBNiMOM8Uttu/rSNJkfJl7Xbmq767iZw== X-Received: by 2002:adf:9444:: with SMTP id 62-v6mr17792664wrq.264.1525356953516; Thu, 03 May 2018 07:15:53 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id u20-v6sm22090298wru.33.2018.05.03.07.15.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 07:15:52 -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 v2 3/6] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Thu, 3 May 2018 16:15:41 +0200 Message-Id: <20bddb7a15984ba05eb1d248162a845af246449b.1525356769.git.andreyknvl@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-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-20180503_071605_932110_14D42E05 X-CRM114-Status: GOOD ( 15.42 ) 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();