From patchwork Thu Apr 9 09:40:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 6186411 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 58F179F349 for ; Thu, 9 Apr 2015 09:41:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 84C8020376 for ; Thu, 9 Apr 2015 09:41:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 994CF20375 for ; Thu, 9 Apr 2015 09:41:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934200AbbDIJkn (ORCPT ); Thu, 9 Apr 2015 05:40:43 -0400 Received: from helcar.hengli.com.au ([209.40.204.226]:52798 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933646AbbDIJkk (ORCPT ); Thu, 9 Apr 2015 05:40:40 -0400 Received: from gondolin.me.apana.org.au ([192.168.0.6]) by norbury.hengli.com.au with esmtp (Exim 4.80 #3 (Debian)) id 1Yg8wv-0007LI-Pc; Thu, 09 Apr 2015 19:40:37 +1000 Received: from herbert by gondolin.me.apana.org.au with local (Exim 4.80) (envelope-from ) id 1Yg8wu-0001Op-7p; Thu, 09 Apr 2015 17:40:36 +0800 Date: Thu, 9 Apr 2015 17:40:35 +0800 From: Herbert Xu To: Stephan Mueller Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] crypto: remove instance when test failed Message-ID: <20150409094035.GA5327@gondor.apana.org.au> References: <1461449.htSjBpksos@tachyon.chronox.de> <20150409074141.GA4394@gondor.apana.org.au> <9590265.Rdkakn8z8k@tauon> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <9590265.Rdkakn8z8k@tauon> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Apr 09, 2015 at 11:22:19AM +0200, Stephan Mueller wrote: > > I tested it and this approach does not work. > > If I see that right, the reason for that is the following: The suggestion is > to grab the ref count at the start of the function followed by a > __crypto_register_alg. __crypto_register_alg however sets the refcount to 1 > unconditionally. That means that the final put of the alg will most likely set > the refcount to 0 that causes an issue with all other operations (at least I > cannot allocate HMAC or CMAC any more -- the ones I currently test). > > So, the grabing of the alg must happen after the invocation of > __crypto_register_alg. Well let's move it then. ---8<--- crypto: api - Move alg ref count init to crypto_check_alg We currently initialise the crypto_alg ref count in the function __crypto_register_alg. As one of the callers of that function crypto_register_instance needs to obtain a ref count before it calls __crypto_register_alg, we need to move the initialisation out of there. Since both callers of __crypto_register_alg call crypto_check_alg, this is the logical place to perform the initialisation. Signed-off-by: Herbert Xu Acked-by: Stephan Mueller diff --git a/crypto/algapi.c b/crypto/algapi.c index f1d0307..1462c68 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -64,6 +64,8 @@ static int crypto_check_alg(struct crypto_alg *alg) if (alg->cra_priority < 0) return -EINVAL; + atomic_set(&alg->cra_refcnt, 1); + return crypto_set_driver_name(alg); } @@ -187,7 +189,6 @@ static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg) ret = -EEXIST; - atomic_set(&alg->cra_refcnt, 1); list_for_each_entry(q, &crypto_alg_list, cra_list) { if (q == alg) goto err;