Enforce a strict output length check in CRYPTO_ccm128_tag
authorGuido Vranken <guidovranken@gmail.com>
Mon, 22 Apr 2019 12:11:12 +0000 (14:11 +0200)
committerMatt Caswell <matt@openssl.org>
Thu, 25 Apr 2019 09:44:18 +0000 (10:44 +0100)
Return error if the output tag buffer size doesn't match
the tag size exactly. This prevents the caller from
using that portion of the tag buffer that remains
uninitialized after an otherwise succesfull call to
CRYPTO_ccm128_tag.

Bug found by OSS-Fuzz.

Fix suggested by Kurt Roeckx.

Signed-off-by: Guido Vranken <guidovranken@gmail.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8810)

crypto/modes/ccm128.c

index 9edf0270e2c155c7e0aa93e9a700d7f0e4d90500..bfa2d4604caf4ed8eb6f7981fc0470966897ad0d 100644 (file)
@@ -425,7 +425,7 @@ size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len)
 
     M *= 2;
     M += 2;
-    if (len < M)
+    if (len != M)
         return 0;
     memcpy(tag, ctx->cmac.c, M);
     return M;