From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-dm3nam03on0131.outbound.protection.outlook.com ([104.47.41.131]:48288 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032604AbeCAPjg (ORCPT ); Thu, 1 Mar 2018 10:39:36 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Kamil Konieczny , Herbert Xu , Sasha Levin Subject: [added to the 4.1 stable tree] crypto: s5p-sss - Fix kernel Oops in AES-ECB mode Date: Thu, 1 Mar 2018 15:27:50 +0000 Message-ID: <20180301152116.1486-503-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-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: Kamil Konieczny This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit c927b080c67e3e97193c81fc1d27f4251bf4e036 ] In AES-ECB mode crypt is done with key only, so any use of IV can cause kernel Oops. Use IV only in AES-CBC and AES-CTR. Signed-off-by: Kamil Konieczny Reported-by: Anand Moon Reviewed-by: Krzysztof Kozlowski Tested-by: Anand Moon Cc: stable@vger.kernel.org # can be applied after commit 8f9702aad138 Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/s5p-sss.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c index 4f0c4a3cc5c5..89219806fd8e 100644 --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -419,16 +419,21 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *d= ev, unsigned long mode) uint32_t aes_control; int err; unsigned long flags; + u8 *iv; =20 aes_control =3D SSS_AES_KEY_CHANGE_MODE; if (mode & FLAGS_AES_DECRYPT) aes_control |=3D SSS_AES_MODE_DECRYPT; =20 - if ((mode & FLAGS_AES_MODE_MASK) =3D=3D FLAGS_AES_CBC) + if ((mode & FLAGS_AES_MODE_MASK) =3D=3D FLAGS_AES_CBC) { aes_control |=3D SSS_AES_CHAIN_MODE_CBC; - else if ((mode & FLAGS_AES_MODE_MASK) =3D=3D FLAGS_AES_CTR) + iv =3D req->info; + } else if ((mode & FLAGS_AES_MODE_MASK) =3D=3D FLAGS_AES_CTR) { aes_control |=3D SSS_AES_CHAIN_MODE_CTR; - + iv =3D req->info; + } else { + iv =3D NULL; /* AES_ECB */ + } if (dev->ctx->keylen =3D=3D AES_KEYSIZE_192) aes_control |=3D SSS_AES_KEY_SIZE_192; else if (dev->ctx->keylen =3D=3D AES_KEYSIZE_256) @@ -458,7 +463,7 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev= , unsigned long mode) goto outdata_error; =20 SSS_AES_WRITE(dev, AES_CONTROL, aes_control); - s5p_set_aes(dev, dev->ctx->aes_key, req->info, dev->ctx->keylen); + s5p_set_aes(dev, dev->ctx->aes_key, iv, dev->ctx->keylen); =20 s5p_set_dma_indata(dev, req->src); s5p_set_dma_outdata(dev, req->dst); --=20 2.14.1