Re: [PATCH] crypto: drbg - convert to guard(mutex)

From: Rajveer Chaudhari

Date: Sun Mar 01 2026 - 06:47:24 EST


On Sat, Feb 28, 2026 at 8:51 AM Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> wrote:
> Please keep the headers sorted alphabetically.
>
> > free_everything:
> > - mutex_unlock(&drbg->drbg_mutex);
> > drbg_uninstantiate(drbg);
> > return ret;
>
> This is a subtle change and now drbg_uninstantiate will be called
> within the critical section. Are you sure this is safe?

Yes, this is safe. I traced through all functions called by
drbg_uninstantiate():

- crypto_free_rng()
- d_ops->crypto_fini()
- drbg_dealloc_state()

None of them attempt to acquire drbg_mutex, so there is no risk of
deadlock. The mutex only coordinates thread access and does not
restrict memory access itself, so drbg_uninstantiate() can safely
access and free drbg fields while the lock is held.

In fact, holding the mutex during drbg_uninstantiate() is
more correct than the original, as it prevents another thread from
accessing the drbg state while it is being freed on the error path.

I will also fix the header ordering in v2.

Thanks for the review.

Regards,
Rajveer Chaudhari