Bug 1076 - X11 applications can sometimes not connect to 127.0.0.1:60xx
Summary: X11 applications can sometimes not connect to 127.0.0.1:60xx
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: -current
Hardware: ix86 Linux
: P2 normal
Assignee: Damien Miller
URL:
Keywords:
Depends on:
Blocks: 1047
  Show dependency treegraph
 
Reported: 2005-08-27 04:31 AEST by Christian Plattner
Modified: 2006-10-07 11:41 AEST (History)
1 user (show)

See Also:


Attachments
Set SO_REUSEADDR for X11 sockets too (1.81 KB, patch)
2005-09-19 21:16 AEST, Damien Miller
no flags Details | Diff
Different patch (351 bytes, patch)
2005-09-20 07:25 AEST, Tomas Mraz
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Plattner 2005-08-27 04:31:09 AEST
With my Java testcode I am able to get the OpenSSH daemon in a state where a
following client connection, e.g., an OpenSSH client, is sometimes not able to
properly use X11 forwarding. 

More technically spoken: when doing X11 forwarding, OpenSSH sometimes attaches
itself to a port (e.g., 6010) when there is still a connection (?) to
127.0.0.1:6010 (in state TIME_WAIT). As a consequence, even though OpenSSH's
bind operation to ::1:6010 goes well, X11 applications are not able to connect
to 127.0.0.1:6010.

The problem is still present in openssh-SNAP-20050826 tested on Fedora Core 2
(2.6.8-1.521smp).

One the one hand, this is probably a problem of the code in the
"x11_create_display_inet" method in channel.c (port selection).

On the other hand, the question is why these kind of TIME_WAIT states as seen in
netstat output only occur occasionally (e.g., local: 127.0.0.1:6010 remote:
127.0.0.1:54806 - and not the other way round!). By killing SSH connections
(closing socket on the client side) which were using X forwarding I was able to
produce such states.
Comment 1 Christian Plattner 2005-08-27 04:32:42 AEST
Here is a part of netstat output if everything is fine (OpenSSH is ready to
forward X11 connections)

Proto Recv-Q Send-Q Local Address               Foreign Address      State
tcp        0      0 127.0.0.1:6010              0.0.0.0:*     LISTEN
tcp        0      0 ::1:6010                    :::*     LISTEN

Here is a part of netstat output when things went wrong (OpenSSH thinks it is
ready to forward X11 connections =)

Proto Recv-Q Send-Q Local Address               Foreign Address      State
tcp        0      0 127.0.0.1:6010              127.0.0.1:54806     TIME_WAIT
tcp        0      0 ::1:6010                    :::*     LISTEN
Comment 2 Damien Miller 2005-09-19 21:16:15 AEST
Created attachment 956 [details]
Set SO_REUSEADDR for X11 sockets too

Please test this patch - it sets SO_REUSEADDR for X11 listeners
Comment 3 Tomas Mraz 2005-09-20 07:25:02 AEST
Created attachment 958 [details]
Different patch

This patch prevents openssh from using ports which are already partially in use
(on IPv4 but not on IPv6) for X11 forwarding.
Comment 4 Christian Plattner 2005-09-22 18:41:10 AEST
I only tested the first patch (the one which sets SO_REUSEADDR on the X11 socket
before binding it) and that resolves the problem. Thanks!

Tested with: openssh-SNAP-20050919.tar.gz on Fedora Core 4 (2.6.12-1.1447_FC4smp).
Comment 5 Damien Miller 2005-10-12 11:22:22 AEST
SO_REUSEADDR patch applied and will be in OpenSSH 4.3.
Comment 6 Darren Tucker 2006-10-07 11:41:49 AEST
Change all RESOLVED bug to CLOSED with the exception of the ones fixed post-4.4.