From patchwork Fri Jul 12 05:27:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 168866 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp394488ilk; Thu, 11 Jul 2019 22:29:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrvzt5w5bwEA24tCJeDzbKU/ili2+7JO64t3oiIi19Xi2nXV0NLzY9VhyquWnLoh8kcVBl X-Received: by 2002:a63:c34c:: with SMTP id e12mr8386102pgd.195.1562909359987; Thu, 11 Jul 2019 22:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562909359; cv=none; d=google.com; s=arc-20160816; b=HAQc3RVdtWpt/L7+ke0yAvjxHvnMYhS6ccO7jxtDScND3087+ZUJ1mUGkpZ9jkmFAP +WDx+gHhE+r/y4xSjd+t0yFNrBWqBnmage1ALFRcnRSIUymOmBWUQib5oExzYJJ3Qplx sMP/glBYGGDG2pEWHJ64munZLzwZbl31uh2hYT4h3I3BVmK6AwfSlXxrLswD0aCIYhtj XboqMVpA5LJ3nj24Gs+Ng0MwRyxAAMTsqoBVA7apeQSbGl6FXvRloE+1nXVTsI8t5Lgh IzFcfFYmVZ5zX1Htv+GMaZguBGYhzySQu1SFH/BQOepViv3OQM8OSB2V+O/yImHaqC/D g15w== 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=QT01JvI7QihgIPKVzSWPBneJbRqcUp54ChHP/sui3EUWvDYZLeVQMGIfwn75WH6zqk 5QzqyElFifvNYlEpjnGeg43IYv38LlkzG2gZjek7E3egjFKC0MbQ479yIL0uIzdrul89 bOtGkv4t2b3fruLZq4vv2kLLTJFGCnNtVOGboM9iHdlPaPk7yvrAqUNerSPp8Uihf2Zp 0Hpn4qW5GRGevQ+37hRQY2X5ZQiv6cml4IYZGlMubkI1mrjgse+DMjJsM3yDSe9koQF1 7xZP91K1tTd57LyH87UOH+DU0TSdDkWa6uXeXrKHfFtbY4X7FWSsr9oAboVIv2mA7IPk W47Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cKXVVMIE; 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 e36si5303191pgm.17.2019.07.11.22.29.19; Thu, 11 Jul 2019 22:29:19 -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=cKXVVMIE; 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 S1726047AbfGLF3T (ORCPT + 13 others); Fri, 12 Jul 2019 01:29:19 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46782 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725791AbfGLF3T (ORCPT ); Fri, 12 Jul 2019 01:29:19 -0400 Received: by mail-pf1-f193.google.com with SMTP id c73so3776202pfb.13 for ; Thu, 11 Jul 2019 22:29:18 -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=cKXVVMIE78QmcDsJ8R1sTpeboiLZLLwZ56moXlqZPVbf8aD8vMMu4Pvrm2aCvGwZUe /q51yWLi8ZVUyVOJ+XpmDnfQMDM0AlfnbywjiCvIB8wYmBsxXtXVZiSU4BC7t9OVilng DG/7xeCbeqrNVTU6/lMYNfpfYsOAMgVe6IN/V03s1mYMoXp5axz+HSBQ0IKiyltXMSFr wRoTudkSz8nW8zy40AXY6gIncpiXe57jVQfwyA15sxy9Dh5Oy0kVl+sjVutCkc/aoLA5 8lD5nJwig2b9lUBOJtdhwXQbno+v6eTUCAbdE1ByEBqwET4r6XcsfkpaytrzUd0dbnYx uTmg== 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=toa87nRIySIZjBRF5MkY7zhkfRm2viFKQidbGMSsDED3OdOWfq8UQm5kfCRDxaRUVB nmcrXcyP2oTKnc3/oNtwjemgqmKGfKMwy0EIyFI1ZjeJU3AFO0jW9oy6OD6lbZqDTXTi LJpbenZLk48POiVU3jvhys5XwauJ2WZnSW6GpvgPXLU4qKeXs2FKRM3VPVaOMNcjs5qO 0PAqv8smFU7Xr/4pc/tEix4qfxFfMNOaP0VYgwzoDXNcPoyk04D1LzyBL15+jBMy8Pyt 8gH4hTeAFjFPyIThK1rktUiqBmOnPk4wIYF/1jXuUbsFvtHmlSsAjaiGtzNV1IdTXwa5 2OZg== X-Gm-Message-State: APjAAAW7HMMG/qhDXJ/2L4eWFBKqWNsGi1r99vGvqAJFz7GLnSkMpokj M8G52wY0pSFoD7UAUovFMYG58dIa2Xo= X-Received: by 2002:a17:90a:cb12:: with SMTP id z18mr9007071pjt.82.1562909358269; Thu, 11 Jul 2019 22:29:18 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id o14sm13901475pfh.153.2019.07.11.22.29.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2019 22:29:17 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Julien Thierry Cc: Viresh Kumar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Marc Zyngier , Mark Rutland , Will Deacon , Russell King , Vincent Guittot , mark.brown@arm.com Subject: [PATCH v4.4 V2 07/43] arm64: uaccess: Prevent speculative use of the current addr_limit Date: Fri, 12 Jul 2019 10:57:55 +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))