From 5822cca9ff5150ecf9f19302ced4fae601c20066 Mon Sep 17 00:00:00 2001 From: Daniel Kubec Date: Sun, 2 Aug 2026 00:23:39 +0000 Subject: [PATCH] Fix heap buffer overflow (8-byte OOB write) in AES-WRAP-PAD unwrap On its integrity-failure paths that primitive writes and cleanses up to inlen bytes of the output buffer. Size the buffer for that worst case so a failed unwrap cannot write past the allocation. Fixes CVE-2026-63072 Reviewed-by: Milan Broz Reviewed-by: Andrew Dinh Merge-date: Mon Aug 24 14:44:55 2026 --- crypto/cms/cms_kari.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crypto/cms/cms_kari.c b/crypto/cms/cms_kari.c index 79697cd337..74d5841233 100644 --- a/crypto/cms/cms_kari.c +++ b/crypto/cms/cms_kari.c @@ -217,6 +217,7 @@ static int cms_kek_cipher(unsigned char **pout, size_t *poutlen, int rv = 0; unsigned char *out = NULL; int outlen; + size_t outsize; keklen = EVP_CIPHER_CTX_get_key_length(kari->ctx); if (keklen > EVP_MAX_KEY_LENGTH) @@ -230,7 +231,13 @@ static int cms_kek_cipher(unsigned char **pout, size_t *poutlen, /* obtain output length of ciphered key */ if (!EVP_CipherUpdate(kari->ctx, NULL, &outlen, in, inlen)) goto err; - out = OPENSSL_malloc(outlen); + /* + * On its integrity-failure paths that primitive writes and cleanses up to + * inlen bytes of the output buffer. Size the buffer for that worst case so + * a failed unwrap cannot write past the allocation. + */ + outsize = (size_t)outlen < inlen ? inlen : (size_t)outlen; + out = OPENSSL_malloc(outsize); if (out == NULL) goto err; if (!EVP_CipherUpdate(kari->ctx, out, &outlen, in, inlen)) -- 2.55.0