From patchwork Thu Aug 29 11:33:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 172584 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2091176ily; Thu, 29 Aug 2019 04:35:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqy023f9upk3wNxpC0qwqBEDeDNRcqAIrjbUwvm1XzUiwOjbqM+c1kXxz7BJrCX6lUnTvRLI X-Received: by 2002:aa7:93cc:: with SMTP id y12mr10814534pff.246.1567078512837; Thu, 29 Aug 2019 04:35:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567078512; cv=none; d=google.com; s=arc-20160816; b=qz/ZT4ziqqoNTH44IrvLzMiYXS2ytLSAzkBFcZscgV5ohFMG+J3VENaohH3I+02fV4 P4BcrHUEgNrZvk0z2FFWVuuiWJ6lY+coGVc46LMl2hLOmRUu8ttWfrQu+Xe3Aqf3haxv JfB/ltJNzyaDRF597xXmMucLJeN+1OUuxbtKJdK3Cr5d5PrsXbTTmTmQ9tbhxb0YLTa0 acW+JSYcUL7Vlxvln4mYP2hLCy9cqGyYmbC6MO0XMgEtLcmceTSUL5jficWnPIPxktor kSsnEtPYDU+XeFpOPaBdDkC/ZFTTThtDLU5lDNy9ztBU4oJjHgZ6CBk6AcoBCxKg9nG5 I8Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gNlfncScxDREAT7VjTEXAFzdaeKYbTqQ4JYCBMZ7gaA=; b=MtBwLWI/DafV5Hz5JONLOiaaUXyxJ6Sj2kaEfPBjmrmUJmQHfmXv0381l9hnwLRSDg z4vsdZN2J4VMWVOb2gzn+hSFvTjLPo5qiPb3KwTdhFefHqo2RNU0Dft77htW2QgXnUa9 fTyIsABM8KL8wrCadts14G3a1cpuAIWlL9Eme4IwabEeyq8YopV43P0Dg2kZfW2aJO2x /6AlePFJ+Wkw16191bZ6xW7bg1y7J42Ku5Io1EUUUYC6WDsMepEAtEmP87PwcreSOhMd GPP04FrDSuQomfUiA8i4xyMRriVqGmuvdxVkgeEAMTNP02xbLl0NHxnoxwJ/QcPRzY7G /maw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nr9Gk8pF; 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; 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 h13si1698624plr.12.2019.08.29.04.35.12; Thu, 29 Aug 2019 04:35:12 -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; dkim=pass header.i=@linaro.org header.s=google header.b=nr9Gk8pF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727131AbfH2LfM (ORCPT + 14 others); Thu, 29 Aug 2019 07:35:12 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38983 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727072AbfH2LfL (ORCPT ); Thu, 29 Aug 2019 07:35:11 -0400 Received: by mail-pg1-f193.google.com with SMTP id u17so1447141pgi.6 for ; Thu, 29 Aug 2019 04:35:11 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=gNlfncScxDREAT7VjTEXAFzdaeKYbTqQ4JYCBMZ7gaA=; b=nr9Gk8pFzTEB0x/gTQjg70ogkUAAe3PHOryfDr3XdOw9hGozLABdCRERUdlFdyM7+w XHQw4yTqjOc8IyDdh+/0FqzVT4e1ygwvvGGySH8M6jc170I3CFooffLknoEUesluak5N cxL5uYIwuadRSsXimRlPBaq/8VvZLJsE1kbwhTrwzDOZqRlUVflQjLZfJfNNwvA1UvUV /0dbHEI2+EGV0WVYNpHt3fXS1ewsXIvWvbUYjW0AFggyhIJSNlYHsFFRF4jIhgR4nxda yIWg7uib71hLdizQQgudJGAhAGNeIYZX+h063Xjs2s6Jkw5Kxyc575C0eeCvUpZxCEt1 B5jg== 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:mime-version:content-transfer-encoding; bh=gNlfncScxDREAT7VjTEXAFzdaeKYbTqQ4JYCBMZ7gaA=; b=dgHmuL2lX84wQdTAO4AztqqoC5c+/PgRYoxF4MBXgKN0SqqFXoVz8eO6uv9Jr/KRnl Cu2YUgbmMO8ESdAtvDv6VYJCNJ2Dtii1cub+Y89F40g5YDtvUNwM2i2oCH9u3YIsUUYv 4UkIkhQ1ZJ2xWZkaO6Hq87uY4yqGHNRtQY9mIpmG6SkuO2kFrHgv8apH/WnQQ3nHLDl5 ZxbNE023IFmAOXUIBX21kt/Z14g1oJuOleM+6KqUsy/O2QKZSpGyoGQ1e+cgqtlaRfwU 8w5CUbcGLEaaWA9Q8bUZGacXOg9scQ2M0OwCHjiHJlFUddT3BJaZJozab+VDqkboC7fP waOA== X-Gm-Message-State: APjAAAWREuNUYcu+X1QvIegzcec/l9zStCl3z9vMTVNWno+a9AN+9Drk CuAkkc9vay9AzQUV1Ac9gpHemAFfkbc= X-Received: by 2002:a63:c03:: with SMTP id b3mr8067964pgl.23.1567078510622; Thu, 29 Aug 2019 04:35:10 -0700 (PDT) Received: from localhost ([122.167.132.221]) by smtp.gmail.com with ESMTPSA id n10sm2183349pgv.67.2019.08.29.04.35.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 04:35:10 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Julien Thierry , Mark Rutland Cc: Viresh Kumar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Marc Zyngier , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH ARM64 v4.4 V3 07/44] arm64: uaccess: Prevent speculative use of the current addr_limit Date: Thu, 29 Aug 2019 17:03:52 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 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: Viresh Kumar --- arch/arm64/include/asm/uaccess.h | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.21.0.rc0.269.g1a574e7a288b Reviewed-by: Mark Rutland [v4.4 backport] diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 75363d723262..fc11c50af558 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -62,6 +62,13 @@ extern int fixup_exception(struct pt_regs *regs); 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(); } #define segment_eq(a, b) ((a) == (b))