[tor-bugs] #15961 [- Select a component]: tor fails to handle half-closed TCP connections: it should forward data back on sockets that were shutdown(SHUT_WR) by client

Tor Bug Tracker & Wiki blackhole at torproject.org
Fri May 8 10:06:46 UTC 2015


#15961: tor fails to handle half-closed TCP connections: it should forward data
back on sockets that were shutdown(SHUT_WR) by client
----------------------------------+---------------------
 Reporter:  yurivict271           |          Owner:
     Type:  defect                |         Status:  new
 Priority:  normal                |      Milestone:
Component:  - Select a component  |        Version:
 Keywords:                        |  Actual Points:
Parent ID:                        |         Points:
----------------------------------+---------------------
 I hit this situation when TCP client sent some data into the socket, then
 called "shutdown(fd, SHUT_WR)". Tor immediately initiates EOF in return.

 However, "shutdown(fd, SHUT_WR)" only shuts down (sends EOF) in one
 direction. Another direction remains open, and tor should still send EOF
 into the circuit, receive response from TCP server, and forward it to the
 client through this half-closed connection, until the TCP server initiates
 EOF.

 The easiest way to reproduce this is to run this script through torsocks:
 {{{
 #!/bin/sh

 echo "GET / HTTP/1.0
 Connection: close

 " | nc -N www.torproject.org 80
 }}}

 It returns no output. Remove "-N" and it will return an output. Run it
 without torsocks, and it will return output with and without "-N".

 "-N" flag causes nc to call shutdown(SHUT_WR) once stdin had EOF.

 So this script with -N option demonstrates how tor fails to handle half-
 closed TCP connections.
 (older versions of nc had no -N flag, and always called shutdown(SHUT_WR))

 The correct behavior here is to keep writing response into such socket
 until 'write' returns some error condition.

 To be fair, squid/DeleGate/nginx proxies all suffer from the same problem.
 But I believe, TOR should be better than them, and do things the right
 way.

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/15961>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list