openssl/ssl
Neil Horman 7d0280a198 Fix SSL_stream_reset for stream objects which have FIN bit set
When calling SSL_stream_reset on a QUIC stream object that has received
all data that is expected to be sent (i.e. when the sender has sent a
STREAM frame with the FIN bit set), we encounter the following segfault:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7f0bd28 in ossl_quic_sstream_get_final_size (qss=0x0, final_size=0x0) at ssl/quic/quic_sstream.c:273
273	    if (!qss->have_final_size)
(gdb) bt
0)  0x00007ffff7f0bd28 in ossl_quic_sstream_get_final_size (qss=0x0, final_size=0x0) at ssl/quic/quic_sstream.c:273
1)  0x00007ffff7ef65bf in quic_validate_for_write (xso=0x5555555efcb0, err=0x7fffffffd5e0) at ssl/quic/quic_impl.c:2513
2)  0x00007ffff7ef8ae3 in ossl_quic_stream_reset (ssl=0x5555555efcb0, args=0x0, args_len=0) at ssl/quic/quic_impl.c:3657
3)  0x00007ffff7ebdaa6 in SSL_stream_reset (s=0x5555555efcb0, args=0x0, args_len=0) at ssl/ssl_lib.c:7635
4)  0x0000555555557527 in build_request_set (
    req_list=0x55555555ebd0 "neil1.txt neil2.txt neil3.txt neil4.txt neil5.txt neil6.txt neil7.txt neil8.txt neil9.txt neil10.txt neil11.txt neil12.txt neil13.txt neil14.txt neil15.txt neil16.txt neil17.txt neil18.txt neil19.txt "..., ssl=0x5555555b6f80)
    at demos/guide/quic-hq-interop.c:545
5)  0x00005555555587b2 in main (argc=4, argv=0x7fffffffe568) at demos/guide/quic-hq-interop.c:941

This occurs because:
1) When the stream FIN bit is set, the quic stack frees the underlying
   stream structures immediately within the QUIC stack
and
2) when SSL_stream_reset is called, the call stack indicates we call
   quic_validate_for_write, which attempts to access the
   xso->stream->sstream QUIC_SSTREAM object, which was already freed in
   (1)

The fix I think is pretty straightforward.  On receipt of a STREAM frame
with a FIN bit set, the QUIC stack sets the QUIC_STREAM object state to
QUIC_SSTREAM_STATE_DATA_RECVD, which means we can use that state to
simply assert that the stream is valid for write, which allows it to be
reset properly.

Fixes #25410

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25910)

(cherry picked from commit bbfffbcaf3)
2024-11-13 11:05:31 -05:00
..
quic Fix SSL_stream_reset for stream objects which have FIN bit set 2024-11-13 11:05:31 -05:00
record tls_common.c: Align the calculation of maximal alignment value 2024-10-24 15:26:13 +02:00
rio QUIC POLLING: Support no-quic builds 2024-02-10 11:37:14 +00:00
statem Use correct alerts for some cert comp errors 2024-11-04 11:51:01 +01:00
bio_ssl.c bio_ssl.c: Do not call SSL_shutdown if not inited 2024-06-25 16:06:17 +02:00
build.info Remove the event queue code 2024-08-07 19:48:26 +02:00
d1_lib.c Copyright year updates 2024-09-05 09:35:49 +02:00
d1_msg.c Copyright year updates 2023-09-07 09:59:15 +01:00
d1_srtp.c Copyright year updates 2024-04-09 13:43:26 +02:00
methods.c Update some inclusions of <openssl/macros.h> 2019-11-07 11:37:25 +01:00
pqueue.c Stop raising ERR_R_MALLOC_FAILURE in most places 2022-10-05 14:02:03 +02:00
priority_queue.c Copyright year updates 2024-09-05 09:35:49 +02:00
s3_enc.c EVP_MD_size() updates 2024-08-29 10:29:53 +02:00
s3_lib.c 3DES ciphersuites are not allowed in FIPS anymore 2024-08-01 17:29:32 +02:00
s3_msg.c Resolve a TODO in ssl3_dispatch_alert 2022-11-14 10:14:41 +01:00
ssl_asn1.c RFC7250 (RPK) support 2023-03-28 13:49:54 -04:00
ssl_cert.c Copyright year updates 2024-09-05 09:35:49 +02:00
ssl_cert_comp.c Copyright year updates 2024-09-05 09:35:49 +02:00
ssl_cert_table.h Make ssl_cert_info read-only 2023-11-27 07:51:33 +00:00
ssl_ciph.c EVP_MD_size() updates 2024-08-29 10:29:53 +02:00
ssl_conf.c Fix memleaks in cmd_RecordPadding() 2024-11-13 12:00:45 +01:00
ssl_err.c Check that a supported_versions extension is present in an HRR 2024-08-07 19:34:23 +02:00
ssl_err_legacy.c Update copyright year 2021-06-17 13:24:59 +01:00
ssl_init.c Copyright year updates 2024-09-05 09:35:49 +02:00
ssl_lib.c Don't complain with "no cipher match" for QUIC objects 2024-11-08 14:36:32 +01:00
ssl_local.h adds TLS signature algorithms list feature 2024-08-13 11:48:54 +10:00
ssl_mcnf.c Copyright year updates 2024-09-05 09:35:49 +02:00
ssl_rsa.c Copyright year updates 2023-09-07 09:59:15 +01:00
ssl_rsa_legacy.c Deprecate RSA harder 2020-11-18 23:38:34 +01:00
ssl_sess.c Incorporate review feedback 2024-06-21 07:57:56 -04:00
ssl_stat.c Copyright year updates 2024-09-05 09:35:49 +02:00
ssl_txt.c Copyright year updates 2024-09-05 09:35:49 +02:00
ssl_utst.c Remove the old buffer management code 2022-10-20 14:39:33 +01:00
sslerr.h QUIC APL: Implement optimised FIN API 2024-01-23 14:20:06 +00:00
t1_enc.c Copyright year updates 2024-04-09 13:43:26 +02:00
t1_lib.c adds TLS signature algorithms list feature 2024-08-13 11:48:54 +10:00
t1_trce.c Copyright year updates 2024-09-05 09:35:49 +02:00
tls13_enc.c Copyright year updates 2024-09-05 09:35:49 +02:00
tls_depr.c SSL object refactoring using SSL_CONNECTION object 2022-07-28 10:04:28 +01:00
tls_srp.c Stop raising ERR_R_MALLOC_FAILURE in most places 2022-10-05 14:02:03 +02:00