[lvc-project] [PATCH] crypto: mpi: add NULL checks to mpi_normalize().

Herbert Xu herbert at gondor.apana.org.au
Fri Aug 2 15:46:52 MSK 2024


On Tue, Jul 16, 2024 at 11:28:25AM +0300, Roman Smirnov wrote:
> If a->d is NULL, the NULL pointer will be dereferenced. It
> is necessary to prevent this case. There is at least one call
> stack that can lead to it:
> 
>     mpi_ec_curve_point()
>       ec_pow2()
>         ec_mulm()
>           ec_mod()
>             mpi_mod()
>               mpi_fdiv_r()
>                 mpi_tdiv_r()
>                   mpi_tdiv_qr()
>                     mpi_resize()
>                       kcalloc()
> 
> mpi_resize can return -ENOMEM, but this case is not handled in any way.
> 
> Next, dereferencing takes place:
> 
>     mpi_ec_curve_point()
>       mpi_cmp()
>         do_mpi_cmp()
>           mpi_normalize()
> 
> Found by Linux Verification Center (linuxtesting.org) with Svace.
> 
> Signed-off-by: Roman Smirnov <r.smirnov at omp.ru>
> ---
>  lib/crypto/mpi/mpi-bit.c | 3 +++
>  1 file changed, 3 insertions(+)

I've just posted a patch to remove mpi_ec_curve_point and mpi_tdiv_qr.
Are there any other code paths with the same problem?

Thanks,
-- 
Email: Herbert Xu <herbert at gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt



More information about the lvc-project mailing list