Skip to content

Add Reproducible Error Injection - #18355

Closed
bernd-edlinger wants to merge 1 commit into
openssl:masterfrom
bernd-edlinger:add_error_injection
Closed

bernd-edlinger wants to merge 1 commit into
openssl:masterfrom
bernd-edlinger:add_error_injection

Conversation

@bernd-edlinger

Copy link
Copy Markdown
Member

This adds reproducible memory error and test-data
error injection, to the fuzzy-test framework.

This feature can be enabled with ./config -DERROR_INJECT
and additionally to enable call stacks -DERROR_CALLSTACK

If enable-asan is used, the callstack is printed by the
sanitizer, otherwise please set a breakpoint
at the function "break_here", which is executed each
time a memory allocation error is injected.

If called with the environment variable ERROR_INJECT
defined to the empty string the initialization value
is printed, and can be used to reproduce the failure
later, by passing the value to the ERROR_INJECT variable.

There is a search script that can be used to look
for errors, and print the command to reproduce the bug:

./testrun.sh

This runs in endless mode until an error is found.

Checklist
  • documentation is added or updated
  • tests are added or updated

@bernd-edlinger bernd-edlinger added branch: master Applies to master branch branch: 3.0 Applies to openssl-3.0 branch (EOL) labels May 20, 2022
@t8m t8m added the triaged: feature The issue/pr requests/adds a feature label May 20, 2022
@bernd-edlinger

Copy link
Copy Markdown
Member Author

While the 1.1.1 survives this kind of error injection test for days,
the master has a lot of errors that are not obvious how to fix.
some examples:

ERROR_INJECT=1653397888 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/00b14db87f31c2b33204bbfdabf96bd422712976
# ./corpora/asn1/00b14db87f31c2b33204bbfdabf96bd422712976
    #0 0x7ff09ba46d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x564253be2714 in my_realloc fuzz/test-corpus.c:129
    #2 0x7ff09a70aaa3 in sk_reserve crypto/stack/stack.c:216
    #3 0x7ff09a70aaa3 in OPENSSL_sk_insert crypto/stack/stack.c:260
    #4 0x7ff09a66038c in alg_do_one crypto/property/property.c:434
    #5 0x7ff09a66038c in alg_do_each crypto/property/property.c:450
    #6 0x7ff09a526ff2 in sa_doall crypto/sparse_array.c:93
    #7 0x7ff09a526ff2 in ossl_sa_doall_arg crypto/sparse_array.c:146
    #8 0x7ff09a662468 in ossl_sa_ALGORITHM_doall_arg crypto/property/property.c:83
    #9 0x7ff09a662468 in ossl_method_store_do_all crypto/property/property.c:463
    #10 0x7ff09a3b663f in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:537
    #11 0x7ff09a3b19ca in OSSL_DECODER_CTX_add_extra crypto/encode_decode/decoder_lib.c:513
    #12 0x7ff09a3b886c in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:501
    #13 0x7ff09a15a0b6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7ff09a15ac00 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x564253be1728 in FuzzerTestOneInput fuzz/asn1.c:364
    #16 0x564253be22a9 in testfile fuzz/test-corpus.c:182
    #17 0x564253bdf89f in main fuzz/test-corpus.c:226
    #18 0x7ff098c9e082 in __libc_start_main ../csu/libc-start.c:308
    #19 0x564253bdfa4d in _start (/home/ed/OPCToolboxV5/Source/Core/OpenSSL/openssl/fuzz/asn1-test+0x9a4d)


=================================================================
==2304247==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7ff09ba39808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7ff09a4fd615 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7ff09a3b5217 in ossl_decoder_new crypto/encode_decode/decoder_meth.c:32
    #3 0x7ff09a3b5217 in ossl_decoder_from_algorithm crypto/encode_decode/decoder_meth.c:186
    #4 0x7ff09a3b5c7c in construct_decoder crypto/encode_decode/decoder_meth.c:287
    #5 0x7ff09a4f2fcf in ossl_method_construct_this crypto/core_fetch.c:84
    #6 0x7ff09a4f275e in algorithm_do_map crypto/core_algorithm.c:68
    #7 0x7ff09a4f275e in algorithm_do_this crypto/core_algorithm.c:110
    #8 0x7ff09a521ff0 in ossl_provider_doall_activated crypto/provider_core.c:1404
    #9 0x7ff09a4f2d76 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #10 0x7ff09a4f387e in ossl_method_construct crypto/core_fetch.c:144
    #11 0x7ff09a3b4ba0 in inner_ossl_decoder_fetch crypto/encode_decode/decoder_meth.c:355
    #12 0x7ff09a3b65ad in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:531
    #13 0x7ff09a3b857a in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:442
    #14 0x7ff09a3b8859 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #15 0x7ff09a15a0b6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #16 0x7ff09a15ac00 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #17 0x564253be1728 in FuzzerTestOneInput fuzz/asn1.c:364
    #18 0x564253be22a9 in testfile fuzz/test-corpus.c:182
    #19 0x564253bdf89f in main fuzz/test-corpus.c:226
    #20 0x7ff098c9e082 in __libc_start_main ../csu/libc-start.c:308
ERROR_INJECT=1653275566 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/00008b24e56209f67fa225a3be3ddf4e4cf0a9d3
# ./corpora/asn1/00008b24e56209f67fa225a3be3ddf4e4cf0a9d3
    #0 0x7f1e79efbd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x55d8107e1794 in my_malloc fuzz/test-corpus.c:114
    #2 0x7f1e789b2615 in CRYPTO_zalloc crypto/mem.c:197
    #3 0x7f1e78bbfc02 in sk_reserve crypto/stack/stack.c:198
    #4 0x7f1e78bbfc02 in OPENSSL_sk_insert crypto/stack/stack.c:260
    #5 0x7f1e78b1c41f in sk_OSSL_PROPERTY_DEFINITION_push crypto/property/property_parse.c:22
    #6 0x7f1e78b1c41f in ossl_parse_property crypto/property/property_parse.c:356
    #7 0x7f1e7886a323 in ossl_decoder_from_algorithm crypto/encode_decode/decoder_meth.c:195
    #8 0x7f1e7886ac7c in construct_decoder crypto/encode_decode/decoder_meth.c:287
    #9 0x7f1e789a7fcf in ossl_method_construct_this crypto/core_fetch.c:84
    #10 0x7f1e789a775e in algorithm_do_map crypto/core_algorithm.c:68
    #11 0x7f1e789a775e in algorithm_do_this crypto/core_algorithm.c:110
    #12 0x7f1e789d6ff0 in ossl_provider_doall_activated crypto/provider_core.c:1404
    #13 0x7f1e789a7d76 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #14 0x7f1e789a887e in ossl_method_construct crypto/core_fetch.c:144
    #15 0x7f1e78869ba0 in inner_ossl_decoder_fetch crypto/encode_decode/decoder_meth.c:355
    #16 0x7f1e7886b5ad in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:531
    #17 0x7f1e7886d57a in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:442
    #18 0x7f1e7886d859 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #19 0x7f1e7860f0b6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #20 0x7f1e7860fc00 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #21 0x55d8107e0728 in FuzzerTestOneInput fuzz/asn1.c:364
    #22 0x55d8107e12a9 in testfile fuzz/test-corpus.c:182
    #23 0x55d8107de89f in main fuzz/test-corpus.c:226
    #24 0x7f1e77153082 in __libc_start_main ../csu/libc-start.c:308
    #25 0x55d8107dea4d in _start (/home/ed/OPCToolboxV5/Source/Core/OpenSSL/openssl/fuzz/asn1-test+0x9a4d)


=================================================================
==2304403==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f1e79eee808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f1e789b2615 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f1e7886a217 in ossl_decoder_new crypto/encode_decode/decoder_meth.c:32
    #3 0x7f1e7886a217 in ossl_decoder_from_algorithm crypto/encode_decode/decoder_meth.c:186
    #4 0x7f1e7886ac7c in construct_decoder crypto/encode_decode/decoder_meth.c:287
    #5 0x7f1e789a7fcf in ossl_method_construct_this crypto/core_fetch.c:84
    #6 0x7f1e789a775e in algorithm_do_map crypto/core_algorithm.c:68
    #7 0x7f1e789a775e in algorithm_do_this crypto/core_algorithm.c:110
    #8 0x7f1e789d6ff0 in ossl_provider_doall_activated crypto/provider_core.c:1404
    #9 0x7f1e789a7d76 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #10 0x7f1e789a887e in ossl_method_construct crypto/core_fetch.c:144
    #11 0x7f1e78869ba0 in inner_ossl_decoder_fetch crypto/encode_decode/decoder_meth.c:355
    #12 0x7f1e7886b5ad in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:531
    #13 0x7f1e7886d57a in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:442
    #14 0x7f1e7886d859 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #15 0x7f1e7860f0b6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #16 0x7f1e7860fc00 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #17 0x55d8107e0728 in FuzzerTestOneInput fuzz/asn1.c:364
    #18 0x55d8107e12a9 in testfile fuzz/test-corpus.c:182
    #19 0x55d8107de89f in main fuzz/test-corpus.c:226
    #20 0x7f1e77153082 in __libc_start_main ../csu/libc-start.c:308

@bernd-edlinger bernd-edlinger added the help wanted We depend on community to resolve this issue. label May 26, 2022
@mattcaswell

Copy link
Copy Markdown
Member

Analysing the second one leads me to this code:

OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder,
void *decoderctx)
{
OSSL_DECODER_INSTANCE *decoder_inst = NULL;
const OSSL_PROVIDER *prov;
OSSL_LIB_CTX *libctx;
const OSSL_PROPERTY_LIST *props;
const OSSL_PROPERTY_DEFINITION *prop;
if (!ossl_assert(decoder != NULL)) {
ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if ((decoder_inst = OPENSSL_zalloc(sizeof(*decoder_inst))) == NULL) {
ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!OSSL_DECODER_up_ref(decoder)) {
ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_INTERNAL_ERROR);
goto err;
}
prov = OSSL_DECODER_get0_provider(decoder);
libctx = ossl_provider_libctx(prov);
props = ossl_decoder_parsed_properties(decoder);
if (props == NULL) {
ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_INVALID_PROPERTY_DEFINITION,
"there are no property definitions with decoder %s",
OSSL_DECODER_get0_name(decoder));
goto err;
}

Your error injection code can cause ossl_decoder_parsed_properties() in the above code to return NULL. This appears to leak the decoder that was up-refed on line 231.

mattcaswell added a commit to mattcaswell/openssl that referenced this pull request May 26, 2022
If an error condition occurs then the the decoder that was up-refed in
ossl_decoder_instance_new can be leaked.

Found due to the error report here:
openssl#18355 (comment)
@mattcaswell

Copy link
Copy Markdown
Member

Fix for the second issue in #18410

@mattcaswell

Copy link
Copy Markdown
Member

For the first issue there are some oddities in the stack trace which I can't quite line up with the code (did you have compiler optimisations switched on?). Anyway my analysis led me to this code which is definitely wrong and is most likely the culprit in this case:

static void collect_all_decoders(OSSL_DECODER *decoder, void *arg)
{
STACK_OF(OSSL_DECODER) *skdecoders = arg;
if (OSSL_DECODER_up_ref(decoder))
sk_OSSL_DECODER_push(skdecoders, decoder);
}

The deoder is up-refed - but if the push fails the ref is not freed.

mattcaswell added a commit to mattcaswell/openssl that referenced this pull request May 26, 2022
If pushing the decoder onto a stack fails then we should free the ref
we just created.

Found due to the error report here:
openssl#18355 (comment)
@mattcaswell

Copy link
Copy Markdown
Member

Probable fix for the first issue in #18411

@bernd-edlinger

Copy link
Copy Markdown
Member Author

I configured with ./config enable-asan enable-ubsan -DERROR_INJECT -DERROR_CALLSTACK
Confirmed: both errors are reproducible with unpatched source code, and go away when I cherry-pick you fix(es).
However if I start a new test run I hit immediately another error:

ERROR_INJECT=1653071137 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/00391d49c845e33056cdd04fb4ff90ef2334ffd0
# ./corpora/asn1/00391d49c845e33056cdd04fb4ff90ef2334ffd0
    #0 0x7f09298a6eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
    #1 0x409794 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f0928406be7 in ossl_provider_set_operation_bit crypto/provider_core.c:1588
    #3 0x7f09283d8e37 in ossl_method_construct_postcondition crypto/core_fetch.c:74
    #4 0x7f09283d81ce in algorithm_do_map crypto/core_algorithm.c:75
    #5 0x7f09283d81ce in algorithm_do_this crypto/core_algorithm.c:110
    #6 0x7f0928406108 in ossl_provider_doall_activated crypto/provider_core.c:1404
    #7 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #8 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #9 0x7f09282cb4ba in inner_ossl_decoder_fetch crypto/encode_decode/decoder_meth.c:355
    #10 0x7f09282cb4ba in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:531
    #11 0x7f09282cd39f in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:442
    #12 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #13 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #16 0x409371 in testfile fuzz/test-corpus.c:182
    #17 0x406e61 in main fuzz/test-corpus.c:226
    #18 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
    #19 0x407016  (/home/ed/OPC/openssl/fuzz/asn1-test+0x407016)


=================================================================
==24523==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 224 byte(s) in 1 object(s) allocated from:
    #0 0x7f092989b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f09283e2940 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f0928404652 in provider_new crypto/provider_core.c:449
    #3 0x7f0928405a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #4 0x7f0928405db3 in ossl_provider_doall_activated crypto/provider_core.c:1343
    #5 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #6 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #7 0x7f0928365a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #8 0x7f0928365a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #9 0x7f0928381beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #10 0x7f09282cd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #11 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #12 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #13 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #14 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #15 0x409371 in testfile fuzz/test-corpus.c:182
    #16 0x406e61 in main fuzz/test-corpus.c:226
    #17 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7f092989b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f09283e2940 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f09280af469 in BIO_meth_new crypto/bio/bio_meth.c:38
    #3 0x7f092869e2f9 in ossl_bio_prov_init_bio_method providers/common/bio_prov.c:210
    #4 0x7f092869d706 in ossl_default_provider_init providers/defltprov.c:585
    #5 0x7f09283ff6ee in provider_init crypto/provider_core.c:903
    #6 0x7f09283ff6ee in provider_activate crypto/provider_core.c:1101
    #7 0x7f0928405a9a in provider_activate_fallbacks crypto/provider_core.c:1302
    #8 0x7f0928405db3 in ossl_provider_doall_activated crypto/provider_core.c:1343
    #9 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #10 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #11 0x7f0928365a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #12 0x7f0928365a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #13 0x7f0928381beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #14 0x7f09282cd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #15 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #16 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #17 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #18 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #19 0x409371 in testfile fuzz/test-corpus.c:182
    #20 0x406e61 in main fuzz/test-corpus.c:226
    #21 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7f092989b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f09283e2940 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f092840beef in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7f0928404663 in provider_new crypto/provider_core.c:453
    #4 0x7f0928405a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #5 0x7f0928405db3 in ossl_provider_doall_activated crypto/provider_core.c:1343
    #6 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #7 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #8 0x7f0928365a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #9 0x7f0928365a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #10 0x7f0928381beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #11 0x7f09282cd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #12 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #13 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #16 0x409371 in testfile fuzz/test-corpus.c:182
    #17 0x406e61 in main fuzz/test-corpus.c:226
    #18 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7f092989b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f09283e2940 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f092840beef in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7f09284046a9 in provider_new crypto/provider_core.c:454
    #4 0x7f0928405a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #5 0x7f0928405db3 in ossl_provider_doall_activated crypto/provider_core.c:1343
    #6 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #7 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #8 0x7f0928365a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #9 0x7f0928365a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #10 0x7f0928381beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #11 0x7f09282cd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #12 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #13 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #16 0x409371 in testfile fuzz/test-corpus.c:182
    #17 0x406e61 in main fuzz/test-corpus.c:226
    #18 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f092989b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f09285ef4f0 in OPENSSL_sk_deep_copy crypto/stack/stack.c:89
    #2 0x7f0928404719 in sk_INFOPAIR_deep_copy crypto/provider_local.h:16
    #3 0x7f0928404719 in provider_new crypto/provider_core.c:456
    #4 0x7f0928405a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #5 0x7f0928405db3 in ossl_provider_doall_activated crypto/provider_core.c:1343
    #6 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #7 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #8 0x7f0928365a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #9 0x7f0928365a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #10 0x7f0928381beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #11 0x7f09282cd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #12 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #13 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #16 0x409371 in testfile fuzz/test-corpus.c:182
    #17 0x406e61 in main fuzz/test-corpus.c:226
    #18 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f092989b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f09283e2940 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f092869d6cd in ossl_default_provider_init providers/defltprov.c:584
    #3 0x7f09283ff6ee in provider_init crypto/provider_core.c:903
    #4 0x7f09283ff6ee in provider_activate crypto/provider_core.c:1101
    #5 0x7f0928405a9a in provider_activate_fallbacks crypto/provider_core.c:1302
    #6 0x7f0928405db3 in ossl_provider_doall_activated crypto/provider_core.c:1343
    #7 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #8 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #9 0x7f0928365a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #10 0x7f0928365a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #11 0x7f0928381beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #12 0x7f09282cd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #13 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #14 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #15 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #16 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #17 0x409371 in testfile fuzz/test-corpus.c:182
    #18 0x406e61 in main fuzz/test-corpus.c:226
    #19 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 19 byte(s) in 1 object(s) allocated from:
    #0 0x7f092989b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f09283e577e in CRYPTO_strdup crypto/o_str.c:27
    #2 0x7f09280af481 in BIO_meth_new crypto/bio/bio_meth.c:41
    #3 0x7f092869e2f9 in ossl_bio_prov_init_bio_method providers/common/bio_prov.c:210
    #4 0x7f092869d706 in ossl_default_provider_init providers/defltprov.c:585
    #5 0x7f09283ff6ee in provider_init crypto/provider_core.c:903
    #6 0x7f09283ff6ee in provider_activate crypto/provider_core.c:1101
    #7 0x7f0928405a9a in provider_activate_fallbacks crypto/provider_core.c:1302
    #8 0x7f0928405db3 in ossl_provider_doall_activated crypto/provider_core.c:1343
    #9 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #10 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #11 0x7f0928365a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #12 0x7f0928365a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #13 0x7f0928381beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #14 0x7f09282cd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #15 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #16 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #17 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #18 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #19 0x409371 in testfile fuzz/test-corpus.c:182
    #20 0x406e61 in main fuzz/test-corpus.c:226
    #21 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f092989b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f09283e577e in CRYPTO_strdup crypto/o_str.c:27
    #2 0x7f09284046de in provider_new crypto/provider_core.c:455
    #3 0x7f0928405a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #4 0x7f0928405db3 in ossl_provider_doall_activated crypto/provider_core.c:1343
    #5 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #6 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #7 0x7f0928365a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #8 0x7f0928365a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #9 0x7f0928381beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #10 0x7f09282cd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #11 0x7f09282cd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #12 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #13 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #14 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #15 0x409371 in testfile fuzz/test-corpus.c:182
    #16 0x406e61 in main fuzz/test-corpus.c:226
    #17 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 3 byte(s) in 1 object(s) allocated from:
    #0 0x7f0929899fa5 in __interceptor_realloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:85
    #1 0x7f0928406be7 in ossl_provider_set_operation_bit crypto/provider_core.c:1588
    #2 0x7f09283d8e37 in ossl_method_construct_postcondition crypto/core_fetch.c:74
    #3 0x7f09283d81ce in algorithm_do_map crypto/core_algorithm.c:75
    #4 0x7f09283d81ce in algorithm_do_this crypto/core_algorithm.c:110
    #5 0x7f0928406108 in ossl_provider_doall_activated crypto/provider_core.c:1404
    #6 0x7f09283d86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #7 0x7f09283d9184 in ossl_method_construct crypto/core_fetch.c:144
    #8 0x7f09282cb4ba in inner_ossl_decoder_fetch crypto/encode_decode/decoder_meth.c:355
    #9 0x7f09282cb4ba in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:531
    #10 0x7f09282c6be7 in OSSL_DECODER_CTX_add_extra crypto/encode_decode/decoder_lib.c:514
    #11 0x7f09282cd77c in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:501
    #12 0x7f092806c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #13 0x7f092806d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #14 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #15 0x409371 in testfile fuzz/test-corpus.c:182
    #16 0x406e61 in main fuzz/test-corpus.c:226
    #17 0x7f0926919f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

SUMMARY: AddressSanitizer: 518 byte(s) leaked in 9 allocation(s).

@mattcaswell

Copy link
Copy Markdown
Member

This doesn't look quite right:

openssl/crypto/provider_core.c

Lines 1401 to 1435 in 7e5e911

for (curr = 0; curr < max; curr++) {
OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(provs, curr);
if (!cb(prov, cbdata))
goto finish;
}
curr = -1;
ret = 1;
goto finish;
err_unlock:
CRYPTO_THREAD_unlock(store->lock);
finish:
/*
* The pop_free call doesn't do what we want on an error condition. We
* either start from the first item in the stack, or part way through if
* we only processed some of the items.
*/
for (curr++; curr < max; curr++) {
OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(provs, curr);
provider_deactivate(prov, 0, 1);
/*
* As above where we did the up-ref, we don't call ossl_provider_free
* to avoid making upcalls. There should always be at least one ref
* to the provider in the store, so this should never drop to 0.
*/
CRYPTO_DOWN_REF(&prov->refcnt, &ref, prov->refcnt_lock);
/*
* Not much we can do if this assert ever fails. So we don't use
* ossl_assert here.
*/
assert(ref > 0);
}

If the cb call on 1404 fails part way through processing a stack of providers we goto finish without resetting curr to -1 (like we do if we finish the loop normally). This means we only free the providers in the stack that we didn't call cb for. We should free all of them.

@mattcaswell

Copy link
Copy Markdown
Member

Possible fix in #18413

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Possible fix in #18413

Confirmed. testrun.sh is now running for 13 seconds...
but then:

ERROR_INJECT=1653475718 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/06bc17ade5d3053d7f10c0619193cf410be020d3
    #0 0x7efc2f0a6eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
    #1 0x409814 in my_malloc fuzz/test-corpus.c:114
    #2 0x7efc2dcfe6f8 in OBJ_NAME_add crypto/objects/o_names.c:200
    #3 0x7efc2dafa846 in openssl_add_all_ciphers_int crypto/evp/c_allc.c:203
    #4 0x7efc2dbe09c8 in ossl_init_add_all_ciphers crypto/init.c:204
    #5 0x7efc2dbe09c8 in ossl_init_add_all_ciphers_ossl_ crypto/init.c:196
    #6 0x7efc2c4d5a7f in __pthread_once (/lib/x86_64-linux-gnu/libpthread.so.0+0xda7f)
    #7 0x7efc2dc0bfea in CRYPTO_THREAD_run_once crypto/threads_pthread.c:156
    #8 0x7efc2dbe1002 in OPENSSL_init_crypto crypto/init.c:549
    #9 0x7efc2ecc1468 in OPENSSL_init_ssl ssl/ssl_init.c:115
    #10 0x4070f0 in FuzzerInitialize fuzz/asn1.c:288
    #11 0x406adf in main fuzz/test-corpus.c:194
    #12 0x7efc2c119f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
    #13 0x407016  (/home/ed/OPC/openssl/fuzz/asn1-test+0x407016)

# ./corpora/asn1/06bc17ade5d3053d7f10c0619193cf410be020d3
    #0 0x7efc2f0a6eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
    #1 0x409794 in my_realloc fuzz/test-corpus.c:129
    #2 0x7efc2dded6fe in sk_reserve crypto/stack/stack.c:216
    #3 0x7efc2dded6fe in OPENSSL_sk_insert crypto/stack/stack.c:260
    #4 0x7efc2d87ccb1 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:660
    #5 0x7efc2d87da9a in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #6 0x7efc2d87b1ed in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:298
    #7 0x7efc2d87e7b1 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #8 0x7efc2d87e7b1 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #9 0x407529 in FuzzerTestOneInput fuzz/asn1.c:314
    #10 0x409371 in testfile fuzz/test-corpus.c:182
    #11 0x406e61 in main fuzz/test-corpus.c:226
    #12 0x7efc2c119f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
    #13 0x407016  (/home/ed/OPC/openssl/fuzz/asn1-test+0x407016)

    #0 0x7efc2f0a6eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
    #1 0x409814 in my_malloc fuzz/test-corpus.c:114
    #2 0x7efc2dbe577e in CRYPTO_strdup crypto/o_str.c:27
    #3 0x7efc2dc046de in provider_new crypto/provider_core.c:455
    #4 0x7efc2dc05a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #5 0x7efc2dc05dae in ossl_provider_doall_activated crypto/provider_core.c:1343
    #6 0x7efc2dbd86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #7 0x7efc2dbd9184 in ossl_method_construct crypto/core_fetch.c:144
    #8 0x7efc2db65a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #9 0x7efc2db65a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #10 0x7efc2db81beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #11 0x7efc2dacd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #12 0x7efc2dacd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #13 0x7efc2d86c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7efc2d86d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #16 0x409371 in testfile fuzz/test-corpus.c:182
    #17 0x406e61 in main fuzz/test-corpus.c:226
    #18 0x7efc2c119f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
    #19 0x407016  (/home/ed/OPC/openssl/fuzz/asn1-test+0x407016)

    #0 0x7efc2f0a6eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
    #1 0x409794 in my_realloc fuzz/test-corpus.c:129
    #2 0x7efc2dded6fe in sk_reserve crypto/stack/stack.c:216
    #3 0x7efc2dded6fe in OPENSSL_sk_insert crypto/stack/stack.c:260
    #4 0x7efc2dd51843 in ossl_property_string crypto/property/property_string.c:174
    #5 0x7efc2dd51843 in ossl_property_value crypto/property/property_string.c:265
    #6 0x7efc2dd4b1b1 in parse_unquoted crypto/property/property_parse.c:219
    #7 0x7efc2dd4b779 in parse_value crypto/property/property_parse.c:251
    #8 0x7efc2dd4d634 in ossl_parse_property crypto/property/property_parse.c:345
    #9 0x7efc2dac9962 in ossl_decoder_from_algorithm crypto/encode_decode/decoder_meth.c:195
    #10 0x7efc2daca20a in construct_decoder crypto/encode_decode/decoder_meth.c:287
    #11 0x7efc2dbd890c in ossl_method_construct_this crypto/core_fetch.c:84
    #12 0x7efc2dbd810e in algorithm_do_map crypto/core_algorithm.c:68
    #13 0x7efc2dbd810e in algorithm_do_this crypto/core_algorithm.c:110
    #14 0x7efc2dc06106 in ossl_provider_doall_activated crypto/provider_core.c:1404
    #15 0x7efc2dbd86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #16 0x7efc2dbd9184 in ossl_method_construct crypto/core_fetch.c:144
    #17 0x7efc2dacb4ba in inner_ossl_decoder_fetch crypto/encode_decode/decoder_meth.c:355
    #18 0x7efc2dacb4ba in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:531
    #19 0x7efc2dacd39f in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:442
    #20 0x7efc2dacd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #21 0x7efc2d86c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #22 0x7efc2d86d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #23 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #24 0x409371 in testfile fuzz/test-corpus.c:182
    #25 0x406e61 in main fuzz/test-corpus.c:226
    #26 0x7efc2c119f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
    #27 0x407016  (/home/ed/OPC/openssl/fuzz/asn1-test+0x407016)


=================================================================
==4348==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 224 byte(s) in 1 object(s) allocated from:
    #0 0x7efc2f09b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7efc2dbe2940 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7efc2dc04652 in provider_new crypto/provider_core.c:449
    #3 0x7efc2dc05a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #4 0x7efc2dc05dae in ossl_provider_doall_activated crypto/provider_core.c:1343
    #5 0x7efc2dbd86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #6 0x7efc2dbd9184 in ossl_method_construct crypto/core_fetch.c:144
    #7 0x7efc2db65a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #8 0x7efc2db65a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #9 0x7efc2db81beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #10 0x7efc2dacd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #11 0x7efc2dacd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #12 0x7efc2d86c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #13 0x7efc2d86d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #14 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #15 0x409371 in testfile fuzz/test-corpus.c:182
    #16 0x406e61 in main fuzz/test-corpus.c:226
    #17 0x7efc2c119f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7efc2f09b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7efc2dbe2940 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7efc2dc0beef in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7efc2dc046a9 in provider_new crypto/provider_core.c:454
    #4 0x7efc2dc05a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #5 0x7efc2dc05dae in ossl_provider_doall_activated crypto/provider_core.c:1343
    #6 0x7efc2dbd86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #7 0x7efc2dbd9184 in ossl_method_construct crypto/core_fetch.c:144
    #8 0x7efc2db65a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #9 0x7efc2db65a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #10 0x7efc2db81beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #11 0x7efc2dacd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #12 0x7efc2dacd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #13 0x7efc2d86c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7efc2d86d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #16 0x409371 in testfile fuzz/test-corpus.c:182
    #17 0x406e61 in main fuzz/test-corpus.c:226
    #18 0x7efc2c119f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7efc2f09b09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7efc2dbe2940 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7efc2dc0beef in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7efc2dc04663 in provider_new crypto/provider_core.c:453
    #4 0x7efc2dc05a0c in provider_activate_fallbacks crypto/provider_core.c:1288
    #5 0x7efc2dc05dae in ossl_provider_doall_activated crypto/provider_core.c:1343
    #6 0x7efc2dbd86c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #7 0x7efc2dbd9184 in ossl_method_construct crypto/core_fetch.c:144
    #8 0x7efc2db65a36 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:288
    #9 0x7efc2db65a36 in evp_generic_do_all crypto/evp/evp_fetch.c:571
    #10 0x7efc2db81beb in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:279
    #11 0x7efc2dacd34b in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:436
    #12 0x7efc2dacd769 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:499
    #13 0x7efc2d86c65c in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7efc2d86d0c5 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x408916 in FuzzerTestOneInput fuzz/asn1.c:364
    #16 0x409371 in testfile fuzz/test-corpus.c:182
    #17 0x406e61 in main fuzz/test-corpus.c:226
    #18 0x7efc2c119f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

SUMMARY: AddressSanitizer: 336 byte(s) leaked in 3 allocation(s).

again the error is reproducible with
ERROR_INJECT=1653475718 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/06bc17ade5d3053d7f10c0619193cf410be020d

mattcaswell added a commit to mattcaswell/openssl that referenced this pull request May 27, 2022
The function ossl_provider_free() decrements the refcnt of the
provider and frees it if it has reached 0. This only works if the
refcnt has already been initialised. We must only call
ossl_provider_free() after this initialisation - otherwise it will fail
to free the provider correctly.

Addresses the issue mentioned here:
openssl#18355 (comment)
@mattcaswell

Copy link
Copy Markdown
Member

Fix for this latest issue in #18417

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Thanks @mattcaswell, confirmed this issue is fixed.
It is slowly getting better, this time the test ran 18 seconds 😄
and stopped with:

ERROR_INJECT=1653843206 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/07fa4af1bd7601f65068dbd52c3b188b17a91995
# ./corpora/asn1/07fa4af1bd7601f65068dbd52c3b188b17a91995
    #0 0x7f7016cf6eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
    #1 0x409794 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f70158236b8 in expand crypto/lhash/lhash.c:224
    #3 0x7f70158236b8 in OPENSSL_LH_insert crypto/lhash/lhash.c:114
    #4 0x7f7015995ea5 in lh_PROPERTY_DEFN_ELEM_insert crypto/property/defn_cache.c:32
    #5 0x7f7015995ea5 in ossl_prop_defn_set crypto/property/defn_cache.c:111
    #6 0x7f7015997788 in ossl_method_store_add crypto/property/property.c:307
    #7 0x7f701572054f in put_encoder_in_store crypto/encode_decode/encoder_meth.c:173
    #8 0x7f70158289ec in ossl_method_construct_this crypto/core_fetch.c:101
    #9 0x7f701582810e in algorithm_do_map crypto/core_algorithm.c:68
    #10 0x7f701582810e in algorithm_do_this crypto/core_algorithm.c:110
    #11 0x7f7015856146 in ossl_provider_doall_activated crypto/provider_core.c:1411
    #12 0x7f70158286c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #13 0x7f7015829184 in ossl_method_construct crypto/core_fetch.c:144
    #14 0x7f7015720c8f in inner_ossl_encoder_fetch crypto/encode_decode/encoder_meth.c:365
    #15 0x7f701572271a in OSSL_ENCODER_do_all_provided crypto/encode_decode/encoder_meth.c:522
    #16 0x7f70157240fc in ossl_encoder_ctx_setup_for_pkey crypto/encode_decode/encoder_pkey.c:280
    #17 0x7f70157240fc in OSSL_ENCODER_CTX_new_for_pkey crypto/encode_decode/encoder_pkey.c:360
    #18 0x7f70157e189b in print_pkey crypto/evp/p_lib.c:1161
    #19 0x7f70157e189b in EVP_PKEY_print_private crypto/evp/p_lib.c:1192
    #20 0x40894b in FuzzerTestOneInput fuzz/asn1.c:364
    #21 0x409371 in testfile fuzz/test-corpus.c:182
    #22 0x406e61 in main fuzz/test-corpus.c:226
    #23 0x7f7013d69f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
    #24 0x407016  (/home/ed/OPC/openssl/fuzz/asn1-test+0x407016)


=================================================================
==7507==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 104 byte(s) in 1 object(s) allocated from:
    #0 0x7f7016ceb09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f701599c2b0 in stack_to_property_list crypto/property/property_parse.c:290
    #2 0x7f701599d5d8 in ossl_parse_property crypto/property/property_parse.c:366
    #3 0x7f701599774d in ossl_method_store_add crypto/property/property.c:304
    #4 0x7f701572054f in put_encoder_in_store crypto/encode_decode/encoder_meth.c:173
    #5 0x7f70158289ec in ossl_method_construct_this crypto/core_fetch.c:101
    #6 0x7f701582810e in algorithm_do_map crypto/core_algorithm.c:68
    #7 0x7f701582810e in algorithm_do_this crypto/core_algorithm.c:110
    #8 0x7f7015856146 in ossl_provider_doall_activated crypto/provider_core.c:1411
    #9 0x7f70158286c9 in ossl_algorithm_do_all crypto/core_algorithm.c:146
    #10 0x7f7015829184 in ossl_method_construct crypto/core_fetch.c:144
    #11 0x7f7015720c8f in inner_ossl_encoder_fetch crypto/encode_decode/encoder_meth.c:365
    #12 0x7f701572271a in OSSL_ENCODER_do_all_provided crypto/encode_decode/encoder_meth.c:522
    #13 0x7f70157240fc in ossl_encoder_ctx_setup_for_pkey crypto/encode_decode/encoder_pkey.c:280
    #14 0x7f70157240fc in OSSL_ENCODER_CTX_new_for_pkey crypto/encode_decode/encoder_pkey.c:360
    #15 0x7f70157e189b in print_pkey crypto/evp/p_lib.c:1161
    #16 0x7f70157e189b in EVP_PKEY_print_private crypto/evp/p_lib.c:1192
    #17 0x40894b in FuzzerTestOneInput fuzz/asn1.c:364
    #18 0x409371 in testfile fuzz/test-corpus.c:182
    #19 0x406e61 in main fuzz/test-corpus.c:226
    #20 0x7f7013d69f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

SUMMARY: AddressSanitizer: 104 byte(s) leaked in 1 allocation(s).

openssl-machine pushed a commit that referenced this pull request Jun 2, 2022
If an error condition occurs then the the decoder that was up-refed in
ossl_decoder_instance_new can be leaked.

Found due to the error report here:
#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Shane Lontis <[email protected]>
(Merged from #18410)
openssl-machine pushed a commit that referenced this pull request Jun 2, 2022
If pushing the decoder onto a stack fails then we should free the ref
we just created.

Found due to the error report here:
#18355 (comment)

Reviewed-by: Richard Levitte <[email protected]>
Reviewed-by: Shane Lontis <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #18411)
openssl-machine pushed a commit that referenced this pull request Jun 2, 2022
The function ossl_provider_free() decrements the refcnt of the
provider and frees it if it has reached 0. This only works if the
refcnt has already been initialised. We must only call
ossl_provider_free() after this initialisation - otherwise it will fail
to free the provider correctly.

Addresses the issue mentioned here:
#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #18417)
openssl-machine pushed a commit that referenced this pull request Jun 2, 2022
If an error condition occurs then the the decoder that was up-refed in
ossl_decoder_instance_new can be leaked.

Found due to the error report here:
#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Shane Lontis <[email protected]>
(Merged from #18410)

(cherry picked from commit 9ec9b96)
openssl-machine pushed a commit that referenced this pull request Jun 2, 2022
If pushing the decoder onto a stack fails then we should free the ref
we just created.

Found due to the error report here:
#18355 (comment)

Reviewed-by: Richard Levitte <[email protected]>
Reviewed-by: Shane Lontis <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #18411)

(cherry picked from commit da31939)
openssl-machine pushed a commit that referenced this pull request Jun 2, 2022
The function ossl_provider_free() decrements the refcnt of the
provider and frees it if it has reached 0. This only works if the
refcnt has already been initialised. We must only call
ossl_provider_free() after this initialisation - otherwise it will fail
to free the provider correctly.

Addresses the issue mentioned here:
#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #18417)

(cherry picked from commit c4ed6f6)
@bernd-edlinger

Copy link
Copy Markdown
Member Author

Hmm, I did not try to run this on the 3.0 branch so far, I just did it now, and the results are devastating. Here is one of the simple errors:

ERROR_INJECT=1656375143 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/00b14db87f31c2b33204bbfdabf96bd422712976
    #0 0x7f329d1f1d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5573c3f297a4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7f329bdb2761 in new_property_string crypto/property/property_string.c:123
    #3 0x7f329bdb2761 in ossl_property_string crypto/property/property_string.c:157
    #4 0x7f329bdb2761 in ossl_property_name crypto/property/property_string.c:219
    #5 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #6 0x7f329bcdf417 in context_init crypto/context.c:101
    #7 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #8 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #9 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #10 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #11 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #12 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #13 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #14 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #15 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #16 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #17 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308
    #18 0x5573c3f26a4d in _start (.../openssl/fuzz/asn1-test+0x9a4d)


=================================================================
==1964649==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f329d1e4808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f329bcec4e5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f329be5cdda in OPENSSL_sk_new_reserve crypto/stack/stack.c:221
    #3 0x7f329bce8704 in CRYPTO_set_ex_data crypto/ex_data.c:470
    #4 0x7f329bcdf16d in ossl_lib_ctx_generic_new crypto/context.c:318
    #5 0x7f329bce84a5 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #6 0x7f329bce0381 in ossl_lib_ctx_get_data crypto/context.c:413
    #7 0x7f329bdb2442 in ossl_property_name crypto/property/property_string.c:214
    #8 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #9 0x7f329bcdf417 in context_init crypto/context.c:101
    #10 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #11 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #12 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #13 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #14 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #15 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #16 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #17 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #18 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #19 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #20 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f329d1e4808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f329bcec4e5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f329bcdb84e in OPENSSL_LH_new crypto/lhash/lhash.c:59
    #3 0x7f329bdb1ec3 in lh_PROPERTY_STRING_new crypto/property/property_string.c:34
    #4 0x7f329bdb1ec3 in property_string_data_new crypto/property/property_string.c:96
    #5 0x7f329bcdf116 in ossl_lib_ctx_generic_new crypto/context.c:309
    #6 0x7f329bce84a5 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7f329bce0381 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7f329bdb2442 in ossl_property_name crypto/property/property_string.c:214
    #9 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #10 0x7f329bcdf417 in context_init crypto/context.c:101
    #11 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #12 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #13 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #14 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #15 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #16 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #17 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #18 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #19 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #20 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #21 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f329d1e4808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f329bcec4e5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f329bcdb84e in OPENSSL_LH_new crypto/lhash/lhash.c:59
    #3 0x7f329bdb1f03 in lh_PROPERTY_STRING_new crypto/property/property_string.c:34
    #4 0x7f329bdb1f03 in property_string_data_new crypto/property/property_string.c:101
    #5 0x7f329bcdf116 in ossl_lib_ctx_generic_new crypto/context.c:309
    #6 0x7f329bce84a5 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7f329bce0381 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7f329bdb2442 in ossl_property_name crypto/property/property_string.c:214
    #9 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #10 0x7f329bcdf417 in context_init crypto/context.c:101
    #11 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #12 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #13 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #14 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #15 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #16 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #17 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #18 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #19 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #20 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #21 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7f329d1e4808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f329bcec4e5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f329bcdb82c in OPENSSL_LH_new crypto/lhash/lhash.c:51
    #3 0x7f329bdb1f03 in lh_PROPERTY_STRING_new crypto/property/property_string.c:34
    #4 0x7f329bdb1f03 in property_string_data_new crypto/property/property_string.c:101
    #5 0x7f329bcdf116 in ossl_lib_ctx_generic_new crypto/context.c:309
    #6 0x7f329bce84a5 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7f329bce0381 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7f329bdb2442 in ossl_property_name crypto/property/property_string.c:214
    #9 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #10 0x7f329bcdf417 in context_init crypto/context.c:101
    #11 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #12 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #13 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #14 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #15 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #16 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #17 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #18 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #19 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #20 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #21 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7f329d1e4808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f329bcec4e5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f329bcdb82c in OPENSSL_LH_new crypto/lhash/lhash.c:51
    #3 0x7f329bdb1ec3 in lh_PROPERTY_STRING_new crypto/property/property_string.c:34
    #4 0x7f329bdb1ec3 in property_string_data_new crypto/property/property_string.c:96
    #5 0x7f329bcdf116 in ossl_lib_ctx_generic_new crypto/context.c:309
    #6 0x7f329bce84a5 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7f329bce0381 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7f329bdb2442 in ossl_property_name crypto/property/property_string.c:214
    #9 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #10 0x7f329bcdf417 in context_init crypto/context.c:101
    #11 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #12 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #13 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #14 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #15 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #16 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #17 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #18 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #19 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #20 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #21 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7f329d1e4808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f329bcec4e5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f329bd15253 in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7f329bdb1e85 in property_string_data_new crypto/property/property_string.c:92
    #4 0x7f329bcdf116 in ossl_lib_ctx_generic_new crypto/context.c:309
    #5 0x7f329bce84a5 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #6 0x7f329bce0381 in ossl_lib_ctx_get_data crypto/context.c:413
    #7 0x7f329bdb2442 in ossl_property_name crypto/property/property_string.c:214
    #8 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #9 0x7f329bcdf417 in context_init crypto/context.c:101
    #10 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #11 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #12 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #13 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #14 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #15 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #16 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #17 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #18 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #19 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #20 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f329d1e4808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f329bcec4e5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f329be5a9ab in sk_reserve crypto/stack/stack.c:192
    #3 0x7f329be5a9ab in OPENSSL_sk_insert crypto/stack/stack.c:254
    #4 0x7f329bce863a in CRYPTO_set_ex_data crypto/ex_data.c:477
    #5 0x7f329bcdf16d in ossl_lib_ctx_generic_new crypto/context.c:318
    #6 0x7f329bce84a5 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7f329bce0381 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7f329bdb2442 in ossl_property_name crypto/property/property_string.c:214
    #9 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #10 0x7f329bcdf417 in context_init crypto/context.c:101
    #11 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #12 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #13 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #14 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #15 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #16 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #17 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #18 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #19 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #20 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #21 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f329d1e4808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f329bcec4e5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f329bdb1e74 in property_string_data_new crypto/property/property_string.c:87
    #3 0x7f329bcdf116 in ossl_lib_ctx_generic_new crypto/context.c:309
    #4 0x7f329bce84a5 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #5 0x7f329bce0381 in ossl_lib_ctx_get_data crypto/context.c:413
    #6 0x7f329bdb2442 in ossl_property_name crypto/property/property_string.c:214
    #7 0x7f329bdb05c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #8 0x7f329bcdf417 in context_init crypto/context.c:101
    #9 0x7f329bcdf7e3 in OSSL_LIB_CTX_new crypto/context.c:193
    #10 0x5573c3f28d25 in fuzz_rand_provider_init fuzz/fuzz_rand.c:148
    #11 0x7f329bd08d7e in provider_init crypto/provider_core.c:918
    #12 0x7f329bd08d7e in provider_activate crypto/provider_core.c:1116
    #13 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1245
    #14 0x7f329bd0beb4 in ossl_provider_activate crypto/provider_core.c:1231
    #15 0x7f329bd04ec6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #16 0x5573c3f28f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #17 0x5573c3f26b1c in FuzzerInitialize fuzz/asn1.c:287
    #18 0x5573c3f26493 in main fuzz/test-corpus.c:194
    #19 0x7f329a3ef082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: 552 byte(s) leaked in 8 allocation(s).

This one is still reproducible in 3.0 all other bugs have been fixed or are at least no more reproducible.

@bernd-edlinger

bernd-edlinger commented Jul 29, 2022

Copy link
Copy Markdown
Member Author

Here are a couple random issues in the 3.0 branch that have each been found after just a few seconds:

ERROR_INJECT=1659108176 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/000458cba2f14f4f273d9f28bf4724f60aa0ef94
# ./corpora/asn1/000458cba2f14f4f273d9f28bf4724f60aa0ef94
    #0 0x7f898d763d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x56307fc5c724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f898c3cb768 in sk_reserve crypto/stack/stack.c:210
    #3 0x7f898c3cb768 in OPENSSL_sk_insert crypto/stack/stack.c:254
    #4 0x7f898c2594ea in CRYPTO_set_ex_data crypto/ex_data.c:477
    #5 0x7f898c24fd5d in ossl_lib_ctx_generic_new crypto/context.c:318
    #6 0x7f898c259355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7f898c250f71 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7f898c317af5 in ossl_prop_defn_get crypto/property/defn_cache.c:76
    #9 0x7f898c31954c in ossl_method_store_add crypto/property/property.c:332
    #10 0x7f898c1d5945 in put_evp_method_in_store crypto/evp/evp_fetch.c:210
    #11 0x7f898c2527df in ossl_method_construct_this crypto/core_fetch.c:123
    #12 0x7f898c251dc1 in algorithm_do_map crypto/core_algorithm.c:77
    #13 0x7f898c251dc1 in algorithm_do_this crypto/core_algorithm.c:122
    #14 0x7f898c27fffe in ossl_provider_doall_activated crypto/provider_core.c:1419
    #15 0x7f898c252356 in ossl_algorithm_do_all crypto/core_algorithm.c:162
    #16 0x7f898c25306e in ossl_method_construct crypto/core_fetch.c:153
    #17 0x7f898c1d8b3a in inner_evp_generic_fetch crypto/evp/evp_fetch.c:344
    #18 0x7f898c1d8b3a in evp_generic_do_all crypto/evp/evp_fetch.c:654
    #19 0x7f898c1f5f9f in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:290
    #20 0x7f898c11730c in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:346
    #21 0x7f898c1179c9 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:450
    #22 0x7f898c47687b in x509_pubkey_ex_d2i_ex crypto/x509/x_pubkey.c:208
    #23 0x7f898be7a7bd in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:262
    #24 0x7f898be7c8ec in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #25 0x7f898be7d398 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #26 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #27 0x7f898be7c8ec in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #28 0x7f898be7d398 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #29 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #30 0x7f898be7c527 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:651
    #31 0x7f898be7d89d in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:534
    #32 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #33 0x7f898be7e0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #34 0x7f898be7e0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #35 0x56307fc59f1f in FuzzerTestOneInput fuzz/asn1.c:315
    #36 0x56307fc5c2b9 in testfile fuzz/test-corpus.c:182
    #37 0x56307fc5989f in main fuzz/test-corpus.c:226
    #38 0x7f898a95d082 in __libc_start_main ../csu/libc-start.c:308
    #39 0x56307fc59a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f898d763d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x56307fc5c724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f898bf1d2b5 in BUF_MEM_grow crypto/buffer/buffer.c:97
    #3 0x7f898c474c2e in x509_name_ex_d2i crypto/x509/x_name.c:177
    #4 0x7f898be7ad7a in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:264
    #5 0x7f898be7c8ec in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #6 0x7f898be7d398 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #7 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #8 0x7f898be7c8ec in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #9 0x7f898be7d398 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #10 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #11 0x7f898be7c527 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:651
    #12 0x7f898be7d89d in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:534
    #13 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #14 0x7f898be7e0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #15 0x7f898be7e0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #16 0x56307fc59f1f in FuzzerTestOneInput fuzz/asn1.c:315
    #17 0x56307fc5c2b9 in testfile fuzz/test-corpus.c:182
    #18 0x56307fc5989f in main fuzz/test-corpus.c:226
    #19 0x7f898a95d082 in __libc_start_main ../csu/libc-start.c:308
    #20 0x56307fc59a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)


=================================================================
==1176101==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7f898d756808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f898c25d395 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f898c24c41c in OPENSSL_LH_new crypto/lhash/lhash.c:51
    #3 0x7f898c24fd06 in ossl_lib_ctx_generic_new crypto/context.c:309
    #4 0x7f898c259355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #5 0x7f898c250f71 in ossl_lib_ctx_get_data crypto/context.c:413
    #6 0x7f898c317af5 in ossl_prop_defn_get crypto/property/defn_cache.c:76
    #7 0x7f898c31954c in ossl_method_store_add crypto/property/property.c:332
    #8 0x7f898c1d5945 in put_evp_method_in_store crypto/evp/evp_fetch.c:210
    #9 0x7f898c2527df in ossl_method_construct_this crypto/core_fetch.c:123
    #10 0x7f898c251dc1 in algorithm_do_map crypto/core_algorithm.c:77
    #11 0x7f898c251dc1 in algorithm_do_this crypto/core_algorithm.c:122
    #12 0x7f898c27fffe in ossl_provider_doall_activated crypto/provider_core.c:1419
    #13 0x7f898c252356 in ossl_algorithm_do_all crypto/core_algorithm.c:162
    #14 0x7f898c25306e in ossl_method_construct crypto/core_fetch.c:153
    #15 0x7f898c1d8b3a in inner_evp_generic_fetch crypto/evp/evp_fetch.c:344
    #16 0x7f898c1d8b3a in evp_generic_do_all crypto/evp/evp_fetch.c:654
    #17 0x7f898c1f5f9f in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:290
    #18 0x7f898c11730c in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:346
    #19 0x7f898c1179c9 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:450
    #20 0x7f898c47687b in x509_pubkey_ex_d2i_ex crypto/x509/x_pubkey.c:208
    #21 0x7f898be7a7bd in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:262
    #22 0x7f898be7c8ec in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #23 0x7f898be7d398 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #24 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #25 0x7f898be7c8ec in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #26 0x7f898be7d398 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #27 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #28 0x7f898be7c527 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:651
    #29 0x7f898be7d89d in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:534
    #30 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #31 0x7f898be7e0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #32 0x7f898be7e0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144

Indirect leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f898d756808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f898c25d395 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f898c24c43e in OPENSSL_LH_new crypto/lhash/lhash.c:59
    #3 0x7f898c24fd06 in ossl_lib_ctx_generic_new crypto/context.c:309
    #4 0x7f898c259355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #5 0x7f898c250f71 in ossl_lib_ctx_get_data crypto/context.c:413
    #6 0x7f898c317af5 in ossl_prop_defn_get crypto/property/defn_cache.c:76
    #7 0x7f898c31954c in ossl_method_store_add crypto/property/property.c:332
    #8 0x7f898c1d5945 in put_evp_method_in_store crypto/evp/evp_fetch.c:210
    #9 0x7f898c2527df in ossl_method_construct_this crypto/core_fetch.c:123
    #10 0x7f898c251dc1 in algorithm_do_map crypto/core_algorithm.c:77
    #11 0x7f898c251dc1 in algorithm_do_this crypto/core_algorithm.c:122
    #12 0x7f898c27fffe in ossl_provider_doall_activated crypto/provider_core.c:1419
    #13 0x7f898c252356 in ossl_algorithm_do_all crypto/core_algorithm.c:162
    #14 0x7f898c25306e in ossl_method_construct crypto/core_fetch.c:153
    #15 0x7f898c1d8b3a in inner_evp_generic_fetch crypto/evp/evp_fetch.c:344
    #16 0x7f898c1d8b3a in evp_generic_do_all crypto/evp/evp_fetch.c:654
    #17 0x7f898c1f5f9f in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:290
    #18 0x7f898c11730c in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:346
    #19 0x7f898c1179c9 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:450
    #20 0x7f898c47687b in x509_pubkey_ex_d2i_ex crypto/x509/x_pubkey.c:208
    #21 0x7f898be7a7bd in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:262
    #22 0x7f898be7c8ec in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #23 0x7f898be7d398 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #24 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #25 0x7f898be7c8ec in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #26 0x7f898be7d398 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #27 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #28 0x7f898be7c527 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:651
    #29 0x7f898be7d89d in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:534
    #30 0x7f898be7b03e in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #31 0x7f898be7e0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #32 0x7f898be7e0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144

SUMMARY: AddressSanitizer: 200 byte(s) leaked in 2 allocation(s).
ERROR_INJECT=1659430778 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/00846bd1e0b3302d5a93c18a3f8562742ca310a6
    #0 0x7f383502fd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x55f7c7da47a4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7f3833b19054 in OPENSSL_LH_insert crypto/lhash/lhash.c:120
    #3 0x7f38339faa7e in err_load_strings crypto/err/err.c:265
    #4 0x7f38339faa7e in err_load_strings crypto/err/err.c:260
    #5 0x7f38339faa7e in ERR_load_strings_const crypto/err/err.c:302
    #6 0x7f38338b96bb in ossl_err_load_DSO_strings crypto/dso/dso_err.c:53
    #7 0x7f3833a1186f in ossl_err_load_crypto_strings crypto/err/err_all.c:81
    #8 0x7f3833b273ac in ossl_init_load_crypto_strings crypto/init.c:190
    #9 0x7f3833b273ac in ossl_init_load_crypto_strings_ossl_ crypto/init.c:181
    #10 0x7f383240a4de in __pthread_once_slow /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_once.c:116
    #11 0x7f3833b5224e in CRYPTO_THREAD_run_once crypto/threads_pthread.c:156
    #12 0x7f3833b279ea in OPENSSL_init_crypto crypto/init.c:549
    #13 0x7f38339fb603 in ossl_err_get_state_int crypto/err/err.c:704
    #14 0x7f3833a1077c in ERR_set_mark crypto/err/err.c:882
    #15 0x7f3833856af1 in CONF_modules_load_file_ex crypto/conf/conf_mod.c:195
    #16 0x7f38338572a3 in ossl_config_int crypto/conf/conf_sap.c:64
    #17 0x7f3833b2732e in ossl_init_config crypto/init.c:249
    #18 0x7f3833b2732e in ossl_init_config_ossl_ crypto/init.c:247
    #19 0x7f383240a4de in __pthread_once_slow /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_once.c:116
    #20 0x7f3833b5224e in CRYPTO_THREAD_run_once crypto/threads_pthread.c:156
    #21 0x7f3833b27cca in OPENSSL_init_crypto crypto/init.c:588
    #22 0x7f3833b4a38b in ossl_provider_find crypto/provider_core.c:427
    #23 0x7f3833b41ccb in OSSL_PROVIDER_try_load crypto/provider.c:25
    #24 0x55f7c7da3f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #25 0x55f7c7da1b1c in FuzzerInitialize fuzz/asn1.c:287
    #26 0x55f7c7da1493 in main fuzz/test-corpus.c:194
    #27 0x7f3832229082 in __libc_start_main ../csu/libc-start.c:308
    #28 0x55f7c7da1a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

# ./corpora/asn1/00846bd1e0b3302d5a93c18a3f8562742ca310a6
    #0 0x7f383502fd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x55f7c7da4724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f383372a9f7 in ASN1_STRING_set crypto/asn1/asn1_lib.c:306
    #3 0x7f3833745736 in asn1_ex_c2i crypto/asn1/tasn_dec.c:943
    #4 0x7f3833745736 in asn1_d2i_ex_primitive crypto/asn1/tasn_dec.c:818
    #5 0x7f3833747562 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:217
    #6 0x7f383374a0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #7 0x7f383374a0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #8 0x7f383372cdb6 in asn1_parse2 crypto/asn1/asn1_parse.c:209
    #9 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #10 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #11 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #12 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #13 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #14 0x7f383372df06 in ASN1_parse_dump crypto/asn1/asn1_parse.c:91
    #15 0x7f38337530f9 in asn1_primitive_print crypto/asn1/tasn_prn.c:525
    #16 0x7f38337559b0 in asn1_item_print_ctx crypto/asn1/tasn_prn.c:175
    #17 0x7f38337559b0 in ASN1_item_print crypto/asn1/tasn_prn.c:131
    #18 0x55f7c7da1f5a in FuzzerTestOneInput fuzz/asn1.c:320
    #19 0x55f7c7da42b9 in testfile fuzz/test-corpus.c:182
    #20 0x55f7c7da189f in main fuzz/test-corpus.c:226
    #21 0x7f3832229082 in __libc_start_main ../csu/libc-start.c:308
    #22 0x55f7c7da1a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f383502fd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x55f7c7da4724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f383372a9f7 in ASN1_STRING_set crypto/asn1/asn1_lib.c:306
    #3 0x7f3833745736 in asn1_ex_c2i crypto/asn1/tasn_dec.c:943
    #4 0x7f3833745736 in asn1_d2i_ex_primitive crypto/asn1/tasn_dec.c:818
    #5 0x7f3833747562 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:217
    #6 0x7f383374a0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #7 0x7f383374a0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #8 0x7f383372cdb6 in asn1_parse2 crypto/asn1/asn1_parse.c:209
    #9 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #10 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #11 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #12 0x7f383372c790 in asn1_parse2 crypto/asn1/asn1_parse.c:143
    #13 0x7f383372df06 in ASN1_parse_dump crypto/asn1/asn1_parse.c:91
    #14 0x7f38337530f9 in asn1_primitive_print crypto/asn1/tasn_prn.c:525
    #15 0x7f383375418f in asn1_item_print_ctx crypto/asn1/tasn_prn.c:175
    #16 0x7f383375418f in asn1_template_print_ctx crypto/asn1/tasn_prn.c:313
    #17 0x7f3833755b4b in asn1_item_print_ctx crypto/asn1/tasn_prn.c:207
    #18 0x7f3833755b4b in ASN1_item_print crypto/asn1/tasn_prn.c:131
    #19 0x55f7c7da1f5a in FuzzerTestOneInput fuzz/asn1.c:320
    #20 0x55f7c7da42b9 in testfile fuzz/test-corpus.c:182
    #21 0x55f7c7da189f in main fuzz/test-corpus.c:226
    #22 0x7f3832229082 in __libc_start_main ../csu/libc-start.c:308
    #23 0x55f7c7da1a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f383502fd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x55f7c7da47a4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7f3833b29395 in CRYPTO_zalloc crypto/mem.c:197
    #3 0x7f3833b1f651 in namemap_add_name_n crypto/core_namemap.c:254
    #4 0x7f3833b21693 in namemap_add_name_n crypto/core_namemap.c:290
    #5 0x7f3833b21693 in ossl_namemap_add_name_n crypto/core_namemap.c:287
    #6 0x7f3833b21e61 in get_legacy_evp_names crypto/core_namemap.c:397
    #7 0x7f3833b21e61 in get_legacy_cipher_names crypto/core_namemap.c:409
    #8 0x7f3833b1a0df in doall_util_fn crypto/lhash/lhash.c:195
    #9 0x7f3833b1a0df in OPENSSL_LH_doall_arg crypto/lhash/lhash.c:210
    #10 0x7f3833b9ad46 in lh_OBJ_NAME_doall_OBJ_DOALL crypto/objects/o_names.c:290
    #11 0x7f3833b9ad46 in OBJ_NAME_do_all crypto/objects/o_names.c:301
    #12 0x7f3833b20ca7 in ossl_namemap_stored crypto/core_namemap.c:493
    #13 0x7f3833aa4f2b in evp_is_a crypto/evp/evp_fetch.c:675
    #14 0x7f3833d3ace8 in X509_CRL_digest crypto/x509/x_all.c:535
    #15 0x7f3833d3d47b in crl_cb crypto/x509/x_crl.c:191
    #16 0x7f38337479a9 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:472
    #17 0x7f383374a0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #18 0x7f383374a0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #19 0x55f7c7da1f1f in FuzzerTestOneInput fuzz/asn1.c:315
    #20 0x55f7c7da42b9 in testfile fuzz/test-corpus.c:182
    #21 0x55f7c7da189f in main fuzz/test-corpus.c:226
    #22 0x7f3832229082 in __libc_start_main ../csu/libc-start.c:308
    #23 0x55f7c7da1a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f383502fd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x55f7c7da4724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f3833c97768 in sk_reserve crypto/stack/stack.c:210
    #3 0x7f3833c97768 in OPENSSL_sk_insert crypto/stack/stack.c:254
    #4 0x7f3833b254ea in CRYPTO_set_ex_data crypto/ex_data.c:477
    #5 0x7f3833b1bd5d in ossl_lib_ctx_generic_new crypto/context.c:318
    #6 0x7f3833b25355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7f3833b1cf71 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7f3833be3af5 in ossl_prop_defn_get crypto/property/defn_cache.c:76
    #9 0x7f3833be554c in ossl_method_store_add crypto/property/property.c:332
    #10 0x7f3833aa1945 in put_evp_method_in_store crypto/evp/evp_fetch.c:210
    #11 0x7f3833b1e7df in ossl_method_construct_this crypto/core_fetch.c:123
    #12 0x7f3833b1ddc1 in algorithm_do_map crypto/core_algorithm.c:77
    #13 0x7f3833b1ddc1 in algorithm_do_this crypto/core_algorithm.c:122
    #14 0x7f3833b4bffe in ossl_provider_doall_activated crypto/provider_core.c:1419
    #15 0x7f3833b1e356 in ossl_algorithm_do_all crypto/core_algorithm.c:162
    #16 0x7f3833b1f06e in ossl_method_construct crypto/core_fetch.c:153
    #17 0x7f3833aa2305 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:344
    #18 0x7f3833aa2305 in evp_generic_fetch crypto/evp/evp_fetch.c:396
    #19 0x7f3833a4eea1 in EVP_MD_fetch crypto/evp/digest.c:1071
    #20 0x7f3833704113 in ossl_asn1_item_digest_ex crypto/asn1/a_digest.c:76
    #21 0x7f3833d3ade0 in X509_CRL_digest crypto/x509/x_all.c:544
    #22 0x7f3833d3d47b in crl_cb crypto/x509/x_crl.c:191
    #23 0x7f38337479a9 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:472
    #24 0x7f383374a0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #25 0x7f383374a0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #26 0x55f7c7da1f1f in FuzzerTestOneInput fuzz/asn1.c:315
    #27 0x55f7c7da42b9 in testfile fuzz/test-corpus.c:182
    #28 0x55f7c7da189f in main fuzz/test-corpus.c:226
    #29 0x7f3832229082 in __libc_start_main ../csu/libc-start.c:308
    #30 0x55f7c7da1a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)


=================================================================
==1180894==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7f3835022808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f3833b29395 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f3833b1841c in OPENSSL_LH_new crypto/lhash/lhash.c:51
    #3 0x7f3833b1bd06 in ossl_lib_ctx_generic_new crypto/context.c:309
    #4 0x7f3833b25355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #5 0x7f3833b1cf71 in ossl_lib_ctx_get_data crypto/context.c:413
    #6 0x7f3833be3af5 in ossl_prop_defn_get crypto/property/defn_cache.c:76
    #7 0x7f3833be554c in ossl_method_store_add crypto/property/property.c:332
    #8 0x7f3833aa1945 in put_evp_method_in_store crypto/evp/evp_fetch.c:210
    #9 0x7f3833b1e7df in ossl_method_construct_this crypto/core_fetch.c:123
    #10 0x7f3833b1ddc1 in algorithm_do_map crypto/core_algorithm.c:77
    #11 0x7f3833b1ddc1 in algorithm_do_this crypto/core_algorithm.c:122
    #12 0x7f3833b4bffe in ossl_provider_doall_activated crypto/provider_core.c:1419
    #13 0x7f3833b1e356 in ossl_algorithm_do_all crypto/core_algorithm.c:162
    #14 0x7f3833b1f06e in ossl_method_construct crypto/core_fetch.c:153
    #15 0x7f3833aa2305 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:344
    #16 0x7f3833aa2305 in evp_generic_fetch crypto/evp/evp_fetch.c:396
    #17 0x7f3833a4eea1 in EVP_MD_fetch crypto/evp/digest.c:1071
    #18 0x7f3833704113 in ossl_asn1_item_digest_ex crypto/asn1/a_digest.c:76
    #19 0x7f3833d3ade0 in X509_CRL_digest crypto/x509/x_all.c:544
    #20 0x7f3833d3d47b in crl_cb crypto/x509/x_crl.c:191
    #21 0x7f38337479a9 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:472
    #22 0x7f383374a0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #23 0x7f383374a0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #24 0x55f7c7da1f1f in FuzzerTestOneInput fuzz/asn1.c:315
    #25 0x55f7c7da42b9 in testfile fuzz/test-corpus.c:182
    #26 0x55f7c7da189f in main fuzz/test-corpus.c:226
    #27 0x7f3832229082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f3835022808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f3833b29395 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f3833b1843e in OPENSSL_LH_new crypto/lhash/lhash.c:59
    #3 0x7f3833b1bd06 in ossl_lib_ctx_generic_new crypto/context.c:309
    #4 0x7f3833b25355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #5 0x7f3833b1cf71 in ossl_lib_ctx_get_data crypto/context.c:413
    #6 0x7f3833be3af5 in ossl_prop_defn_get crypto/property/defn_cache.c:76
    #7 0x7f3833be554c in ossl_method_store_add crypto/property/property.c:332
    #8 0x7f3833aa1945 in put_evp_method_in_store crypto/evp/evp_fetch.c:210
    #9 0x7f3833b1e7df in ossl_method_construct_this crypto/core_fetch.c:123
    #10 0x7f3833b1ddc1 in algorithm_do_map crypto/core_algorithm.c:77
    #11 0x7f3833b1ddc1 in algorithm_do_this crypto/core_algorithm.c:122
    #12 0x7f3833b4bffe in ossl_provider_doall_activated crypto/provider_core.c:1419
    #13 0x7f3833b1e356 in ossl_algorithm_do_all crypto/core_algorithm.c:162
    #14 0x7f3833b1f06e in ossl_method_construct crypto/core_fetch.c:153
    #15 0x7f3833aa2305 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:344
    #16 0x7f3833aa2305 in evp_generic_fetch crypto/evp/evp_fetch.c:396
    #17 0x7f3833a4eea1 in EVP_MD_fetch crypto/evp/digest.c:1071
    #18 0x7f3833704113 in ossl_asn1_item_digest_ex crypto/asn1/a_digest.c:76
    #19 0x7f3833d3ade0 in X509_CRL_digest crypto/x509/x_all.c:544
    #20 0x7f3833d3d47b in crl_cb crypto/x509/x_crl.c:191
    #21 0x7f38337479a9 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:472
    #22 0x7f383374a0e4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #23 0x7f383374a0e4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #24 0x55f7c7da1f1f in FuzzerTestOneInput fuzz/asn1.c:315
    #25 0x55f7c7da42b9 in testfile fuzz/test-corpus.c:182
    #26 0x55f7c7da189f in main fuzz/test-corpus.c:226
    #27 0x7f3832229082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: 200 byte(s) leaked in 2 allocation(s).
ERROR_INJECT=1659798631 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/03caabfee6f225029ce335b279b8b36e7ca8d748
    #0 0x7fd817274d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x55a4c68627a4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7fd815d5e054 in OPENSSL_LH_insert crypto/lhash/lhash.c:120
    #3 0x7fd815e34851 in lh_PROPERTY_STRING_insert crypto/property/property_string.c:34
    #4 0x7fd815e34851 in ossl_property_string crypto/property/property_string.c:158
    #5 0x7fd815e34851 in ossl_property_name crypto/property/property_string.c:219
    #6 0x7fd815e325c6 in ossl_property_parse_init crypto/property/property_parse.c:557
    #7 0x7fd815d61007 in context_init crypto/context.c:101
    #8 0x7fd815d61113 in default_context_do_init crypto/context.c:154
    #9 0x7fd815d61113 in default_context_do_init_ossl_ crypto/context.c:151
    #10 0x7fd81464f4de in __pthread_once_slow /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_once.c:116
    #11 0x7fd815d9724e in CRYPTO_THREAD_run_once crypto/threads_pthread.c:156
    #12 0x7fd815d61536 in get_thread_default_context crypto/context.c:165
    #13 0x7fd815d61536 in get_default_context crypto/context.c:173
    #14 0x7fd815d61536 in ossl_lib_ctx_get_concrete crypto/context.c:280
    #15 0x7fd815d61536 in ossl_lib_ctx_get_concrete crypto/context.c:276
    #16 0x7fd815d61970 in ossl_lib_ctx_get_data crypto/context.c:358
    #17 0x7fd815d8d408 in get_provider_store crypto/provider_core.c:339
    #18 0x7fd815d8d408 in ossl_provider_info_add_to_store crypto/provider_core.c:365
    #19 0x7fd815d87146 in OSSL_PROVIDER_add_builtin crypto/provider.c:131
    #20 0x55a4c6861f2c in FuzzerSetRand fuzz/fuzz_rand.c:159
    #21 0x55a4c685fb1c in FuzzerInitialize fuzz/asn1.c:287
    #22 0x55a4c685f493 in main fuzz/test-corpus.c:194
    #23 0x7fd81446e082 in __libc_start_main ../csu/libc-start.c:308
    #24 0x55a4c685fa4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

crypto/threads_pthread.c:97:9: runtime error: null pointer passed as argument 1, which is declared to never be null
    #0 0x7fd81590e087 in CRYPTO_THREAD_read_lock crypto/threads_pthread.c:97
    #1 0x7fd815d6199d in ossl_lib_ctx_get_data crypto/context.c:362
    #2 0x7fd815d8d408 in get_provider_store crypto/provider_core.c:339
    #3 0x7fd815d8d408 in ossl_provider_info_add_to_store crypto/provider_core.c:365
    #4 0x7fd815d87146 in OSSL_PROVIDER_add_builtin crypto/provider.c:131
    #5 0x55a4c6861f2c in FuzzerSetRand fuzz/fuzz_rand.c:159
    #6 0x55a4c685fb1c in FuzzerInitialize fuzz/asn1.c:287
    #7 0x55a4c685f493 in main fuzz/test-corpus.c:194
    #8 0x7fd81446e082 in __libc_start_main ../csu/libc-start.c:308
    #9 0x55a4c685fa4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)
ERROR_INJECT=1659627797 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/00846bd1e0b3302d5a93c18a3f8562742ca310a6
    #0 0x7fce01b4ed4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x55e26129c724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7fce007b6768 in sk_reserve crypto/stack/stack.c:210
    #3 0x7fce007b6768 in OPENSSL_sk_insert crypto/stack/stack.c:254
    #4 0x7fce006444ea in CRYPTO_set_ex_data crypto/ex_data.c:477
    #5 0x7fce0063ad5d in ossl_lib_ctx_generic_new crypto/context.c:318
    #6 0x7fce00644355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7fce0063bf71 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7fce00500258 in get_decoder_store crypto/encode_decode/decoder_meth.c:123
    #9 0x7fce00500258 in ossl_decoder_store_cache_flush crypto/encode_decode/decoder_meth.c:478
    #10 0x7fce00667f2f in provider_flush_store_cache crypto/provider_core.c:1177
    #11 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1246
    #12 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1231
    #13 0x7fce00660d76 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #14 0x55e26129bf72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #15 0x55e261299b1c in FuzzerInitialize fuzz/asn1.c:287
    #16 0x55e261299493 in main fuzz/test-corpus.c:194
    #17 0x7fcdfed48082 in __libc_start_main ../csu/libc-start.c:308
    #18 0x55e261299a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)
    
# ./corpora/asn1/00846bd1e0b3302d5a93c18a3f8562742ca310a6
    
=================================================================
==1164914==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7fce01b41808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fce00648395 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fce007040a3 in ossl_method_store_new crypto/property/property.c:250
    #3 0x7fce0063ad06 in ossl_lib_ctx_generic_new crypto/context.c:309
    #4 0x7fce00644355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #5 0x7fce0063bf71 in ossl_lib_ctx_get_data crypto/context.c:413
    #6 0x7fce00500258 in get_decoder_store crypto/encode_decode/decoder_meth.c:123
    #7 0x7fce00500258 in ossl_decoder_store_cache_flush crypto/encode_decode/decoder_meth.c:478
    #8 0x7fce00667f2f in provider_flush_store_cache crypto/provider_core.c:1177
    #9 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1246
    #10 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1231
    #11 0x7fce00660d76 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #12 0x55e26129bf72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #13 0x55e261299b1c in FuzzerInitialize fuzz/asn1.c:287
    #14 0x55e261299493 in main fuzz/test-corpus.c:194
    #15 0x7fcdfed48082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7fce01b41808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fce00648395 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fce00671133 in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7fce00704103 in ossl_method_store_new crypto/property/property.c:254
    #4 0x7fce0063ad06 in ossl_lib_ctx_generic_new crypto/context.c:309
    #5 0x7fce00644355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #6 0x7fce0063bf71 in ossl_lib_ctx_get_data crypto/context.c:413
    #7 0x7fce00500258 in get_decoder_store crypto/encode_decode/decoder_meth.c:123
    #8 0x7fce00500258 in ossl_decoder_store_cache_flush crypto/encode_decode/decoder_meth.c:478
    #9 0x7fce00667f2f in provider_flush_store_cache crypto/provider_core.c:1177
    #10 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1246
    #11 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1231
    #12 0x7fce00660d76 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #13 0x55e26129bf72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #14 0x55e261299b1c in FuzzerInitialize fuzz/asn1.c:287
    #15 0x55e261299493 in main fuzz/test-corpus.c:194
    #16 0x7fcdfed48082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7fce01b41808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fce00648395 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fce00671133 in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7fce00704131 in ossl_method_store_new crypto/property/property.c:255
    #4 0x7fce0063ad06 in ossl_lib_ctx_generic_new crypto/context.c:309
    #5 0x7fce00644355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #6 0x7fce0063bf71 in ossl_lib_ctx_get_data crypto/context.c:413
    #7 0x7fce00500258 in get_decoder_store crypto/encode_decode/decoder_meth.c:123
    #8 0x7fce00500258 in ossl_decoder_store_cache_flush crypto/encode_decode/decoder_meth.c:478
    #9 0x7fce00667f2f in provider_flush_store_cache crypto/provider_core.c:1177
    #10 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1246
    #11 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1231
    #12 0x7fce00660d76 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #13 0x55e26129bf72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #14 0x55e261299b1c in FuzzerInitialize fuzz/asn1.c:287
    #15 0x55e261299493 in main fuzz/test-corpus.c:194
    #16 0x7fcdfed48082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7fce01b41808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fce00648395 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fce007040d1 in ossl_sa_ALGORITHM_new crypto/property/property.c:94
    #3 0x7fce007040d1 in ossl_method_store_new crypto/property/property.c:253
    #4 0x7fce0063ad06 in ossl_lib_ctx_generic_new crypto/context.c:309
    #5 0x7fce00644355 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #6 0x7fce0063bf71 in ossl_lib_ctx_get_data crypto/context.c:413
    #7 0x7fce00500258 in get_decoder_store crypto/encode_decode/decoder_meth.c:123
    #8 0x7fce00500258 in ossl_decoder_store_cache_flush crypto/encode_decode/decoder_meth.c:478
    #9 0x7fce00667f2f in provider_flush_store_cache crypto/provider_core.c:1177
    #10 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1246
    #11 0x7fce00667f2f in ossl_provider_activate crypto/provider_core.c:1231
    #12 0x7fce00660d76 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #13 0x55e26129bf72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #14 0x55e261299b1c in FuzzerInitialize fuzz/asn1.c:287
    #15 0x55e261299493 in main fuzz/test-corpus.c:194
    #16 0x7fcdfed48082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: 192 byte(s) leaked in 4 allocation(s).

@bernd-edlinger

bernd-edlinger commented Jul 29, 2022

Copy link
Copy Markdown
Member Author

And here I've got a use-after-free bug in master:

ERROR_INJECT=1659266030 ../util/shlib_wrap.sh ./server-test ./corpora/server/0f3357bcff07f23b9024bf50ec53aaad8f7ebdb4
# ./corpora/server/0f3357bcff07f23b9024bf50ec53aaad8f7ebdb4
    #0 0x7fbed1818d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5590fb91ab24 in my_realloc fuzz/test-corpus.c:129
    #2 0x7fbed01188ce in ERR_vset_error crypto/err/err_blocks.c:103
    #3 0x7fbed01192d9 in ERR_set_error crypto/err/err_blocks.c:45
    #4 0x7fbed01ab90d in inner_evp_generic_fetch crypto/evp/evp_fetch.c:341
    #5 0x7fbed01ab90d in evp_generic_fetch crypto/evp/evp_fetch.c:364
    #6 0x7fbed01a4011 in EVP_CIPHER_fetch crypto/evp/evp_enc.c:1670
    #7 0x7fbed13ef762 in ssl_evp_cipher_fetch ssl/ssl_lib.c:6789
    #8 0x7fbed13c1706 in ssl_load_ciphers ssl/ssl_ciph.c:333
    #9 0x7fbed13f4496 in SSL_CTX_new_ex ssl/ssl_lib.c:3679
    #10 0x7fbed13f4496 in SSL_CTX_new_ex ssl/ssl_lib.c:3608
    #11 0x5590fb919aff in FuzzerTestOneInput fuzz/server.c:542
    #12 0x5590fb91a6b9 in testfile fuzz/test-corpus.c:182
    #13 0x5590fb9191df in main fuzz/test-corpus.c:226
    #14 0x7fbece921082 in __libc_start_main ../csu/libc-start.c:308
    #15 0x5590fb91938d in _start (.../openssl-master/fuzz/server-test+0x538d)

    #0 0x7fbed1818d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5590fb91aba4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7fbed02317b5 in CRYPTO_zalloc crypto/mem.c:197
    #3 0x7fbed025d643 in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #4 0x7fbed13e0a55 in ossl_ssl_init ssl/ssl_lib.c:706
    #5 0x7fbed13f086e in ossl_ssl_connection_new ssl/ssl_lib.c:731
    #6 0x5590fb919fa6 in FuzzerTestOneInput fuzz/server.c:690
    #7 0x5590fb91a6b9 in testfile fuzz/test-corpus.c:182
    #8 0x5590fb9191df in main fuzz/test-corpus.c:226
    #9 0x7fbece921082 in __libc_start_main ../csu/libc-start.c:308
    #10 0x5590fb91938d in _start (.../openssl-master/fuzz/server-test+0x538d)

=================================================================
==3038664==ERROR: AddressSanitizer: heap-use-after-free on address 0x624000006118 at pc 0x7fbed13f076a bp 0x7fff5e58fa10 sp 0x7fff5e58fa00
WRITE of size 4 at 0x624000006118 thread T0
    #0 0x7fbed13f0769 in CRYPTO_DOWN_REF include/internal/refcount.h:50
    #1 0x7fbed13f0769 in SSL_free ssl/ssl_lib.c:1314
    #2 0x7fbed13f1c0a in ossl_ssl_connection_new ssl/ssl_lib.c:890
    #3 0x5590fb919fa6 in FuzzerTestOneInput fuzz/server.c:690
    #4 0x5590fb91a6b9 in testfile fuzz/test-corpus.c:182
    #5 0x5590fb9191df in main fuzz/test-corpus.c:226
    #6 0x7fbece921082 in __libc_start_main ../csu/libc-start.c:308
    #7 0x5590fb91938d in _start (.../openssl-master/fuzz/server-test+0x538d)

0x624000006118 is located 24 bytes inside of 7616-byte region [0x624000006100,0x624000007ec0)
freed by thread T0 here:
    #0 0x7fbed180b40f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122
    #1 0x7fbed13f1c63 in ossl_ssl_connection_new ssl/ssl_lib.c:732
    #2 0x5590fb919fa6 in FuzzerTestOneInput fuzz/server.c:690
    #3 0x5590fb91a6b9 in testfile fuzz/test-corpus.c:182
    #4 0x5590fb9191df in main fuzz/test-corpus.c:226
    #5 0x7fbece921082 in __libc_start_main ../csu/libc-start.c:308

previously allocated by thread T0 here:
    #0 0x7fbed180b808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fbed02317b5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fbed13f084d in ossl_ssl_connection_new ssl/ssl_lib.c:726
    #3 0x5590fb919fa6 in FuzzerTestOneInput fuzz/server.c:690
    #4 0x5590fb91a6b9 in testfile fuzz/test-corpus.c:182
    #5 0x5590fb9191df in main fuzz/test-corpus.c:226
    #6 0x7fbece921082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: heap-use-after-free include/internal/refcount.h:50 in CRYPTO_DOWN_REF
Shadow bytes around the buggy address:
  0x0c487fff8bd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c487fff8be0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c487fff8bf0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c487fff8c00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c487fff8c10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c487fff8c20: fd fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c487fff8c30: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c487fff8c40: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c487fff8c50: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c487fff8c60: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c487fff8c70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==3038664==ABORTING

DDvO pushed a commit to mpeylo/cmpossl that referenced this pull request Aug 5, 2022
Triggered by a  memory allocation failure.
Detected by PR openssl#18355

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from openssl#18670)
MartinPetkov pushed a commit to MartinPetkov/oss-fuzz that referenced this pull request Aug 15, 2022
As part of openssl/openssl#18355 "Add Reproducible Error Injection"
I want to add an executable testrun.sh script to the fuzz directory.
Ideally I would like to set the executable bit on that file,
but unfortunately this confuses the CIFuzz build.

This excludes *.sh from the find command in build.sh
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
If an error condition occurs then the the decoder that was up-refed in
ossl_decoder_instance_new can be leaked.

Found due to the error report here:
openssl#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Shane Lontis <[email protected]>
(Merged from openssl#18410)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
If pushing the decoder onto a stack fails then we should free the ref
we just created.

Found due to the error report here:
openssl#18355 (comment)

Reviewed-by: Richard Levitte <[email protected]>
Reviewed-by: Shane Lontis <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#18411)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
The function ossl_provider_free() decrements the refcnt of the
provider and frees it if it has reached 0. This only works if the
refcnt has already been initialised. We must only call
ossl_provider_free() after this initialisation - otherwise it will fail
to free the provider correctly.

Addresses the issue mentioned here:
openssl#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#18417)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
The module_list_lock is used by CONF_modules_unload(). That function relies
on the RUN_ONCE in CONF_modules_finish() to initialise that lock. However
if the RUN_ONCE fails that failure is not propagated to
CONF_modules_unload() and so it erroneously tries to use the lock anyway.

Found due to:
openssl#18355 (comment)

Reviewed-by: Todd Short <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#18460)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Also check if we have d2i_public_key() function pointer.

Fixes openssl#18355 (comment)

Reviewed-by: Todd Short <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#18462)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
If we get a failure during evp_pkey_copy_downgraded() and on entry *dest
was NULL then we leak the EVP_PKEY that was automatically allocated and
stored in *dest.

Found due to this comment:
openssl#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from openssl#18470)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
If the call to OSSL_PARAM_BLD_to_param() failed then ec_export was
reporting success, even though it has never called the param_cb.

Found due to:
openssl#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#18483)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
If the call to ossl_prop_defn_set() fails then the OSSL_PROPERTY_LIST
we just created will leak.

Found as a result of:
openssl#18355 (comment)

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Todd Short <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#18458)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Triggered by a  memory allocation failure.
Detected by PR openssl#18355

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from openssl#18670)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
BN_one() uses the expand function which calls malloc which may fail.
All other places that reference BN_one() check the return value.

The issue is triggered by a memory allocation failure.
Detected by PR openssl#18355

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#18697)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Occurs if a failure happens after the malloc call in the second call to
EVP_PKEY_get_octet_string_param().

Detected by PR openssl#18355

Some calling code assumes that nothing is allocated in the returned
pointer if there was a failure. Other calling code always trys freeing.
The third case is in ecdh_cms_encrypt() where it does not check the
return value. I am assuming this change is ok since the legacy path in
EVP_PKEY_get1_encoded_public_key() also does not return the pointer on
failure.

Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#18739)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Fix multiple places that could potentially segfault if memory
allocations fail. e.g. ssl_load_ciphers() could fail while calling
ssl_evp_md_fetch().

Found by openssl#18355

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Dmitry Belyavskiy <[email protected]>
(Merged from openssl#18784)
rsbeckerca added a commit to ituglib/openssl-1.1.1 that referenced this pull request Oct 11, 2022
commit 6fd6179191702eb0562ccbfb22a37405c669b90e
Author: Randall S. Becker <[email protected]>
Date:   Tue Jul 5 17:50:13 2022 -0400

    Missed include on NonStop for memcmp in test/v3ext.c

commit d97281f16602e50f040756029b555645315253df
Author: Randall S. Becker <[email protected]>
Date:   Tue Jul 5 10:37:54 2022 -0400

    Squashed commit of the following:

    commit 29708a562a1887a91de0fa6ca668c71871accde9
    Author: Richard Levitte <[email protected]>
    Date:   Tue Jul 5 11:08:33 2022 +0200

        Prepare for 1.1.1q release

        Reviewed-by: Paul Dale <[email protected]>
        Release: yes

    commit 95a17c0ead00885452d13309eaffd04c1737d05d
    Author: Richard Levitte <[email protected]>
    Date:   Tue Jul 5 10:33:00 2022 +0200

        Update copyright year

        Reviewed-by: Paul Dale <[email protected]>
        Release: yes

    commit 78ba51a3b8b505d8d03abca8fa95e4fb1464d94e
    Author: Richard Levitte <[email protected]>
    Date:   Tue Jul 5 10:25:00 2022 +0200

        Update CHANGES and NEWS for upcoming release 1.1.1q

        Reviewed-by: Paul Dale <[email protected]>
        Release: yes

    commit 9131afdca30b6d1650af9ea6179569a80ab8cb06
    Author: Alex Chernyakhovsky <[email protected]>
    Date:   Thu Jun 16 12:02:37 2022 +1000

        AES OCB test vectors

        Add test vectors for AES OCB for x86 AES-NI multiple of 96 byte issue.

        Co-authored-by: Alejandro Sedeño <[email protected]>
        Co-authored-by: David Benjamin <[email protected]>

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>

    commit 919925673d6c9cfed3c1085497f5dfbbed5fc431
    Author: Alex Chernyakhovsky <[email protected]>
    Date:   Thu Jun 16 12:00:22 2022 +1000

        Fix AES OCB encrypt/decrypt for x86 AES-NI

        aesni_ocb_encrypt and aesni_ocb_decrypt operate by having a fast-path
        that performs operations on 6 16-byte blocks concurrently (the
        "grandloop") and then proceeds to handle the "short" tail (which can
        be anywhere from 0 to 5 blocks) that remain.

        As part of initialization, the assembly initializes $len to the true
        length, less 96 bytes and converts it to a pointer so that the $inp
        can be compared to it. Each iteration of "grandloop" checks to see if
        there's a full 96-byte chunk to process, and if so, continues. Once
        this has been exhausted, it falls through to "short", which handles
        the remaining zero to five blocks.

        Unfortunately, the jump at the end of "grandloop" had a fencepost
        error, doing a `jb` ("jump below") rather than `jbe` (jump below or
        equal). This should be `jbe`, as $inp is pointing to the *end* of the
        chunk currently being handled. If $inp == $len, that means that
        there's a whole 96-byte chunk waiting to be handled. If $inp > $len,
        then there's 5 or fewer 16-byte blocks left to be handled, and the
        fall-through is intended.

        The net effect of `jb` instead of `jbe` is that the last 16-byte block
        of the last 96-byte chunk was completely omitted. The contents of
        `out` in this position were never written to. Additionally, since
        those bytes were never processed, the authentication tag generated is
        also incorrect.

        The same fencepost error, and identical logic, exists in both
        aesni_ocb_encrypt and aesni_ocb_decrypt.

        This addresses CVE-2022-2097.

        Co-authored-by: Alejandro Sedeño <[email protected]>
        Co-authored-by: David Benjamin <[email protected]>

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>

    commit 6495cab1c876ad80ce983d848ccaa1dc286a63e1
    Author: slontis <[email protected]>
    Date:   Fri Jul 1 13:47:11 2022 +1000

        Fix bn_gcd code to check return value when calling BN_one()

        BN_one() uses the expand function which calls malloc which may fail.
        All other places that reference BN_one() check the return value.

        The issue is triggered by a memory allocation failure.
        Detected by PR #18355

        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18697)

        (cherry picked from commit 7fe7cc57af3db1e497877f0329ba17609b2efc8b)

    commit 7a05fcb1fc276a7ecfe599d45655d4e617c5e2d4
    Author: xkernel <[email protected]>
    Date:   Mon Jun 20 17:46:39 2022 +0800

        v3_sxnet: add a check for the return of i2s_ASN1_INTEGER()

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Ben Kaduk <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18608)

        (cherry picked from commit 9ef1f848a646565d4dd86e56542cf921d4921ad9)

    commit a1d80edcf830739131e0567dc03b1e80b7988b1e
    Author: Matt Caswell <[email protected]>
    Date:   Fri Jun 10 15:58:58 2022 +0100

        Fix range_should_be_prefix() to actually return the correct result

        range_should_be_prefix() was misidentifying whether an IP address range
        should in fact be represented as a prefix. This was due to a bug introduced
        in commit 42d7d7dd which made this incorrect change:

        -    OPENSSL_assert(memcmp(min, max, length) <= 0);
        +    if (memcmp(min, max, length) <= 0)
        +        return -1;

        This error leads to incorrect DER being encoded/accepted.

        Reported by Theo Buehler (@botovq)

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18524)

        (cherry picked from commit 30532e59f475e0066c030693e4d614311a9e0cae)
        (cherry picked from commit 2c6550c6db9b1b69dc24f968b4ceb534edcf4841)

    commit 4c1cf6d39bb8e85658ac8c743dcff8ede730f76a
    Author: Bernd Edlinger <[email protected]>
    Date:   Fri Jun 17 10:25:24 2022 +0200

        Fix compile issues in test/v3ext.c with no-rfc3779

        There are no ASIdentifiers if OPENSSL_NO_RFC3779 is defined,
        therefore the test cannot be compiled.

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18634)

        (cherry picked from commit b76efe61ea9710a8f69e1cb8caf1aeb2ba6f1ebe)
        (cherry picked from commit 665ab12ed3f0d78e7cb6a55cdd2b83a2fe150232)

    commit 882573246695088d65956355ca6c954642dcac31
    Author: olszomal <[email protected]>
    Date:   Fri Jun 17 15:01:11 2022 +0200

        SSL_get_current_cipher() and SSL_get_pending_cipher() return 'const SSL_CIPHER *'

        Fix the documentation.

        CLA: trivial

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Todd Short <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18599)

        (cherry picked from commit d842b6eff0940b6ce337536cb718a8d561290f50)

    commit 6c8879c8bf6030666c851623f93fff03c1266715
    Author: Bernd Edlinger <[email protected]>
    Date:   Wed Jun 22 17:05:55 2022 +0200

        Fix a memory leak in EC_GROUP_new_from_ecparameters

        This can be reproduced with my error injection patch.

        The test vector has been validated on the 1.1.1 branch
        but the issue is of course identical in all branches.

        $ ERROR_INJECT=1656112173 ../util/shlib_wrap.sh ./x509-test ./corpora/x509/fe543a8d7e09109a9a08114323eefec802ad79e2
            #0 0x7fb61945eeba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
            #1 0x402f84 in my_malloc fuzz/test-corpus.c:114
            #2 0x7fb619092430 in CRYPTO_zalloc crypto/mem.c:230
            #3 0x7fb618ef7561 in bn_expand_internal crypto/bn/bn_lib.c:280
            #4 0x7fb618ef7561 in bn_expand2 crypto/bn/bn_lib.c:304
            #5 0x7fb618ef819d in BN_bin2bn crypto/bn/bn_lib.c:454
            #6 0x7fb618e7aa13 in asn1_string_to_bn crypto/asn1/a_int.c:503
            #7 0x7fb618e7aa13 in ASN1_INTEGER_to_BN crypto/asn1/a_int.c:559
            #8 0x7fb618fd8e79 in EC_GROUP_new_from_ecparameters crypto/ec/ec_asn1.c:814
            #9 0x7fb618fd98e8 in EC_GROUP_new_from_ecpkparameters crypto/ec/ec_asn1.c:935
            #10 0x7fb618fd9aec in d2i_ECPKParameters crypto/ec/ec_asn1.c:966
            #11 0x7fb618fdace9 in d2i_ECParameters crypto/ec/ec_asn1.c:1184
            #12 0x7fb618fd1fc7 in eckey_type2param crypto/ec/ec_ameth.c:119
            #13 0x7fb618fd57b4 in eckey_pub_decode crypto/ec/ec_ameth.c:165
            #14 0x7fb6191a9c62 in x509_pubkey_decode crypto/x509/x_pubkey.c:124
            #15 0x7fb6191a9e42 in pubkey_cb crypto/x509/x_pubkey.c:46
            #16 0x7fb618eac032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
            #17 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #18 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #19 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #20 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #21 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #22 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #23 0x7fb618eadd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #24 0x7fb618eade35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #25 0x40310c in FuzzerTestOneInput fuzz/x509.c:33
            #26 0x402afb in testfile fuzz/test-corpus.c:182
            #27 0x402656 in main fuzz/test-corpus.c:226
            #28 0x7fb618551f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
            #29 0x402756  (/home/ed/OPC/openssl/fuzz/x509-test+0x402756)

        =================================================================
        ==12221==ERROR: LeakSanitizer: detected memory leaks

        Direct leak of 24 byte(s) in 1 object(s) allocated from:
            #0 0x7fb61945309f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
            #1 0x7fb619092430 in CRYPTO_zalloc crypto/mem.c:230
            #2 0x7fb618ef5f11 in BN_new crypto/bn/bn_lib.c:246
            #3 0x7fb618ef82f4 in BN_bin2bn crypto/bn/bn_lib.c:440
            #4 0x7fb618fd8933 in EC_GROUP_new_from_ecparameters crypto/ec/ec_asn1.c:618
            #5 0x7fb618fd98e8 in EC_GROUP_new_from_ecpkparameters crypto/ec/ec_asn1.c:935
            #6 0x7fb618fd9aec in d2i_ECPKParameters crypto/ec/ec_asn1.c:966
            #7 0x7fb618fdace9 in d2i_ECParameters crypto/ec/ec_asn1.c:1184
            #8 0x7fb618fd1fc7 in eckey_type2param crypto/ec/ec_ameth.c:119
            #9 0x7fb618fd57b4 in eckey_pub_decode crypto/ec/ec_ameth.c:165
            #10 0x7fb6191a9c62 in x509_pubkey_decode crypto/x509/x_pubkey.c:124
            #11 0x7fb6191a9e42 in pubkey_cb crypto/x509/x_pubkey.c:46
            #12 0x7fb618eac032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
            #13 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #14 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #15 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #16 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #17 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #18 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #19 0x7fb618eadd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #20 0x7fb618eade35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #21 0x40310c in FuzzerTestOneInput fuzz/x509.c:33
            #22 0x402afb in testfile fuzz/test-corpus.c:182
            #23 0x402656 in main fuzz/test-corpus.c:226
            #24 0x7fb618551f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

        Indirect leak of 56 byte(s) in 1 object(s) allocated from:
            #0 0x7fb61945309f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
            #1 0x7fb619092430 in CRYPTO_zalloc crypto/mem.c:230
            #2 0x7fb618ef7561 in bn_expand_internal crypto/bn/bn_lib.c:280
            #3 0x7fb618ef7561 in bn_expand2 crypto/bn/bn_lib.c:304
            #4 0x7fb618ef819d in BN_bin2bn crypto/bn/bn_lib.c:454
            #5 0x7fb618fd8933 in EC_GROUP_new_from_ecparameters crypto/ec/ec_asn1.c:618
            #6 0x7fb618fd98e8 in EC_GROUP_new_from_ecpkparameters crypto/ec/ec_asn1.c:935
            #7 0x7fb618fd9aec in d2i_ECPKParameters crypto/ec/ec_asn1.c:966
            #8 0x7fb618fdace9 in d2i_ECParameters crypto/ec/ec_asn1.c:1184
            #9 0x7fb618fd1fc7 in eckey_type2param crypto/ec/ec_ameth.c:119
            #10 0x7fb618fd57b4 in eckey_pub_decode crypto/ec/ec_ameth.c:165
            #11 0x7fb6191a9c62 in x509_pubkey_decode crypto/x509/x_pubkey.c:124
            #12 0x7fb6191a9e42 in pubkey_cb crypto/x509/x_pubkey.c:46
            #13 0x7fb618eac032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
            #14 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #15 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #16 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #17 0x7fb618eacaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #18 0x7fb618ead288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #19 0x7fb618eab9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #20 0x7fb618eadd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #21 0x7fb618eade35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #22 0x40310c in FuzzerTestOneInput fuzz/x509.c:33
            #23 0x402afb in testfile fuzz/test-corpus.c:182
            #24 0x402656 in main fuzz/test-corpus.c:226
            #25 0x7fb618551f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

        SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s).

        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Kurt Roeckx <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18632)

    commit 7f77ecd2facbd9df62ed727fbd1f522376d44bd3
    Author: Matt Caswell <[email protected]>
    Date:   Tue Jun 21 14:39:48 2022 +0100

        Prepare for 1.1.1q-dev

        Reviewed-by: Richard Levitte <[email protected]>
        Release: yes

    commit 8aaca20cf9996257d1ce2e6f4d3059b3698dde3d
    Author: Matt Caswell <[email protected]>
    Date:   Tue Jun 21 14:39:39 2022 +0100

        Prepare for 1.1.1p release

        Reviewed-by: Richard Levitte <[email protected]>
        Release: yes

    commit a3fc812c0c78e2f5db8b9d45bddaff62dfc958ae
    Author: Matt Caswell <[email protected]>
    Date:   Tue Jun 21 14:07:32 2022 +0100

        Update copyright year

        Reviewed-by: Richard Levitte <[email protected]>
        Release: yes

    commit 51e06520734063d6f52b2e596e1089d36d3781e7
    Author: Matt Caswell <[email protected]>
    Date:   Mon Jun 20 14:14:20 2022 +0100

        Update CHANGES and NEWS for new release

        Reviewed-by: Tomas Mraz <[email protected]>
        Release: yes

    commit 9639817dac8bbbaa64d09efad7464ccc405527c7
    Author: Daniel Fiala <[email protected]>
    Date:   Sun May 29 20:11:24 2022 +0200

        Fix file operations in c_rehash.

        CVE-2022-2068

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Richard Levitte <[email protected]>

    commit 20af01d46ca4086f6b1339b67c15c81d8b4a040d
    Author: Fraser Tweedale <[email protected]>
    Date:   Wed Jun 15 10:50:57 2022 +1000

        Fix documentation of BIO_FLAGS_BASE64_NO_NL

        Commit 8bfb7506d210841f2ee4eda8afe96441a0e33fa5 updated
        `BIO_f_base64(3)` to improve the documentation of the
        `BIO_FLAGS_BASE64_NO_NL` flag.  In particular, the updated text
        states that when this flag is used, all newlines in the input are
        ignored.  This is incorrect, as the following program proves:

        ```c

        unsigned char *in_buf =
            "IlRoZSBxdWljayBicm93biBmb3gganVt\ncHMgb3ZlciBhIGxhenkgZG9nLiI=\n";

        int main(int argc, char **argv) {
            BIO *b64 = BIO_new(BIO_f_base64());
            if (b64 == NULL) return 1;
            BIO_set_flags(b64, BIO_get_flags(b64) | BIO_FLAGS_BASE64_NO_NL);
            int in_len = strlen(in_buf);
            BIO *in = BIO_new_mem_buf(in_buf, in_len);
            if (in == NULL) return 2;
            in = BIO_push(b64, in);
            unsigned char *out_buf = calloc(in_len, sizeof(unsigned char));
            if (out_buf == NULL) return 3;
            size_t out_len;
            int r = BIO_read_ex(in, out_buf, in_len, &out_len);
            printf("rv = %d\n", r);
            printf("decoded = %s\n", out_buf);
            return 0;
        }
        ```

        Update the text of `BIO_f_base64(3)` to clarify that when the flag
        is set, the data must be all on one line (with or without a trailing
        newline character).

        Signed-off-by: Fraser Tweedale <[email protected]>

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18568)

        (cherry picked from commit 0edcbacca99ab2b716da395f204610fc2775ea83)

    commit 8438d3a7b7309cbea521d3628fddeda7bd6d6e20
    Author: Tomas Mraz <[email protected]>
    Date:   Thu Jun 9 16:20:05 2022 +0200

        Add an extra reduction step to RSAZ mod_exp implementations

        Inspired by BoringSSL fix by David Benjamin.

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18511)

    commit 0ed27fb7a8d85685cb671bf0a1e41bcdfc2624dc
    Author: Tomas Mraz <[email protected]>
    Date:   Thu Jun 9 12:34:55 2022 +0200

        Always end BN_mod_exp_mont_consttime with normal Montgomery reduction.

        This partially fixes a bug where, on x86_64, BN_mod_exp_mont_consttime
        would sometimes return m, the modulus, when it should have returned
        zero. Thanks to Guido Vranken for reporting it. It is only a partial fix
        because the same bug also exists in the "rsaz" codepath.

        The bug only affects zero outputs (with non-zero inputs), so we believe
        it has no security impact on our cryptographic functions.

        The fx is to delete lowercase bn_from_montgomery altogether, and have the
        mont5 path use the same BN_from_montgomery ending as the non-mont5 path.
        This only impacts the final step of the whole exponentiation and has no
        measurable perf impact.

        See the original BoringSSL commit
        https://boringssl.googlesource.com/boringssl/+/13c9d5c69d04485a7a8840c12185c832026c8315
        for further analysis.

        Original-author: David Benjamin <[email protected]>

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18511)

    commit 8f078819556da83c15751678c39558a59bc746fc
    Author: Matt Caswell <[email protected]>
    Date:   Thu Jun 9 16:57:30 2022 +0100

        Fix a crash in X509v3_asid_subset()

        If the asnum or rdi fields are NULL and the ASIdentifiers are otherwise
        subsets then this will result in a crash. Of note is that rdi will usually
        be NULL.

        Reported by Theo Buehler (@botovq)

        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Paul Yang <[email protected]>
        Reviewed-by: Todd Short <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18514)

        (cherry picked from commit 01fc9b6bce82f0534d6673659a0e59a71f57ee82)

    commit ab7d05617a444cfcf4f930f81caa4cf66495ab9b
    Author: Tomas Mraz <[email protected]>
    Date:   Thu Jun 2 18:12:05 2022 +0200

        Update further expiring certificates that affect tests

        Namely the smime certificates used in test_cms
        will expire soon and affect tests.

        Fixes #15179

        Reviewed-by: Dmitry Belyavskiy <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18481)

    commit 3bd976551e549c030bdbd150c7aa8a1980cb00fe
    Author: Tomas Mraz <[email protected]>
    Date:   Tue Mar 29 13:31:34 2022 +0200

        Fix strict client chain check with TLS-1.3

        When TLS-1.3 is used and the server does not send any CA names
        the ca_dn will be NULL. sk_X509_NAME_num() returns -1 on null
        argument.

        Reviewed-by: Todd Short <[email protected]>
        Reviewed-by: Matt Caswell <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/17986)

        (cherry picked from commit 89dd85430770d39cbfb15eb586c921958ca7687f)

    commit b7ce611887cfac633aacc052b2e71a7f195418b8
    Author: Tomas Mraz <[email protected]>
    Date:   Wed Jun 1 13:06:46 2022 +0200

        ct_test.c: Update the epoch time

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Dmitry Belyavskiy <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18446)

    commit 73db5d82489b3ec09ccc772dfcee14fef0e8e908
    Author: Tomas Mraz <[email protected]>
    Date:   Wed Jun 1 12:47:44 2022 +0200

        Update expired SCT certificates

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Dmitry Belyavskiy <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18446)

    commit 8754fa5f60ac4fdb5127f2eded9c7bbe0651c880
    Author: Bernd Edlinger <[email protected]>
    Date:   Sat May 21 07:50:46 2022 +0200

        Fix a memory leak in crl_set_issuers

        This can be reproduced with my error injection patch.

        The test vector has been validated on the 1.1.1 branch
        but the issue is of course identical in all branches.

        $ ERROR_INJECT=1653520461 ../util/shlib_wrap.sh ./cms-test ./corpora/cms/3eff1d2f1232bd66d5635db2c3f9e7f23830dfd1
        log file: cms-3eff1d2f1232bd66d5635db2c3f9e7f23830dfd1-32454-test.out
        ERROR_INJECT=1653520461
            #0 0x7fd5d8b8eeba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
            #1 0x402fc4 in my_realloc fuzz/test-corpus.c:129
            #2 0x7fd5d8893c49 in sk_reserve crypto/stack/stack.c:198
            #3 0x7fd5d8893c49 in OPENSSL_sk_insert crypto/stack/stack.c:242
            #4 0x7fd5d88d6d7f in sk_GENERAL_NAMES_push include/openssl/x509v3.h:168
            #5 0x7fd5d88d6d7f in crl_set_issuers crypto/x509/x_crl.c:111
            #6 0x7fd5d88d6d7f in crl_cb crypto/x509/x_crl.c:246
            #7 0x7fd5d85dc032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
            #8 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #9 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #10 0x7fd5d85db2b5 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:259
            #11 0x7fd5d85dc813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
            #12 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #13 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #14 0x7fd5d85dca28 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:633
            #15 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #16 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #17 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #18 0x7fd5d85dd7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
            #19 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #20 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #21 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #22 0x7fd5d85a77e0 in ASN1_item_d2i_bio crypto/asn1/a_d2i_fp.c:69
            #23 0x402845 in FuzzerTestOneInput fuzz/cms.c:43
            #24 0x402bbb in testfile fuzz/test-corpus.c:182
            #25 0x402626 in main fuzz/test-corpus.c:226
            #26 0x7fd5d7c81f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
            #27 0x402706  (/home/ed/OPC/openssl/fuzz/cms-test+0x402706)

        =================================================================
        ==29625==ERROR: LeakSanitizer: detected memory leaks

        Direct leak of 32 byte(s) in 1 object(s) allocated from:
            #0 0x7fd5d8b8309f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
            #1 0x7fd5d87c2430 in CRYPTO_zalloc crypto/mem.c:230
            #2 0x7fd5d889501f in OPENSSL_sk_new_reserve crypto/stack/stack.c:209
            #3 0x7fd5d85dcbc3 in sk_ASN1_VALUE_new_null include/openssl/asn1t.h:928
            #4 0x7fd5d85dcbc3 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:577
            #5 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #6 0x7fd5d85db104 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:178
            #7 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #8 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #9 0x7fd5d88f86d9 in X509V3_EXT_d2i crypto/x509v3/v3_lib.c:142
            #10 0x7fd5d88d6d3c in crl_set_issuers crypto/x509/x_crl.c:97
            #11 0x7fd5d88d6d3c in crl_cb crypto/x509/x_crl.c:246
            #12 0x7fd5d85dc032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
            #13 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #14 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #15 0x7fd5d85db2b5 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:259
            #16 0x7fd5d85dc813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
            #17 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #18 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #19 0x7fd5d85dca28 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:633
            #20 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #21 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #22 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #23 0x7fd5d85dd7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
            #24 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #25 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #26 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #27 0x7fd5d85a77e0 in ASN1_item_d2i_bio crypto/asn1/a_d2i_fp.c:69
            #28 0x402845 in FuzzerTestOneInput fuzz/cms.c:43
            #29 0x402bbb in testfile fuzz/test-corpus.c:182
            #30 0x402626 in main fuzz/test-corpus.c:226
            #31 0x7fd5d7c81f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

        SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18391)

        (cherry picked from commit e9007e09792e3735d4973743634ff55d354fc7d8)

    commit 4a28f8451fbc1848fd2d1b99203a7c75876123f6
    Author: Bernd Edlinger <[email protected]>
    Date:   Sun May 22 20:12:56 2022 +0200

        Fix a crash in ssl_security_cert_chain

        Prior to the crash there is an out of memory error
        in X509_verify_cert which makes the chain NULL or
        empty.  The error is ignored by ssl_add_cert_chain,
        and ssl_security_cert_chain crashes due to the
        unchecked null pointer.

        This is reproducible with my error injection patch.

        The test vector has been validated on the 1.1.1 branch
        but the issue is of course identical in all branches.

        $ ERROR_INJECT=1652848273 ../util/shlib_wrap.sh ./server-test ./corpora/server/47c8e933c4ec66fa3c309422283dfe0f31aafae8# ./corpora/server/47c8e933c4ec66fa3c309422283dfe0f31aafae8
            #0 0x7f3a8f766eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
            #1 0x403ba4 in my_malloc fuzz/test-corpus.c:114
            #2 0x7f3a8f39a430 in CRYPTO_zalloc crypto/mem.c:230
            #3 0x7f3a8f46bd3b in sk_reserve crypto/stack/stack.c:180
            #4 0x7f3a8f46bd3b in OPENSSL_sk_insert crypto/stack/stack.c:242
            #5 0x7f3a8f4a4fd8 in sk_X509_push include/openssl/x509.h:99
            #6 0x7f3a8f4a4fd8 in X509_verify_cert crypto/x509/x509_vfy.c:286
            #7 0x7f3a8fed726e in ssl_add_cert_chain ssl/statem/statem_lib.c:959
            #8 0x7f3a8fed726e in ssl3_output_cert_chain ssl/statem/statem_lib.c:1015
            #9 0x7f3a8fee1c50 in tls_construct_server_certificate ssl/statem/statem_srvr.c:3812
            #10 0x7f3a8feb8b0a in write_state_machine ssl/statem/statem.c:843
            #11 0x7f3a8feb8b0a in state_machine ssl/statem/statem.c:443
            #12 0x7f3a8fe84b3f in SSL_do_handshake ssl/ssl_lib.c:3718
            #13 0x403202 in FuzzerTestOneInput fuzz/server.c:740
            #14 0x40371b in testfile fuzz/test-corpus.c:182
            #15 0x402856 in main fuzz/test-corpus.c:226
            #16 0x7f3a8e859f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
            #17 0x402936  (/home/ed/OPC/openssl/fuzz/server-test+0x402936)

        AddressSanitizer:DEADLYSIGNAL
        =================================================================
        ==8400==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000158 (pc 0x7f3a8f4d822f bp 0x7ffc39b76190 sp 0x7ffc39b760a0 T0)
        ==8400==The signal is caused by a READ memory access.
        ==8400==Hint: address points to the zero page.
            #0 0x7f3a8f4d822f in x509v3_cache_extensions crypto/x509v3/v3_purp.c:386
            #1 0x7f3a8f4d9d3a in X509_check_purpose crypto/x509v3/v3_purp.c:84
            #2 0x7f3a8f4da02a in X509_get_extension_flags crypto/x509v3/v3_purp.c:921
            #3 0x7f3a8feff7d2 in ssl_security_cert_sig ssl/t1_lib.c:2518
            #4 0x7f3a8feff7d2 in ssl_security_cert ssl/t1_lib.c:2542
            #5 0x7f3a8feffa03 in ssl_security_cert_chain ssl/t1_lib.c:2562
            #6 0x7f3a8fed728d in ssl_add_cert_chain ssl/statem/statem_lib.c:963
            #7 0x7f3a8fed728d in ssl3_output_cert_chain ssl/statem/statem_lib.c:1015
            #8 0x7f3a8fee1c50 in tls_construct_server_certificate ssl/statem/statem_srvr.c:3812
            #9 0x7f3a8feb8b0a in write_state_machine ssl/statem/statem.c:843
            #10 0x7f3a8feb8b0a in state_machine ssl/statem/statem.c:443
            #11 0x7f3a8fe84b3f in SSL_do_handshake ssl/ssl_lib.c:3718
            #12 0x403202 in FuzzerTestOneInput fuzz/server.c:740
            #13 0x40371b in testfile fuzz/test-corpus.c:182
            #14 0x402856 in main fuzz/test-corpus.c:226
            #15 0x7f3a8e859f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
            #16 0x402936  (/home/ed/OPC/openssl/fuzz/server-test+0x402936)

        AddressSanitizer can not provide additional info.
        SUMMARY: AddressSanitizer: SEGV crypto/x509v3/v3_purp.c:386 in x509v3_cache_extensions
        ==8400==ABORTING

        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Matt Caswell <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18376)

        (cherry picked from commit dc0ef292f7df4ce0c49c64b47726a6768f9ac044)

    commit 59b8eca400d9ea7b77dc98fe08a91bbfe35d025a
    Author: Bernd Edlinger <[email protected]>
    Date:   Sat May 21 15:41:46 2022 +0200

        Fix a memory leak in X509_issuer_and_serial_hash

        This is reproducible with my error injection patch:

        $ ERROR_INJECT=1653267699 ../util/shlib_wrap.sh ./x509-test ./corpora/x509/5f4034ae85d6587dcad4da3e812e80f3d312894d
        ERROR_INJECT=1653267699
            #0 0x7fd485a6ad4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
            #1 0x55c12d268724 in my_malloc fuzz/test-corpus.c:114
            #2 0x7fd484f51a75 in CRYPTO_zalloc crypto/mem.c:230
            #3 0x7fd484ed778d in EVP_DigestInit_ex crypto/evp/digest.c:139
            #4 0x7fd4850a9849 in X509_issuer_and_serial_hash crypto/x509/x509_cmp.c:44
            #5 0x55c12d268951 in FuzzerTestOneInput fuzz/x509.c:44
            #6 0x55c12d268239 in testfile fuzz/test-corpus.c:182
            #7 0x55c12d267c7f in main fuzz/test-corpus.c:226
            #8 0x7fd483a42082 in __libc_start_main ../csu/libc-start.c:308
            #9 0x55c12d267e5d in _start (/home/ed/OPCToolboxV5/Source/Core/OpenSSL/openssl/fuzz/x509-test+0x3e5d)

        =================================================================
        ==1058475==ERROR: LeakSanitizer: detected memory leaks

        Direct leak of 268 byte(s) in 1 object(s) allocated from:
            #0 0x7fd485a5dc3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
            #1 0x7fd484d2eb9b in BUF_MEM_grow crypto/buffer/buffer.c:97
            #2 0x7fd4850b2913 in X509_NAME_oneline crypto/x509/x509_obj.c:43
            #3 0x7fd4850a982f in X509_issuer_and_serial_hash crypto/x509/x509_cmp.c:41
            #4 0x55c12d268951 in FuzzerTestOneInput fuzz/x509.c:44
            #5 0x55c12d268239 in testfile fuzz/test-corpus.c:182
            #6 0x55c12d267c7f in main fuzz/test-corpus.c:226
            #7 0x7fd483a42082 in __libc_start_main ../csu/libc-start.c:308

        SUMMARY: AddressSanitizer: 268 byte(s) leaked in 1 allocation(s).

        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Matt Caswell <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18370)

    commit e4b84b7514e5cbcbfc80e31b4ce609c7584e14bb
    Author: Bernd Edlinger <[email protected]>
    Date:   Fri May 20 16:54:41 2022 +0200

        Fix undefined behaviour in EC_GROUP_new_from_ecparameters

        This happens for instance with
        fuzz/corpora/asn1/65cf44e85614c62f10cf3b7a7184c26293a19e4a
        and causes the OPENSSL_malloc below to choke on the
        zero length allocation request.

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18363)

    commit 8e1ece20cdb4a584be5311370256c4e813c09826
    Author: Bernd Edlinger <[email protected]>
    Date:   Fri May 20 16:15:44 2022 +0200

        Fix a memory leak in ec_key_simple_oct2priv

        This is reproducible with my error injection patch:

        $ ERROR_INJECT=1652710284 ../util/shlib_wrap.sh ./server-test ./corpora/server/4e48da8aecce6b9b58e8e4dbbf0523e6d2dd56dc
        140587884632000:error:03078041:bignum routines:bn_expand_internal:malloc failure:crypto/bn/bn_lib.c:282:
        140587884632000:error:10103003:elliptic curve routines:ec_key_simple_oct2priv:BN lib:crypto/ec/ec_key.c:662:
        140587884632000:error:100DE08E:elliptic curve routines:old_ec_priv_decode:decode error:crypto/ec/ec_ameth.c:464:
        140587884632000:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto/asn1/tasn_dec.c:1149:
        140587884632000:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:309:Type=X509_ALGOR
        140587884632000:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:646:Field=pkeyalg, Type=PKCS8_PRIV_KEY_INFO
        140587884632000:error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib:crypto/pem/pem_pkey.c:88:

        =================================================================
        ==19676==ERROR: LeakSanitizer: detected memory leaks

        Direct leak of 24 byte(s) in 1 object(s) allocated from:
            #0 0x7fdd2a6bb09f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
            #1 0x7fdd2a2fa430 in CRYPTO_zalloc crypto/mem.c:230
            #2 0x7fdd2a15df11 in BN_new crypto/bn/bn_lib.c:246
            #3 0x7fdd2a15df88 in BN_secure_new crypto/bn/bn_lib.c:257
            #4 0x7fdd2a247390 in ec_key_simple_oct2priv crypto/ec/ec_key.c:655
            #5 0x7fdd2a241fc5 in d2i_ECPrivateKey crypto/ec/ec_asn1.c:1030
            #6 0x7fdd2a23dac5 in old_ec_priv_decode crypto/ec/ec_ameth.c:463
            #7 0x7fdd2a109db7 in d2i_PrivateKey crypto/asn1/d2i_pr.c:46
            #8 0x7fdd2a33ab16 in PEM_read_bio_PrivateKey crypto/pem/pem_pkey.c:84
            #9 0x7fdd2a3330b6 in PEM_read_bio_ECPrivateKey crypto/pem/pem_all.c:151
            #10 0x402dba in FuzzerTestOneInput fuzz/server.c:592
            #11 0x40370b in testfile fuzz/test-corpus.c:182
            #12 0x402846 in main fuzz/test-corpus.c:226
            #13 0x7fdd297b9f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

        SUMMARY: AddressSanitizer: 24 byte(s) leaked in 1 allocation(s).

        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Matt Caswell <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18361)

    commit 8e60f41d064786f95440e4c56660ffe9777783d7
    Author: Bernd Edlinger <[email protected]>
    Date:   Fri May 20 08:02:47 2022 +0200

        Fix a crash in asn1_item_embed_new

        This happens usually if an template object is created
        and there is an out of memory error before the ASN1_OP_NEW_POST
        method is called, but asn1_item_embed_free calls now the
        ASN1_OP_FREE_POST which may crash because the object is not
        properly initialized.  Apparently that is only an issue with
        the ASN1_OP_FREE_POST handling of crypot/x509/x_crl.c, which
        ought to be tolerant to incomplete initialized objects.

        The error can be reproduced with the reproducible error injection patch:

        $ ERROR_INJECT=1652890550 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/0ff17293911f54d1538b9896563a4048d67d9ee4
            #0 0x7faae9dbeeba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
            #1 0x408dc4 in my_malloc fuzz/test-corpus.c:114
            #2 0x7faae99f2430 in CRYPTO_zalloc crypto/mem.c:230
            #3 0x7faae97f09e5 in ASN1_STRING_type_new crypto/asn1/asn1_lib.c:341
            #4 0x7faae98118f7 in asn1_primitive_new crypto/asn1/tasn_new.c:318
            #5 0x7faae9812401 in asn1_item_embed_new crypto/asn1/tasn_new.c:78
            #6 0x7faae9812401 in asn1_template_new crypto/asn1/tasn_new.c:240
            #7 0x7faae9812315 in asn1_item_embed_new crypto/asn1/tasn_new.c:137
            #8 0x7faae9812315 in asn1_template_new crypto/asn1/tasn_new.c:240
            #9 0x7faae9812a54 in asn1_item_embed_new crypto/asn1/tasn_new.c:137
            #10 0x7faae9812a54 in ASN1_item_ex_new crypto/asn1/tasn_new.c:39
            #11 0x7faae980be51 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:325
            #12 0x7faae980c813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
            #13 0x7faae980d288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #14 0x7faae980b9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #15 0x7faae980caf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #16 0x7faae980d7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
            #17 0x7faae980b9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #18 0x7faae980dd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #19 0x7faae980de35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #20 0x40712c in FuzzerTestOneInput fuzz/asn1.c:301
            #21 0x40893b in testfile fuzz/test-corpus.c:182
            #22 0x406b86 in main fuzz/test-corpus.c:226
            #23 0x7faae8eb1f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

        AddressSanitizer:DEADLYSIGNAL
        =================================================================
        ==1194==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x7faae9b0625f bp 0x7fffffe41a00 sp 0x7fffffe41920 T0)
        ==1194==The signal is caused by a READ memory access.
        ==1194==Hint: address points to the zero page.
            #0 0x7faae9b0625f in crl_cb crypto/x509/x_crl.c:258
            #1 0x7faae9811255 in asn1_item_embed_free crypto/asn1/tasn_fre.c:113
            #2 0x7faae9812a65 in asn1_item_embed_new crypto/asn1/tasn_new.c:150
            #3 0x7faae9812a65 in ASN1_item_ex_new crypto/asn1/tasn_new.c:39
            #4 0x7faae980be51 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:325
            #5 0x7faae980c813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
            #6 0x7faae980d288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #7 0x7faae980b9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #8 0x7faae980caf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #9 0x7faae980d7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
            #10 0x7faae980b9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #11 0x7faae980dd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #12 0x7faae980de35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #13 0x40712c in FuzzerTestOneInput fuzz/asn1.c:301
            #14 0x40893b in testfile fuzz/test-corpus.c:182
            #15 0x406b86 in main fuzz/test-corpus.c:226
            #16 0x7faae8eb1f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

        AddressSanitizer can not provide additional info.
        SUMMARY: AddressSanitizer: SEGV crypto/x509/x_crl.c:258 in crl_cb
        ==1194==ABORTING

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18360)

        (cherry picked from commit 557825acd622f98fc21423aba092e374db84f483)

    commit 17519e2595b5ed8211a7763ff6eb2d6cf47c13cb
    Author: Bernd Edlinger <[email protected]>
    Date:   Thu May 19 15:50:28 2022 +0200

        Backport a missing bug-fix from master

        This is a backport of the following commit from master:

        commit 61b0fead5e6079ca826594df5b9ca00e65883cb0
        Author: Matt Caswell <[email protected]>
        Date:   Thu Nov 19 13:58:21 2020 +0000

            Don't Overflow when printing Thawte Strong Extranet Version

            When printing human readable info on the Thawte Strong Extranet extension
            the version number could overflow if the version number == LONG_MAX. This
            is undefined behaviour.

            Issue found by OSSFuzz.

            Reviewed-by: Ben Kaduk <[email protected]>
            (Merged from https://github.com/openssl/openssl/pull/13452)

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18347)

    commit 03ba56f1525c93eb3dfe72f85cdc698b97918e59
    Author: Bernd Edlinger <[email protected]>
    Date:   Thu May 19 10:59:25 2022 +0200

        Backport some fuzzing data files from master

        This is a backport of the following commit from master:

        commit 415e6ac80405e13b20b083315747e431274fbd33
        Author: Tavis Ormandy <[email protected]>
        Date:   Tue Sep 21 15:48:27 2021 -0700

            increase x509 code coverage metrics

            Reviewed-by: Matt Caswell <[email protected]>
            Reviewed-by: Tomas Mraz <[email protected]>
            (Merged from https://github.com/openssl/openssl/pull/16651)

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18347)

    commit e04ba889594d84a8805f3d0caeadf0527470e508
    Author: Daniel Fiala <[email protected]>
    Date:   Tue May 10 08:46:37 2022 +0000

        s_serve: Report an error if init-connection fails without an attempt to read.

        Fixes: openssl#18047.

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18283)

    commit 6ef91d8153e04a2302bff11b29caf7e888b62fe8
    Author: basavesh <[email protected]>
    Date:   Tue Apr 5 17:49:09 2022 +0200

        Fix leakage when the cacheline is 32-bytes in CBC_MAC_ROTATE_IN_PLACE

        rotated_mac is a 64-byte aligned buffer of size 64 and rotate_offset is secret.
        Consider a weaker leakage model(CL) where only cacheline base address is leaked,
        i.e address/32 for 32-byte cacheline(CL32).

        Previous code used to perform two loads
            1. rotated_mac[rotate_offset ^ 32] and
            2. rotated_mac[rotate_offset++]
        which would leak 2q + 1, 2q for 0 <= rotate_offset < 32
        and 2q, 2q + 1 for 32 <= rotate_offset < 64

        The proposed fix performs load operations which will always leak 2q, 2q + 1 and
        selects the appropriate value in constant-time.

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18050)

    commit c7d6c08290b67cbeef2b4f636f04788ea405520a
    Author: Tomas Mraz <[email protected]>
    Date:   Fri Apr 29 17:02:19 2022 +0200

        Add test for empty supported-groups extension

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Matt Caswell <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18213)

    commit bd164884f258d99ca876f6cdcdf9bd0dcceee6ad
    Author: Tomas Mraz <[email protected]>
    Date:   Fri Apr 29 16:36:36 2022 +0200

        Do not send an empty supported groups extension

        This allows handshake to proceed if the maximum TLS version enabled is <1.3

        Fixes #13583

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Matt Caswell <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18213)

    commit ac2d4cb656b3a796db3dc6f8873e91e67907372d
    Author: Allan Jude <[email protected]>
    Date:   Fri Nov 19 19:06:52 2021 +0000

        1_1_1-stable: Detect arm64-*-*bsd and enable assembly optimizations

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Dmitry Belyavskiy <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/17085)

    commit ec1b4bf26c1b2440546f323873c578374f60b2de
    Author: Hugo Landau <[email protected]>
    Date:   Wed Apr 27 10:11:08 2022 +0100

        (1.1) Add SSL_(CTX_)?get0_(verify|chain)_cert_store functions

        Backport of #18038 to 1.1.

        Fixes #18035.

        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Dmitry Belyavskiy <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18190)

    commit 988c7b2d9361dd0ade5ef7ef068fb4ed770ce2a2
    Author: Matt Caswell <[email protected]>
    Date:   Tue May 3 14:41:23 2022 +0100

        Prepare for 1.1.1p-dev

        Reviewed-by: Tomas Mraz <[email protected]>
        Release: yes

