Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1661243

[PATCH 18/23] KEYS: DH: forbid using digest_null as the KDF hash

From David Howells <dhowells@redhat.com>
Newsgroups linux.kernel
Subject [PATCH 18/23] KEYS: DH: forbid using digest_null as the KDF hash
Date 2017-06-08 15:50 +0200
Message-ID <tQ5Z2-4WL-71@gated-at.bofh.it> (permalink)
References <tQ5Z0-4WL-11@gated-at.bofh.it>
Organization Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903

Show all headers | View raw


From: Eric Biggers <ebiggers@google.com>

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 <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Stephan Mueller <smueller@chronox.de>
---

 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)

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/23] KEYS: Fixes David Howells <dhowells@redhat.com> - 2017-06-08 15:50 +0200
  [PATCH 05/23] KEYS: Delete an error message for a failed memory  allocation in get_derived_key() David Howells <dhowells@redhat.com> - 2017-06-08 15:50 +0200
  [PATCH 18/23] KEYS: DH: forbid using digest_null as the KDF hash David Howells <dhowells@redhat.com> - 2017-06-08 15:50 +0200
  [PATCH 10/23] KEYS: encrypted: use constant-time HMAC comparison David Howells <dhowells@redhat.com> - 2017-06-08 15:50 +0200
  [PATCH 04/23] X.509: Fix error code in x509_cert_parse() David Howells <dhowells@redhat.com> - 2017-06-08 15:50 +0200
  [PATCH 07/23] KEYS: encrypted: avoid encrypting/decrypting stack  buffers David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 20/23] KEYS: DH: ensure the KDF counter is properly aligned David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 19/23] KEYS: DH: don't feed uninitialized "otherinfo" into  KDF David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 16/23] KEYS: trusted: sanitize all key material David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 21/23] KEYS: DH: add __user annotations to keyctl_kdf_params David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 13/23] KEYS: sanitize add_key() and keyctl() key payloads David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 14/23] KEYS: user_defined: sanitize key payloads David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 22/23] crypto : asymmetric_keys : verify_pefile:zero memory  content before freeing David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 23/23] KEYS: Convert KEYCTL_DH_COMPUTE to use the crypto KPP  API David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 11/23] KEYS: fix dereferencing NULL payload with nonzero  length David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 09/23] KEYS: encrypted: fix race causing incorrect HMAC  calculations David Howells <dhowells@redhat.com> - 2017-06-08 16:00 +0200
  [PATCH 08/23] KEYS: encrypted: fix buffer overread in  valid_master_desc() David Howells <dhowells@redhat.com> - 2017-06-08 16:10 +0200
  [PATCH 02/23] security: use READ_ONCE instead of deprecated  ACCESS_ONCE David Howells <dhowells@redhat.com> - 2017-06-08 16:10 +0200
  Re: [PATCH 00/23] KEYS: Fixes James Morris <jmorris@namei.org> - 2017-06-08 16:40 +0200
    Re: [PATCH 00/23] KEYS: Fixes David Howells <dhowells@redhat.com> - 2017-06-08 16:50 +0200

csiph-web