Artifacts Associated With Ticket 40b1814b93e50b4a
Ticket change [354da95bc2] (rid 241367) by apnadkarni on 2025-06-13 17:43:50:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
The offending tsdPtr access is [here](https://core.tcl-lang.org/tcl/file?ci=950d15a307bcbf94&name=win/tclWinSock.c&ln=3055) 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.
- foundin initialized to: "trunk"
- is_private initialized to: "0"
- login: "apnadkarni"
- priority initialized to: "5 Medium"
- private_contact initialized to: "9546e9877f1a8899e25a89082561ee694e7fb402"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "apnadkarni"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to:
App verifier shows user-after-free on ThreadSpecificData for Windows sockets
- type initialized to: "Bug"
Ticket change [b4f9ae787c] (rid 241374) by apnadkarni on 2025-06-14 03:32:00:
- icomment:
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 ```
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [867ce3ac5d] (rid 241379) by apnadkarni on 2025-06-14 05:37:49:
- icomment:
Also, use-after-free of socket handle [here](https://core.tcl-lang.org/tcl/file?ci=d2bd980da407586f&name=win/tclWinSock.c&ln=2308) 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](https://core.tcl-lang.org/tcl/info/bbb565eca787dfad). 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.
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [83459a1b23] (rid 241975) by apnadkarni on 2025-06-25 15:49:01:
- closedate changed to: "2460852.15904826"
- closer changed to: "apnadkarni"
- icomment: "Fixed in [a36f76eb6b]."
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"