All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers3@gmail.com>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
	Salvatore Benedetto <salvatore.benedetto@intel.com>,
	Tudor-Dan Ambarus <tudor.ambarus@microchip.com>,
	Mat Martineau <mathew.j.martineau@linux.intel.com>,
	Stephan Mueller <smueller@chronox.de>,
	qat-linux@intel.com, keyrings@vger.kernel.org,
	Eric Biggers <ebiggers@google.com>,
	stable@vger.kernel.org
Subject: [PATCH v2 3/5] crypto: dh - Don't permit 'key' or 'g' size longer than 'p'
Date: Mon, 06 Nov 2017 02:30:46 +0000	[thread overview]
Message-ID: <20171106023048.8067-4-ebiggers3@gmail.com> (raw)
In-Reply-To: <20171106023048.8067-1-ebiggers3@gmail.com>

From: Eric Biggers <ebiggers@google.com>

The "qat-dh" DH implementation assumes that 'key' and 'g' can be copied
into a buffer with size 'p_size'.  However it was never checked that
that was actually the case, which most likely allowed users to cause a
buffer underflow via KEYCTL_DH_COMPUTE.

Fix this by updating crypto_dh_decode_key() to verify this precondition
for all DH implementations.

Fixes: c9839143ebbf ("crypto: qat - Add DH support")
Cc: <stable@vger.kernel.org> # v4.8+
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/dh_helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/crypto/dh_helper.c b/crypto/dh_helper.c
index 708ae20d2d3c..7f00c771fe8d 100644
--- a/crypto/dh_helper.c
+++ b/crypto/dh_helper.c
@@ -83,6 +83,14 @@ int crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params)
 	if (secret.len != crypto_dh_key_len(params))
 		return -EINVAL;
 
+	/*
+	 * Don't permit the buffer for 'key' or 'g' to be larger than 'p', since
+	 * some drivers assume otherwise.
+	 */
+	if (params->key_size > params->p_size ||
+	    params->g_size > params->p_size)
+		return -EINVAL;
+
 	/* Don't allocate memory. Set pointers to data within
 	 * the given buffer
 	 */
-- 
2.15.0


WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers3@gmail.com>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
	Salvatore Benedetto <salvatore.benedetto@intel.com>,
	Tudor-Dan Ambarus <tudor.ambarus@microchip.com>,
	Mat Martineau <mathew.j.martineau@linux.intel.com>,
	Stephan Mueller <smueller@chronox.de>,
	qat-linux@intel.com, keyrings@vger.kernel.org,
	Eric Biggers <ebiggers@google.com>,
	stable@vger.kernel.org
Subject: [PATCH v2 3/5] crypto: dh - Don't permit 'key' or 'g' size longer than 'p'
Date: Sun,  5 Nov 2017 18:30:46 -0800	[thread overview]
Message-ID: <20171106023048.8067-4-ebiggers3@gmail.com> (raw)
In-Reply-To: <20171106023048.8067-1-ebiggers3@gmail.com>

From: Eric Biggers <ebiggers@google.com>

The "qat-dh" DH implementation assumes that 'key' and 'g' can be copied
into a buffer with size 'p_size'.  However it was never checked that
that was actually the case, which most likely allowed users to cause a
buffer underflow via KEYCTL_DH_COMPUTE.

Fix this by updating crypto_dh_decode_key() to verify this precondition
for all DH implementations.

Fixes: c9839143ebbf ("crypto: qat - Add DH support")
Cc: <stable@vger.kernel.org> # v4.8+
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/dh_helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/crypto/dh_helper.c b/crypto/dh_helper.c
index 708ae20d2d3c..7f00c771fe8d 100644
--- a/crypto/dh_helper.c
+++ b/crypto/dh_helper.c
@@ -83,6 +83,14 @@ int crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params)
 	if (secret.len != crypto_dh_key_len(params))
 		return -EINVAL;
 
+	/*
+	 * Don't permit the buffer for 'key' or 'g' to be larger than 'p', since
+	 * some drivers assume otherwise.
+	 */
+	if (params->key_size > params->p_size ||
+	    params->g_size > params->p_size)
+		return -EINVAL;
+
 	/* Don't allocate memory. Set pointers to data within
 	 * the given buffer
 	 */
-- 
2.15.0

  parent reply	other threads:[~2017-11-06  2:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-06  2:30 [PATCH v2 0/5] crypto: dh - input validation fixes Eric Biggers
2017-11-06  2:30 ` Eric Biggers
2017-11-06  2:30 ` [PATCH v2 1/5] crypto: dh - Fix double free of ctx->p Eric Biggers
2017-11-06  2:30   ` Eric Biggers
2017-11-06  8:55   ` Tudor Ambarus
2017-11-06  8:55     ` Tudor Ambarus
2017-11-06  2:30 ` [PATCH v2 2/5] crypto: dh - Don't permit 'p' to be 0 Eric Biggers
2017-11-06  2:30   ` Eric Biggers
2017-11-06  2:30 ` Eric Biggers [this message]
2017-11-06  2:30   ` [PATCH v2 3/5] crypto: dh - Don't permit 'key' or 'g' size longer than 'p' Eric Biggers
2017-11-06 10:29   ` Tudor Ambarus
2017-11-06 10:29     ` Tudor Ambarus
2017-11-06  2:30 ` [PATCH v2 4/5] crypto: qat - Clean up error handling in qat_dh_set_secret() Eric Biggers
2017-11-06  2:30   ` Eric Biggers
2017-11-06  2:30 ` [PATCH v2 5/5] crypto: dh - Remove pointless checks for NULL 'p' and 'g' Eric Biggers
2017-11-06  2:30   ` Eric Biggers
2017-11-06 10:29   ` Tudor Ambarus
2017-11-06 10:29     ` Tudor Ambarus
2017-11-10 11:36 ` [PATCH v2 0/5] crypto: dh - input validation fixes Herbert Xu
2017-11-10 11:36   ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171106023048.8067-4-ebiggers3@gmail.com \
    --to=ebiggers3@gmail.com \
    --cc=ebiggers@google.com \
    --cc=giovanni.cabiddu@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=mathew.j.martineau@linux.intel.com \
    --cc=qat-linux@intel.com \
    --cc=salvatore.benedetto@intel.com \
    --cc=smueller@chronox.de \
    --cc=stable@vger.kernel.org \
    --cc=tudor.ambarus@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.