From patchwork Thu Aug 1 08:16:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11070315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F26091395 for ; Thu, 1 Aug 2019 08:25:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E387127F3E for ; Thu, 1 Aug 2019 08:25:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D512827CF3; Thu, 1 Aug 2019 08:25:59 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 7DA832624C for ; Thu, 1 Aug 2019 08:25:59 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=bi4ewPtLKTBcimYIKpRdEUQKGor8SYwZxaAAcPy9vcM=; b=kElg/6lRJwmBwL 4AbjT/z9Qbujxk/WRyJiz1f1GWXZkvID15epD5fR/DncDjK/NowgJsk1LwaVkursEzVVQfxE1LG58 caoPyKcSB0Gc+nz56uijEUAsn0wuc8XlAu2esm3+YZj7lR15Xd/0Ee6Wk6TMfr8+A2iliRDZXbSyP oaLjj7NuF4mhRe0oZY1VFfkA/hgK5tybR7rMxPD2gtIwsCIxhQXY0oCwt4ne+yKWIGQ1dmGU7jjLF FMttt58KSiduNYQsBK93hkb0HjPTIx6IG8caABomG3+fFxM91zO4okoFepo/2UsXMSDAomKw7RWjF IDwuBAu1xxWF6KWAUSGw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1ht6PP-0002Ab-3B; Thu, 01 Aug 2019 08:25:59 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1ht6KZ-0002zu-Dl for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2019 08:21:00 +0000 Received: by mail-pg1-x541.google.com with SMTP id n9so27509866pgc.1 for ; Thu, 01 Aug 2019 01:20:58 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=83Q5DLuQYSva53SfstGNLwQ+WusgochK7tEX54DLnZk=; b=rI4dN04PCrS8oEfhhu1FimQvBZ8VBzO1CvaxoGD0C6HzZI6J1xXoWDHX2NESLp/Gu7 7/G8HfBb07K3/rgxPknRTOvB3aLF023teB3bfyIRyAR+J8H4K9LaMWtxu70jFDgK74EX d5yKiB/4rRbxtd1QdEtqb0PY9C3bjQM4DYhFHaErCxKRZDpe+KlfB4THeuDtUHgMKne0 tAcVx3VWyyaYMIEQmAFWy51kwzUYHaZxrC4iPgcfUez/yyp4OS9lBBifrZ0sEM4m2uBe HN9oapm4F9z9UV++zkll/G0/DnOcFJFTYG1xzjUUiBgS5qLQw/8M46c9Qq8EW4MJ4sTk pdDg== 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:mime-version:content-transfer-encoding; bh=83Q5DLuQYSva53SfstGNLwQ+WusgochK7tEX54DLnZk=; b=drUiJ5h2JQSIlhc0/k89kS+KQcDgYalVGUglGDjBouD4UJr8VzeBIBjPKwKQcx1Vub NBM1xxc8szQS8DGxfOaV1W8JbTJ+rjnvozGbPnguRYh8DjspNnWoq99lKkjOhuk1iMCo uE1JXNUIvWk9yEQP+h8D86liCm+jVBIlOCZVuzO9s+AgcAOXwWiDgZmtcGAfwCPsdSyl HzMCzkZTn4iesbDiV1K+Q5cuAWivYjnOpOAuAlkeIzGb8rCJEmTJIjn16UBTkVyeuVDx 5Gvu/osrGcjNmonQfAKbiXbHQsADJbmyXzaeEa5htD6nr2HN6xp5oEwssfQDZEV9K197 XoXQ== X-Gm-Message-State: APjAAAVEtYPIBcGbz9kflYvLPxufawQol4NyHZUWvUAjBWtOHe97H9P7 eWSI0NEcX47EEMnNADUz7D47pg== X-Google-Smtp-Source: APXvYqzngxuyD04VCRkFZTzoAlqHmHgivTldcuqpxXRziSfFGEKiXB/CnfRGlITASbXm+JzerEuOIA== X-Received: by 2002:a62:14c4:: with SMTP id 187mr50562879pfu.241.1564647658137; Thu, 01 Aug 2019 01:20:58 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id j1sm95276210pgl.12.2019.08.01.01.20.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 01:20:57 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org Subject: [PATCH ARM32 v4.4 V2 32/47] ARM: 8794/1: uaccess: Prevent speculative use of the current addr_limit Date: Thu, 1 Aug 2019 13:46:16 +0530 Message-Id: <74663c62c712201d35d012eba43ad611b6c5a3fe.1564646727.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190801_012059_483825_2659E109 X-CRM114-Status: GOOD ( 11.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Julien Thierry , Marc Zyngier , Viresh Kumar , guohanjun@huawei.com, Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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: Julien Thierry Commit 621afc677465db231662ed126ae1f355bf8eac47 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. Porting commit c2f0ad4fc089cff8 ("arm64: uaccess: Prevent speculative use of the current addr_limit"). Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: Viresh Kumar --- arch/arm/include/asm/uaccess.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index ecd159b45f12..a782201a2629 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -99,6 +99,14 @@ extern int __put_user_bad(void); 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(); + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER); }