Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp387705pxj; Thu, 20 May 2021 11:37:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYTRXbn4wXpDNn9COXU0ZdZWlceXDRatjA/we2pwAceqH01SaKYjYgYfIXXqWv5O/oZFqD X-Received: by 2002:a02:7354:: with SMTP id a20mr8134011jae.94.1621535826277; Thu, 20 May 2021 11:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621535826; cv=none; d=google.com; s=arc-20160816; b=v3dq69rJeQkarY8ONnoUnafoGlNN+VmZhyW5EiAwxi4z6YY+Z/lIwu9+M2KQGfwDZ3 NsFkG/HvuDsnQZYNBNpLvMFp87N1+8GyuCF2yE+9imDUAPPX8Ds9XXw9oL2xXgO275t0 JsNp8PaKKmIXENS5agTXfoRWcslLVWNlPcn+BSk6p5eTuGpOaYzEKFzQC1ReBq0Ree7O uriQRzTJhT3nIYSXY9JOZB9beBgBvzvPoS3qP/fwU5cNAPOT2DCgmcfGq1IM49iah7CK qob/D1+nMuXybp4Yx4ihxhYWAtu5NooK9x1BnQsKXX6EJP/q//C7JXzZWbi5HbMzWsFh YxnQ== 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=oKTlTSQhxC0/ZUNOTn1rgIFjgFiXaHh0rNvYS/WnFpFr7LcWMET5BcQmE005ktcRv/ WwVk1q7skv3ggbodACw5hAPlkTB3M4h8dQG8i/uCbOvXpsqeOeQRK4hluxD77mi+9xsh 1k1+lCuRRPuueJusTF1HFLqxL3VPrvq30Y90fdVqSmKN/eIte5v7M44wKbWM87rV0ejN h7fb4xusMCYiSBfAMg3drAMlXVxQGMy9OF1hdOJ7TRkiAoBpvw9sfJCixkNgyA8+lguW DIaBeirOwwMw7T07Zgqs+2BHdK4egbGup7PJosF9a/rtQ1ptiIctqhCapTKkGxy7QdJC 4wnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GjOByuRM; 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 m20si3075747ioy.69.2021.05.20.11.36.51; Thu, 20 May 2021 11:37:06 -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=GjOByuRM; 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 S236549AbhETKYR (ORCPT + 99 others); Thu, 20 May 2021 06:24:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:48100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235257AbhETKNM (ORCPT ); Thu, 20 May 2021 06:13:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1E55C61441; Thu, 20 May 2021 09:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503849; bh=sHKdvmsp+KQS0Z+nfjFa5eZqQDZRwqxO69LGBBAmmcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GjOByuRMmjCsm9W0h3K7vbgPve5bEkLU4dOKNE6eaMlDCmpWzbnny9TpY1tu30r0Z c+yGee3/YscCBSTDPrw7skCzCVehbkCsgpxAWbrAhXC0tUhcL9wDliqTM6DM2fgFU1 OVb6WW2fUn7U75iHk6D9UgOdoEgJeIVgdofUD6s4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman Subject: [PATCH 4.19 363/425] powerpc/64s: Fix crashes when toggling stf barrier Date: Thu, 20 May 2021 11:22:12 +0200 Message-Id: <20210520092143.343257913@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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)