|
2026-10-23
| ||
| 07:07 | • New ticket [72d1c8c271] Windows 8.6: under ephemeral port exhaustion, sockets ge... artifact: c1d7527219 user: serhiy.storchaka | |
|
2025-06-25
| ||
| 16:41 | Merge 9.0 - Fix [40b1814b93] and [7c2716733a] Window handle use-after-frees. check-in: 54eb90319d user: apnadkarni tags: trunk, main | |
| 15:49 | • Closed ticket [40b1814b93]: App verifier shows user-after-free on ThreadSpecific... artifact: 83459a1b23 user: apnadkarni | |
| 15:48 | Fix [40b1814b93] - use after free on TSD in Winsock check-in: a36f76eb6b user: apnadkarni tags: core-9-0-branch | |
|
2025-06-14
| ||
| 05:37 | • Ticket [40b1814b93] App verifier shows user-after-free on ThreadSpecificData for... artifact: 867ce3ac5d user: apnadkarni | |
| 05:31 | Bug [40b1814b93] - Proposed fix for Winsock use-after-frees check-in: bbb565eca7 user: apnadkarni tags: bug-40b1814b93 | |
| 03:32 | • Ticket [40b1814b93] App verifier shows user-after-free on ThreadSpecificData for... artifact: b4f9ae787c user: apnadkarni | |
|
2025-06-13
| ||
| 17:43 | • New ticket [40b1814b93]. artifact: 354da95bc2 user: apnadkarni | |
App verifier shows user-after-free on ThreadSpecificData for Windows sockets
The offending tsdPtr access is here and happens on exit.
Preliminary thoughts:
Why does this show up only under AppVerifier? Because it scrubs memory and protects freed blocks (above requires compile with -DPURIFY so Tcl_Alloc translates directly to malloc). Under normal operation, the freed tsdPtr page remains accessible though the memory block has been freed. The tsdPtr->readyEvent actually is garbage data and so the SetEvent call which checks for valid handles returns an error which Tcl ignores.
Note the tsdPtr referenced above is thread specific data in a different thread which is really asking for trouble but it appears to have been that way forever, likely even before 8.6.
c1d7527219New ticket [72d1c8c271] Windows 8.6: under ephemeral port exhaustion, sockets get disabled for the whole process and Tcl sometimes crashes. ticket2026-10-23 07:07:2554eb90319dMerge 9.0 - Fix [40b1814b93] and [7c2716733a] Window handle use-after-frees. check-in2025-06-25 16:41:27a36f76eb6bFix [40b1814b93] - use after free on TSD in Winsock check-in2025-06-25 15:48:13bbb565eca7Bug [40b1814b93] - Proposed fix for Winsock use-after-frees check-in2025-06-14 05:31:49
Notes for reproduction:
Build as
nmake /f makefile.vc /nologo INSTALLDIR=C:\Tcl\wip\%VSCMD_ARG_TGT_ARCH%-debug OPTS=pdbs cdebug="-Zi -Od -DPURIFY" tcltest
Add tcltest90.exe to AppVerifier. Run tcltest90 within a VS debugger (that's where AppVerifier messages will show up).
close [socket www.example.com 443]
exit <- where the use after free is triggered
Also, use-after-free of socket handle here on socket_inet-2.9.
The tsdPtr bug appears to be caused by use of the same event handle to communicate socket notifications and worker thread completion to the main thread. The main thread waits for completion of worker to ensure its TSD is still available but mistakenly confuses a pending socket notification for thread completion as they use the same event and frees the TSD immediately while the worker thread is still active.
Proposed fix for both is in commit bug-40b1814b93. The tsdPtr bug is fixed by waiting on the worker thread handle rather than the notification event handle. The socket handle bug is a simple failure to mark socket closed in a loop error and then attempting to close it again.
Fixed in [a36f76eb6b].