Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5505660pxb; Wed, 26 Jan 2022 13:38:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJya2+AXi33WmpCoDcoeBlN1SKGErXfqgKpSI6Ily1OcxHUjDGFJ/dBbb3a3DTIri7pa5HnX X-Received: by 2002:a17:907:1c0c:: with SMTP id nc12mr467070ejc.653.1643233135159; Wed, 26 Jan 2022 13:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643233135; cv=none; d=google.com; s=arc-20160816; b=ooRnYu1FZlrGX0nyUwcr4jONArp3zZrdPBixwHYfjs3eOeCxcZVCueDPgpIS0OF3jX 7f346AWTS8qqZOXyw+IONoOaUVyj+0V813LAK454N2anG+HzSNiR7ycEXiYciHz4JVtt dvNUGs2S/sbbff26P7SpIf5kaA8zAx0VX0IGkYHzgbeJnfKhNLyQrntX6v/o/Dhi+8hj rLCdLZUqVWoQXjBIwg9zaxMyIz2NQyCzaz/H+OaSbXEVszvw0I0PsuEVXxsR7HrZijP0 GOCyPRXFnfm25eho2VYdpuYRjrW0ufzfczsShMxR9Eg0JuhzVJXo9DZRw7Fxqy4OYBIx XNlw== 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 :message-id:date:subject:cc:to:from; bh=5RsHN/Yt/J+IU4KUw56KEWGbBYUZEJnHdu88pXXwHUI=; b=tYEj9Tzf6cduJDF9vQwSKTWhD30O9cktLvc6n0luU8gkujz8A4eMiepTYYu38fliHk PB1IPx74Pji1HcxKq5X7z2m+pdnznSXhTlUfIX27+IYaw1UHwGK2rWreUWs6oul9+xCQ dBp+Qgt2AcO2EVaygvQGiNuJmRXx6vTYu9zhzfMbi+oSpUTthUEGt0aW+tifB/mtJXkj rAPOXU3QC5Y9nf9r0YwPMHhAO306zMoMFEpQQtGXqRrSauxbZvZgCIWhv3gQzrSv+zcp xCVubGyJzsNZ4eLQbvZD4pLsOLzLZoAh3D0L2GFFbTyyW/7CbOedcrH/vBUZqFpkg2+s D2Zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si232669ejk.169.2022.01.26.13.38.28; Wed, 26 Jan 2022 13:38:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242339AbiAZOxd (ORCPT + 99 others); Wed, 26 Jan 2022 09:53:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235644AbiAZOxd (ORCPT ); Wed, 26 Jan 2022 09:53:33 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E297CC06161C for ; Wed, 26 Jan 2022 06:53:32 -0800 (PST) Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1nCjfv-0004Wa-B0; Wed, 26 Jan 2022 15:53:31 +0100 From: Philipp Zabel To: linux-crypto@vger.kernel.org Cc: Herbert Xu , "David S. Miller" , kernel@pengutronix.de Subject: [PATCH] crypto: algapi - Remove test larvals to fix error paths Date: Wed, 26 Jan 2022 15:53:22 +0100 Message-Id: <20220126145322.646723-1-p.zabel@pengutronix.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-crypto@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org If crypto_unregister_alg() is called with an algorithm that still has a pending test larval, the algorithm will have a reference count of 2 and crypto_unregister_alg() will trigger a BUG(). This can happen during cleanup if the error path is taken for a built-in algorithm, before crypto_algapi_init() was called. Kill test larvals for untested algorithms during removal to fix the reference count. Fixes: adad556efcdd ("crypto: api - Fix built-in testing dependency failures") Signed-off-by: Philipp Zabel --- crypto/algapi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crypto/algapi.c b/crypto/algapi.c index a366cb3e8aa1..fc3b75e59d0e 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -458,6 +458,28 @@ void crypto_unregister_alg(struct crypto_alg *alg) if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name)) return; + /* If there is a test larval holding a reference, remove it */ + if (!(alg->cra_flags & CRYPTO_ALG_TESTED)) { + struct crypto_alg *q, *n; + + list_for_each_entry_safe(q, n, &crypto_alg_list, cra_list) { + struct crypto_larval *l; + + if (!crypto_is_larval(q)) + continue; + + l = (void *)q; + + if (!crypto_is_test_larval(l)) + continue; + + if (l->adult != alg) + continue; + + crypto_larval_kill(q); + } + } + BUG_ON(refcount_read(&alg->cra_refcnt) != 1); if (alg->cra_destroy) alg->cra_destroy(alg); base-commit: e783362eb54cd99b2cac8b3a9aeac942e6f6ac07 -- 2.30.2