Skip to contentSkip to conversation

lib/mpi: fix off-by-one check on index "no"

PATCH Superseded Colin King 2 participants 2 messages Sep 29, 2020 – Sep 30, 2020 Kernel janitors

lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 lib/mpi: fix off-by-one check on index "no"

From: Colin Ian King <[email protected]>

There is an off-by-one range check on the upper limit of index "no". Fix this by changing the > comparison to >
Addresses-Coverity: ("Out-of-bounds read")

Fixes a8ea8bdd9df9 ("lib/mpi: Extend the MPI library")
---
 lib/mpi/mpiutil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/mpi/mpiutil.c +1 -1
index 3c63710c20c6..632d0a4bf93f 100644
@@ -69,7 +69,7 @@ postcore_initcall(mpi_init);
  */
 MPI mpi_const(enum gcry_mpi_constants no)
 {
-	if ((int)no < 0 || no > MPI_NUMBER_OF_CONSTANTS)
+	if ((int)no < 0 || no >= MPI_NUMBER_OF_CONSTANTS)
 		pr_err("MPI: invalid mpi_const selector %d\n", no);
 	if (!constants[no])
 		pr_err("MPI: MPI subsystem not initialized\n");
Signature · 1 line
2.27.0
#1 lore raw
Quoted 10 lines · Colin King

From: Colin Ian King <[email protected]>

There is an off-by-one range check on the upper limit of index "no". Fix this by changing the > comparison to >>
Addresses-Coverity: ("Out-of-bounds read")

Fixes a8ea8bdd9df9 ("lib/mpi: Extend the MPI library")
---
 lib/mpi/mpiutil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Could you resend this with a cc to linux-crypto?

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt