Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp33089pxj; Thu, 20 May 2021 03:58:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqa7LiyegA0zr23Qlbf2j+rjJANLzKdqIYHFWXzK13qdFPWRJo5ALZBwOCv76AKxFrl6CY X-Received: by 2002:aa7:cd6b:: with SMTP id ca11mr4342841edb.115.1621508296615; Thu, 20 May 2021 03:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621508296; cv=none; d=google.com; s=arc-20160816; b=kpiUWHcPtDITG0ioPYOpHJzrfsWiLMUyU6M6ewv39vPRDbcagG0JpCNHTmx4nFjkQL 1KDwP6Sd36YusnGMtXwrNRioNYr+S0fxdcyN9pKp/jANrpEu30zsrvMWw9k/pUXbvc8L /LYf4OzhkgFxhHts1YgSkxxTmOonDlz87218BHqvKOV/OdPT0PIT/xNbumrb3JsEF1yU xCj/b1exa5epSPkmwtppzfQg7TU8OTNUltCfNjBuBmTdAMnVi/8rvsQk2ki2eipm05gz 6F2zb+kDibe8KKpHjVLqXPLm9G7DQg/sQPtL1z9vPkYHeLxma7r8nFJQWgm9zrr1cYKB uxgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bx8xl9JWc7hf/RpsVZwOMBBtZ1cLjlNAcMwcGh2SR7g=; b=sN9OVltuxauF6+h2sciGiFo/XvAvmeG8uc8Kqe25ps7T08P0JOuZH38O9O3EGSX+Ka pvqsta5+El0Ask+P+AMwOp1elBn514moLvFf2HZazaIA94KnPdfUYL09Ty+iw43J91Q2 qIxwSozplccEtNUsTF/uZipgt8iFtz0IZ7i93nJJqbJPJzfPk/7cJ3Mcn2ttz5Qq9nb+ LGmvhN6WVqs/CIDcw/ysgHFlZwKGHnYD7MQAHvruQ4OXHvQripEFX6kO/W9b7L7j+jMj iKl5LptJd5HC+VrxDlqTmNzxXHKi4fUL4u/Rp6/u/Xxp8Gu1FYvqci5HJ6r2PnRL3HxR kTdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eQ0pk6hC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s25si2272783eju.101.2021.05.20.03.57.50; Thu, 20 May 2021 03:58:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eQ0pk6hC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238391AbhETK4M (ORCPT + 99 others); Thu, 20 May 2021 06:56:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:43874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236341AbhETKkn (ORCPT ); Thu, 20 May 2021 06:40:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 18FF161C76; Thu, 20 May 2021 09:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504545; bh=sHKdvmsp+KQS0Z+nfjFa5eZqQDZRwqxO69LGBBAmmcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eQ0pk6hCpaxgty4zVBk5dIR2P/NLU/Fmhe7V5AmcezkFz5T5Ge/GuNCV2nCxQUY8t 2mgOcImHiQ2/L+VnLfsehs5QEe1aOtSxBXaZI3voruWgMgeKudht7lBqiEeLi5fqJr 5jaa5+oplieDLH8VJVJrA3n1vf8aASAiEl+tefI8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman Subject: [PATCH 4.14 277/323] powerpc/64s: Fix crashes when toggling stf barrier Date: Thu, 20 May 2021 11:22:49 +0200 Message-Id: <20210520092129.716570446@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Ellerman commit 8ec7791bae1327b1c279c5cd6e929c3b12daaf0a upstream. The STF (store-to-load forwarding) barrier mitigation can be enabled/disabled at runtime via a debugfs file (stf_barrier), which causes the kernel to patch itself to enable/disable the relevant mitigations. However depending on which mitigation we're using, it may not be safe to do that patching while other CPUs are active. For example the following crash: User access of kernel address (c00000003fff5af0) - exploit attempt? (uid: 0) segfault (11) at c00000003fff5af0 nip 7fff8ad12198 lr 7fff8ad121f8 code 1 code: 40820128 e93c00d0 e9290058 7c292840 40810058 38600000 4bfd9a81 e8410018 code: 2c030006 41810154 3860ffb6 e9210098 7d295279 39400000 40820a3c Shows that we returned to userspace without restoring the user r13 value, due to executing the partially patched STF exit code. Fix it by doing the patching under stop machine. The CPUs that aren't doing the patching will be spinning in the core of the stop machine logic. That is currently sufficient for our purposes, because none of the patching we do is to that code or anywhere in the vicinity. Fixes: a048a07d7f45 ("powerpc/64s: Add support for a store forwarding barrier at kernel entry/exit") Cc: stable@vger.kernel.org # v4.17+ Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210506044959.1298123-1-mpe@ellerman.id.au Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/lib/feature-fixups.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) --- a/arch/powerpc/lib/feature-fixups.c +++ b/arch/powerpc/lib/feature-fixups.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -225,11 +226,25 @@ void do_stf_exit_barrier_fixups(enum stf : "unknown"); } +static int __do_stf_barrier_fixups(void *data) +{ + enum stf_barrier_type *types = data; + + do_stf_entry_barrier_fixups(*types); + do_stf_exit_barrier_fixups(*types); + + return 0; +} void do_stf_barrier_fixups(enum stf_barrier_type types) { - do_stf_entry_barrier_fixups(types); - do_stf_exit_barrier_fixups(types); + /* + * The call to the fallback entry flush, and the fallback/sync-ori exit + * flush can not be safely patched in/out while other CPUs are executing + * them. So call __do_stf_barrier_fixups() on one CPU while all other CPUs + * spin in the stop machine core with interrupts hard disabled. + */ + stop_machine(__do_stf_barrier_fixups, &types, NULL); } void do_uaccess_flush_fixups(enum l1d_flush_type types)