commit 5ea6414f0bf861e8fece53b5bf35c849bad64774
Author: Randall S. Becker <[email protected]>
Date:   Wed Jun 22 06:26:40 2022 -0600

    Squashed commit of the following:

    commit 8aaca20cf9996257d1ce2e6f4d3059b3698dde3d
    Author: Matt Caswell <[email protected]>
    Date:   Tue Jun 21 14:39:39 2022 +0100

        Prepare for 1.1.1p release

        Reviewed-by: Richard Levitte <[email protected]>
        Release: yes

    commit a3fc812c0c78e2f5db8b9d45bddaff62dfc958ae
    Author: Matt Caswell <[email protected]>
    Date:   Tue Jun 21 14:07:32 2022 +0100

        Update copyright year

        Reviewed-by: Richard Levitte <[email protected]>
        Release: yes

    commit 51e06520734063d6f52b2e596e1089d36d3781e7
    Author: Matt Caswell <[email protected]>
    Date:   Mon Jun 20 14:14:20 2022 +0100

        Update CHANGES and NEWS for new release

        Reviewed-by: Tomas Mraz <[email protected]>
        Release: yes

    commit 9639817dac8bbbaa64d09efad7464ccc405527c7
    Author: Daniel Fiala <[email protected]>
    Date:   Sun May 29 20:11:24 2022 +0200

        Fix file operations in c_rehash.

        CVE-2022-2068

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Richard Levitte <[email protected]>

    commit 20af01d46ca4086f6b1339b67c15c81d8b4a040d
    Author: Fraser Tweedale <[email protected]>
    Date:   Wed Jun 15 10:50:57 2022 +1000

        Fix documentation of BIO_FLAGS_BASE64_NO_NL

        Commit 8bfb7506d210841f2ee4eda8afe96441a0e33fa5 updated
        `BIO_f_base64(3)` to improve the documentation of the
        `BIO_FLAGS_BASE64_NO_NL` flag.  In particular, the updated text
        states that when this flag is used, all newlines in the input are
        ignored.  This is incorrect, as the following program proves:

        ```c

        unsigned char *in_buf =
            "IlRoZSBxdWljayBicm93biBmb3gganVt\ncHMgb3ZlciBhIGxhenkgZG9nLiI=\n";

        int main(int argc, char **argv) {
            BIO *b64 = BIO_new(BIO_f_base64());
            if (b64 == NULL) return 1;
            BIO_set_flags(b64, BIO_get_flags(b64) | BIO_FLAGS_BASE64_NO_NL);
            int in_len = strlen(in_buf);
            BIO *in = BIO_new_mem_buf(in_buf, in_len);
            if (in == NULL) return 2;
            in = BIO_push(b64, in);
            unsigned char *out_buf = calloc(in_len, sizeof(unsigned char));
            if (out_buf == NULL) return 3;
            size_t out_len;
            int r = BIO_read_ex(in, out_buf, in_len, &out_len);
            printf("rv = %d\n", r);
            printf("decoded = %s\n", out_buf);
            return 0;
        }
        ```

        Update the text of `BIO_f_base64(3)` to clarify that when the flag
        is set, the data must be all on one line (with or without a trailing
        newline character).

        Signed-off-by: Fraser Tweedale <[email protected]>

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18568)

        (cherry picked from commit 0edcbacca99ab2b716da395f204610fc2775ea83)

    commit 8438d3a7b7309cbea521d3628fddeda7bd6d6e20
    Author: Tomas Mraz <[email protected]>
    Date:   Thu Jun 9 16:20:05 2022 +0200

        Add an extra reduction step to RSAZ mod_exp implementations

        Inspired by BoringSSL fix by David Benjamin.

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18511)

    commit 0ed27fb7a8d85685cb671bf0a1e41bcdfc2624dc
    Author: Tomas Mraz <[email protected]>
    Date:   Thu Jun 9 12:34:55 2022 +0200

        Always end BN_mod_exp_mont_consttime with normal Montgomery reduction.

        This partially fixes a bug where, on x86_64, BN_mod_exp_mont_consttime
        would sometimes return m, the modulus, when it should have returned
        zero. Thanks to Guido Vranken for reporting it. It is only a partial fix
        because the same bug also exists in the "rsaz" codepath.

        The bug only affects zero outputs (with non-zero inputs), so we believe
        it has no security impact on our cryptographic functions.

        The fx is to delete lowercase bn_from_montgomery altogether, and have the
        mont5 path use the same BN_from_montgomery ending as the non-mont5 path.
        This only impacts the final step of the whole exponentiation and has no
        measurable perf impact.

        See the original BoringSSL commit
        https://boringssl.googlesource.com/boringssl/+/13c9d5c69d04485a7a8840c12185c832026c8315
        for further analysis.

        Original-author: David Benjamin <[email protected]>

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18511)

    commit 8f078819556da83c15751678c39558a59bc746fc
    Author: Matt Caswell <[email protected]>
    Date:   Thu Jun 9 16:57:30 2022 +0100

        Fix a crash in X509v3_asid_subset()

        If the asnum or rdi fields are NULL and the ASIdentifiers are otherwise
        subsets then this will result in a crash. Of note is that rdi will usually
        be NULL.

        Reported by Theo Buehler (@botovq)

        Reviewed-by: Tomas Mraz <[email protected]>
        Reviewed-by: Paul Yang <[email protected]>
        Reviewed-by: Todd Short <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18514)

        (cherry picked from commit 01fc9b6bce82f0534d6673659a0e59a71f57ee82)

    commit ab7d05617a444cfcf4f930f81caa4cf66495ab9b
    Author: Tomas Mraz <[email protected]>
    Date:   Thu Jun 2 18:12:05 2022 +0200

        Update further expiring certificates that affect tests

        Namely the smime certificates used in test_cms
        will expire soon and affect tests.

        Fixes #15179

        Reviewed-by: Dmitry Belyavskiy <[email protected]>
        Reviewed-by: Paul Dale <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18481)

    commit 3bd976551e549c030bdbd150c7aa8a1980cb00fe
    Author: Tomas Mraz <[email protected]>
    Date:   Tue Mar 29 13:31:34 2022 +0200

        Fix strict client chain check with TLS-1.3

        When TLS-1.3 is used and the server does not send any CA names
        the ca_dn will be NULL. sk_X509_NAME_num() returns -1 on null
        argument.

        Reviewed-by: Todd Short <[email protected]>
        Reviewed-by: Matt Caswell <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/17986)

        (cherry picked from commit 89dd85430770d39cbfb15eb586c921958ca7687f)

    commit b7ce611887cfac633aacc052b2e71a7f195418b8
    Author: Tomas Mraz <[email protected]>
    Date:   Wed Jun 1 13:06:46 2022 +0200

        ct_test.c: Update the epoch time

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Dmitry Belyavskiy <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18446)

    commit 73db5d82489b3ec09ccc772dfcee14fef0e8e908
    Author: Tomas Mraz <[email protected]>
    Date:   Wed Jun 1 12:47:44 2022 +0200

        Update expired SCT certificates

        Reviewed-by: Matt Caswell <[email protected]>
        Reviewed-by: Dmitry Belyavskiy <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18446)

    commit 8754fa5f60ac4fdb5127f2eded9c7bbe0651c880
    Author: Bernd Edlinger <[email protected]>
    Date:   Sat May 21 07:50:46 2022 +0200

        Fix a memory leak in crl_set_issuers

        This can be reproduced with my error injection patch.

        The test vector has been validated on the 1.1.1 branch
        but the issue is of course identical in all branches.

        $ ERROR_INJECT=1653520461 ../util/shlib_wrap.sh ./cms-test ./corpora/cms/3eff1d2f1232bd66d5635db2c3f9e7f23830dfd1
        log file: cms-3eff1d2f1232bd66d5635db2c3f9e7f23830dfd1-32454-test.out
        ERROR_INJECT=1653520461
            #0 0x7fd5d8b8eeba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
            #1 0x402fc4 in my_realloc fuzz/test-corpus.c:129
            #2 0x7fd5d8893c49 in sk_reserve crypto/stack/stack.c:198
            #3 0x7fd5d8893c49 in OPENSSL_sk_insert crypto/stack/stack.c:242
            #4 0x7fd5d88d6d7f in sk_GENERAL_NAMES_push include/openssl/x509v3.h:168
            #5 0x7fd5d88d6d7f in crl_set_issuers crypto/x509/x_crl.c:111
            #6 0x7fd5d88d6d7f in crl_cb crypto/x509/x_crl.c:246
            #7 0x7fd5d85dc032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
            #8 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #9 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #10 0x7fd5d85db2b5 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:259
            #11 0x7fd5d85dc813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
            #12 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #13 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #14 0x7fd5d85dca28 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:633
            #15 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #16 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #17 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #18 0x7fd5d85dd7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
            #19 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #20 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #21 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #22 0x7fd5d85a77e0 in ASN1_item_d2i_bio crypto/asn1/a_d2i_fp.c:69
            #23 0x402845 in FuzzerTestOneInput fuzz/cms.c:43
            #24 0x402bbb in testfile fuzz/test-corpus.c:182
            #25 0x402626 in main fuzz/test-corpus.c:226
            #26 0x7fd5d7c81f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
            #27 0x402706  (/home/ed/OPC/openssl/fuzz/cms-test+0x402706)

        =================================================================
        ==29625==ERROR: LeakSanitizer: detected memory leaks

        Direct leak of 32 byte(s) in 1 object(s) allocated from:
            #0 0x7fd5d8b8309f in __interceptor_malloc ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:69
            #1 0x7fd5d87c2430 in CRYPTO_zalloc crypto/mem.c:230
            #2 0x7fd5d889501f in OPENSSL_sk_new_reserve crypto/stack/stack.c:209
            #3 0x7fd5d85dcbc3 in sk_ASN1_VALUE_new_null include/openssl/asn1t.h:928
            #4 0x7fd5d85dcbc3 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:577
            #5 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #6 0x7fd5d85db104 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:178
            #7 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #8 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #9 0x7fd5d88f86d9 in X509V3_EXT_d2i crypto/x509v3/v3_lib.c:142
            #10 0x7fd5d88d6d3c in crl_set_issuers crypto/x509/x_crl.c:97
            #11 0x7fd5d88d6d3c in crl_cb crypto/x509/x_crl.c:246
            #12 0x7fd5d85dc032 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:432
            #13 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #14 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #15 0x7fd5d85db2b5 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:259
            #16 0x7fd5d85dc813 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:611
            #17 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #18 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #19 0x7fd5d85dca28 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:633
            #20 0x7fd5d85dd288 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:518
            #21 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #22 0x7fd5d85dcaf5 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:643
            #23 0x7fd5d85dd7d3 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:494
            #24 0x7fd5d85db9ce in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:382
            #25 0x7fd5d85ddd1f in ASN1_item_ex_d2i crypto/asn1/tasn_dec.c:124
            #26 0x7fd5d85dde35 in ASN1_item_d2i crypto/asn1/tasn_dec.c:114
            #27 0x7fd5d85a77e0 in ASN1_item_d2i_bio crypto/asn1/a_d2i_fp.c:69
            #28 0x402845 in FuzzerTestOneInput fuzz/cms.c:43
            #29 0x402bbb in testfile fuzz/test-corpus.c:182
            #30 0x402626 in main fuzz/test-corpus.c:226
            #31 0x7fd5d7c81f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

        SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).

        Reviewed-by: Paul Dale <[email protected]>
        Reviewed-by: Tomas Mraz <[email protected]>
        (Merged from https://github.com/openssl/openssl/pull/18391)

        (cherry picked from commit e9007e09792e3735d4973743634ff55d354fc7d8)

    commit 4a28f8451fbc1848fd2d1b99203a7c75876123f6
    Author: Bernd Edlinger <[email protected]>
    Date:   Sun May 22 20:12:56 2022 +0200

        Fix a crash in ssl_security_cert_chain

        Prior to the crash there is an out of memory error
        in X509_verify_cert which makes the chain NULL or
        empty.  The error is ignored by ssl_add_cert_chain,
        and ssl_security_cert_chain crashes due to the
        unchecked null pointer.

        This is reproducible with my error injection patch.

        The test vector has been validated on the 1.1.1 branch
        but the issue is of course identical in all branches.

        $ ERROR_INJECT=1652848273 ../util/shlib_wrap.sh ./server-test ./corpora/server/47c8e933c4ec66fa3c309422283dfe0f31aafae8# ./corpora/server/47c8e933c4ec66fa3c309422283dfe0f31aafae8
            #0 0x7f3a8f766eba in __sanitizer_print_stack_trace ../../../../gcc-trunk/libsanitizer/asan/asan_stack.cpp:87
            #1 0x403ba4 in my_malloc fuzz/test-corpus.c:114
            #2 0x7f3a8f39a430 in CRYPTO_zalloc crypto/mem.c:230
            #3 0x7f3a8f46bd3b in sk_reserve crypto/stack/stack.c:180
            #4 0x7f3a8f46bd3b in OPENSSL_sk_insert crypto/stack/stack.c:242
            #5 0x7f3a8f4a4fd8 in sk_X509_push include/openssl/x509.h:99
            #6 0x7f3a8f4a4fd8 in X509_verify_cert crypto/x509/x509_vfy.c:286
            #7 0x7f3a8fed726e in ssl_add_cert_chain ssl/statem/statem_lib.c:959
            #8 0x7f3a8fed726e in ssl3_output_cert_chain ssl/statem/statem_lib.c:1015
            #9 0x7f3a8fee1c50 in tls_construct_server_certificate ssl/statem/statem_srvr.c:3812
            #10 0x7f3a8feb8b0a in write_state_machine ssl/statem/statem.c:843
            #11 0x7f3a8feb8b0a in state_machine ssl/statem/statem.c:443
            #12 0x7f3a8fe84b3f in SSL_do_handshake ssl/ssl_lib.c:3718
            #13 0x403202 in FuzzerTestOneInput fuzz/server.c:740
            #14 0x40371b in testfile fuzz/test-corpus.c:182
            #15 0x402856 in main fuzz/test-corpus.c:226
            #16 0x7f3a8e859f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
            #17 0x402936  (/home/ed/OPC/openssl/fuzz/server-test+0x402936)

        AddressSanitizer:DEADLYSIGNAL
        =================================================================
        ==8400==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000158 (pc 0x7f3a8f4d822f bp 0x7ffc39b76190 sp 0x7ffc39b760a0 T0)
        ==8400==The signal is caused by a READ memory access.
        ==8400==Hint: address points to the zero page.
            #0 0x7f3a8f4d822f in x509v3_cache_extensions crypto/x509v3/v3_purp.c:386
            #1 0x7f3a8f4d9d3a in X509_check_purpose crypto/x509v3/v3_purp.c:84
            #2 0x7f3a8f4da02a in X509_get_extension_flags crypto/x509v3/v3_purp.c:921
            #3 0x7f3a8feff7d2 in ssl_security_cert_sig ssl/t1_lib.c:2518
            #4 0x7f3a8feff7d2 in ssl_security_cert ssl/t1_lib.c:2542
            #5 0x7f3a8feffa03 in ssl_security_cert_chain ssl/t1_lib.c:2562
            #6 0x7f3a8fed728d in ssl_add_cert_chain ssl/statem/statem_lib.c:963
            #7 0x7f3a8fed728d in ssl3_output_cert_chain ssl/statem/statem_lib.c:1015
            #8 0x7f3a8fee1c50 in tls_construct_server_certificate ssl/statem/statem_srvr.c:3812
            #9 0x7f3a8feb8b0a in write_state_machine ssl/statem/statem.c:843
            #10 0x7f3a8feb8b0a in state_machine ssl/statem/statem.c:443
            #11 0x7f3a8fe84b3f in SSL_do_handshake ssl/ssl_lib.c:3718
            #12 0x403202 in FuzzerTestOneInput fuzz/server.c:740
            #13 0x40371b in testfile fuzz/test-corpus.c:182
            #14 0x402856 in main fuzz/test-corpus.c:226
            #15 0x7f3a8e859f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
            #16 0x402936  (/home/ed/OPC/openssl/fuzz/server-test+0x402936)

        AddressSanitizer can not provide additional info.
        SUMMARY: AddressSanitizer: SEGV crypt…
@t8m t8m removed help wanted We depend on community to resolve this issue. branch: 3.0 Applies to openssl-3.0 branch (EOL) labels Oct 24, 2022
@kroeckx

kroeckx commented Nov 11, 2022

Copy link
Copy Markdown
Member

Can you clarify what the current state of this is? Are you still finding issues in certain branches?

I guess since you use the corpora in the repository, it's probably useful to have more coverage. I'll try to create a PR to improve the corpora soon.

@bernd-edlinger

bernd-edlinger commented Nov 11, 2022

Copy link
Copy Markdown
Member Author

Can you clarify what the current state of this is? Are you still finding issues in certain branches?

I guess since you use the corpora in the repository, it's probably useful to have more coverage. I'll try to create a PR to improve the corpora soon.

Yes, of course.

status 3.0: I used b697ae1 and cherry-picked this PR on top,
configured as: ./config enable-asan enable-ubsan enable-rc5 enable-md2 enable-ec_nistp_64_gcc_128 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DERROR_INJECT -DERROR_CALLSTACK
result after 7 seconds:

Fr 11. Nov 20:25:55 CET 2022: running asn1
Fr 11. Nov 20:26:08 CET 2022: error detected
ERROR_INJECT=1667404761 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/03caabfee6f225029ce335b279b8b36e7ca8d748
log file: asn1-03caabfee6f225029ce335b279b8b36e7ca8d748-3219163-test.out
ERROR_INJECT=1667404761
# ./corpora/asn1/03caabfee6f225029ce335b279b8b36e7ca8d748
    #0 0x7f7b81504d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5597eaa33724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f7b7fc6ed35 in BUF_MEM_grow crypto/buffer/buffer.c:97
    #3 0x7f7b801d487e in x509_name_ex_d2i crypto/x509/x_name.c:177
    #4 0x7f7b7fbcbe3a in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:264
    #5 0x7f7b7fbcd9ac in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #6 0x7f7b7fbce458 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #7 0x7f7b7fbcc0fe in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #8 0x7f7b7fbcd9ac in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #9 0x7f7b7fbce458 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #10 0x7f7b7fbcc0fe in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #11 0x7f7b7fbcd5e7 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:651
    #12 0x7f7b7fbce458 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #13 0x7f7b7fbcc0fe in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #14 0x7f7b7fbcf1a4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #15 0x7f7b7fbcf1a4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #16 0x5597eaa30f1f in FuzzerTestOneInput fuzz/asn1.c:315
    #17 0x5597eaa332b9 in testfile fuzz/test-corpus.c:182
    #18 0x5597eaa3089f in main fuzz/test-corpus.c:226
    #19 0x7f7b7e680082 in __libc_start_main ../csu/libc-start.c:308
    #20 0x5597eaa30a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f7b81504d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5597eaa33724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f7b7fc6ed35 in BUF_MEM_grow crypto/buffer/buffer.c:97
    #3 0x7f7b801d487e in x509_name_ex_d2i crypto/x509/x_name.c:177
    #4 0x7f7b7fbcbe3a in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:264
    #5 0x7f7b7fbcd9ac in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #6 0x7f7b7fbce458 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #7 0x7f7b7fbcc0fe in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #8 0x7f7b7fbcd9ac in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #9 0x7f7b7fbce458 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #10 0x7f7b7fbcc0fe in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #11 0x7f7b7fbcd5e7 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:651
    #12 0x7f7b7fbce458 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #13 0x7f7b7fbcc0fe in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #14 0x7f7b7fbcf1a4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #15 0x7f7b7fbcf1a4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #16 0x5597eaa30f1f in FuzzerTestOneInput fuzz/asn1.c:315
    #17 0x5597eaa332b9 in testfile fuzz/test-corpus.c:182
    #18 0x5597eaa3089f in main fuzz/test-corpus.c:226
    #19 0x7f7b7e680082 in __libc_start_main ../csu/libc-start.c:308
    #20 0x5597eaa30a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f7b81504d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5597eaa33724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f7b8012ace3 in sk_reserve crypto/stack/stack.c:215
    #3 0x7f7b8012ace3 in OPENSSL_sk_insert crypto/stack/stack.c:271
    #4 0x7f7b7ffabf5a in ossl_namemap_doall_names crypto/core_namemap.c:168
    #5 0x7f7b7fe68768 in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:364
    #6 0x7f7b7fe689c9 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:450
    #7 0x7f7b7fbbe0d6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #8 0x7f7b7fbbec20 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #9 0x5597eaa32728 in FuzzerTestOneInput fuzz/asn1.c:366
    #10 0x5597eaa332b9 in testfile fuzz/test-corpus.c:182
    #11 0x5597eaa3089f in main fuzz/test-corpus.c:226
    #12 0x7f7b7e680082 in __libc_start_main ../csu/libc-start.c:308
    #13 0x5597eaa30a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f7b81504d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5597eaa337a4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7f7b7ffb8227 in CRYPTO_strndup crypto/o_str.c:43
    #3 0x7f7b7ffac8e0 in namemap_name2num_n crypto/core_namemap.c:179
    #4 0x7f7b7ffac8e0 in namemap_add_name_n crypto/core_namemap.c:251
    #5 0x7f7b7ffac8e0 in ossl_namemap_add_names crypto/core_namemap.c:351
    #6 0x7f7b7fe65e14 in construct_decoder crypto/encode_decode/decoder_meth.c:327
    #7 0x7f7b7ffaaa0d in ossl_method_construct_this crypto/core_fetch.c:109
    #8 0x7f7b7ffaa0e1 in algorithm_do_map crypto/core_algorithm.c:77
    #9 0x7f7b7ffaa0e1 in algorithm_do_this crypto/core_algorithm.c:122
    #10 0x7f7b7ffd862e in ossl_provider_doall_activated crypto/provider_core.c:1431
    #11 0x7f7b7ffaa676 in ossl_algorithm_do_all crypto/core_algorithm.c:162
    #12 0x7f7b7ffab38e in ossl_method_construct crypto/core_fetch.c:153
    #13 0x7f7b7fe64cd3 in inner_ossl_decoder_fetch crypto/encode_decode/decoder_meth.c:412
    #14 0x7f7b7fe6685f in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:583
    #15 0x7f7b7fe68632 in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:392
    #16 0x7f7b7fe689c9 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:450
    #17 0x7f7b7fbbe0d6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #18 0x7f7b7fbbec20 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #19 0x5597eaa32728 in FuzzerTestOneInput fuzz/asn1.c:366
    #20 0x5597eaa332b9 in testfile fuzz/test-corpus.c:182
    #21 0x7f7b7e680082 in __libc_start_main ../csu/libc-start.c:308
    #22 0x5597eaa30a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f7b81504d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5597eaa337a4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7f7b7ffb8227 in CRYPTO_strndup crypto/o_str.c:43
    #3 0x7f7b7ffad406 in namemap_name2num_n crypto/core_namemap.c:179
    #4 0x7f7b7ffad406 in ossl_namemap_name2num_n crypto/core_namemap.c:203
    #5 0x7f7b7fe666fa in OSSL_DECODER_is_a crypto/encode_decode/decoder_meth.c:556
    #6 0x7f7b7fe61d17 in collect_extra_decoder crypto/encode_decode/decoder_lib.c:373
    #7 0x7f7b7fe61d17 in OSSL_DECODER_CTX_add_extra crypto/encode_decode/decoder_lib.c:539
    #8 0x7f7b7fe689dc in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:452
    #9 0x7f7b7fbbe0d6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #10 0x7f7b7fbbec20 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #11 0x5597eaa32728 in FuzzerTestOneInput fuzz/asn1.c:366
    #12 0x5597eaa332b9 in testfile fuzz/test-corpus.c:182
    #13 0x5597eaa3089f in main fuzz/test-corpus.c:226
    #14 0x7f7b7e680082 in __libc_start_main ../csu/libc-start.c:308
    #15 0x5597eaa30a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)

    #0 0x7f7b81504d4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5597eaa33724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7f7b8012ace3 in sk_reserve crypto/stack/stack.c:215
    #3 0x7f7b8012ace3 in OPENSSL_sk_insert crypto/stack/stack.c:271
    #4 0x7f7b7fe61135 in sk_OSSL_DECODER_INSTANCE_push crypto/encode_decode/encoder_local.h:115
    #5 0x7f7b7fe61135 in ossl_decoder_ctx_add_decoder_inst crypto/encode_decode/decoder_lib.c:296
    #6 0x7f7b7fe67b75 in collect_decoder crypto/encode_decode/decoder_pkey.c:286
    #7 0x7f7b8007766c in alg_do_one crypto/property/property.c:469
    #8 0x7f7b8007766c in alg_do_each crypto/property/property.c:485
    #9 0x7f7b7ffdd812 in sa_doall crypto/sparse_array.c:93
    #10 0x7f7b7ffdd812 in ossl_sa_doall_arg crypto/sparse_array.c:148
    #11 0x7f7b800798c8 in ossl_sa_ALGORITHM_doall_arg crypto/property/property.c:96
    #12 0x7f7b800798c8 in ossl_method_store_do_all crypto/property/property.c:498
    #13 0x7f7b7fe668f8 in OSSL_DECODER_do_all_provided crypto/encode_decode/decoder_meth.c:589
    #14 0x7f7b7fe68632 in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:392
    #15 0x7f7b7fe689c9 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:450
    #16 0x7f7b7fbbe0d6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #17 0x7f7b7fbbec20 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #18 0x5597eaa32728 in FuzzerTestOneInput fuzz/asn1.c:366
    #19 0x5597eaa332b9 in testfile fuzz/test-corpus.c:182
    #20 0x5597eaa3089f in main fuzz/test-corpus.c:226
    #21 0x7f7b7e680082 in __libc_start_main ../csu/libc-start.c:308
    #22 0x5597eaa30a4d in _start (.../openssl-3.0/fuzz/asn1-test+0x9a4d)


=================================================================
==3223511==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7f7b814f7808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f7b7ffb56b5 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7f7b7ffab971 in namemap_add_name_n crypto/core_namemap.c:254
    #3 0x7f7b7ffad9b3 in namemap_add_name_n crypto/core_namemap.c:290
    #4 0x7f7b7ffad9b3 in ossl_namemap_add_name_n crypto/core_namemap.c:287
    #5 0x7f7b7ffadc5a in get_legacy_evp_names crypto/core_namemap.c:391
    #6 0x7f7b7ffad20d in get_legacy_pkey_meth_names crypto/core_namemap.c:449
    #7 0x7f7b7ffad20d in ossl_namemap_stored crypto/core_namemap.c:500
    #8 0x7f7b7ff308d2 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:271
    #9 0x7f7b7ff308d2 in evp_generic_do_all crypto/evp/evp_fetch.c:654
    #10 0x7f7b7ff4e19f in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:290
    #11 0x7f7b7fe6830c in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:346
    #12 0x7f7b7fe689c9 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:450
    #13 0x7f7b7fbbe0d6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7f7b7fbbec20 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x5597eaa32728 in FuzzerTestOneInput fuzz/asn1.c:366
    #16 0x5597eaa332b9 in testfile fuzz/test-corpus.c:182
    #17 0x5597eaa3089f in main fuzz/test-corpus.c:226
    #18 0x7f7b7e680082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x7f7b814f7808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f7b7ffb8227 in CRYPTO_strndup crypto/o_str.c:43
    #2 0x7f7b7ffab994 in namemap_add_name_n crypto/core_namemap.c:255
    #3 0x7f7b7ffad9b3 in namemap_add_name_n crypto/core_namemap.c:290
    #4 0x7f7b7ffad9b3 in ossl_namemap_add_name_n crypto/core_namemap.c:287
    #5 0x7f7b7ffadc5a in get_legacy_evp_names crypto/core_namemap.c:391
    #6 0x7f7b7ffad20d in get_legacy_pkey_meth_names crypto/core_namemap.c:449
    #7 0x7f7b7ffad20d in ossl_namemap_stored crypto/core_namemap.c:500
    #8 0x7f7b7ff308d2 in inner_evp_generic_fetch crypto/evp/evp_fetch.c:271
    #9 0x7f7b7ff308d2 in evp_generic_do_all crypto/evp/evp_fetch.c:654
    #10 0x7f7b7ff4e19f in EVP_KEYMGMT_do_all_provided crypto/evp/keymgmt_meth.c:290
    #11 0x7f7b7fe6830c in ossl_decoder_ctx_setup_for_pkey crypto/encode_decode/decoder_pkey.c:346
    #12 0x7f7b7fe689c9 in OSSL_DECODER_CTX_new_for_pkey crypto/encode_decode/decoder_pkey.c:450
    #13 0x7f7b7fbbe0d6 in d2i_PrivateKey_decoder crypto/asn1/d2i_pr.c:49
    #14 0x7f7b7fbbec20 in d2i_AutoPrivateKey_ex crypto/asn1/d2i_pr.c:224
    #15 0x5597eaa32728 in FuzzerTestOneInput fuzz/asn1.c:366
    #16 0x5597eaa332b9 in testfile fuzz/test-corpus.c:182
    #17 0x5597eaa3089f in main fuzz/test-corpus.c:226
    #18 0x7f7b7e680082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: 20 byte(s) leaked in 2 allocation(s).

This leak is reproducible.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Likewise for 3.1, I did the same with 66ecce2 current tip revision of 3.1:

Fr 11. Nov 20:39:57 CET 2022: running asn1
Fr 11. Nov 20:40:00 CET 2022: error detected
ERROR_INJECT=1667564861 ../util/shlib_wrap.sh ./asn1-test ./corpora/asn1/009d67ce4166bc56e29f8992e5a63c6fe4832442
log file: asn1-009d67ce4166bc56e29f8992e5a63c6fe4832442-3453504-test.out
ERROR_INJECT=1667564861
    #0 0x7fc6e2decd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5649ed261724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7fc6e1a06a73 in sk_reserve crypto/stack/stack.c:215
    #3 0x7fc6e1a06a73 in OPENSSL_sk_insert crypto/stack/stack.c:271
    #4 0x7fc6e17e13da in CRYPTO_set_ex_data crypto/ex_data.c:477
    #5 0x7fc6e17d7c4d in ossl_lib_ctx_generic_new crypto/context.c:318
    #6 0x7fc6e17e1245 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #7 0x7fc6e17d8e61 in ossl_lib_ctx_get_data crypto/context.c:413
    #8 0x7fc6e175fbe5 in get_evp_method_store crypto/evp/evp_fetch.c:82
    #9 0x7fc6e175fbe5 in evp_method_store_cache_flush crypto/evp/evp_fetch.c:458
    #10 0x7fc6e180693e in provider_flush_store_cache crypto/provider_core.c:1185
    #11 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1257
    #12 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1242
    #13 0x7fc6e17ff6c6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #14 0x5649ed260f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #15 0x5649ed25eb1c in FuzzerInitialize fuzz/asn1.c:287
    #16 0x5649ed25e493 in main fuzz/test-corpus.c:194
    #17 0x7fc6dfea7082 in __libc_start_main ../csu/libc-start.c:308
    #18 0x5649ed25ea4d in _start (.../openssl-3.1/fuzz/asn1-test+0x9a4d)

    #0 0x7fc6e2decd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5649ed2617a4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7fc6e17d4f44 in OPENSSL_LH_insert crypto/lhash/lhash.c:120
    #3 0x7fc6e1908780 in lh_OBJ_NAME_insert crypto/objects/obj_local.h:12
    #4 0x7fc6e1908780 in OBJ_NAME_add crypto/objects/o_names.c:214
    #5 0x7fc6e17886bd in EVP_add_digest crypto/evp/names.c:41
    #6 0x7fc6e16d416e in openssl_add_all_digests_int crypto/evp/c_alld.c:42
    #7 0x7fc6e17e325c in ossl_init_add_all_digests crypto/init.c:232
    #8 0x7fc6e17e325c in ossl_init_add_all_digests_ossl_ crypto/init.c:224
    #9 0x7fc6e00884de in __pthread_once_slow /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_once.c:116
    #10 0x7fc6e180faae in CRYPTO_THREAD_run_once crypto/threads_pthread.c:156
    #11 0x7fc6e17e3994 in OPENSSL_init_crypto crypto/init.c:567
    #12 0x7fc6e29aff66 in OPENSSL_init_ssl ssl/ssl_init.c:115
    #13 0x5649ed25eb65 in FuzzerInitialize fuzz/asn1.c:299
    #14 0x5649ed25e493 in main fuzz/test-corpus.c:194
    #15 0x7fc6dfea7082 in __libc_start_main ../csu/libc-start.c:308
    #16 0x5649ed25ea4d in _start (.../openssl-3.1/fuzz/asn1-test+0x9a4d)

# ./corpora/asn1/009d67ce4166bc56e29f8992e5a63c6fe4832442
    #0 0x7fc6e2decd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5649ed2617a4 in my_malloc fuzz/test-corpus.c:114
    #2 0x7fc6e17e7c63 in CRYPTO_strdup crypto/o_str.c:27
    #3 0x7fc6e16c487d in err_set_debug crypto/err/err_local.h:60
    #4 0x7fc6e16c487d in ERR_set_debug crypto/err/err_blocks.c:37
    #5 0x7fc6e13f9c34 in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:685
    #6 0x7fc6e13fa658 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #7 0x7fc6e13f82fe in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #8 0x7fc6e13fb3a4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #9 0x7fc6e13fb3a4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #10 0x5649ed25ef1f in FuzzerTestOneInput fuzz/asn1.c:315
    #11 0x5649ed2612b9 in testfile fuzz/test-corpus.c:182
    #12 0x5649ed25e89f in main fuzz/test-corpus.c:226
    #13 0x7fc6dfea7082 in __libc_start_main ../csu/libc-start.c:308
    #14 0x5649ed25ea4d in _start (.../openssl-3.1/fuzz/asn1-test+0x9a4d)

    #0 0x7fc6e2decd4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x5649ed261724 in my_realloc fuzz/test-corpus.c:129
    #2 0x7fc6e13dbcb7 in ASN1_STRING_set crypto/asn1/asn1_lib.c:306
    #3 0x7fc6e13b7570 in ossl_c2i_ASN1_INTEGER crypto/asn1/a_int.c:306
    #4 0x7fc6e13f6172 in asn1_ex_c2i crypto/asn1/tasn_dec.c:892
    #5 0x7fc6e13f6172 in asn1_d2i_ex_primitive crypto/asn1/tasn_dec.c:818
    #6 0x7fc6e13f8822 in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:217
    #7 0x7fc6e13f9bac in asn1_template_noexp_d2i crypto/asn1/tasn_dec.c:682
    #8 0x7fc6e13fa658 in asn1_template_ex_d2i crypto/asn1/tasn_dec.c:558
    #9 0x7fc6e13f82fe in asn1_item_embed_d2i crypto/asn1/tasn_dec.c:422
    #10 0x7fc6e13fb3a4 in asn1_item_ex_d2i_intern crypto/asn1/tasn_dec.c:118
    #11 0x7fc6e13fb3a4 in ASN1_item_d2i_ex crypto/asn1/tasn_dec.c:144
    #12 0x5649ed25ef1f in FuzzerTestOneInput fuzz/asn1.c:315
    #13 0x5649ed2612b9 in testfile fuzz/test-corpus.c:182
    #14 0x5649ed25e89f in main fuzz/test-corpus.c:226
    #15 0x7fc6dfea7082 in __libc_start_main ../csu/libc-start.c:308
    #16 0x5649ed25ea4d in _start (.../openssl-3.1/fuzz/asn1-test+0x9a4d)


=================================================================
==3454053==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7fc6e2ddf808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fc6e17e5285 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fc6e1953b63 in ossl_method_store_new crypto/property/property.c:252
    #3 0x7fc6e17d7bf6 in ossl_lib_ctx_generic_new crypto/context.c:309
    #4 0x7fc6e17e1245 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #5 0x7fc6e17d8e61 in ossl_lib_ctx_get_data crypto/context.c:413
    #6 0x7fc6e175fbe5 in get_evp_method_store crypto/evp/evp_fetch.c:82
    #7 0x7fc6e175fbe5 in evp_method_store_cache_flush crypto/evp/evp_fetch.c:458
    #8 0x7fc6e180693e in provider_flush_store_cache crypto/provider_core.c:1185
    #9 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1257
    #10 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1242
    #11 0x7fc6e17ff6c6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #12 0x5649ed260f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #13 0x5649ed25eb1c in FuzzerInitialize fuzz/asn1.c:287
    #14 0x5649ed25e493 in main fuzz/test-corpus.c:194
    #15 0x7fc6dfea7082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7fc6e2ddf808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fc6e17e5285 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fc6e180f993 in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7fc6e1953bc3 in ossl_method_store_new crypto/property/property.c:256
    #4 0x7fc6e17d7bf6 in ossl_lib_ctx_generic_new crypto/context.c:309
    #5 0x7fc6e17e1245 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #6 0x7fc6e17d8e61 in ossl_lib_ctx_get_data crypto/context.c:413
    #7 0x7fc6e175fbe5 in get_evp_method_store crypto/evp/evp_fetch.c:82
    #8 0x7fc6e175fbe5 in evp_method_store_cache_flush crypto/evp/evp_fetch.c:458
    #9 0x7fc6e180693e in provider_flush_store_cache crypto/provider_core.c:1185
    #10 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1257
    #11 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1242
    #12 0x7fc6e17ff6c6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #13 0x5649ed260f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #14 0x5649ed25eb1c in FuzzerInitialize fuzz/asn1.c:287
    #15 0x5649ed25e493 in main fuzz/test-corpus.c:194
    #16 0x7fc6dfea7082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7fc6e2ddf808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fc6e17e5285 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fc6e180f993 in CRYPTO_THREAD_lock_new crypto/threads_pthread.c:50
    #3 0x7fc6e1953bf1 in ossl_method_store_new crypto/property/property.c:257
    #4 0x7fc6e17d7bf6 in ossl_lib_ctx_generic_new crypto/context.c:309
    #5 0x7fc6e17e1245 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #6 0x7fc6e17d8e61 in ossl_lib_ctx_get_data crypto/context.c:413
    #7 0x7fc6e175fbe5 in get_evp_method_store crypto/evp/evp_fetch.c:82
    #8 0x7fc6e175fbe5 in evp_method_store_cache_flush crypto/evp/evp_fetch.c:458
    #9 0x7fc6e180693e in provider_flush_store_cache crypto/provider_core.c:1185
    #10 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1257
    #11 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1242
    #12 0x7fc6e17ff6c6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #13 0x5649ed260f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #14 0x5649ed25eb1c in FuzzerInitialize fuzz/asn1.c:287
    #15 0x5649ed25e493 in main fuzz/test-corpus.c:194
    #16 0x7fc6dfea7082 in __libc_start_main ../csu/libc-start.c:308

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7fc6e2ddf808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7fc6e17e5285 in CRYPTO_zalloc crypto/mem.c:197
    #2 0x7fc6e1953b91 in ossl_sa_ALGORITHM_new crypto/property/property.c:96
    #3 0x7fc6e1953b91 in ossl_method_store_new crypto/property/property.c:255
    #4 0x7fc6e17d7bf6 in ossl_lib_ctx_generic_new crypto/context.c:309
    #5 0x7fc6e17e1245 in ossl_crypto_alloc_ex_data_intern crypto/ex_data.c:456
    #6 0x7fc6e17d8e61 in ossl_lib_ctx_get_data crypto/context.c:413
    #7 0x7fc6e175fbe5 in get_evp_method_store crypto/evp/evp_fetch.c:82
    #8 0x7fc6e175fbe5 in evp_method_store_cache_flush crypto/evp/evp_fetch.c:458
    #9 0x7fc6e180693e in provider_flush_store_cache crypto/provider_core.c:1185
    #10 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1257
    #11 0x7fc6e180693e in ossl_provider_activate crypto/provider_core.c:1242
    #12 0x7fc6e17ff6c6 in OSSL_PROVIDER_try_load crypto/provider.c:31
    #13 0x5649ed260f72 in FuzzerSetRand fuzz/fuzz_rand.c:161
    #14 0x5649ed25eb1c in FuzzerInitialize fuzz/asn1.c:287
    #15 0x5649ed25e493 in main fuzz/test-corpus.c:194
    #16 0x7fc6dfea7082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: 192 byte(s) leaked in 4 allocation(s).

Also reproducible, everybody should be able to reproduce and debug this result,
all that is needed is the exact build-spec and the initialization vector.

@bernd-edlinger

Copy link
Copy Markdown
Member Author

Status of master is a major regression:
I used a0783b8 as base revision,
and the same build-spec: ./config enable-asan enable-ubsan enable-rc5 enable-md2 enable-ec_nistp_64_gcc_128 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DERROR_INJECT -DERROR_CALLSTACK

now it is a dead-lock reproducible as follows:

$ ERROR_INJECT=1667700707 ../util/shlib_wrap.sh gdb --args ./asn1parse-test ./corpora/asn1parse/02262ecda0
47a99c1bbbb56e80cc0d31dff6fc38
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./asn1parse-test...
(gdb) r
Starting program: /home/ed/OPCToolboxV5/Source/Core/OpenSSL/openssl-master/fuzz/asn1parse-test ./corpora/asn1parse/02262ecda047a99c1bbbb56e80cc0d31dff6fc38
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    #0 0x7ffff768ed4f in __sanitizer_print_stack_trace ../../../../src/libsanitizer/asan/asan_stack.cc:36
    #1 0x555555558694 in my_malloc fuzz/test-corpus.c:114
    #2 0x7ffff653a26c in CRYPTO_malloc crypto/mem.c:177
    #3 0x7ffff652a744 in OPENSSL_LH_insert crypto/lhash/lhash.c:114
    #4 0x7ffff6401b7e in err_load_strings crypto/err/err.c:265
    #5 0x7ffff6401b7e in err_load_strings crypto/err/err.c:260
    #6 0x7ffff6401b7e in ERR_load_strings_const crypto/err/err.c:302
    #7 0x7ffff692100b in ossl_err_load_PROV_strings providers/common/provider_err.c:226
    #8 0x7ffff6417b55 in ossl_err_load_crypto_strings crypto/err/err_all.c:107
    #9 0x7ffff653847c in ossl_init_load_crypto_strings crypto/init.c:190
    #10 0x7ffff653847c in ossl_init_load_crypto_strings_ossl_ crypto/init.c:181
    #11 0x7ffff4da24de in __pthread_once_slow /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_once.c:116
    #12 0x7ffff656587e in CRYPTO_THREAD_run_once crypto/threads_pthread.c:154
    #13 0x7ffff6538aca in OPENSSL_init_crypto crypto/init.c:553
    #14 0x555555557e2f in FuzzerInitialize fuzz/asn1parse.c:29
    #15 0x555555557783 in main fuzz/test-corpus.c:194
    #16 0x7ffff4bc3082 in __libc_start_main ../csu/libc-start.c:308
    #17 0x555555557d3d in _start (/home/ed/OPCToolboxV5/Source/Core/OpenSSL/openssl-master/fuzz/asn1parse-test+0x3d3d)

^C
Program received signal SIGINT, Interrupt.
futex_wait (private=0, expected=1, futex_word=0x7ffff756f720 <load_crypto_strings>) at ../sysdeps/nptl/futex-internal.h:141
141     ../sysdeps/nptl/futex-internal.h: No such file or directory.
(gdb) bt
#0  futex_wait (private=0, expected=1, futex_word=0x7ffff756f720 <load_crypto_strings>) at ../sysdeps/nptl/futex-internal.h:141
#1  futex_wait_simple (private=0, expected=1, futex_word=0x7ffff756f720 <load_crypto_strings>) at ../sysdeps/nptl/futex-internal.h:172
#2  __pthread_once_slow (once_control=0x7ffff756f720 <load_crypto_strings>, init_routine=0x7ffff6538470 <ossl_init_load_crypto_strings_ossl_>) at pthread_once.c:105
#3  0x00007ffff4da2595 in __GI___pthread_once (once_control=once_control@entry=0x7ffff756f720 <load_crypto_strings>,
    init_routine=init_routine@entry=0x7ffff6538470 <ossl_init_load_crypto_strings_ossl_>) at pthread_once.c:143
#4  0x00007ffff656587f in CRYPTO_THREAD_run_once (once=once@entry=0x7ffff756f720 <load_crypto_strings>,
    init=init@entry=0x7ffff6538470 <ossl_init_load_crypto_strings_ossl_>) at crypto/threads_pthread.c:154
#5  0x00007ffff6538acb in OPENSSL_init_crypto (opts=opts@entry=2, settings=settings@entry=0x0) at crypto/init.c:539
#6  0x00007ffff640270c in ossl_err_get_state_int () at crypto/err/err.c:707
#7  0x00007ffff6417d3a in ERR_new () at crypto/err/err_blocks.c:20
#8  0x00007ffff653a2cd in CRYPTO_malloc (num=num@entry=24, file=file@entry=0x7ffff69bda40 "crypto/lhash/lhash.c", line=line@entry=114) at crypto/mem.c:205
#9  0x00007ffff652a745 in OPENSSL_LH_insert (lh=0x6070000003a0, data=data@entry=0x7ffff6b266f0 <PROV_str_reasons+1360>) at crypto/lhash/lhash.c:114
#10 0x00007ffff6401b7f in err_load_strings (str=0x7ffff6b266f0 <PROV_str_reasons+1360>) at include/openssl/err.h:374
#11 err_load_strings (str=0x7ffff6b261a0 <PROV_str_reasons>) at crypto/err/err.c:260
#12 ERR_load_strings_const (str=str@entry=0x7ffff6b261a0 <PROV_str_reasons>) at crypto/err/err.c:302
#13 0x00007ffff692100c in ossl_err_load_PROV_strings () at providers/common/provider_err.c:226
#14 0x00007ffff6417b56 in ossl_err_load_crypto_strings () at crypto/err/err_all.c:50
#15 0x00007ffff653847d in ossl_init_load_crypto_strings () at crypto/init.c:190
#16 ossl_init_load_crypto_strings_ossl_ () at crypto/init.c:181
#17 0x00007ffff4da24df in __pthread_once_slow (once_control=0x7ffff756f720 <load_crypto_strings>, init_routine=0x7ffff6538470 <ossl_init_load_crypto_strings_ossl_>)
    at pthread_once.c:116
