openssl/crypto/x509
Bernd Edlinger 557825acd6 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 <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18360)
2022-05-23 06:20:48 +02:00
..
build.info
by_dir.c Update copyright year 2022-05-03 13:34:51 +01:00
by_file.c
by_store.c
ext_dat.h
pcy_cache.c fix some code with obvious wrong coding style 2021-10-28 13:10:46 +10:00
pcy_data.c
pcy_lib.c
pcy_local.h
pcy_map.c
pcy_node.c fix some code with obvious wrong coding style 2021-10-28 13:10:46 +10:00
pcy_tree.c
standard_exts.h
t_crl.c
t_req.c
t_x509.c Update copyright year 2022-05-03 13:34:51 +01:00
v3_addr.c
v3_admis.c fix some code with obvious wrong coding style 2021-10-28 13:10:46 +10:00
v3_admis.h
v3_akeya.c
v3_akid.c Update copyright year 2022-05-03 13:34:51 +01:00
v3_asid.c
v3_bcons.c
v3_bitst.c
v3_conf.c Add and use HAS_PREFIX() and CHECK_AND_SKIP_PREFIX() for checking if string has literal prefix 2021-11-17 15:48:34 +01:00
v3_cpols.c Add and use HAS_PREFIX() and CHECK_AND_SKIP_PREFIX() for checking if string has literal prefix 2021-11-17 15:48:34 +01:00
v3_crld.c Update copyright year 2022-05-03 13:34:51 +01:00
v3_enum.c
v3_extku.c
v3_genn.c
v3_ia5.c
v3_info.c
v3_int.c
v3_ist.c Update copyright year 2022-05-03 13:34:51 +01:00
v3_lib.c
v3_ncons.c Add and use HAS_PREFIX() and CHECK_AND_SKIP_PREFIX() for checking if string has literal prefix 2021-11-17 15:48:34 +01:00
v3_pci.c Add and use HAS_PREFIX() and CHECK_AND_SKIP_PREFIX() for checking if string has literal prefix 2021-11-17 15:48:34 +01:00
v3_pcia.c fix some code with obvious wrong coding style 2021-10-28 13:10:46 +10:00
v3_pcons.c
v3_pku.c
v3_pmaps.c
v3_prn.c
v3_purp.c
v3_san.c X509V3_set_ctx(): Clarify subject/req parameter for constructing SAN email addresses from subject DN 2021-12-07 15:14:49 +01:00
v3_skid.c X509V3_set_ctx(): Clarify use of subject/req parameter for constructing SKID by hash of pubkey 2021-12-07 15:13:26 +01:00
v3_sxnet.c Update copyright year 2022-05-03 13:34:51 +01:00
v3_tlsf.c Update copyright year 2022-05-03 13:34:51 +01:00
v3_utf8.c Update copyright year 2022-05-03 13:34:51 +01:00
v3_utl.c Update copyright year 2022-05-03 13:34:51 +01:00
v3err.c Update copyright year 2022-05-03 13:34:51 +01:00
x509_att.c
x509_cmp.c Fix: invoking X509_self_signed improperly 2021-11-09 08:50:40 +01:00
x509_d2.c
x509_def.c
x509_err.c
x509_ext.c
x509_local.h
x509_lu.c X509{,_LOOKUP}: Improve distinction between not found and fatal/internal error 2022-05-04 16:25:44 +02:00
x509_meth.c
x509_obj.c
x509_r2x.c
x509_req.c
x509_set.c
x509_trust.c X509{,_LOOKUP}: Improve distinction between not found and fatal/internal error 2022-05-04 16:25:44 +02:00
x509_txt.c
x509_v3.c
x509_vfy.c X509{,_LOOKUP}: Improve distinction between not found and fatal/internal error 2022-05-04 16:25:44 +02:00
x509_vpm.c
x509cset.c
x509name.c
x509rset.c
x509spki.c
x509type.c
x_all.c
x_attrib.c
x_crl.c Fix a crash in asn1_item_embed_new 2022-05-23 06:20:48 +02:00
x_exten.c
x_name.c Fix: invoking x509_name_cannon improperly 2021-11-09 10:05:09 +10:00
x_pubkey.c Update copyright year 2022-05-03 13:34:51 +01:00
x_req.c
x_x509.c
x_x509a.c