SIGSEGV in BIO_new_ex via ossl_read_der / der2key_decode: invalid provctx pointer pointing to "SubjectPublicKeyInfo"
OpenSSL Version
OpenSSL 3.6.4 (package openssl 3.6.4-1 on Arch Linux / x86_64)
Operating System / Architecture
Linux (x86_64)
Description
A segmentation fault occurs in BIO_new_ex() during X.509 certificate decoding via the OSSL_DECODER pipeline (OSSL_DECODER_from_data -> spki2typespki_decode -> der2key_decode).
Inspection of the core dump reveals that inside der2key_decode() (decode_der2key.c), the ctx->provctx pointer held an address pointing to the literal string "SubjectPublicKeyInfo" instead of a valid PROV_CTX structure.
When der2key_decode() invokes ossl_read_der(ctx->provctx, cin, &der, &der_len) -> ossl_bio_new_from_core_bio():
/* providers/common/bio_prov.c:234 */
if ((outbio = BIO_new(corebiometh)) == NULL)In assembly (providers/common/bio_prov.c):
0x00007fc592e655f5 <+21>: mov 0x10(%rdi), %rbx # %rdi is provctx, 0x10(%rdi) is corebiomethBecause %rdi was pointing to the ASCII string "SubjectPublicKeyInfo\0", offset +0x10 read the last four bytes of the string ("Info"), resulting in corebiometh = 0x7f006f666e49.
Subsequently, BIO_new_ex() attempted to dereference method->create at offset +0x48:
0x00007fc592c806b9 <+105>: mov 0x48(%r12), %rax # %r12 = 0x7f006f666e49This crashed immediately with SIGSEGV (invalid memory address).
Stack Trace
#0 0x00007fc593a9a17c in ?? () from /usr/lib/libc.so.6
#1 0x00007fc593a3e5d0 in raise () from /usr/lib/libc.so.6
#2 <signal handler called>
#3 0x00007fc592c806b9 in BIO_new_ex (libctx=<optimized out>, method=0x7f006f666e49) at crypto/bio/bio_lib.c:98
#4 0x00007fc592e6560e in ossl_bio_new_from_core_bio (provctx=<optimized out>, corebio=0x7fc53eb00210) at providers/common/bio_prov.c:234
#5 0x00007fc592ea375b in ossl_read_der (provctx=<optimized out>, cin=<optimized out>, data=0x7fc567ffc558, len=0x7fc567ffc548) at providers/implementations/encode_decode/endecoder_common.c:90
#6 0x00007fc592e87f1e in der2key_decode (vctx=0x7fc53eb12a80, cin=<optimized out>, selection=134, data_cb=0x7fc592d39670 <decoder_process>, data_cbarg=0x7fc567ffc6d0, pw_cb=<optimized out>, pw_cbarg=0x7fc53eac7c58) at providers/implementations/encode_decode/decode_der2key.c:304
#7 0x00007fc592d399a5 in decoder_process (params=<optimized out>, arg=0x7fc567ffca20) at crypto/encode_decode/decoder_lib.c:1125
#8 0x00007fc592e8b070 in ossl_spki2typespki_der_decode (der=0x7fc53ea6b000 "...", len=550, data_cb=0x7fc592d39670 <decoder_process>, data_cbarg=0x7fc567ffca20, ...) at providers/implementations/encode_decode/decode_spki2typespki.c:193
#9 0x00007fc592e8b766 in spki2typespki_decode (vctx=<optimized out>, cin=<optimized out>, selection=<optimized out>, data_cb=0x7fc592d39670 <decoder_process>, data_cbarg=0x7fc567ffca20, ...) at providers/implementations/encode_decode/decode_spki2typespki.c:133
#10 0x00007fc592d399a5 in decoder_process (params=0x0, arg=0x7fc567ffcab0) at crypto/encode_decode/decoder_lib.c:1125
#11 0x00007fc592d39e24 in OSSL_DECODER_from_bio (ctx=0x7fc53eac7c20, in=0x7fc53eb0f180) at crypto/encode_decode/decoder_lib.c:82
#12 0x00007fc592d3a19b in OSSL_DECODER_from_data (ctx=0x7fc53eac7c20, pdata=0x7fc567ffcb88, pdata_len=0x7fc567ffcb80) at crypto/encode_decode/decoder_lib.c:159
#13 0x00007fc592c6d3be in ASN1_item_d2i_ex (pval=0x7fc567ffd098, in=<optimized out>, len=<optimized out>, it=..., libctx=<optimized out>, propq=<optimized out>) at crypto/asn1/tasn_dec.c:169Additional GDB Dump Details
At frame 8:
(gdb) print *(struct der2key_ctx_st*)vctx
$1 = {provctx = 0x7fc58f8d4100, propq = '\000' <repeats 255 times>, desc = 0x7fc5931a1e60 <SubjectPublicKeyInfo_rsa_desc>, selection = 134, flag_fatal = 0}
(gdb) x/s 0x7fc58f8d4100
0x7fc58f8d4100: "SubjectPublicKeyInfo"Source: openssl/openssl