Re: [PATCH] crypto: rsa - add a check for allocation failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 30, 2023 at 12:15:19PM +0300, Dan Carpenter wrote:
> On Mon, Oct 30, 2023 at 05:11:33PM +0800, Herbert Xu wrote:
> > On Mon, Oct 30, 2023 at 12:02:59PM +0300, Dan Carpenter wrote:
> > > Static checkers insist that the mpi_alloc() allocation can fail so add
> > > a check to prevent a NULL dereference.  Small allocations like this
> > > can't actually fail in current kernels, but adding a check is very
> > > simple and makes the static checkers happy.
> > > 
> > > Fixes: 6637e11e4ad2 ("crypto: rsa - allow only odd e and restrict value in FIPS mode")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> > > ---
> > >  crypto/rsa.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > 
> > Nack.  Please fix the static checker instead.
> 
> The checker is not wrong.  Kernel policy is that every allocation has
> to be checked for failure.  In *current* kernels it won't but we have
> discussed changing this so the policy makes sense.

One way to fix the code would be to take gfp parameter and let people
pass a GFP_NOFAIL.  Unless there is a GFP_NOFAIL then the policy is that
the allocation can fail.

Or you could take the brtfs v1 approach and follow every kmalloc() with
a:
	p = kmalloc();
	BUG_on(!p);

regards,
dan carpenter




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux