From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [128.1.224.119] ([128.1.224.119]:43822 "EHLO ringil.hmeau.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752439AbdLKLLB (ORCPT ); Mon, 11 Dec 2017 06:11:01 -0500 Date: Mon, 11 Dec 2017 22:10:57 +1100 From: Herbert Xu To: stable@vger.kernel.org Subject: [christophe.leroy@c-s.fr: [PATCH 03/18] crypto: talitos - fix setkey to check key weakness] Message-ID: <20171211111057.GC10372@gondor.apana.org.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="HG+GLK89HZ1zG0kk" Content-Disposition: inline Sender: stable-owner@vger.kernel.org List-ID: --HG+GLK89HZ1zG0kk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline commit f384cdc4faf350fdb6ad93c5f26952b9ba7c7566 For kernels 4.9+. -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt --HG+GLK89HZ1zG0kk Content-Type: message/rfc822 Content-Disposition: inline Return-path: Envelope-to: herbert@localhost Delivery-date: Fri, 06 Oct 2017 21:04:34 +0800 Received: from localhost ([::1] helo=gondobar.mordor.me.apana.org.au) by gondobar with esmtp (Exim 4.84_2) (envelope-from ) id 1e0SIs-0000el-DL for herbert@localhost; Fri, 06 Oct 2017 21:04:34 +0800 Received: from deadmen.mordor.me.apana.org.au [192.168.137.2] by gondobar.mordor.me.apana.org.au with IMAP (fetchmail-6.3.26) for (single-drop); Fri, 06 Oct 2017 21:04:34 +0800 (CST) Received: from pegase1.c-s.fr ([93.17.236.30]) by deadmen.hmeau.com with esmtp (Exim 4.84_2 #2 (Debian)) id 1e0SIg-00058I-Ms for ; Fri, 06 Oct 2017 21:04:23 +0800 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 3y7qbV0mtbz9tvg6; Fri, 6 Oct 2017 15:04:22 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id xDKJxWu-Olff; Fri, 6 Oct 2017 15:04:22 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 3y7qbV06pzz9tvfg; Fri, 6 Oct 2017 15:04:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AA47B8B7EE; Fri, 6 Oct 2017 15:04:37 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id pkMV3iWn6Fh9; Fri, 6 Oct 2017 15:04:37 +0200 (CEST) Received: from po15668-vm-win7.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8E0D28B7E8; Fri, 6 Oct 2017 15:04:37 +0200 (CEST) Received: by po15668-vm-win7.idsi0.si.c-s.fr (Postfix, from userid 0) id 816FD697EE; Fri, 6 Oct 2017 15:04:37 +0200 (CEST) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH 03/18] crypto: talitos - fix setkey to check key weakness To: Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Fri, 6 Oct 2017 15:04:37 +0200 (CEST) Crypto manager test report the following failures: [ 3.061081] alg: skcipher: setkey failed on test 5 for ecb-des-talitos: flags=100 [ 3.069342] alg: skcipher-ddst: setkey failed on test 5 for ecb-des-talitos: flags=100 [ 3.077754] alg: skcipher-ddst: setkey failed on test 5 for ecb-des-talitos: flags=100 This is due to setkey being expected to detect weak keys. Signed-off-by: Christophe Leroy --- drivers/crypto/talitos.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 1e799886c57d..8aa1212086f4 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1507,12 +1507,20 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); + u32 tmp[DES_EXPKEY_WORDS]; if (keylen > TALITOS_MAX_KEY_SIZE) { crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); return -EINVAL; } + if (unlikely(crypto_ablkcipher_get_flags(cipher) & + CRYPTO_TFM_REQ_WEAK_KEY) && + !des_ekey(tmp, key)) { + crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_WEAK_KEY); + return -EINVAL; + } + memcpy(&ctx->key, key, keylen); ctx->keylen = keylen; -- 2.13.3 --HG+GLK89HZ1zG0kk--