race condition with ControlMaster=auto

Damien Miller djm at mindrot.org
Sat Aug 4 11:26:26 EST 2007


On Fri, 3 Aug 2007, Tony Finch wrote:

> There is a race in the setup of the ControlMaster socket in auto mode, as
> illustrated by the following command line:
> 
> ssh -oControlMaster=auto -oControlPath=sock localhost 'sleep 1; echo 1' &
> ssh -oControlMaster=auto -oControlPath=sock localhost 'sleep 2; echo 2' &
> 
> Both of the commands will try to start up as a control client, find that
> sock does not exist, and switch into control master mode. One will succeed
> in creating the control master socket and the other will fail and bomb.

Yes, this is annoying. The other approach to fixing it that I thought of
but didn't yet implement was to create the sockets with mkstemp (i.e.
with a random suffix) and try to rename them into place when ready. If
the rename fails then the ssh client can just turn off master mode,
unlink its temporarily named socket and act as a regular client.

> The attached patch eliminates this race by trying to create a control
> master socket first, and falling back to control client mode if master
> mode fails.

Please file a bug at http://bugzilla.mindrot.org with your patch.

-d


More information about the openssh-unix-dev mailing list