From patchwork Mon Feb 26 08:19:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10241549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 77B9E60386 for ; Mon, 26 Feb 2018 08:32:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61BF729171 for ; Mon, 26 Feb 2018 08:32:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 562BD29AEB; Mon, 26 Feb 2018 08:32:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C400329171 for ; Mon, 26 Feb 2018 08:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6y6p51xH8U1fd9fga/WqUIzTfglr5czxWQM8fQjFMXE=; b=XoSpQSOH8IwA5+ hWuRoaJkXpztfto0xGhZgsSvU9K+Qgum8QMYo0RgxaVMKbAJSoUwpyQoS+SAk2G0r2OPsCyEEe0qT CuGdyv+AP44TToBdhW1z3g19jiuKzQaoSbkYhWZLTMMO+YmV2hu1+wlM7qO1A7qDQ7q3yqbt3slPk 9F6t/v16ZZzq123lFrJk+t9IztT7oYSzszGlQQzY+CHCLvWJD09UG/Okj6SKeKCg7qe//AOa+nMok OQeTG5lCSKdBPpQOo/uIdN3wE4n95cvmKIISEICjsJg38eKvFORl/sTMCW3xA7RM6SLnfhLHdw1ys K1YJFulbNO00C9GAqjOw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqECf-0000Jf-NG; Mon, 26 Feb 2018 08:32:09 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE3h-0000wR-86 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:23:41 +0000 Received: by mail-pg0-x243.google.com with SMTP id w17so5908109pgv.6 for ; Mon, 26 Feb 2018 00:22:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=XoltgftvsVb6cg5EoqmIT2rqheB1dI0xAlZ6dp7AzjE=; b=Gwp5XxQ5/4x2yaA+PNjtbUdklQAqRcBSTLsVH2yEcJ82PNXHXaU0l1ySt5nIRcTuGK 4R8cZTxwdd6iUCur12qIqRiJc0U+vm8Jf79x2yclDajkrNKApkZ5eqzGc2z55Hev20Vq n6jl9CmDbpIxQFDB6z2DjMxnVnJbEOp22qwQo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=XoltgftvsVb6cg5EoqmIT2rqheB1dI0xAlZ6dp7AzjE=; b=oMnJpbta0+DPN0G2+KNW0gL2Yv+oUIUfzFPn8hDhDgNdxYXCNJoLK9t/cj4X/rE8JP FAokdqsJuC3LZaoVNMh+1SDMUtw0ONfDGTG3hMj7h6vz0ixEU2seqCY5n6Egue5tDXgI K//y/YUXXmrumC+uOFjipss9zqWkCWQFxHI+JSAA6ijeiq0MaIwRyeWv7m4ZFkx8DT2s xEVV7Bh2f0u/JGtlqPKLKSEC8xahTUKmXaTibCieB6m6opel54h/85Myn4htZVrSBiVh MJw90uGpFBNvS0/WmId+TF6Ts378+fZ5hnofP1CzHs+UjHxryt4pOjjuFDwJjNvf8pRy 0YhQ== X-Gm-Message-State: APf1xPD/3h+Fff89yZDyUBeDO0CVlkJZ0xdk69xAR66glsf425/Vz0Bq /Njo/aCqujOcTBIZbuDT8Y+hSw== X-Google-Smtp-Source: AH8x226Utj9n1mLXHehVHWNBZG1NM5teBxS6V+bChGMzrv/h27rDqDGc3zBZI1lGIGoX+K7jElHNUQ== X-Received: by 10.99.5.197 with SMTP id 188mr7795225pgf.196.1519633362563; Mon, 26 Feb 2018 00:22:42 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.22.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:22:42 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 13/52] arm64: uaccess: Prevent speculative use of the current addr_limit Date: Mon, 26 Feb 2018 16:19:47 +0800 Message-Id: <1519633227-29832-14-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_002254_033421_D71D833F X-CRM114-Status: GOOD ( 12.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Will Deacon commit c2f0ad4fc089 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: Alex Shi Conflicts: no set_thread_flag(TIF_FSCHECK) in arch/arm64/include/asm/uaccess.h --- arch/arm64/include/asm/uaccess.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 3531fec..00025c5 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -71,6 +71,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. */