Return-Path: Received: from mail-by2nam01on0106.outbound.protection.outlook.com ([104.47.34.106]:13662 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933155AbeCCW2N (ORCPT ); Sat, 3 Mar 2018 17:28:13 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Pierre , Herbert Xu , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 16/84] crypto: ecc - Fix NULL pointer deref. on no default_rng Date: Sat, 3 Mar 2018 22:26:09 +0000 Message-ID: <20180303222518.26271-16-alexander.levin@microsoft.com> References: <20180303222518.26271-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222518.26271-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Pierre [ Upstream commit 4c0e22c90510308433272d7ba281b1eb4eda8209 ] If crypto_get_default_rng returns an error, the function ecc_gen_privkey should return an error. Instead, it currently tries to use the default_rng nevertheless, thus creating a kernel panic with a NULL pointer dereference. Returning the error directly, as was supposedly intended when looking at the code, fixes this. Signed-off-by: Pierre Ducroquet Reviewed-by: PrasannaKumar Muralidharan Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/ecc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/ecc.c b/crypto/ecc.c index 633a9bcdc574..18f32f2a5e1c 100644 --- a/crypto/ecc.c +++ b/crypto/ecc.c @@ -964,7 +964,7 @@ int ecc_gen_privkey(unsigned int curve_id, unsigned int= ndigits, u64 *privkey) * DRBG with a security strength of 256. */ if (crypto_get_default_rng()) - err =3D -EFAULT; + return -EFAULT; =20 err =3D crypto_rng_get_bytes(crypto_default_rng, (u8 *)priv, nbytes); crypto_put_default_rng(); --=20 2.14.1