Skip to content

Commit

Permalink
crypto: dh - Don't permit 'key' or 'g' size longer than 'p'
Browse files Browse the repository at this point in the history
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: c983914 ("crypto: qat - Add DH support")
Cc: <[email protected]> # v4.8+
Signed-off-by: Eric Biggers <[email protected]>
Reviewed-by: Tudor Ambarus <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
ebiggers authored and herbertx committed Nov 10, 2017
1 parent 199512b commit ccd9888
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crypto/dh_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit ccd9888

Please sign in to comment.