#18 0x00007ffff4da2595 in __GI___pthread_once (once_control=once_control@entry=0x7ffff756f720 <load_crypto_strings>,
    init_routine=init_routine@entry=0x7ffff6538470 <ossl_init_load_crypto_strings_ossl_>) at pthread_once.c:143
#19 0x00007ffff656587f in CRYPTO_THREAD_run_once (once=once@entry=0x7ffff756f720 <load_crypto_strings>,
    init=init@entry=0x7ffff6538470 <ossl_init_load_crypto_strings_ossl_>) at crypto/threads_pthread.c:154
#20 0x00007ffff6538acb in OPENSSL_init_crypto (opts=opts@entry=2, settings=settings@entry=0x0) at crypto/init.c:539
#21 0x0000555555557e30 in FuzzerInitialize (argc=<optimized out>, argv=<optimized out>) at fuzz/asn1parse.c:29
#22 0x0000555555557784 in main (argc=2, argv=0x7fffffffe238) at fuzz/test-corpus.c:194
(gdb)

Looks like a major regression introduced by 5639ee7
Actually I never understood the idea why that improvement is worth the risk of a possible recursion
in the error code.
@DDvO might want to have a look.

@DDvO

DDvO commented Nov 14, 2022

Copy link
Copy Markdown
Contributor

