Commit 03be55adfb for strongswan.org

commit 03be55adfb4a93c985c9008532988ae2ecf38205
Author: raghu netrakar <raghu@security.bugqore.com>
Date:   Thu Oct 22 19:52:46 2026 +0530

    pkcs12: Validate MAC salt length and iteration count

    The MAC salt and iteration count parsed from the MacData of a PKCS#12
    PFX were used without any bounds check.  The salt is passed to
    pkcs12_derive_key()/derive_key(), where its length feeds a chunk_alloca()
    on the stack, so a PFX with a multi-megabyte macSalt overflows the stack
    (AddressSanitizer reports a stack-overflow in pkcs12_derive_key()).  An
    unbounded iteration count spins the key derivation loop practically
    forever.

    This is the same class of issue as the one fixed for PKCS#5 in
    f60a55e36f95 (CVE-2026-78129). However, PKCS#12 files are only loaded
    locally (unlike PKCS#7 via IKEv1), so this was not covered by that
    change.

    Closes strongswan/strongswan#3183

    Fixes: feef637368c6 ("Add pkcs12 plugin which adds support for decoding PKCS#12 containers")

diff --git a/src/libstrongswan/plugins/pkcs12/pkcs12_decode.c b/src/libstrongswan/plugins/pkcs12/pkcs12_decode.c
index 4147871c3f..98aaf8ecdd 100644
--- a/src/libstrongswan/plugins/pkcs12/pkcs12_decode.c
+++ b/src/libstrongswan/plugins/pkcs12/pkcs12_decode.c
@@ -16,12 +16,20 @@

 #include "pkcs12_decode.h"

+#include <inttypes.h>
+
 #include <utils/debug.h>
 #include <asn1/oid.h>
 #include <asn1/asn1.h>
 #include <asn1/asn1_parser.h>
 #include <credentials/sets/mem_cred.h>

+/** maximum accepted length for the MAC salt in a parsed PFX */
+#define PKCS12_SALT_LEN_MAX		128
+
+/** maximum accepted MAC iteration count in a parsed PFX */
+#define PKCS12_ITERATIONS_MAX	1000000
+
 typedef struct private_pkcs12_t private_pkcs12_t;

 /**
@@ -530,6 +538,19 @@ end_parse:
 			{
 				goto end;
 			}
+			if (salt.len > PKCS12_SALT_LEN_MAX)
+			{
+				DBG1(DBG_ASN, "  MAC salt length %zu exceeds maximum of %zu "
+					 "bytes", salt.len, (size_t)PKCS12_SALT_LEN_MAX);
+				goto end;
+			}
+			if (!iterations || iterations > PKCS12_ITERATIONS_MAX)
+			{
+				DBG1(DBG_ASN, "  MAC iteration count %" PRIu64 " is out of "
+					 "range (1-%" PRIu64 ")", iterations,
+					 (uint64_t)PKCS12_ITERATIONS_MAX);
+				goto end;
+			}
 			creds = mem_cred_create();
 			if (!verify_mac(hash, salt, iterations, data, digest, creds))
 			{