From patchwork Thu Mar 1 12:53:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 130193 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2761712edc; Thu, 1 Mar 2018 04:57:03 -0800 (PST) X-Google-Smtp-Source: AG47ELvWLvwSpIMroIOGghOVHkXei1hUS2jUDOlJvvoJvtqngUcZhINAJ8UgypOD2zr/BX5qyiHV X-Received: by 10.101.101.204 with SMTP id y12mr1509884pgv.450.1519909023553; Thu, 01 Mar 2018 04:57:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909023; cv=none; d=google.com; s=arc-20160816; b=VlQOzRbPR1+wcCSV9A7GeO56etKxemDdUEMjYA0+eW8JTDptpWv73Vt5uYE09pDlVs KBVNw++dkwbMl+U1M/E2GTTmiiCurDOrd77M3agOyyhVkqjpyQ4gWDyROzNteMw2VoI5 6kc4sup2JSqX19hXaB6VlKBkQCB7uPQtURbSzez5FEaeCLjmeebDcTxRu7IpK+VaAiBl ZDzz3mWV54/vqnfHXK3wGfjC+MdMPa3ZAI25yG4jEmBbYMjdaBfQc3i+f+DOrgsFfn5H 2JkWWG0ivLmD4JcCWhLEauuL0CU8rEkZ7kSTP/FrN+RJtJSGAwIT+cTS4ialIeOxDqeU 5Lrw== 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:cc:to:from:dkim-signature:arc-authentication-results; bh=B9j5UF0uESTYsHgGAtUITtbvy9Mt1eVCWXup4v2dg9E=; b=jTKD3qiHqz+e1o8QLX463+ix2jx1jCTFFzkzTpdP3w+hUB6712CeEcBvzOJnnbPioj hJhLD2jim3rf19Jp7Hy3wnTLM/ymQeVOlRY/1liILV4v0O4dJnblm3YRPgAAJwgpynJ6 kvzadrMeLzId58hFDaextsrDEIOVv9ACrQgMPnV0g4RyJ13J2Gdd6Xtxd9XLcH0z+fby I4k77JeU/gOiQ7UOIZ8e/Q8Jedfpgx+aOH38mHj1hr7yF78RRhajYvx1ApEoAAQfF2io kTI3/5g6P5Ckpl+LAWTunGUa4xcyvAK3FbjhM3mT5DteeKNqmZzsdPgtdpQ0Z2TLRxOP qbaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L/9E5Ltp; 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 b185si2439066pga.370.2018.03.01.04.57.03; Thu, 01 Mar 2018 04:57:03 -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=L/9E5Ltp; 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 S1030787AbeCAM46 (ORCPT + 28 others); Thu, 1 Mar 2018 07:56:58 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:34554 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030545AbeCAM4z (ORCPT ); Thu, 1 Mar 2018 07:56:55 -0500 Received: by mail-pl0-f65.google.com with SMTP id u13-v6so3594424plq.1 for ; Thu, 01 Mar 2018 04:56:54 -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=B9j5UF0uESTYsHgGAtUITtbvy9Mt1eVCWXup4v2dg9E=; b=L/9E5LtpJm2HVM2hM3oZ4BRU2ItlnylsxSkB+i33/7KgxxYnknzyJd7p/POIFigpYd TEKeg92LwkyH/j9FPEJZUVnwTG9Rsypub2fGgBV80aHn9kjh5aE66gPNJncuu4LJ7w0/ IrZ66XFjwkpfm64Q1AWGMJ3lHm4MFNt2vaRhA= 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=B9j5UF0uESTYsHgGAtUITtbvy9Mt1eVCWXup4v2dg9E=; b=toyvw6udMxxpJL5gNpnuCoJIxPmKU0R/GF0iKIVTFHyau03syYe5Mv/7r/Pxz7YjTH w/AB3y5hOHcJORK9Bqy9KN4VgagXeHGMU1ZX0fuDtJeq+YmlcIDeNf+S9HEz88D/UWWh RH0f16KgWjlSebyLJKPSLwwSS7wd3Oidjdam4Teaem0gkznRuzFzu4QfTKylvWySr3gu yAccDGBplo7vRwtWnjdD7ecMh7EyRluh5KerJG2D+t1gd62d46WOw1YartfpoGxxIsCT UKoaGd76CNUTn6UA3I/hmLimv2MUk/X/TdHW1qWkRz8sFdkOt3Vkc1L4uIPZA7xikomO eyyw== X-Gm-Message-State: APf1xPASBbGQx05CpS7zKyBb4vRuRkSXetVCeBCWlrbKyNit5EikOxV2 yf60zmLR0wkP++OUSHidjAUkMA== X-Received: by 2002:a17:902:7182:: with SMTP id b2-v6mr1823353pll.331.1519909014428; Thu, 01 Mar 2018 04:56:54 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.56.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:56:53 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 13/45] arm64: uaccess: Prevent speculative use of the current addr_limit Date: Thu, 1 Mar 2018 20:53:50 +0800 Message-Id: <1519908862-11425-14-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-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 --- 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. */