Bug 2562

Summary: CanonicalizeHostname causes duplicate LocalForward attempts
Product: Portable OpenSSH Reporter: Matthew Ghali <matt+openssh>
Component: sshAssignee: Damien Miller <djm>
Status: CLOSED FIXED    
Severity: normal CC: djm, dtucker
Priority: P5    
Version: 7.1p1   
Hardware: ix86   
OS: Mac OS X   
Bug Depends on:    
Bug Blocks: 2543    
Attachments:
Description Flags
don't record duplicate forwards dtucker: ok+

Description Matthew Ghali 2016-04-04 09:55:51 AEST
When CanonicalizeHostname reloads ssh config, LocalForward entries end up duplicated; this causes a connection failure if ExitOnForwardFailure is set.

test config:
Host mini
    IdentityFile ~/.ssh/keys/id_rsa
    LocalForward localhost:8000 localhost:80

Host *
    CanonicalizeHostname yes
    ExitOnForwardFailure yes


result:
mghali@ernie.int.snark.net:~$ ssh -v -F tmp/config mini
OpenSSH_7.1p1, OpenSSL 1.0.1j 15 Oct 2014
debug1: Reading configuration data tmp/config
debug1: tmp/config line 1: Applying options for mini
debug1: tmp/config line 5: Applying options for *
debug1: Re-reading configuration after hostname canonicalisation
debug1: Reading configuration data tmp/config
debug1: tmp/config line 1: Applying options for mini
debug1: tmp/config line 5: Applying options for *
debug1: Connecting to mini [192.168.0.250] port 22.
debug1: Connection established.
[...]
Authenticated to mini ([192.168.0.250]:22).
debug1: Local connections to localhost:8000 forwarded to remote address localhost:80
debug1: Local forwarding listening on ::1 port 8000.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 8000.
debug1: channel 1: new [port listener]
debug1: Local connections to localhost:8000 forwarded to remote address localhost:80
debug1: Local forwarding listening on ::1 port 8000.
bind: Address already in use
debug1: Local forwarding listening on 127.0.0.1 port 8000.
bind: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 8000
Could not request local forwarding.

Disabling CanonicalizeHostname results in a single set of port forwarding actions and success:
mghali@ernie.int.snark.net:~$ ssh -v -F tmp/config -o 'CanonicalizeHostname no' mini
OpenSSH_7.1p1, OpenSSL 1.0.1j 15 Oct 2014
debug1: Reading configuration data tmp/config
debug1: tmp/config line 1: Applying options for mini
debug1: tmp/config line 5: Applying options for *
debug1: Connecting to mini [192.168.0.250] port 22.
debug1: Connection established.
[...]
Authenticated to mini ([192.168.0.250]:22).
debug1: Local connections to localhost:8000 forwarded to remote address localhost:80
debug1: Local forwarding listening on ::1 port 8000.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 8000.
debug1: channel 1: new [port listener]
debug1: channel 2: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
Comment 1 Damien Miller 2016-04-05 15:31:52 AEST
Created attachment 2803 [details]
don't record duplicate forwards

Thanks. This patch should help.
Comment 2 Matthew Ghali 2016-04-05 15:48:46 AEST
Thanks - I see this already was fixed in 7.2p2 - sorry I didn't check first!
Comment 3 Damien Miller 2016-04-08 13:31:54 AEST
patch is committed and will appear in openssh-7.3. Thanks!
Comment 4 Damien Miller 2016-08-02 10:40:48 AEST
Close all resolved bugs after 7.3p1 release