Commit faaef82348 for openssl.org
commit faaef82348e2e98e03c85f22658ed2d41a023257
Author: Greensi7 <adam.tabak04@gmail.com>
Date: Wed Aug 12 00:27:22 2026 +0200
Add cms_verify fuzzer
Fuzz CMS_verify() with CMS_NO_SIGNER_CERT_VERIFY
to exercise signature verification without requiring
trusted certificate store.
Motivated by : CVE-2026-45447 which affects PKCS7_verify(),
and add coverage for similar CMS_verify().
Assisted-by: ChatGPT:gpt-5.6
Reviewed-by: Jakub Zelenka <jakub.zelenka@openssl.foundation>
Reviewed-by: Milan Broz <mbroz@openssl.org>
Merge-date: Tue Sep 15 15:00:01 2026
Merged-from: https://github.com/openssl/openssl/pull/32342
diff --git a/fuzz/build.info b/fuzz/build.info
index cde654c089..90954aad0e 100644
--- a/fuzz/build.info
+++ b/fuzz/build.info
@@ -32,7 +32,7 @@ IF[{- !$disabled{"fuzz-afl"} || !$disabled{"fuzz-libfuzzer"} -}]
ENDIF
IF[{- !$disabled{"cms"} -}]
- PROGRAMS{noinst}=cms
+ PROGRAMS{noinst}=cms cms_verify
ENDIF
IF[{- !$disabled{"ct"} -}]
@@ -87,6 +87,10 @@ IF[{- !$disabled{"fuzz-afl"} || !$disabled{"fuzz-libfuzzer"} -}]
INCLUDE[cms]=../include {- $ex_inc -}
DEPEND[cms]=../libcrypto {- $ex_lib -}
+ SOURCE[cms_verify]=cms_verify.c driver.c
+ INCLUDE[cms_verify]=../include {- $ex_inc -}
+ DEPEND[cms_verify]=../libcrypto {- $ex_lib -}
+
SOURCE[pkcs12]=pkcs12.c driver.c
INCLUDE[pkcs12]=../include {- $ex_inc -}
DEPEND[pkcs12]=../libcrypto {- $ex_lib -}
@@ -218,7 +222,7 @@ IF[{- !$disabled{tests} -}]
ENDIF
IF[{- !$disabled{"cms"} -}]
- PROGRAMS{noinst}=cms-test
+ PROGRAMS{noinst}=cms-test cms_verify-test
ENDIF
IF[{- !$disabled{"ct"} -}]
@@ -286,6 +290,10 @@ IF[{- !$disabled{tests} -}]
INCLUDE[cms-test]=../include ../test/mfail
DEPEND[cms-test]=../libcrypto.a
+ SOURCE[cms_verify-test]=cms_verify.c $FUZZTESTSRC
+ INCLUDE[cms_verify-test]=../include ../test/mfail
+ DEPEND[cms_verify-test]=../libcrypto.a
+
SOURCE[pkcs12-test]=pkcs12.c $FUZZTESTSRC
INCLUDE[pkcs12-test]=../include ../test/mfail
DEPEND[pkcs12-test]=../libcrypto.a
diff --git a/fuzz/cms_verify.c b/fuzz/cms_verify.c
new file mode 100644
index 0000000000..7e9ce3eafc
--- /dev/null
+++ b/fuzz/cms_verify.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * https://www.openssl.org/source/license.html
+ * or in the file LICENSE in the source distribution.
+ */
+#include <limits.h>
+#include <openssl/bio.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+#include "fuzzer.h"
+
+int FuzzerInitialize(int *argc, char ***argv)
+{
+ return 1;
+}
+
+int FuzzerTestOneInput(const uint8_t *buf, size_t len)
+{
+ BIO *indata = NULL;
+ BIO *out = NULL;
+ CMS_ContentInfo *cms = NULL;
+ const unsigned char *in;
+ size_t consumed;
+ size_t remaining;
+
+ if (len > LONG_MAX)
+ return 0;
+
+ in = buf;
+ cms = d2i_CMS_ContentInfo(NULL, &in, (long)len);
+ if (cms == NULL)
+ goto err;
+
+ consumed = (size_t)(in - buf);
+ remaining = len - consumed;
+ if (remaining > INT_MAX)
+ goto err;
+
+ if (consumed < len) {
+ indata = BIO_new_mem_buf(in, (int)remaining);
+ if (indata == NULL)
+ goto err;
+ }
+
+ out = BIO_new(BIO_s_null());
+ if (out == NULL)
+ goto err;
+
+ CMS_verify(cms, NULL, NULL, indata, out,
+ CMS_NO_SIGNER_CERT_VERIFY);
+
+err:
+ BIO_free(out);
+ CMS_ContentInfo_free(cms);
+ BIO_free(indata);
+ ERR_clear_error();
+ return 0;
+}
+
+void FuzzerCleanup(void)
+{
+}
diff --git a/test/recipes/99-test_fuzz_cms_verify.t b/test/recipes/99-test_fuzz_cms_verify.t
new file mode 100644
index 0000000000..c29f33e7a9
--- /dev/null
+++ b/test/recipes/99-test_fuzz_cms_verify.t
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+# Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (the "License"). You may not use
+# this file except in compliance with the License. You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
+use strict;
+use warnings;
+
+use OpenSSL::Test qw/:DEFAULT srctop_file/;
+use OpenSSL::Test::Utils;
+
+my $fuzzer = "cms_verify";
+setup("test_fuzz_${fuzzer}");
+
+plan skip_all => "This test requires cms support"
+ if disabled("cms");
+
+plan tests => 2; # one more due to below require_ok(...)
+
+require_ok(srctop_file('test','recipes','fuzz.pl'));
+
+fuzz_ok($fuzzer);