[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4575667.y41LbVH5lo@tauon.chronox.de>
Date: Fri, 05 Jun 2020 08:52:57 +0200
From: Stephan Mueller <smueller@...onox.de>
To: Eric Biggers <ebiggers@...nel.org>
Cc: Dan Carpenter <dan.carpenter@...cle.com>, davem@...emloft.net,
herbert@...dor.apana.org.au, linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com,
syzbot <syzbot+2e635807decef724a1fa@...kaller.appspotmail.com>
Subject: Re: [PATCH v2] crypto: DRBG - always try to free Jitter RNG instance
Am Freitag, 5. Juni 2020, 08:16:46 CEST schrieb Eric Biggers:
Hi Eric,
> On Fri, Jun 05, 2020 at 07:58:15AM +0200, Stephan Mueller wrote:
> > Am Freitag, 5. Juni 2020, 02:43:36 CEST schrieb Eric Biggers:
> >
> > Hi Eric,
> >
> > > On Thu, Jun 04, 2020 at 08:41:00AM +0200, Stephan Müller wrote:
> > > > The Jitter RNG is unconditionally allocated as a seed source follwoing
> > > > the patch 97f2650e5040. Thus, the instance must always be deallocated.
> > > >
> > > > Reported-by: syzbot+2e635807decef724a1fa@...kaller.appspotmail.com
> > > > Fixes: 97f2650e5040 ("crypto: drbg - always seeded with SP800-90B
> > > > ...")
> > > > Signed-off-by: Stephan Mueller <smueller@...onox.de>
> > > > ---
> > > >
> > > > crypto/drbg.c | 3 +++
> > > > 1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/crypto/drbg.c b/crypto/drbg.c
> > > > index 37526eb8c5d5..8a0f16950144 100644
> > > > --- a/crypto/drbg.c
> > > > +++ b/crypto/drbg.c
> > > > @@ -1631,6 +1631,9 @@ static int drbg_uninstantiate(struct drbg_state
> > > > *drbg)>
> > > >
> > > > if (drbg->random_ready.func) {
> > > >
> > > > del_random_ready_callback(&drbg->random_ready);
> > > > cancel_work_sync(&drbg->seed_work);
> > > >
> > > > + }
> > > > +
> > > > + if (!IS_ERR_OR_NULL(drbg->jent)) {
> > > >
> > > > crypto_free_rng(drbg->jent);
> > > > drbg->jent = NULL;
> > > >
> > > > }
> > >
> > > It it okay that ->jent can be left as an ERR_PTR() value?
> > >
> > > Perhaps it should always be set to NULL?
> >
> > The error value is used in the drbg_instantiate function. There it is
> > checked whether -ENOENT (i.e. the cipher is not available) or any other
> > error is present. I am not sure we should move that check.
> >
> > Thanks for the review.
>
> drbg_seed() and drbg_async_seed() check for drbg->jent being NULL.
>
> Will that now break due it drbg->jent possibly being an ERR_PTR()?
>
> Hence why I'm asking whether drbg_uninstantiate() should set it to NULL.
The allocation happens in drbg_prepare_hrng that is only invoked by
drbg_instantiate.
drbg_instantiate checks for the ERR_PTR and sets it to NULL in case the error
is deemed ok.
Thus, any subsequent functions would see either a valid pointer or NULL. The
only exception is drbg_uninstantiate when invoked from the error case
ret = drbg_prepare_hrng(drbg);
if (ret)
goto free_everything;
Thus, I think that the two functions you mention will never see any values
other than NULL or a valid pointer.
Thanks
Ciao
Stephan
Powered by blists - more mailing lists