]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
lib/mpi: use kcalloc in mpi_resize
authorHongbo Li <herberthbli@tencent.com>
Thu, 5 Aug 2021 08:53:32 +0000 (16:53 +0800)
committerKelsey Skunberg <kelsey.skunberg@canonical.com>
Mon, 11 Oct 2021 23:08:45 +0000 (17:08 -0600)
commit8fd04787c1bd75bd474377dbde0853edd192a809
tree18140c7437be784200ee4b45521554320e938f19
parent65d7312dc575bf671611f51f90b52fbef539061f
lib/mpi: use kcalloc in mpi_resize

BugLink: https://bugs.launchpad.net/bugs/1946024
[ Upstream commit b6f756726e4dfe75be1883f6a0202dcecdc801ab ]

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: cdec9cb5167a ("crypto: GnuPG based MPI lib - source files (part 1)")
Signed-off-by: Hongbo Li <herberthbli@tencent.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
lib/mpi/mpiutil.c