Artifacts Associated With Ticket d6c1d2f78e
Ticket change [15e9fe54dd] (rid 258527) by serhiy.storchaka on 2026-10-17 10:51:11:
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
Socket channel names are <tt>sock</tt> followed by the address of the socket's <tt>TcpState</tt> structure in hex, so every socket handle reveals a heap address. A safe interpreter that is given a socket (<nowiki>[interp transfer]</nowiki>, <nowiki>[interp share]</nowiki>, or an alias returning the name) learns it from the handle alone, which helps defeat ASLR if some other memory bug is reachable from scripts. Safe interpreters otherwise have no way to see addresses (<nowiki>[tcl::unsupported::representation]</nowiki> is hidden there). <verbatim> set srv [socket -server {apply {{c a p} {close $c}}} -myaddr 127.0.0.1 0] set c [socket 127.0.0.1 [lindex [chan configure $srv -sockname] 2]] set s [interp create -safe] interp transfer {} $c $s puts [interp eval $s {chan names}] </verbatim> Actual (9.1, 9.0, 8.6.18 on Linux): <tt>sock5644b332a410</tt>. Expected: a name that does not depend on memory layout, e.g. <tt>sock</tt> plus a counter, as reflected channels already do (<tt>rc%lu</tt> in generic/tclIORChan.c). Where the names are formed: * Unix: <tt>SOCK_TEMPLATE</tt> in unix/tclUnixSock.c, used with <tt>PTR2INT(statePtr)</tt> at all four <tt>Tcl_CreateChannel</tt> calls. Since [8eefe5a06f] (2011, the IPv6 socket merge, first in 8.6.0); up to 8.5 the name was <tt>sock</tt> + fd. The fd could not be kept because a listening socket may have several fds. * Windows: <tt>SOCK_TEMPLATE "sock%p"</tt> in win/tclWinSock.c since [fdd8917252] (2014, first in 8.6.2). In addition <tt>TclWinGenerateChannelName</tt> (win/tclWinChan.c) names file, pipe, serial and console channels <tt>file</tt> + pointer to their info structure; that has been so at least since 8.4 (<tt>"file%lx"</tt>). Not tested on Windows, read from the sources. * Unix file, pipe and serial channels use the fd (<tt>file%d</tt>, <tt>serial%d</tt>), zipfs channels an archive offset and a counter, reflected channels a counter; stacked channels (zlib, transforms) keep the name of the base channel. Those do not leak addresses. Because the address is reused once the structure is freed, the same name also comes back quickly after a close (three connect/close cycles above gave <tt>sock...a490 sock...a510 sock...a490</tt>), the same reuse problem as with fd-based names ([2826430fff]). A per-process counter, as for reflected channels, would fix both. This is a narrower part of [1577730fff] (channel names given to a safe interpreter show the channel type); unlike that ticket it needs no new API. - foundin initialized to: "8.6.18, 9.0.5, 9.1.0"
- login: "serhiy.storchaka"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- subsystem initialized to: "27. Channel Types"
- title initialized to:
Socket channel names contain a heap address (visible to safe interps)
- type initialized to: "Bug"
Ticket change [f712c13fa9] (rid 258591) by serhiy.storchaka on 2026-10-17 12:39:35:
- icomment:
Proposed fix in branch [/timeline?r=channel-names-no-address|channel-names-no-address]: the number in socket names on Unix, and in all channel names on Windows (<tt>TclWinGenerateChannelName()</tt>), is now a per-process counter instead of an address. Names are no longer reused after a close either. Test socket-bug-d6c1d2f78e, passes on Linux and Windows.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [ebad0e5da1] (rid 259533) by serhiy.storchaka on 2026-10-20 18:11:29:
- submitter changed to: "serhiy.storchaka"