Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp452733pxj; Tue, 18 May 2021 07:07:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8B6ld/h5TRl1QghF7CzenjvUpIoIje62LYL7nDD4w5ZmDw7zYAtEJlwamZqe81yxqsIrs X-Received: by 2002:a05:6402:354b:: with SMTP id f11mr7413201edd.139.1621346832484; Tue, 18 May 2021 07:07:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621346832; cv=none; d=google.com; s=arc-20160816; b=RvtBZAx9a2lb6L0qe/VtOopxz+G3TAI4yZ3uGrFlUvLA6jSansuL9YZrUJVcfonRUJ QtTBvFpSjtuR46fSQHO9//+0gRoVWEd3OQCX8P15uBVa6PfxKX5xUdfUYXL6RJsXTc6m rEgQ7Gus0ief8w4f+Gb+1s+EhlIhIPG5a7HG4PNgUDQCGW+zn3QHpeP4HtW2OwDvM5oV 3NdFyI9f50B2fj7L4PYlPTnHgVM9CJUKJvrUCku4UeoRRvcY4TuSq4HYTYd+AcdmG8qs 3qKcB06BByomCBk4Nca5o8XP4dJVoeFpFvS8KkKECJaLdKVVFMicDk+B7Sh85WumK0HM wfnA== 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=T++344QwVE/237ZAPkMmout2MesAxO8fEs92fYnt/Zs=; b=sNxzBxiB2FtDK7942zTjz3K35XV26sggUeCIDXLpkhPa3XpvvbsmZ+WPK7dTPKOvs5 Qm5E7mtVTpR9Nakh1YfqijAvCT9BPsLLw/+EcvaMEBoY162FeO5CNbBWsQWNPnELlnE5 vByE2Is46VNViBPL14cKPLqc1aBa4UTMq1MuF4jWvRTBG9S4b8ro7BqbSaZbaH/WJ3ZQ rKRwcwHO+S71RRGwIJZx4rDSinrMpqWOahRqSnmOFE5uI7SX5yBoMmtCDC97xyFt8l3C I8RRvox5RMg+kjIIHVjvMul0VsCY53ZbJJEpS/+pXmtR+6oQ0TZGCwgbQ68Wei93RTlB 8Ngw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xVlZe1LT; 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 w1si9123658edq.222.2021.05.18.07.06.47; Tue, 18 May 2021 07:07:12 -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=xVlZe1LT; 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 S245004AbhEQPko (ORCPT + 99 others); Mon, 17 May 2021 11:40:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:40630 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243503AbhEQP0L (ORCPT ); Mon, 17 May 2021 11:26:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7EEDB61926; Mon, 17 May 2021 14:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262180; bh=EAfkBS4b60opCiLOVlnBupkfa4IP9sMSU+ZZMIUm5Rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xVlZe1LTRXMlmAakNhHbe713MM+X3ZIEqyf0wPMqyaKnl77zH8ZSyotz08u7VI/iL 1SZemeNtbUB0YOfNQzdHMdNjWaid+YrG4He9g6SnJ9H9CmTTFbelh/Jvo/z/TxlS3z MXP+ZvrP8Izj5l87gDW3MwBoYkFDghheqcBdQcbE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman Subject: [PATCH 5.11 233/329] powerpc/64s: Fix crashes when toggling stf barrier Date: Mon, 17 May 2021 16:02:24 +0200 Message-Id: <20210517140309.993358897@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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 @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -227,11 +228,25 @@ static void do_stf_exit_barrier_fixups(e : "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)