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: 10251451 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 627DA60211 for ; Thu, 1 Mar 2018 13:40:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4281626E46 for ; Thu, 1 Mar 2018 13:40:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40A1D28543; Thu, 1 Mar 2018 13:40:57 +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 4D21326E46 for ; Thu, 1 Mar 2018 13:40:30 +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=Ippjgm3Vg1zMxUe1fhGqppUtnNSQpwHYV42SC2kBBnw=; b=pnGPMKpPYaosfiZLPjoyFQ5MMs BXSDOI5+KkUDyzo/P/TyAxWYACtioCnoV5xbOrxQi4C+eYR12Cj8uTczZYnj/pgzRgh6HA1itx3Z2 3SIo/kbR5naKut8I7Qqt/y+9b0CszeETkgaHW5uDeai49ZF9dZswWly9IC+E8i98h9b3IZdk3uv5v 6DmZC1zD+Qav7PyZdTXOYniSGlVaO+Zy9qdIyXkU0nVWP35gm7vcPu+6bQnHDlxWB6L92wStrUE/F 9XQ64eHeo/eRng0IGJSjqWbLnBEsm0NBBkW6SqzLXEn6nLF5IMZIf+kl7SC1VL+XsIRUmXB/KrYFk GxMOk5Vw==; 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 1erORb-00032S-Dn; Thu, 01 Mar 2018 13:40:23 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erOHR-0001sV-3o for linux-arm-kernel@bombadil.infradead.org; Thu, 01 Mar 2018 13:29:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=B9j5UF0uESTYsHgGAtUITtbvy9Mt1eVCWXup4v2dg9E=; b=uRfKh7m6OaYDqJQrDzj8fSYKr rxcvTG0vRtr9bNp82ZUbj5RocVhPt8anOh4SBRr1FI0XFEhFWYXNDFjUVaqe5AgUZ6bKQeMn01MCV F8q7q+shSv9/jKRYpD3XGwir1/sox1ft625OcsMDP/v/KEH5/LzTWDuHh4NyxGVqgY+jDY4XpZvwM 27uvlI30pliEgZzdj8RLSTCDwmkVXKxXtmKJ3ZdrSpawavumhl356NysEDX6cj0hFubvlnDt5zN3e hrfGZtAf33z0QXS+Qd4c5ULNpVOWu5rja5HTo3sXhSE/9Ho1Qj5v+wYTTGbY8J1mRMjLz0hgxBxje 2VGEiSTlQ==; Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNli-0002Di-Mo for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 12:57:08 +0000 Received: by mail-pl0-x241.google.com with SMTP id m22-v6so70650pls.5 for ; Thu, 01 Mar 2018 04:56:56 -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=FBybUwHCmADX2XHiNIMYXUspD8yU9n1ZM3jOlk8swUwVDw/in//jQRu1JkkPbp0NHf k1jGRBxUXLsIhLbXtHUzf4HNfJ2YTz3OReW4rBlKUzEJwt5shFofb4FzUhNdTWHAHckm u24j0aQxCRvX2jWpwKHPzVI6WQiKsJRL0zz8LhU++/LZumbfY89ZMaZRTZoex5WXGLRd zqZiuvadsNVefBJ4IqrckAi/Omr3zdyjdEPXDxDrsPW/CBB8cP+Z1CCrsMwViPhiRvdf CcnVMMo1ToBUWIwTp7PrG99algNu7Gv2FNYPczRTwzAY/X5d6AaXvn5PxvjDWR8+6+6J XT6Q== X-Gm-Message-State: APf1xPAnp6iVFFxEjO/ja+qTaX1mPiDw/nMaEiku36v2QT1Mhb/b/9jx XQIDhdIQfehqjwYaUly9hb7geQ== X-Google-Smtp-Source: AG47ELvCpEunRQHWeOqLoDTvu+swGgZUBdPEg3zyzzVel6A0znw3pOXx7vuihGz9xKQb/258cC5GKg== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_075706_765176_D3BB85DC X-CRM114-Status: GOOD ( 13.08 ) 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 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. */