From patchwork Fri Mar 9 09:06:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10270113 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 7367760236 for ; Fri, 9 Mar 2018 09:12:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C2D029AAE for ; Fri, 9 Mar 2018 09:12:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F98529ACB; Fri, 9 Mar 2018 09:12:46 +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 E015E29AAE for ; Fri, 9 Mar 2018 09:12:45 +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:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0shUs+5X/k1LOT0UjdrKkLP9cq1nUqBSS+v1U2htcbs=; b=NJxxDwl1RWuNlxmSqt44e3C2uV iyhkI2QME56MF376IAwqeyeosizoYVO7HCzk40opO2ev0KZPXsTELMxHNsDO53fPaKUgxA5ynPB/x bBbbY8C6itu9QZOKxQy0uXetuH1YrBy0UyZaoVoP4IrQYplqmVgt3rYEatjWgBj4zNAOOnomKMZON DWVFq7153gb31EIhuJ6IwIFAeFL/ETO1IPtm4LkwsOV5Gae1W5fpva9ZUzCuB5Xnbjyv9gvwT5vkP rpYSMDd5Hv40X75lZbvk1W3/miFreX4gGguMtEwhdxLHKMkdgQbEokmmIaMplNpSxcfJjM2mcaUbC +tB7dG3w==; 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 1euE4r-0006yj-UL; Fri, 09 Mar 2018 09:12:37 +0000 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euE1V-0003dD-OF for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:10:01 +0000 Received: by mail-pg0-x244.google.com with SMTP id s15so696161pgv.8 for ; Fri, 09 Mar 2018 01:08:59 -0800 (PST) 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; bh=Iji1rDmC8rAMYXZ4f5mgpRtQoesahQl3wOL++6hC8Is=; b=WnP1V+Q0PJXwxk0C5or7AIeYqF9rAN47hwsvWkKUdJ+j57DmtKi2/Al88Lu1ZWSn4s v+ppt9izAQab/jrEoJo/fHV5K0rZngb1Ap8rvqCsOH1zLu5T2Q5wVCo75StM+HpfYbI0 eurN3W6HfiyHEPKqBEmfXBtFTfYcYcZpcQLYw= 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; bh=Iji1rDmC8rAMYXZ4f5mgpRtQoesahQl3wOL++6hC8Is=; b=fTFikMy1MBihWJblNOOBY3IYbzNbrkhNyjp6VCr3f4gxSPEtDE9clq6MzNBwy5cJNB 2UHF86K/Jr0FHmaju9YLDzfHa/K6owicI4Qxg03qDrCAVgmUEdjBiZJ/y30wCZNpfRYe /6Vtl/0DpaQwj5I0p5lJeLx2b9olHZgCR3HfXIIv79S1vHkzoUtxnyUHYPeNI3B6uhpj G+Bah1qbXrhieWKujCgphJtXLhzWfLqMvar0CMgD2R1TC61hfYenGvjPq9hWMwNAztQ1 Q/iR77BVmCwV5uA2kWlh4QVpnTuLtKoP6/5SKKkN7DIw54rS8LTjJgIjI0sWWZlGMriv Gpnw== X-Gm-Message-State: AElRT7FPG1oiiKLjdhXslu6f8thI/6aurZUiy7ZVXs2qdK/jmVjOq4bt HhCJgXdi5c593WcTPuUNy2uPpw== X-Google-Smtp-Source: AG47ELueDDWL79xOrb8cKlw1cdLxudQZMtcw+PyltwqpPYruZGvwGx6TIRzKzYvrm/2R+f1o6c10cw== X-Received: by 10.99.97.138 with SMTP id v132mr510141pgb.138.1520586538677; Fri, 09 Mar 2018 01:08:58 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id c7sm1961752pfg.36.2018.03.09.01.08.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:08:58 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , broonie@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 08/39] arm64: uaccess: Prevent speculative use of the current addr_limit Date: Fri, 9 Mar 2018 17:06:51 +0800 Message-Id: <20180309090722.26279-9-alex.shi@linaro.org> X-Mailer: git-send-email 2.16.2.440.gc6284da In-Reply-To: <20180309090722.26279-1-alex.shi@linaro.org> References: <20180309090722.26279-1-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_010910_634100_5C138CD9 X-CRM114-Status: GOOD ( 12.73 ) 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: , Cc: Alex Shi 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 --- 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 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))