Cached TLS sessions being invalidated by `isc_tls_free()`
The call to isc_tls_free()
would invalidate a cached TLS session as seen in this ThreadSanitizer report:
WARNING: ThreadSanitizer: data race
Write of size 8 at 0x000000000001 by main thread:
#0 free <null> (BuildId: 4037c6a3ca411fc7713f28ef5e1cb780845c5d8e)
#1 sdallocx lib/isc/jemalloc_shim.h:82 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#2 mem_put lib/isc/mem.c:326
#3 isc__mem_free lib/isc/mem.c:844
#4 isc__tls_free_ex lib/isc/tls.c:92 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#5 CRYPTO_free crypto/mem.c:278 (BuildId: e62d0a8748810c4705471e1b7ba50fecee236014)
#6 CRYPTO_clear_free crypto/mem.c:291 (BuildId: e62d0a8748810c4705471e1b7ba50fecee236014)
#7 SSL_SESSION_free ssl/ssl_sess.c:864 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#8 SSL_SESSION_free ssl/ssl_sess.c:833
#9 tls_process_new_session_ticket ssl/statem/statem_clnt.c:2746 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#10 ossl_statem_client_process_message ssl/statem/statem_clnt.c:1122 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#11 read_state_machine ssl/statem/statem.c:684 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#12 state_machine ssl/statem/statem.c:478
#13 ossl_statem_connect ssl/statem/statem.c:297 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#14 ssl3_read_bytes ssl/record/rec_layer_s3.c:1022 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#15 ssl3_read_internal ssl/s3_lib.c:4528 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#16 ssl3_read_internal ssl/s3_lib.c:4518 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#17 ssl3_read ssl/s3_lib.c:4551
#18 ssl_read_internal ssl/ssl_lib.c:2314 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#19 SSL_read_ex ssl/ssl_lib.c:2342 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#20 tls_do_bio netmgr/tlsstream.c:675 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#21 tls_readcb netmgr/tlsstream.c:845 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#22 isc___nm_readcb netmgr/netmgr.c:1859 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#23 isc__nm_readcb netmgr/netmgr.c:1874
#24 isc__nm_tcp_read_cb netmgr/tcp.c:778 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#25 uv__read src/unix/stream.c:1143 (BuildId: 88ab6adf9c4eae7aa6a059d6bcc98a1b9881dbd7)
#26 uv__stream_io src/unix/stream.c:1203 (BuildId: 88ab6adf9c4eae7aa6a059d6bcc98a1b9881dbd7)
#27 uv__io_poll src/unix/linux.c:1528 (BuildId: 88ab6adf9c4eae7aa6a059d6bcc98a1b9881dbd7)
#28 uv_run src/unix/core.c:448 (BuildId: 88ab6adf9c4eae7aa6a059d6bcc98a1b9881dbd7)
#29 loop_thread lib/isc/loop.c:288 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#30 thread_body lib/isc/thread.c:85 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#31 isc_thread_main lib/isc/thread.c:116
#32 isc_loopmgr_run lib/isc/loop.c:462 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#33 run_test_doh_recv_send_POST_TLS tests/isc/doh_test.c:1078 (BuildId: 00621a09540ede57c27fd23ba32ec3b3f237a059)
#34 cmocka_run_one_test_or_fixture <null> (BuildId: 15c7b0dcfb7fbd67bc47738f5832ffb6ad4154db)
#35 __libc_start_call_main <null> (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
Previous atomic write of size 4 at 0x000000000001 by thread T0001:
#0 CRYPTO_DOWN_REF include/internal/refcount.h:51 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#1 SSL_SESSION_free ssl/ssl_sess.c:839
#2 ossl_ssl_connection_free ssl/ssl_lib.c:1424 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#3 SSL_free ssl/ssl_lib.c:1387 (BuildId: dd487bdbf729307dab6635ba8c51e1691a3ec18a)
#4 SSL_free ssl/ssl_lib.c:1372
#5 isc_tls_free lib/isc/tls.c:764 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#6 isc__nm_tls_cleanup_data netmgr/tlsstream.c:1345 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#7 nmsocket_cleanup netmgr/netmgr.c:479 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#8 nmsocket_maybe_destroy netmgr/netmgr.c:567 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#9 isc___nmsocket_prep_destroy netmgr/netmgr.c:629 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#10 isc___nmsocket_detach netmgr/netmgr.c:656 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#11 isc__nm_tls_cleanup_data netmgr/tlsstream.c:1375 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#12 nmsocket_cleanup netmgr/netmgr.c:479 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#13 nmsocket_maybe_destroy netmgr/netmgr.c:567 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#14 isc___nmsocket_prep_destroy netmgr/netmgr.c:629 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#15 tcp_close_sock netmgr/tcp.c:1213 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#16 tcp_close_cb netmgr/tcp.c:1221
#17 uv__finish_close src/unix/core.c:351 (BuildId: 88ab6adf9c4eae7aa6a059d6bcc98a1b9881dbd7)
#18 uv__run_closing_handles src/unix/core.c:365
#19 uv_run src/unix/core.c:463
#20 loop_thread lib/isc/loop.c:288 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#21 thread_body lib/isc/thread.c:85 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#22 thread_run lib/isc/thread.c:100
Thread T0001 'isc-loop-0001' (running) created by main thread at:
#0 pthread_create <null> (BuildId: 4037c6a3ca411fc7713f28ef5e1cb780845c5d8e)
#1 isc_thread_create lib/isc/thread.c:139 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#2 isc_loopmgr_run lib/isc/loop.c:456 (BuildId: 25276ce062221d31957ca1b423b4bf4a294484a1)
#3 run_test_doh_recv_send_POST_TLS tests/isc/doh_test.c:1078 (BuildId: 00621a09540ede57c27fd23ba32ec3b3f237a059)
#4 cmocka_run_one_test_or_fixture <null> (BuildId: 15c7b0dcfb7fbd67bc47738f5832ffb6ad4154db)
#5 __libc_start_call_main <null> (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
SUMMARY: ThreadSanitizer: data race (BuildId: 4037c6a3ca411fc7713f28ef5e1cb780845c5d8e) in free