From: Roman Smirnov <r.smirnov@omp.ru>
To: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: Roman Smirnov <r.smirnov@omp.ru>,
Mimi Zohar <zohar@linux.ibm.com>,
Sergey Shtylyov <s.shtylyov@omp.ru>,
<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<lvc-project@linuxtesting.org>
Subject: [PATCH] crypto: mpi: add NULL checks to mpi_normalize().
Date: Tue, 16 Jul 2024 11:28:25 +0300 [thread overview]
Message-ID: <20240716082825.65219-1-r.smirnov@omp.ru> (raw)
If a->d is NULL, the NULL pointer will be dereferenced. It
is necessary to prevent this case. There is at least one call
stack that can lead to it:
mpi_ec_curve_point()
ec_pow2()
ec_mulm()
ec_mod()
mpi_mod()
mpi_fdiv_r()
mpi_tdiv_r()
mpi_tdiv_qr()
mpi_resize()
kcalloc()
mpi_resize can return -ENOMEM, but this case is not handled in any way.
Next, dereferencing takes place:
mpi_ec_curve_point()
mpi_cmp()
do_mpi_cmp()
mpi_normalize()
Found by Linux Verification Center (linuxtesting.org) with Svace.
Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
---
lib/crypto/mpi/mpi-bit.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/crypto/mpi/mpi-bit.c b/lib/crypto/mpi/mpi-bit.c
index 070ba784c9f1..d7420bdb4ff2 100644
--- a/lib/crypto/mpi/mpi-bit.c
+++ b/lib/crypto/mpi/mpi-bit.c
@@ -29,6 +29,9 @@
*/
void mpi_normalize(MPI a)
{
+ if (!a || !a->d)
+ return;
+
for (; a->nlimbs && !a->d[a->nlimbs - 1]; a->nlimbs--)
;
}
--
2.34.1
next reply other threads:[~2024-07-16 8:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 8:28 Roman Smirnov [this message]
2024-08-02 12:46 ` [PATCH] crypto: mpi: add NULL checks to mpi_normalize() Herbert Xu
2024-08-07 14:20 ` Roman Smirnov
2024-08-09 4:28 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240716082825.65219-1-r.smirnov@omp.ru \
--to=r.smirnov@omp.ru \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=s.shtylyov@omp.ru \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox