Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp34227pxj; Mon, 17 May 2021 20:10:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyckrr9bnpiyan/zWxIOT19bpq8hWSyzhFUOV0WqX0x7j0NYvyP3eW+CG3FcuIbE51UfjJj X-Received: by 2002:a5d:81c9:: with SMTP id t9mr2544155iol.45.1621307453625; Mon, 17 May 2021 20:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621307453; cv=none; d=google.com; s=arc-20160816; b=Zmfzlm0FbU3X6f9MQx41x/KJDL2FFr/PK+7FUfMpDJEfZJgJB1V9AWyt2cxrVAlomS tfCcg7BDbjV5SYr6v0+KvmnWFV+M7iggF26WL5l+zSNQRuDQE42ILGWNodjXNvvZnVO+ vCC1zERPC7yLBnPfHqcDrh/ufuJZ19SkFs8B2LHK2GJKccaVfAr9yJKjIT1+muWskE/0 VHCbIe0Wrivwmzi4yXeaffwrPv2iBb3tO9giBGpPL7QnhYAbae5xwwNdL7XgUkERLsA8 J/IbDChHnEb8JQUbbagwtRhsLlyYOG66zGGzlqLicYq+abpTNHaRC49Gpg6m4AkxzY4k K6nQ== 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=QI1KNBFnLt6gRPgU1QP5ezrtM7/xfEL9Z6Cgmpgi9q6I0/aaQ1AwTJkr0Gqe4LRPqf PfmJ6FDVyFpjuD0WmwM/fsBwNvfWSx/m73UrF5N7RN+puBJ2jkVyxgtAJ1lhSF83EniY M6Nr+Pej/Zrh6Iys5IRUyUAJ79D8IOplNS4+1oRbTWAqwOmLL03RleqBMbt0q8Cl4UW7 dBpO/zD8aTW9VaSYZQvxtd76Y+9H1SOe043qukRgpfzsoyOc2NCquJBDcZIyJdmLBRdV 8UwEBCXLUe93F2DNhEXWRynXfBwK8vwWLc7AEyI9RNEvuGdkZoCu6zDEQ30zms3/ZiqF AOSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xBsEARLu; 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 a17si24136539iol.19.2021.05.17.20.10.13; Mon, 17 May 2021 20:10:53 -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=xBsEARLu; 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 S241050AbhEQOi3 (ORCPT + 99 others); Mon, 17 May 2021 10:38:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:43198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240264AbhEQOdl (ORCPT ); Mon, 17 May 2021 10:33:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 15F626191D; Mon, 17 May 2021 14:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260972; bh=EAfkBS4b60opCiLOVlnBupkfa4IP9sMSU+ZZMIUm5Rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xBsEARLuxr5fnzrtqgf49C3Cfp2rKDNBz6u7gzkSFyaC5aWzDxyVoF+V+SujDO3KM iyYGb3JzTslK1Y5Ks4HfHHVMG7ZU9m5vfQhqaYLmLU0PjtcAMnfyJJfnvighiA54Xi BoY97ENOkIi6qdV1FGA/Lk81lj2fdrRvwteTkjpg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman Subject: [PATCH 5.12 252/363] powerpc/64s: Fix crashes when toggling stf barrier Date: Mon, 17 May 2021 16:01:58 +0200 Message-Id: <20210517140311.112554612@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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)