From a0abb6a10f4c5fc6dd20c487aa0db085fbfb3562 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Thu, 17 May 2018 12:53:07 +0100 Subject: Add a sanity check on the length of pkeyutl inputs When signing or verifying a file using pkeyutl the input is supposed to be a hash. Some algorithms sanity check the length of the input, while others don't and silently truncate. To avoid accidents we check that the length of the input looks sane. Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/6284) --- apps/pkeyutl.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c index 911cc57642..2c4e524b69 100644 --- a/apps/pkeyutl.c +++ b/apps/pkeyutl.c @@ -282,7 +282,7 @@ int pkeyutl_main(int argc, char **argv) buf_inlen = bio_to_mem(&buf_in, keysize * 10, in); if (buf_inlen < 0) { BIO_printf(bio_err, "Error reading input Data\n"); - exit(1); + goto end; } if (rev) { size_t i; @@ -296,6 +296,16 @@ int pkeyutl_main(int argc, char **argv) } } + /* Sanity check the input */ + if (buf_inlen > EVP_MAX_MD_SIZE + && (pkey_op == EVP_PKEY_OP_SIGN + || pkey_op == EVP_PKEY_OP_VERIFY + || pkey_op == EVP_PKEY_OP_VERIFYRECOVER)) { + BIO_printf(bio_err, + "Error: The input data looks too long to be a hash\n"); + goto end; + } + if (pkey_op == EVP_PKEY_OP_VERIFY) { rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen, buf_in, (size_t)buf_inlen); -- cgit v1.2.3-70-g09d2