lkml.org 
[lkml]   [2015]   [Apr]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v3] crypto: remove instance when test failed
Date
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


\
 
 \ /
  Last update: 2015-04-09 12:01    [W:0.054 / U:3.452 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site