Bug 3290

Summary: ControlPersist opens shell even with -N
Product: Portable OpenSSH Reporter: Richard Schwab <bugzillamindroto-mzk3bxkyqa>
Component: sshAssignee: Damien Miller <djm>
Status: CLOSED FIXED    
Severity: minor CC: djm, dtucker
Priority: P5    
Version: 8.5p1   
Hardware: amd64   
OS: All   
Bug Depends on:    
Bug Blocks: 3302    
Attachments:
Description Flags
ssh_config
none
sshd_config
none
client logs with ControlPersist
none
client logs without ControlPersist
none
handle -N with ControlPersist none

Description Richard Schwab 2021-03-30 09:32:11 AEDT
I'm trying to use an SSH tunnel through a host that only allows local port forwarding, nothing else.

For reproducibility purposes the example in this report uses a pretty much default ssh configuration with the users shell being a shell script echoing that the user isn't supposed to login and then exits.

As I'm defaulting to using ControlMaster and ControlPersist in my ssh_config I came across this, as it effectively makes this connection impossible to use unless ControlMaster and ControlPath are explicitly disabled for this destination.

A working example would be

ssh -F /dev/null -vvv -N -o ControlMaster=auto -o ControlPath=~/cptest localhost

In this case I can open a connection and nothing happens, as expected. Adding a port forward with -L works fine too and I can reach the intended destination. Great.

Once I add ControlPersist to this command however it breaks:

ssh -F /dev/null -vvv -N -o ControlMaster=auto -o ControlPath=~/cptest -o ControlPersist=5 localhost

Leading up to the exit I find this in the SSH logs (some lines omitted):

debug2: channel 2: request shell confirm 1
debug2: shell request accepted on channel 2
This is not a real shell, you are not supposed to login.
debug1: client_input_channel_req: channel 2 rtype exit-status reply 0
debug3: mux_exit_message: channel 2: exit message, exitval 0

The message is coming from the users shell.

The ControlMaster keeps running in the background until ControlPersist times out. I can also verify that it still has a working session as I can access a -L forwarded port before it's closing the ControlMaster session.

Client and server config as well as -vvv client logs of both scenarios are attached.

Tested on 8.1 (macOS), 8.2 (Linux) and 8.5 (Linux).
Comment 1 Richard Schwab 2021-03-30 09:32:45 AEDT
Created attachment 3490 [details]
ssh_config
Comment 2 Richard Schwab 2021-03-30 09:33:01 AEDT
Created attachment 3491 [details]
sshd_config
Comment 3 Richard Schwab 2021-03-30 09:33:40 AEDT
Created attachment 3492 [details]
client logs with ControlPersist
Comment 4 Richard Schwab 2021-03-30 09:33:55 AEDT
Created attachment 3493 [details]
client logs without ControlPersist
Comment 5 Damien Miller 2021-05-07 14:35:01 AEST
Created attachment 3512 [details]
handle -N with ControlPersist
Comment 6 Damien Miller 2021-05-14 13:11:16 AEST
A similar fix was committed in 1e9fa55f4dc4b and will be in OpenSSH 8.7
Comment 7 Damien Miller 2022-02-25 13:59:09 AEDT
closing bugs resolved before openssh-8.9