* [PATCH] crypto: ecc: fix NULL pointer dereferencing in ecc_gen_privkey()
@ 2024-03-07 7:13 Roman Smirnov
2024-03-21 9:54 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Roman Smirnov @ 2024-03-07 7:13 UTC (permalink / raw)
To: Herbert Xu, David S. Miller
Cc: Roman Smirnov, Sergey Shtylyov, Karina Yankevich, linux-crypto,
linux-kernel, lvc-project
ecc_get_curve() can return NULL. It is necessary to check
for NULL before dereferencing.
Found by Linux Verification Center (linuxtesting.org) with Svace.
Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---
crypto/ecc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/crypto/ecc.c b/crypto/ecc.c
index f53fb4d6af99..fd63e354895b 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -1471,9 +1471,14 @@ int ecc_gen_privkey(unsigned int curve_id, unsigned int ndigits, u64 *privkey)
const struct ecc_curve *curve = ecc_get_curve(curve_id);
u64 priv[ECC_MAX_DIGITS];
unsigned int nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT;
- unsigned int nbits = vli_num_bits(curve->n, ndigits);
+ unsigned int nbits;
int err;
+ if (!curve)
+ return -EINVAL;
+
+ nbits = vli_num_bits(curve->n, ndigits);
+
/* Check that N is included in Table 1 of FIPS 186-4, section 6.1.1 */
if (nbits < 160 || ndigits > ARRAY_SIZE(priv))
return -EINVAL;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: ecc: fix NULL pointer dereferencing in ecc_gen_privkey()
2024-03-07 7:13 [PATCH] crypto: ecc: fix NULL pointer dereferencing in ecc_gen_privkey() Roman Smirnov
@ 2024-03-21 9:54 ` Herbert Xu
2024-03-21 12:01 ` Roman Smirnov
0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2024-03-21 9:54 UTC (permalink / raw)
To: Roman Smirnov
Cc: David S. Miller, Sergey Shtylyov, Karina Yankevich, linux-crypto,
linux-kernel, lvc-project
On Thu, Mar 07, 2024 at 10:13:18AM +0300, Roman Smirnov wrote:
> ecc_get_curve() can return NULL. It is necessary to check
> for NULL before dereferencing.
>
> Found by Linux Verification Center (linuxtesting.org) with Svace.
>
> Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> ---
> crypto/ecc.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
Please point me to the exact code path where this can happen.
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: ecc: fix NULL pointer dereferencing in ecc_gen_privkey()
2024-03-21 9:54 ` Herbert Xu
@ 2024-03-21 12:01 ` Roman Smirnov
0 siblings, 0 replies; 3+ messages in thread
From: Roman Smirnov @ 2024-03-21 12:01 UTC (permalink / raw)
To: Herbert Xu
Cc: David S. Miller, Sergey Shtylyov, Karina Yankevich,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
lvc-project@linuxtesting.org
On Thu, 21 Mar 2024 17:54:44 +0800, Herbert Xu wrote:
> On Thu, Mar 07, 2024 at 10:13:18AM +0300, Roman Smirnov wrote:
> > ecc_get_curve() can return NULL. It is necessary to check
> > for NULL before dereferencing.
> >
> > Found by Linux Verification Center (linuxtesting.org) with Svace.
> >
> > Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
> > Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> > ---
> > crypto/ecc.c | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
>
> Please point me to the exact code path where this can happen.
I didn't find a specific path. Several places in the file have this
check:
ecc_make_pub_key()
crypto_ecdh_shared_secret()
I thought it was needed in this place too.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-21 12:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07 7:13 [PATCH] crypto: ecc: fix NULL pointer dereferencing in ecc_gen_privkey() Roman Smirnov
2024-03-21 9:54 ` Herbert Xu
2024-03-21 12:01 ` Roman Smirnov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox