linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephan Mueller <smueller@chronox.de>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] crypto: remove instance when test failed
Date: Thu, 09 Apr 2015 11:22:19 +0200	[thread overview]
Message-ID: <9590265.Rdkakn8z8k@tauon> (raw)
In-Reply-To: <20150409074141.GA4394@gondor.apana.org.au>

Am Donnerstag, 9. April 2015, 15:41:41 schrieb Herbert Xu:

Hi Herbert,

>On Thu, Apr 09, 2015 at 09:36:03AM +0200, Stephan Mueller wrote:
>> diff --git a/crypto/algapi.c b/crypto/algapi.c
>> index f1d0307..cfca1de 100644
>> --- a/crypto/algapi.c
>> +++ b/crypto/algapi.c
>> @@ -533,6 +533,13 @@ int crypto_register_instance(struct crypto_template
>> *tmpl,> 
>>  	if (IS_ERR(larval))
>>  	
>>  		goto unlock;
>> 
>> +	err = -EAGAIN;
>> +	if (unlikely(!crypto_mod_get(&inst->alg))) {
>> +		up_write(&crypto_alg_sem);
>> +		crypto_unregister_instance(inst);
>> +		goto err;
>> +	}
>
>Just grab the reference count as soon as you enter the function
>and then you can unconditionally drop the reference count at the
>end.  If you fail to grab it then just return an error and the
>caller will free it for you.

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.
>
>Cheers,


Ciao
Stephan

  reply	other threads:[~2015-04-09  9:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-09  7:36 [PATCH v3] crypto: remove instance when test failed Stephan Mueller
2015-04-09  7:41 ` Herbert Xu
2015-04-09  9:22   ` Stephan Mueller [this message]
2015-04-09  9:40     ` Herbert Xu
2015-04-09 10:05       ` Stephan Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9590265.Rdkakn8z8k@tauon \
    --to=smueller@chronox.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).