Ricky Zhou
2011-Oct-13 09:18 UTC
[PATCH] Fix control persist and stdio forward interaction
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. Thus, it seems like a reasonable fix to not call client_setup_stdio_fwd if need_controlpersist_detach is set, and just allow it to happen later. Does the attached patch look OK? Thanks, Ricky -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20111013/1801e07e/attachment.bin>
Ricky Zhou
2011-Oct-13 09:24 UTC
[PATCH] Fix control persist and stdio forward interaction
On 2011-10-13 05:18:43 AM, Ricky Zhou wrote:> Does the attached patch look OK?Oops, looks like I forgot to attach the patch, so here it is. Thanks, Ricky -------------- next part -------------- Index: ssh.c ==================================================================RCS file: /cvs/openssh/ssh.c,v retrieving revision 1.362 diff -u -r1.362 ssh.c --- ssh.c 2 Oct 2011 07:59:03 -0000 1.362 +++ ssh.c 13 Oct 2011 09:16:27 -0000 @@ -1087,9 +1087,16 @@ if (!compat20) { fatal("stdio forwarding require Protocol 2"); } - if (!client_setup_stdio_fwd(stdio_forward_host, - stdio_forward_port)) - fatal("Failed to connect in stdio forward mode."); + + /* + * If control persist is on, the stdio fwd is setup on the + * master through the muxserver. + */ + if (!need_controlpersist_detach) { + if (!client_setup_stdio_fwd(stdio_forward_host, + stdio_forward_port)) + fatal("Failed to connect in stdio forward mode."); + } } /* Initiate local TCP/IP port forwardings. */ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20111013/ab62c998/attachment.bin>
Possibly Parallel Threads
- [Bug 1943] New: [PATCH] ssh -W opens two connections when ControlPersist is enabled.
- Possible issue with stdio forwarding
- [PATCH/RFC 0/6] New mux client request to list open tcp forwardings.
- ssh -f and -O ControlPersist=yes, ControlMaster=yes leaves stderr open
- perl on CentOS 4.4 : PERLIO=perlio vs stdio, readline error handling