Commit d922629cec for strongswan.org

commit d922629cec233da7e9e42809c9168a2b5fe94721
Author: raghu netrakar <raghu@security.bugqore.com>
Date:   Sat Nov 21 16:48:27 2026 +0530

    pkcs7: Verify length of encrypted content before decrypting it

    The encryptedContent of enveloped-data was passed to the crypter without
    checking that its length is a multiple of the block size, as required by
    crypter_t.  With a non-aligned length, the aes crypter never writes the
    first len % 16 bytes of the allocated output and uses bytes preceding the
    input as CBC chaining value, while the des crypter reads up to seven
    bytes past the end of the input.  If the decrypted remainder happens to
    form valid padding, the uninitialized heap memory is returned as
    plaintext, e.g. by `pki --pkcs7 --decrypt`.

    Reject such content before decrypting it, like pkcs5.c and the PEM
    decryption already do.

diff --git a/src/libstrongswan/plugins/pkcs7/pkcs7_enveloped_data.c b/src/libstrongswan/plugins/pkcs7/pkcs7_enveloped_data.c
index d88e498484..6854006400 100644
--- a/src/libstrongswan/plugins/pkcs7/pkcs7_enveloped_data.c
+++ b/src/libstrongswan/plugins/pkcs7/pkcs7_enveloped_data.c
@@ -164,6 +164,14 @@ static bool decrypt(private_key_t *private, chunk_t key, chunk_t iv, int oid,
 		crypter->destroy(crypter);
 		return FALSE;
 	}
+	if (encrypted.len % crypter->get_block_size(crypter))
+	{
+		DBG1(DBG_LIB, "encrypted content length %d is not a multiple of the "
+			 "block size", encrypted.len);
+		free(plain_key.ptr);
+		crypter->destroy(crypter);
+		return FALSE;
+	}
 	if (!crypter->set_key(crypter, plain_key) ||
 		!crypter->decrypt(crypter, encrypted, iv, plain))
 	{