Skip to content

Commit 8fd0478

Browse files
herberthbliKelsey Skunberg
authored andcommitted
lib/mpi: use kcalloc in mpi_resize
BugLink: https://bugs.launchpad.net/bugs/1946024 [ Upstream commit b6f7567 ] We should set the additional space to 0 in mpi_resize(). So use kcalloc() instead of kmalloc_array(). 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() said, the additional space need to be 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 bug may cause mpi api which use mpi_resize() get wrong result under the condition of using the additional space without initiation. If this condition is not met, the bug would not be triggered. Currently in kernel, rsa, sm2 and dh use mpi lib, and they works well, so the bug is not triggered in these cases. add_points_edwards() use the additional space directly, so it will get a wrong result. Fixes: cdec9cb ("crypto: GnuPG based MPI lib - source files (part 1)") Signed-off-by: Hongbo Li <[email protected]> Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Kelsey Skunberg <[email protected]>
1 parent 65d7312 commit 8fd0478

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/mpi/mpiutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int mpi_resize(MPI a, unsigned nlimbs)
9191
return 0; /* no need to do it */
9292

9393
if (a->d) {
94-
p = kmalloc_array(nlimbs, sizeof(mpi_limb_t), GFP_KERNEL);
94+
p = kcalloc(nlimbs, sizeof(mpi_limb_t), GFP_KERNEL);
9595
if (!p)
9696
return -ENOMEM;
9797
memcpy(p, a->d, a->alloced * sizeof(mpi_limb_t));

0 commit comments

Comments
 (0)