comparison src/event/quic/ngx_event_quic.c @ 9112:d59277dd3d8c

QUIC: fixed post-close use-after-free. Previously, ngx_quic_close_connection() could be called in a way that QUIC connection was accessed after the call. In most cases the connection is not closed right away, but close timeout is scheduled. However, it's not always the case. Also, if the close process started earlier for a different reason, calling ngx_quic_close_connection() may actually close the connection. The connection object should not be accessed after that. Now, when possible, return statement is added to eliminate post-close connection object access. In other places ngx_quic_close_connection() is substituted with posting close event. Also, the new way of closing connection in ngx_quic_stream_cleanup_handler() fixes another problem in this function. Previously it passed stream connection instead of QUIC connection to ngx_quic_close_connection(). This could result in incomplete connection shutdown. One consequence of that could be that QUIC streams were freed without shutting down their application contexts. This could result in another use-after-free. Found by Coverity (CID 1530402).
author Roman Arutyunyan <arut@nginx.com>
date Mon, 22 May 2023 15:59:42 +0400
parents 9553eea74f2a
children bba136612fe4
comparison
equal deleted inserted replaced
9111:68fa4b86ed46 9112:d59277dd3d8c
842 if (ngx_quic_handle_stateless_reset(c, pkt) == NGX_OK) { 842 if (ngx_quic_handle_stateless_reset(c, pkt) == NGX_OK) {
843 ngx_log_error(NGX_LOG_INFO, c->log, 0, 843 ngx_log_error(NGX_LOG_INFO, c->log, 0,
844 "quic stateless reset packet detected"); 844 "quic stateless reset packet detected");
845 845
846 qc->draining = 1; 846 qc->draining = 1;
847 ngx_quic_close_connection(c, NGX_OK); 847 ngx_post_event(&qc->close, &ngx_posted_events);
848 848
849 return NGX_OK; 849 return NGX_OK;
850 } 850 }
851 } 851 }
852 852
1388 return NGX_ERROR; 1388 return NGX_ERROR;
1389 } 1389 }
1390 1390
1391 if (do_close) { 1391 if (do_close) {
1392 qc->draining = 1; 1392 qc->draining = 1;
1393 ngx_quic_close_connection(c, NGX_OK); 1393 ngx_post_event(&qc->close, &ngx_posted_events);
1394 } 1394 }
1395 1395
1396 if (pkt->path != qc->path && nonprobing) { 1396 if (pkt->path != qc->path && nonprobing) {
1397 1397
1398 /* 1398 /*