From patchwork Fri Jun 14 03:07:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 166746 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1505402ilk; Thu, 13 Jun 2019 20:12:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEpbNq0Ke22hOizvE9F6++awskSrmo2oVxSnluS/0f7guvvN/pOwdJW/QC21jFkcgSUxNt X-Received: by 2002:a63:5726:: with SMTP id l38mr34992645pgb.344.1560481936948; Thu, 13 Jun 2019 20:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560481936; cv=none; d=google.com; s=arc-20160816; b=bwCCJm4J/p2QBDQ3e4CCS0GiEpX2nkz2QKGpKZe95CJE2vJQTQm3Vv+HhhMq4s4Tuq 15bWz1CfXd83RRVZY4hv53LtUBLUuUvX7oroRnn9Pkh1XStTbeFSDk6Fn3r2oqIxYjiY UJVGhZFSTuimKXau6Jy4FE9pN5U2G3QvgoCTHAGEeC+TUr635uW1V3F53Mgf+JQYZyIA YN2ebUj/otF69VAiVnIKaYURNIHll3EBMtFuUCcwI8/mRdCuXZtCMPC6v4NbV+pZfbNQ emrccaHfg3nRfbZv9xOBbtpZuJ1vhrxw8hEdMTnXYzUrzLKkOI4zwCf3xEZgRyL6XhSz mpvQ== 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=PHiT/8BNrFK9Xb2LFEK7QkNQ/ko7qIOKfzpG8Yv4ck5MaL2he3GW/qz8j0LEX6DX8O TnY6lgObjqE1bqtvEfchJ3It3IxKa7JuvxMhfmi8eg5wSJZzVs9HF1RZnuEHPywB/G3m hICh77QcoQkXcIKr09jkGceWteVE1dd+1Qw1uyDEF0tC3LCMSevYRaikcqyIb1uonAlw on9j6MX/VaNKd960LC6iHell3iQi9Qek30QtIqRH5Ik/Q9QJ3g3LTvr9lnfhYNF2EnOQ zM8CHQ1/UT4PYLgw4uU0s+hR7XUT287JvxZdn9E+6Tt+BrXI0I2HJE3euo9JQA8UfJtp oGiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wDBo+IsE; 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 e8si1073936plb.420.2019.06.13.20.12.16; Thu, 13 Jun 2019 20:12:16 -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=wDBo+IsE; 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 S1725981AbfFNDMQ (ORCPT + 14 others); Thu, 13 Jun 2019 23:12:16 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45352 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725819AbfFNDMQ (ORCPT ); Thu, 13 Jun 2019 23:12:16 -0400 Received: by mail-pg1-f195.google.com with SMTP id s21so654929pga.12 for ; Thu, 13 Jun 2019 20:12:15 -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=wDBo+IsE5CxYBr/gG7jlwGTkzvTi/KgR2RgJSMhJe7bSxoaXzF0+TdDNJK6dLehXAQ KEE7UfEPuEEdzLtOeDJj3d79e7YtVNq/zUYfIVHlxutsUIdQWnMOok8xzhUVGO/wTU68 ulCOJAXaMZaEp6vk5Lt1C67hIvkuulYIejzeRyCLcBuX3IVSZwH8JSIlylhk7jf5ZZAp ekJFzgWJkOPfXRXpgRLg5XEs6n3l8kd4NqIboYgsZw8aMww1p5p+juY2j8+fPoHS7L27 QCdRJg5NSWYQy3xOzfV5YkvCjGSfOV9srWU2QmGPVppmd2e1TGCJfqCvS3ceOE1+BmUc vgBA== 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=YsqKHugJFKF64pqYBz4Ekr4RpHUVH5do3LIEaSH44EZOP1r6N7AuLHNSOKXFDvlYJF G8f6KfgbR1qmBV6A0kfRiAEGQm4UKjnAxBf2SjmodWb597URVxjMwyle0do+Vml+hKBa RizgKW6cdl4q+9RDR+GHpbK4TJ7IhwaAWgdBANmZqtEMDZi/CJTR+oPBEA64Z2xFzSqT FbFSaHRVVAyN6w82JYt/272gvFLsQwM1HYnZLN9HmYaU7KjW2rYqJ/ifwyH4AG2M3efr levUnNnflThquLqyMxB4oETAmDahlponzxYX3LMd0X+DSt4Yc4D0RhYNNom45sXsWuH9 uuwQ== X-Gm-Message-State: APjAAAUVBKClRp3PnISZp+Owwd7Wrd4nF1U4GrhsvKTvWuKTU+j92D/Z biDx1xmGQZ//SPJ0bG1XbOf6wg== X-Received: by 2002:a63:e60b:: with SMTP id g11mr13414619pgh.172.1560481935400; Thu, 13 Jun 2019 20:12:15 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id g8sm1048468pfi.8.2019.06.13.20.12.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 20:12:14 -0700 (PDT) From: Viresh Kumar To: linux-arm-kernel@lists.infradead.org, Julien Thierry Cc: Viresh Kumar , stable@vger.kernel.org, Catalin Marinas , Marc Zyngier , Mark Rutland , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH v4.4 08/45] arm64: uaccess: Prevent speculative use of the current addr_limit Date: Fri, 14 Jun 2019 08:37:51 +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 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))