From patchwork Thu Apr 20 05:46:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9689477 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D895601D4 for ; Thu, 20 Apr 2017 05:48:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6020228437 for ; Thu, 20 Apr 2017 05:48:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 552282844C; Thu, 20 Apr 2017 05:48:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2FB228437 for ; Thu, 20 Apr 2017 05:48:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S940651AbdDTFsk (ORCPT ); Thu, 20 Apr 2017 01:48:40 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:33435 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763679AbdDTFsV (ORCPT ); Thu, 20 Apr 2017 01:48:21 -0400 Received: by mail-oi0-f66.google.com with SMTP id a189so5945578oib.0; Wed, 19 Apr 2017 22:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9DU/On1cXTb96OYUHKXnyw1akpcCb/3rHlkVCOjvIjA=; b=Y8VUiFjz76ZYaa1dEB1VbO/a3IKnCVPBuIbhrhgfQIfUFdOyN/jouCZIeMdvCgvtJ7 mTsmdXe/z1ikQCB7A1YDyAWf+YXQAlmLCMJr1Vsd0RVybH4Zy7pxD2YHgJMeUX9ejlW7 W4TStTUtq7eiSQ8To25CqRKH1ZgLpHBDhP/C0hkRQmFhU4VnCy9r/yKBHwXIi8eM08C6 47PyVVdGUz/Y7pdccVg9w1Mf8RZn9a+ipeU4Q/LkzA6+I6bunafg6oW7+T6D/gB7Fj5H znvSIVf0qzMuPfNQQIOuFI9m+nG2UTtDMFGxL2SI6f8t/CMpXla7kDgDB7rKw3MplVKF JaFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9DU/On1cXTb96OYUHKXnyw1akpcCb/3rHlkVCOjvIjA=; b=Pe0kToLhxF9P8w6RjJVi45MvTutRK8UK0iFEavYlstRxEFMxygKqiIXqQwD3Ov/TVt EdJ+loo5YuJSzUmBHy5Tr/tj02qpIuT6KsSFbnI50TuVdJtCvsQM5uW3IMo31b+Zhs7E ilxRB+WtPJzq7eLEr3veznn8eKyOj/0LQGZsUxJPWewwVEJJx4BoTjyGfTOEgj7lei10 77HQNf6ZaSrjgHUy5N877SpjS1y3JWE/VI/ZlBOPFQZ1vxzjflH71xOoC+gsVStYxA0o UbLfUn3mCRPLtmoaIMyishY+LBJtR0m2TKkIS0nWx7hOlccBLe0ApW6xYLadNsNVCj9Y DBWA== X-Gm-Message-State: AN3rC/6lqbEwnDm0ktrIRuOHQ1Y+zUSHt1cT4gObfUmXPnsSaME9CVoX w4CGiA6NN/GHJw== X-Received: by 10.98.103.217 with SMTP id t86mr6506670pfj.135.1492667299776; Wed, 19 Apr 2017 22:48:19 -0700 (PDT) Received: from localhost.localdomain (c-73-239-167-150.hsd1.wa.comcast.net. [73.239.167.150]) by smtp.gmail.com with ESMTPSA id d83sm7686230pfe.40.2017.04.19.22.48.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Apr 2017 22:48:19 -0700 (PDT) From: Eric Biggers To: keyrings@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Stephan Mueller , David Howells , Herbert Xu , mathew.j.martineau@linux.intel.com, Eric Biggers Subject: [PATCH 1/5] KEYS: DH: forbid using digest_null as the KDF hash Date: Wed, 19 Apr 2017 22:46:29 -0700 Message-Id: <20170420054633.14572-2-ebiggers3@gmail.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170420054633.14572-1-ebiggers3@gmail.com> References: <20170420054633.14572-1-ebiggers3@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Requesting "digest_null" in the keyctl_kdf_params caused an infinite loop in kdf_ctr() because the "null" hash has a digest size of 0. Fix it by rejecting hash algorithms with a digest size of 0. Signed-off-by: Eric Biggers --- security/keys/dh.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/security/keys/dh.c b/security/keys/dh.c index e603bd912e4c..8abc70ebe22d 100644 --- a/security/keys/dh.c +++ b/security/keys/dh.c @@ -89,6 +89,7 @@ static int kdf_alloc(struct kdf_sdesc **sdesc_ret, char *hashname) struct crypto_shash *tfm; struct kdf_sdesc *sdesc; int size; + int err; /* allocate synchronous hash */ tfm = crypto_alloc_shash(hashname, 0, 0); @@ -97,16 +98,25 @@ static int kdf_alloc(struct kdf_sdesc **sdesc_ret, char *hashname) return PTR_ERR(tfm); } + err = -EINVAL; + if (crypto_shash_digestsize(tfm) == 0) + goto out_free_tfm; + + err = -ENOMEM; size = sizeof(struct shash_desc) + crypto_shash_descsize(tfm); sdesc = kmalloc(size, GFP_KERNEL); if (!sdesc) - return -ENOMEM; + goto out_free_tfm; sdesc->shash.tfm = tfm; sdesc->shash.flags = 0x0; *sdesc_ret = sdesc; return 0; + +out_free_tfm: + crypto_free_shash(tfm); + return err; } static void kdf_dealloc(struct kdf_sdesc *sdesc)