KEYS: encrypted: fix buffer overread in valid_master_desc()
authorEric Biggers <ebiggers@google.com>
Thu, 8 Jun 2017 13:48:18 +0000 (14:48 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Feb 2018 11:35:57 +0000 (12:35 +0100)
commit9692602ab850eec484d8cc5a740803d34f00016c
tree987de600f4860b0661d7fc8a406797c347b1c1d2
parent0a01ecbd23a9547b60b1a1d7e83f60704b176925
KEYS: encrypted: fix buffer overread in valid_master_desc()

commit 794b4bc292f5d31739d89c0202c54e7dc9bc3add upstream.

With the 'encrypted' key type it was possible for userspace to provide a
data blob ending with a master key description shorter than expected,
e.g. 'keyctl add encrypted desc "new x" @s'.  When validating such a
master key description, validate_master_desc() could read beyond the end
of the buffer.  Fix this by using strncmp() instead of memcmp().  [Also
clean up the code to deduplicate some logic.]

Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
security/keys/encrypted-keys/encrypted.c