Actually I never understood the idea why that improvement is worth the risk of a possible recursion
in the error code.
@DDvO might want to have a look.

Currently I do not have time to have a closer look unfortunately,
and on a brief look I do not understand

  • why/how the above two stack traces indicate a deadlock,
  • why this indicates infinite recursion involving malloc and error reporting, and
  • why this may be realistic and not just an artifact of the fuzzing technique?

@bernd-edlinger

Copy link
Copy Markdown
Member Author

I have created a CI test run, that runs on my openssl-111-feature branch here:

bernd-edlinger@ebd831c

This is how the output looks like when no error is found:
https://github.com/bernd-edlinger/openssl/actions/runs/3472678771/jobs/5803812602

And in the 3.0 branch the same error is found that I mentioned above:
https://github.com/bernd-edlinger/openssl/actions/runs/3459678986/jobs/5775334456

I tried also if it can reproduce the deadlock that is currently happening in master,
that was a bit challenging, but finally it works:
https://github.com/bernd-edlinger/openssl/actions/runs/3459262668/jobs/5774475325

I don't know if you are interested in having this for 1.1.1 (well, I already know the answer),
or for 3.0, 3.1 and/or master, although that is not stable enough to get interesting results
from this short CI run?

@t8m

t8m commented Sep 3, 2024

Copy link
Copy Markdown
Member

Closing in favor of #21668

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch triaged: feature The issue/pr requests/adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants