2021-05-19 05:42:37

by Eric Biggers

[permalink] [raw]
Subject: Re: [PATCH 2/7] lib/mpi: use kcalloc in mpi_resize(Internet mail)

On Thu, May 13, 2021 at 02:49:03PM +0000, herberthbli(李弘博) wrote:
> 在 2021/5/13 3:08, Eric Biggers 写道:
>
> On Wed, May 12, 2021 at 10:04:09PM +0800, Hongbo Li wrote:
>
>
> From: Hongbo Li <[email protected]><mailto:[email protected]>
>
> We should set the additional space to 0 in mpi_resize().
> So use kcalloc() instead of kmalloc_array().
>
> Signed-off-by: Hongbo Li <[email protected]><mailto:[email protected]>
>
>
>
> Is this fixing something, and if so what?
>
> - Eric
>
>
>
> In lib/mpi/ec.c:
>
> /****************
> * Resize the array of A to NLIMBS. the additional space is cleared
> * (set to 0) [done by m_realloc()]
> */
> int mpi_resize(MPI a, unsigned nlimbs)
>
> Like the comment of kernel's mpi_resize(), the additional space need to set to 0,
> but when a->d is not NULL, it does not set.
>
> The kernel's mpi lib is from libgcrypt, the mpi resize in libgcrypt is _gcry_mpi_resize()
> which set the additional space to 0.
>
> This issue will cause add_points_edwards() get a wrong result, and lead to a failed
> eddsa verification.
>

That sounds like it's fixing an existing bug, regardless of the ed25519 support.
If that's indeed the case, what is the impact of that bug, and what commit is it
fixing? Please explain in the commit message and not just email.

- Eric


2021-05-19 18:12:46

by Hongbo Li

[permalink] [raw]
Subject: Re: [PATCH 2/7] lib/mpi: use kcalloc in mpi_resize(Internet mail)

Ok, I'll explain it in the next version of patches.
Regards,
Hongbo

Eric Biggers <[email protected]> 于2021年5月18日周二 上午5:29写道:
>
> On Thu, May 13, 2021 at 02:49:03PM +0000, herberthbli(李弘博) wrote:
> > 在 2021/5/13 3:08, Eric Biggers 写道:
> >
> > On Wed, May 12, 2021 at 10:04:09PM +0800, Hongbo Li wrote:
> >
> >
> > From: Hongbo Li <[email protected]><mailto:[email protected]>
> >
> > We should set the additional space to 0 in mpi_resize().
> > So use kcalloc() instead of kmalloc_array().
> >
> > Signed-off-by: Hongbo Li <[email protected]><mailto:[email protected]>
> >
> >
> >
> > Is this fixing something, and if so what?
> >
> > - Eric
> >
> >
> >
> > In lib/mpi/ec.c:
> >
> > /****************
> > * Resize the array of A to NLIMBS. the additional space is cleared
> > * (set to 0) [done by m_realloc()]
> > */
> > int mpi_resize(MPI a, unsigned nlimbs)
> >
> > Like the comment of kernel's mpi_resize(), the additional space need to set to 0,
> > but when a->d is not NULL, it does not set.
> >
> > The kernel's mpi lib is from libgcrypt, the mpi resize in libgcrypt is _gcry_mpi_resize()
> > which set the additional space to 0.
> >
> > This issue will cause add_points_edwards() get a wrong result, and lead to a failed
> > eddsa verification.
> >
>
> That sounds like it's fixing an existing bug, regardless of the ed25519 support.
> If that's indeed the case, what is the impact of that bug, and what commit is it
> fixing? Please explain in the commit message and not just email.
>
> - Eric