As reported earlier at https://lists.mindrot.org/pipermail/openssh-unix-dev/2011-March/029441.html there is some strange interaction between ControlPersist and ssh -W that breaks things if you're using both. Specifically, ssh -W host:port with ControlPersist enabled opens up two connections to host:port and sends data from both back. I think this is happening because channel_connect_stdio_fwd is being called twice, once in client_setup_stdio_fwd, which is called from ssh_init_forwarding, and once in process_mux_stdio_fwd, which is called once the client process starts talking to the master process. It looks like the way ControlPersist is implemented, the process forks, with the child becoming the master process and the child making its connection through that. This patch makes client_setup_stdio_fwd not get called the first time if need_controlpersist_detach is set, and lets it happen through the master process.
Created attachment 2100 [details] bz1943.diff fix dupe stdio forward with ControlPersist
patch applied - this will be in openssh-6.0. Thanks!
A workaround for versions before 6.0: instead of ssh -W %h:%p gateway Use: sh -c "ssh gateway true < /dev/null && ssh -W %h:%p gateway" The first ssh call does not use -W so it is not affected by this bug. It makes sure that the master process is running. The second call does not need to fork a master so it is not affected either.
Set all RESOLVED bugs to CLOSED with release of OpenSSH 7.1