crypto: dh - Don't permit 'key' or 'g' size longer than 'p'
authorEric Biggers <ebiggers@google.com>
Mon, 6 Nov 2017 02:30:46 +0000 (18:30 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 21 Nov 2017 09:24:34 +0000 (10:24 +0100)
commit38957dc97f3039c0dc35c7ecde848c3ea9a54e9b
treef31e689779dc771783ab3bf7ddefb52e287f7a3e
parent208116d5b7390720b5922413f05209947700a28c
crypto: dh - Don't permit 'key' or 'g' size longer than 'p'

commit ccd9888f14a8019c0bbdeeae758aba1f58693712 upstream.

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")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
crypto/dh_helper.c