Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5972884pxb; Thu, 27 Jan 2022 03:50:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCa484IGjBO+rVA3xbVOLkO33BBsBRAHHcLUUWDhtJgACtDBNNMJkQR+epG/0nO9wmkz1f X-Received: by 2002:a05:6402:2079:: with SMTP id bd25mr3321166edb.274.1643284212060; Thu, 27 Jan 2022 03:50:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643284212; cv=none; d=google.com; s=arc-20160816; b=xK+3Wp6Hvr51JCH66vqgUxQtxHr0sjqCse0pHcRSTF0lkZYIB6Hb3FxOKgaE+uKDk1 ELUgh2Rg0KaCscRJSdV+LAxLAyX1ZAOBQRs/KBa2WeJi3kaWHkq2hi8IWK6HjnruqDll kQN26YiICbIsuWM+H6tkwQQQWoFBacS+h2Gys1l2XlUyDmN4RDfX4rCRxqWC6zEKozKa XFmReCKNmIOTaDN9vsUloOkTzV8GtOrPk7ItfLCyv196zEfmW4SqhJx7NR2EQgxKVUNr 3/tRNhuh3pP6G6Cyz/1rVRgt0uahji4+Pyjo4HXyHCOrZSAreShbe69uqRjqwUM2aO3P q5QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=64puiuqIEYh0aR25fDc8Kco5qw9Bo42+ITIkvJnUZ3U=; b=hf2tHdN0X2EW35U4NkIPlPAxSbDN9PFtMlQW/Yul5KwoWNbdiNedtRBSopBNYlfTiC dEWO+Xr/JZRpIgeUtU1UFMYwRPkTMwekuFF3WvhFa7EERL3WV8NsvxJWoZgcJa8fOPat P8W+mERy5bVRcHjphjMwJaRHno6xpXJ1b4TJU3pMUvZzMjQXx6fJFnrqfWjpER2SkKgx 1TyZjKguJ03gx85xrPGsE2lsB8RiTLPrlI6D34EBG/TKjyGsyTIueEJzdilz4aGvVIoP ihDcl8nrHtmMQeqeGxmQqmEe+komDKW3HJZmLZ0BOn07HU66By8V9LymGQRcxgJm5u8t fYKw== 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 18si1192114ejm.511.2022.01.27.03.49.40; Thu, 27 Jan 2022 03:50:11 -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 S236054AbiA0Ele (ORCPT + 99 others); Wed, 26 Jan 2022 23:41:34 -0500 Received: from helcar.hmeau.com ([216.24.177.18]:60508 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbiA0Eld (ORCPT ); Wed, 26 Jan 2022 23:41:33 -0500 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.103.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1nCwbC-0007sh-UK; Thu, 27 Jan 2022 15:41:32 +1100 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Thu, 27 Jan 2022 15:41:30 +1100 Date: Thu, 27 Jan 2022 15:41:30 +1100 From: Herbert Xu To: Philipp Zabel Cc: linux-crypto@vger.kernel.org, "David S. Miller" , kernel@pengutronix.de Subject: Re: [PATCH] crypto: algapi - Remove test larvals to fix error paths Message-ID: References: <20220126145322.646723-1-p.zabel@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220126145322.646723-1-p.zabel@pengutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Jan 26, 2022 at 03:53:22PM +0100, Philipp Zabel wrote: > 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(+) Yes this is definitely a bug. However, I think simply fixing this for test larvals is not enough. After all, another thread could come through the middle and take a reference to our newly minted algorithm before a subsequent algorithm registration failure and thus would trigger exactly the same crash. So we need something a bit more general. Previously we relied on module reference counts to stop the unregistering of live algorithms. But that is clearly not of any use in this case. It also fails for hardware devices than can be unplugged. One solution would be to simply allow the unregistration to continue and only free the data structures after all references have gone away. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt