Forwarded ports not closed to remote ssh2 server in FIN_WAIT_2

Bug #582740 reported by Jka
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
openssh (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

This appears to have been introduced with Lucid 10.04, this problem doesn't appear on 9.04 and 9.10. I'm not sure if this is an openSSL bug or an openssh problem so I'll target the first point of contact, ssh.

I'll try and answer any questions but I'll have to respect the security of the information provided.

I use ssh port forwarding to hop to a remote server which happens to be a ssh2 server. With Lucid 10.04 ssh any completed forwarded sessions (session 2) are left in a FIN_WAIT_2 state on the passthru server and hang when the initiating session closes only method is to Control-C session 1.

I've decided to alert this as a security vulnerability because the initiating session, on close, still appears to wait for the forwarded ports to close and so will still allow connections to the local port to be made. Control-C on Session one terminates the forwarding.

The test: Two Local sessions (10.04 lucid), one passthru ssh server and a target ssh2 server.
  Session 1: login to passthru server - setup local port forward to remote target ssh2.
  Session 2: login to target ssh2 server via local port
  Session 2: Issue 'exit' command and session 2 returns to local system prompt, as expected.
  Session 1: Issue 'netstat | grep ssh' on passthru server, shows forwarded connection to remote ssh2 server in FIN_WAIT_2
  Session 1: Issue 'exit' command and the session hangs, doesn't return to local system prompt. not expected.
  Session 2: Login in to target ssh2 server via local port, accepted. security risk, local forward port still active.
  Session 2: Issue 'exit' and session 2 again returns to local system prompt, as expected.
  Session 1: Control-C hung session. ssh vvv debugging shows ports left open and closes.

 When the above test is repeated using 9.10,or 9.04 both session close down as expected.

 Examination of netstat on passthru server still shows FIN_WAIT_2 connections to remote ssh2 target server still active and using up resources.

Lucid 10.04 local sessions, debugging -vvv on session 1 output (I've attached replaced addresses full output of session 1), show the closing of session 2 as:

debug2: channel 3: read<=0 rfd 10 len 0
debug2: channel 3: read failed
debug2: channel 3: close_read
debug2: channel 3: input open -> drain
debug3: Wrote 144 bytes for a total of 5687
debug2: channel 3: ibuf empty
debug2: channel 3: send eof
debug2: channel 3: input drain -> closed
debug3: Wrote 32 bytes for a total of 5719

UNLIKE 9.10 local sessions, debugging -vvv on session 1 output, shows the closing of session 2 as:

debug2: channel 2: read<=0 rfd 8 len 0
debug2: channel 2: read failed
debug2: channel 2: close_read
debug2: channel 2: input open -> drain
debug2: channel 2: ibuf empty
debug2: channel 2: send eof
debug2: channel 2: input drain -> closed
debug2: channel 2: rcvd eof
debug2: channel 2: output open -> drain
debug2: channel 2: obuf empty
debug2: channel 2: close_write
debug2: channel 2: output drain -> closed
debug2: channel 2: rcvd close
debug3: channel 2: will not send data after close
debug2: channel 2: send close
debug2: channel 2: is dead
debug2: channel 2: garbage collecting
debug1: channel 2: free: direct-tcpip: listening port 5341 for iii.iii.iii.iii port 22, connect from 127.0.0.1 port 58799, nchannels 3
debug3: channel 2: status: The following connections are open:
  #1 client-session (t4 r0 i0/0 o0/0 fd 5/6 cfd -1)
  #2 direct-tcpip: listening port 5341 for iii.iii.iii.iii port 22, connect from 127.0.0.1 port 58799 (t4 r1 i3/0 o3/0 fd 8/8 cfd -1)

debug3: channel 2: close_fds r 8 w 8 e -1 c -1

Any ideas why these sessions are now being left open in Lucid ?

Tags: openssl
Revision history for this message
Jka (jka-pub) wrote :
Revision history for this message
Jka (jka-pub) wrote :

added session 2 vvv output, to show session that uses the forward port finishing and closing.

Revision history for this message
Jka (jka-pub) wrote :

Update:
If I use the ssh binary from package openssh-client_5.1p1-6ubuntu2_amd64.deb 9.10 (Karmic) on my 10.04 system as the Session 2 caller to the remote ssh2 server, then session 1 shows the ports closing down correctly confirming the channel is dead, like they would on a native 9.10 system.

security vulnerability: yes → no
visibility: private → public
Revision history for this message
Jka (jka-pub) wrote :

Problem still present in todays proposed release

ii openssh-client 1:5.3p1-3ubuntu4 secure shell (SSH) client, for secure access
ii openssh-server 1:5.3p1-3ubuntu4 secure shell (SSH) server, for secure access

Current workaround is to use 'ssh' binary from openssh-client_5.1p1-6ubuntu2_amd64.deb

Revision history for this message
Jka (jka-pub) wrote :

Bug doesn't occur in 5.5p1 current Openssh daily snapshot, it's specific to 5.3

Revision history for this message
Scott Moser (smoser) wrote :

are you able to test if this issue is present in maverick , which has 1:5.5p1-4ubuntu1 ?

Additionally, in the interim, you can quite likely use Collin's ppa for lucid: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/blosxom/ubuntu/2010-05-10-openssh-5.5p1-for-lucid.html

Changed in openssh (Ubuntu):
status: New → Triaged
Revision history for this message
Jka (jka-pub) wrote :

Scott - I switched to Colins PPA a few hours after testing the daily snapshot and can confirm it's fixed in his PPA, 1:5.5p1-3ubuntu1.

It'd be nice to streamline standard lucid with 5.5p1 - though I understand 5.5 has many new features.

For me 1:5.3p1-3ubuntu3 and 1:5.3p1-3ubuntu4 has a defect that will keep me well away from having it installed.

Changed in openssh (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Paul Crawford (psc-sat) wrote :

With 10.04 i386 on my Dell Latitude 2100 laptop I find that attempting to exit from "ssh -X username@remotemachine" is not returning to the local command prompt after using an X-session on the remote machine. It returns fine when I don't start an X program though.

Is this related to port forwarding of the usual 6000 x-windows port?

I have to Ctrl+C to get back to the local prompt, which is a touch worrying.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Marking Fix Released per reporter's comments. Feel free to nominate for release for an SRU for Lucid if a minimal patch can be found to address the issue. Thanks.

Changed in openssh (Ubuntu):
status: Triaged → Fix Released
Revision history for this message
Paul Crawford (psc-sat) wrote :

If this is supposedly fixed, how come using "ssh -X user@server" still hangs if you have run an X-windows program like 'eog' or similar?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.