Received: by 10.223.185.116 with SMTP id b49csp7393040wrg; Thu, 1 Mar 2018 04:59:12 -0800 (PST) X-Google-Smtp-Source: AG47ELvbp0tiayN2pAFzhwKeFcXYHXB3BJ7UCV7Eqd/WKkbj9WcGDj3jlvjeY4Niivc8xNyvASAO X-Received: by 2002:a17:902:7c87:: with SMTP id y7-v6mr1921513pll.112.1519909152423; Thu, 01 Mar 2018 04:59:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909152; cv=none; d=google.com; s=arc-20160816; b=DDDtcuGPcakSGDPsrpcxrWZnWPeFeHPAQdnx7YJvUV+FE1IBJvdVUwhhPHy85VcYpA 3LNHjNAIlvlSmcg44aXsP4e2MlkXFRKfUHyJbT7syMlLQnoTueS2yfoVzBbH37AiXmZl wiJZcIkuVeLOIzt87QM1JIuIl2m6749OCl7yZVNl92Wtr/be6WliPSoPPXYWsYfNOJqy JuMeH/5KwTP8D08xfdB0YU753v1dgqV+EsGLtGADi3NviITrI8cVuJocIbH6aEUfywkW Xe9/eJo9E7ah6ILJpVWgzVyA9oSxgSORMCvN1o41xlTbQsoiFNGa+k4PvMGWEYznrG0B NKvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=i4j5LLlcJTrNi6a03osuM7FMBFfhyS0MAdksfWz86sU=; b=l55OG9Clip40FMSmaGspwWNvky6d+RB77UlF4HWJ75SK+uCD3LuUwXlrghzL6DvVfC rEXWU7JrY046xt5w3rmuDNCPGHpKqB1OlxLDvEY0GzfjoMe3/nF1u8F+A7rHGL1myO5K zQXRqE4V9xt1CFo+Vm4ppRxpXY8Rdt1+5JymqTht4Xw7goJrp7FTK5/WHb5YHH/ULwGO 18N25N4NymqzCtrSsFufBKhUbwG7/4uQrfFIgaO21FScmBSUKmMq1bu4Cx+uVqlOkJ7V 3UL1GuwSG7x+FdoyOFoMMnvxDLiF7l/CQALQ14hJ65ez7DlhmZKkeKVRv4VQqOOwbDfF o4gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0saQ4fw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 71-v6si3049770plf.575.2018.03.01.04.58.57; Thu, 01 Mar 2018 04:59:12 -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; dkim=pass header.i=@linaro.org header.s=google header.b=R0saQ4fw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030740AbeCAM4e (ORCPT + 99 others); Thu, 1 Mar 2018 07:56:34 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:34518 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030577AbeCAM4b (ORCPT ); Thu, 1 Mar 2018 07:56:31 -0500 Received: by mail-pl0-f68.google.com with SMTP id u13-v6so3593880plq.1 for ; Thu, 01 Mar 2018 04:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i4j5LLlcJTrNi6a03osuM7FMBFfhyS0MAdksfWz86sU=; b=R0saQ4fweThOggq/TobnvzHWJpLRton+5jJ0eFNYqO5Snpv2UioTyy6aGI6w4P0KOB ON5T9SkWwhlF0sSoZBtM07coOH5WOu7BJ3Wu1f+tjr6cxw9qZo+ztL/JTJLREOdqttzI 7BYcQCOeS00mxpxGtGWiH+X72LTRbi7E3+YJA= 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; bh=i4j5LLlcJTrNi6a03osuM7FMBFfhyS0MAdksfWz86sU=; b=UjpEExiOXBkvuy0VqH3amxe99glcl4TPWYdK5trYpfMswF/yfvjg0GB0sW0ANtWtcQ MO/aT+5dyE9h15fAY95hXAK3Yaqq8uIH5ZQNo2Y17QAydHA2zljJ2lKcbCnzmggh0vdL pZ2AYlWYAgTElaF2ANMhcoklj+GZgyEV1nNDxcUSrIfevrZZMgh2wsLzHr+Q4U8F2Kqc jgI85AeI1lSpq+Mlrz+B9WSDdYkkzLtzkpIuzgR4trWdl7LcV1OMsKacp2NRFwTw7cds evAJWa1LgoYjXxXN+r/PJmgImDWGLoxteWitbs2dQm1Pf7Hh/VXgJaLIwgzGKG8Bs9bK NMgA== X-Gm-Message-State: APf1xPBdge0XkQFF6ZkKooqGp2TGQzxiRI3dyM2sIcyYxK5aI/u/GPCl sLKVLcEohJ+kRbkdXoZhkwWF6Q== X-Received: by 2002:a17:902:b605:: with SMTP id b5-v6mr1873928pls.354.1519908991099; Thu, 01 Mar 2018 04:56:31 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.56.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:56:30 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Robin Murphy Subject: [PATCH 10/45] arm64: Use pointer masking to limit uaccess speculation Date: Thu, 1 Mar 2018 20:53:47 +0800 Message-Id: <1519908862-11425-11-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/arm64/include/asm/uaccess.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 7b1eb49..3531fec 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -170,6 +170,26 @@ static inline void uaccess_enable_not_uao(void) } /* + * 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. @@ -241,7 +261,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); \ }) @@ -307,7 +327,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; \ }) @@ -368,7 +388,7 @@ static inline unsigned long __must_check copy_in_user(void __user *to, const voi 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; } -- 2.7.4