From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44558C77B7D for ; Sun, 7 May 2023 04:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230039AbjEGEJL (ORCPT ); Sun, 7 May 2023 00:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbjEGEJH (ORCPT ); Sun, 7 May 2023 00:09:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5F0372BA for ; Sat, 6 May 2023 21:09:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 77966617DA for ; Sun, 7 May 2023 04:09:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80C87C433EF; Sun, 7 May 2023 04:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1683432545; bh=x67cAvSCcH0HEy2IYm3cCHQnPKHQq1kAOz5nSFBuXI8=; h=Subject:To:Cc:From:Date:From; b=2vyAJY7LTic3J1s6njIR1fH5fMhzUPBR/qcIEVCdgY+bF6PIdywXKKtuQ8O4bvtR8 47/ulyjoqKYJQ/YbRtm374D54YTSvjO/XnRbgB7sykZsUMK94YZasp7qden02xdXek zlYrwo8jGvLoqx1pzBcRf8Ioa9qg8veKGMRgXvmg= Subject: FAILED: patch "[PATCH] crypto: api - Demote BUG_ON() in crypto_unregister_alg() to a" failed to apply to 4.19-stable tree To: toke@redhat.com, herbert@gondor.apana.org.au Cc: From: Date: Sun, 07 May 2023 06:09:02 +0200 Message-ID: <2023050702-hasty-matted-a47d@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch below does not apply to the 4.19-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-4.19.y git checkout FETCH_HEAD git cherry-pick -x a543ada7db729514ddd3ba4efa45f4c7b802ad85 # git commit -s git send-email --to '' --in-reply-to '2023050702-hasty-matted-a47d@gregkh' --subject-prefix 'PATCH 4.19.y' HEAD^.. Possible dependencies: a543ada7db72 ("crypto: api - Demote BUG_ON() in crypto_unregister_alg() to a WARN_ON()") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From a543ada7db729514ddd3ba4efa45f4c7b802ad85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= Date: Mon, 13 Mar 2023 10:17:24 +0100 Subject: [PATCH] crypto: api - Demote BUG_ON() in crypto_unregister_alg() to a WARN_ON() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The crypto_unregister_alg() function expects callers to ensure that any algorithm that is unregistered has a refcnt of exactly 1, and issues a BUG_ON() if this is not the case. However, there are in fact drivers that will call crypto_unregister_alg() without ensuring that the refcnt has been lowered first, most notably on system shutdown. This causes the BUG_ON() to trigger, which prevents a clean shutdown and hangs the system. To avoid such hangs on shutdown, demote the BUG_ON() in crypto_unregister_alg() to a WARN_ON() with early return. Cc stable because this problem was observed on a 6.2 kernel, cf the link below. Link: https://lore.kernel.org/r/87r0tyq8ph.fsf@toke.dk Cc: stable@vger.kernel.org Signed-off-by: Toke Høiland-Jørgensen Signed-off-by: Herbert Xu diff --git a/crypto/algapi.c b/crypto/algapi.c index 9b7e263ed469..d7eb8f9e9883 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -491,7 +491,9 @@ void crypto_unregister_alg(struct crypto_alg *alg) if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name)) return; - BUG_ON(refcount_read(&alg->cra_refcnt) != 1); + if (WARN_ON(refcount_read(&alg->cra_refcnt) != 1)) + return; + if (alg->cra_destroy) alg->cra_destroy(alg);