Message ID | 1620828254-25545-3-git-send-email-herbert.tencent@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Herbert Xu |
Headers | show |
Series | crypto: add eddsa support for x509 | expand |
On Wed, May 12, 2021 at 10:04:09PM +0800, Hongbo Li wrote: > From: Hongbo Li <herberthbli@tencent.com> > > We should set the additional space to 0 in mpi_resize(). > So use kcalloc() instead of kmalloc_array(). > > Signed-off-by: Hongbo Li <herberthbli@tencent.com> Is this fixing something, and if so what? - Eric
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 <herberthbli@tencent.com><mailto:herberthbli@tencent.com> > > We should set the additional space to 0 in mpi_resize(). > So use kcalloc() instead of kmalloc_array(). > > Signed-off-by: Hongbo Li <herberthbli@tencent.com><mailto:herberthbli@tencent.com> > > > > 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
Ok, I'll explain it in the next version of patches. Regards, Hongbo Eric Biggers <ebiggers@kernel.org> 于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 <herberthbli@tencent.com><mailto:herberthbli@tencent.com> > > > > We should set the additional space to 0 in mpi_resize(). > > So use kcalloc() instead of kmalloc_array(). > > > > Signed-off-by: Hongbo Li <herberthbli@tencent.com><mailto:herberthbli@tencent.com> > > > > > > > > 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
diff --git a/lib/mpi/mpiutil.c b/lib/mpi/mpiutil.c index 3c63710..e6c4b31 100644 --- a/lib/mpi/mpiutil.c +++ b/lib/mpi/mpiutil.c @@ -148,7 +148,7 @@ int mpi_resize(MPI a, unsigned nlimbs) return 0; /* no need to do it */ if (a->d) { - p = kmalloc_array(nlimbs, sizeof(mpi_limb_t), GFP_KERNEL); + p = kcalloc(nlimbs, sizeof(mpi_limb_t), GFP_KERNEL); if (!p) return -ENOMEM; memcpy(p, a->d, a->alloced * sizeof(mpi_limb_t));