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: 129569 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3356432lja; Mon, 26 Feb 2018 00:22:53 -0800 (PST) X-Google-Smtp-Source: AH8x226MA7FR6kAML62tKfIzqFyGzy943e+ZWpN9xhyIM9w/XK5VLdSlMumz2GMQXF6E6hc3c6Ty X-Received: by 2002:a17:902:d20a:: with SMTP id t10-v6mr9913774ply.257.1519633373308; Mon, 26 Feb 2018 00:22:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633373; cv=none; d=google.com; s=arc-20160816; b=Ok/0+CJA85Y5UThV/beZGAOt/ALr/tzKx63AiAQ3MD2TWe+FJgRZ537t2Ku/lz7Jjq j3KenhMzKmKfET3lxAW2BO4nTqab4KHJ2In26jwEtVugDcS4ob/AEvzaR0fRcvLnPaw0 HIgwaRbEny5VlSuYBrHtjmdg/37lWN/TdurZVcuaxUW/jl/UdJZ/nMuWnBKiBa9UD9ZN 4mG/eJnzsQLj9RPeQpK9nZSVxrulzs0f4A+nsj5gSDb/ISgZbj7AaeBdDvQAQizxIoQ+ T+eFhtvj3CtAdxIT53zdmPuYb9OX4hDoztroxYYomIr7KA3pL3QZmFC7DDqyAhj6Lwn8 mRfQ== 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:to:from:dkim-signature:arc-authentication-results; bh=XoltgftvsVb6cg5EoqmIT2rqheB1dI0xAlZ6dp7AzjE=; b=MikrICAlhvKbMJW+iQeDutfBIOsr4ZLTqhfkKvemNUic0Qwqsb+7p8hpijkaPrB6ZJ orDEQOrSJuF2wyt+5aGiVaLc8cBakFyeRAoUMQ2Tl6KmLnG5lz2ewHOFJ5bnq71hJoTw Tg+WHKvcs6wHLuGpsjTpOBuMamqRENWoBYJM7fOVThypreyIZTuToG+2JSaOEXF3BRcX FUjJ4pE0shpXaVhRheiloyy9NssTB297pf79cpwpSVETXjx4+dIqzyusF0zMCXNKiMGL DnTOH0Z62wKjMe9oJACdb04CfOb8y6+hzT3gnLcKqEDa9LgxS7zt4Uq3MoWdSxM7A3t/ p90g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gwp5XxQ5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 c6si5261838pgt.111.2018.02.26.00.22.52; Mon, 26 Feb 2018 00:22:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=Gwp5XxQ5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1752458AbeBZIWt (ORCPT + 28 others); Mon, 26 Feb 2018 03:22:49 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:42877 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752449AbeBZIWn (ORCPT ); Mon, 26 Feb 2018 03:22:43 -0500 Received: by mail-pg0-f66.google.com with SMTP id y8so5905259pgr.9 for ; Mon, 26 Feb 2018 00:22:42 -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=EujGS2/mW5dboMXU2CeUxSzz90ADYlgqHuKmNu9j/Gwe3FceAIGEEDNVt38dWUyOAk vpm6od7VG1E6llI2p9VhaJc3ZwusZWadK1TgyR3o187Dv0D4qZDlkyD+Hwl/S0txfuxQ 50+Bcff2di6qor8N2f3A7NYAfSgeMMntKjzysSE0EwDtzV4DgqYkgZ4E56by/vJZq0f4 yXAmpie46tlZ1+fOwbiTgIcui/d5Jbf1zOWEE8xvaC+i9dIhsZZFXlSDMwVkkrZ+xqY/ kB/Qmi6bFznzX8p4GRSPtLs81WUu6MKPgqvsqamB3tIIsfS9tIr7+mQhmonFQRiJLpLg qU1g== X-Gm-Message-State: APf1xPBCBtvmttTOiumBvnuwqGc5fNLIJ/rOSFtDsffQZt2BM1eeoMaU +WwX1pFdMln0ORZ5Nhm1PP6Wig== 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) -- 2.7.4 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. */