From patchwork Thu Apr 12 11:11:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 133202 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1571318ljb; Thu, 12 Apr 2018 04:12:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/9h3WOrz+kS/XVtkRHbo1HShNa/+pjLdXaVVjsJKFBujUg/Sc6kLzLDZFY0iJuFjiZ7HLk X-Received: by 10.98.63.75 with SMTP id m72mr7216047pfa.167.1523531537562; Thu, 12 Apr 2018 04:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523531537; cv=none; d=google.com; s=arc-20160816; b=N3WkOHVLUOIuquG8OIffDrnI7eDuNAVpq71FVLY1sS136uzRZyzHtNTfm1fSkfzWUj hDtT6I9duRkKQxC4caoCERa4xANpYaAIn6ybhhKc0KNw4hqZhIjI4CCgKlIGKIxpLrbz V1LJg+F9XphP0jOLhkkon8tXAOZBEb4+bd/EUkMzdyoBsrXrcZBT4yeFBLBZfeOwUXNR 4ZIDrSZ4aahp0n2Fg/IR8SyDX5oHEiLg3+3Ic36abwAkBgbdjGY1+ATOrg3/mu+dbE4n p6qF0yUXgDI7xvhJJ2FgeoK60lOsp8gwrgMiESn0wTw9xcSzUfqcz+i8PJHl8paMS0sJ Xgog== 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:arc-authentication-results; bh=I7AZZwk+p8WpjXRhWhaTELtEqmEfk3ZCKklEQbtsiZY=; b=bJeyNQMPHmQB3u8Px1cL2uPtoqZ/9bnV6v21Xzo6h99nhXIfKIA7piFD43WujYXN7h 2Rf2tu9A7B43FngZH6jFgwuJ0WyB2x0M+9xF243Di/9KfJbCu55ctPp9+cG2PZ7cWKNo N2nAis3rv3XxTGVZ1lWiSEa8cPluK8bw34rhuazhUNSe9vqTS4dQ9KXSSC4y1XP8ehU8 KV8qK8ALXoltEIGTEQ0dH0TRN0K9WuwdnRv5u/a/7yHEbd4gS+Q0L2huQwAIuWf48W6b IVl5WCijWRcloO7UkCPmakAe0Xyq7Xa56FaFNdZOqJ6KzrAeyZg1RtxUNO9z7HObNey0 SERQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 bg3-v6si3001807plb.118.2018.04.12.04.12.17; Thu, 12 Apr 2018 04:12:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752484AbeDLLMQ (ORCPT + 11 others); Thu, 12 Apr 2018 07:12:16 -0400 Received: from foss.arm.com ([217.140.101.70]:59360 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752428AbeDLLMQ (ORCPT ); Thu, 12 Apr 2018 07:12:16 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2EEE21596; Thu, 12 Apr 2018 04:12:16 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 84D913F24A; Thu, 12 Apr 2018 04:12:14 -0700 (PDT) From: Mark Rutland To: stable@vger.kernel.org Cc: mark.brown@linaro.org, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, will.deacon@arm.com, catalin.marinas@arm.com, ghackmann@google.com, shankerd@codeaurora.org Subject: [PATCH v4.9.y 07/42] arm64: uaccess: Prevent speculative use of the current addr_limit Date: Thu, 12 Apr 2018 12:11:03 +0100 Message-Id: <20180412111138.40990-8-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180412111138.40990-1-mark.rutland@arm.com> References: <20180412111138.40990-1-mark.rutland@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Will Deacon commit c2f0ad4fc089cff81cef6a13d04b399980ecbfcc upstream. A mispredicted conditional call to set_fs could result in the wrong addr_limit being forwarded under speculation to a subsequent access_ok check, potentially forming part of a spectre-v1 attack using uaccess routines. This patch prevents this forwarding from taking place, but putting heavy barriers in set_fs after writing the addr_limit. Reviewed-by: Mark Rutland Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Mark Rutland [v4.9 backport] --- arch/arm64/include/asm/uaccess.h | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.11.0 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index a9db051b967f..900397e73fa6 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -68,6 +68,13 @@ static inline void set_fs(mm_segment_t fs) current_thread_info()->addr_limit = fs; /* + * Prevent a mispredicted conditional call to set_fs from forwarding + * the wrong address limit to access_ok under speculation. + */ + dsb(nsh); + isb(); + + /* * Enable/disable UAO so that copy_to_user() etc can access * kernel memory with the unprivileged instructions. */