Received: by 10.223.185.116 with SMTP id b49csp387353wrg; Fri, 16 Feb 2018 00:15:56 -0800 (PST) X-Google-Smtp-Source: AH8x227rFDA8bMlvDu+We3h1XPnF4KBy1BjbrGhm6iEfm8XkFdi2MpOAuyCIUDQANwoE/oG+q48N X-Received: by 2002:a17:902:8b88:: with SMTP id ay8-v6mr5181855plb.197.1518768956619; Fri, 16 Feb 2018 00:15:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518768956; cv=none; d=google.com; s=arc-20160816; b=YpMWoPoOTd/0BZ1lKPiDAzE8QFBNM3N2AbOs5tuen++1PrisBPHMNvNXkaJH7Y5BQn HlUsyak5keVr8oeUAqX+Iufdg3h87VlMmBKz22Z3ICa/JOvxIVBAFrgsOp9IeEkJZ1uq Mvdhx7RNWWvAt7uxWgt11+I9aq4ELuSouVDmRjsT1bM/dhZoQ87M/OTX73xwLYGY3DnN t5zYWJ4kJ47NxSnPdOZMPhO3uEO6X3C5QQdsA6D1l82iy+wvO09ED6+COzGTTHf9gwT7 KcQWictTPtMX6/vQbmzuOG04sOoSdDH9EHmr9vL6d+4+EgNwGf31CsJ3OeL43Ap7tO33 vSfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=LNbwE97mkqJNvrVEMZ4ZNxijO5XhqeuzPP1UFBzZmqM=; b=bbGUVVxH2oPLd3HNx+QlLILvXya69J9yEJpzkE234lLGR2SwYQpNp+O3gQ52yobQjK kE1WENS6zLblli2O0dGSlKR6zwxN3cQbdxAMVyQ4vWh+2nf3GXjUlpV1jaMmpPyKDTYM mb0BT25y1zvC4JbZdiKVUkvJ2JaSeizXJhqZU4x4tE5d4YlPq1Rs/kNlTe+6AMLkXfzt 0cc2RAT2YL5i2rcfPPCfalxLHV0TCkR3V983SGXn2uA24GNXsILfAmdG/iGYZ0mJ33Zr ys1tst67VPfQWSb0Y5lqocb/TAuZGYMKnpyJza7P4D+7v2q/0t5xjh/YhnV+xtXyIyDQ eaCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c5-v6si726985plm.9.2018.02.16.00.15.41; Fri, 16 Feb 2018 00:15:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425916AbeBOQ3a (ORCPT + 99 others); Thu, 15 Feb 2018 11:29:30 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:33346 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424181AbeBOPme (ORCPT ); Thu, 15 Feb 2018 10:42:34 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4487EF91; Thu, 15 Feb 2018 15:42:33 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Murphy , Will Deacon , Catalin Marinas Subject: [PATCH 4.15 052/202] [Variant 1/Spectre-v1] arm64: Use pointer masking to limit uaccess speculation Date: Thu, 15 Feb 2018 16:15:52 +0100 Message-Id: <20180215151715.956044292@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Robin Murphy Commit 4d8efc2d5ee4 upstream. Similarly to x86, mitigate speculation past an access_ok() check by masking the pointer against the address limit before use. Even if we don't expect speculative writes per se, it is plausible that a CPU may still speculate at least as far as fetching a cache line for writing, hence we also harden put_user() and clear_user() for peace of mind. Signed-off-by: Robin Murphy Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/uaccess.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -216,6 +216,26 @@ static inline void uaccess_enable_not_ua } /* + * Sanitise a uaccess pointer such that it becomes NULL if above the + * current addr_limit. + */ +#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; + + asm volatile( + " bics xzr, %1, %2\n" + " csel %0, %1, xzr, eq\n" + : "=&r" (safe_ptr) + : "r" (ptr), "r" (current_thread_info()->addr_limit) + : "cc"); + + csdb(); + return safe_ptr; +} + +/* * The "__xxx" versions of the user access functions do not verify the address * space - it must have been done previously with a separate "access_ok()" * call. @@ -285,7 +305,7 @@ do { \ __typeof__(*(ptr)) __user *__p = (ptr); \ might_fault(); \ access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \ - __get_user((x), __p) : \ + __p = uaccess_mask_ptr(__p), __get_user((x), __p) : \ ((x) = 0, -EFAULT); \ }) @@ -349,7 +369,7 @@ do { \ __typeof__(*(ptr)) __user *__p = (ptr); \ might_fault(); \ access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \ - __put_user((x), __p) : \ + __p = uaccess_mask_ptr(__p), __put_user((x), __p) : \ -EFAULT; \ }) @@ -365,7 +385,7 @@ extern unsigned long __must_check __clea static inline unsigned long __must_check clear_user(void __user *to, unsigned long n) { if (access_ok(VERIFY_WRITE, to, n)) - n = __clear_user(to, n); + n = __clear_user(__uaccess_mask_ptr(to), n); return n; }