Return-Path: Received: from omzsmtpe02.verizonbusiness.com ([199.249.25.209]:62064 "EHLO omzsmtpe02.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753304AbdJGWhw (ORCPT ); Sat, 7 Oct 2017 18:37:52 -0400 From: "Levin, Alexander (Sasha Levin)" Cc: Harald Freudenberger , Martin Schwidefsky , "Levin, Alexander (Sasha Levin)" To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH review for 4.9 46/50] s390/crypto: Extend key length check for AES-XTS in fips mode. Date: Sat, 7 Oct 2017 22:36:57 +0000 Message-ID: <20171007223636.24797-46-alexander.levin@verizon.com> References: <20171007223636.24797-1-alexander.levin@verizon.com> In-Reply-To: <20171007223636.24797-1-alexander.levin@verizon.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: Harald Freudenberger [ Upstream commit a4f2779ecf2f42b0997fedef6fd20a931c40a3e3 ] In fips mode only xts keys with 128 bit or 125 bit are allowed. This fix extends the xts_aes_set_key function to check for these valid key lengths in fips mode. Signed-off-by: Harald Freudenberger Signed-off-by: Martin Schwidefsky Signed-off-by: Sasha Levin --- arch/s390/crypto/aes_s390.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c index 303d28eb03a2..591cbdf615af 100644 --- a/arch/s390/crypto/aes_s390.c +++ b/arch/s390/crypto/aes_s390.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include =20 @@ -501,6 +502,12 @@ static int xts_aes_set_key(struct crypto_tfm *tfm, con= st u8 *in_key, if (err) return err; =20 + /* In fips mode only 128 bit or 256 bit keys are valid */ + if (fips_enabled && key_len !=3D 32 && key_len !=3D 64) { + tfm->crt_flags |=3D CRYPTO_TFM_RES_BAD_KEY_LEN; + return -EINVAL; + } + /* Pick the correct function code based on the key length */ fc =3D (key_len =3D=3D 32) ? CPACF_KM_XTS_128 : (key_len =3D=3D 64) ? CPACF_KM_XTS_256 : 0; --=20 2.11.0