Bug 3290 - ControlPersist opens shell even with -N
Summary: ControlPersist opens shell even with -N
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 8.5p1
Hardware: amd64 All
: P5 minor
Assignee: Damien Miller
URL:
Keywords:
Depends on:
Blocks: V_8_7
  Show dependency treegraph
 
Reported: 2021-03-30 09:32 AEDT by Richard Schwab
Modified: 2023-01-13 13:41 AEDT (History)
2 users (show)

See Also:


Attachments
ssh_config (3.89 KB, text/plain)
2021-03-30 09:32 AEDT, Richard Schwab
no flags Details
sshd_config (4.06 KB, text/plain)
2021-03-30 09:33 AEDT, Richard Schwab
no flags Details
client logs with ControlPersist (16.30 KB, text/plain)
2021-03-30 09:33 AEDT, Richard Schwab
no flags Details
client logs without ControlPersist (11.73 KB, text/plain)
2021-03-30 09:33 AEDT, Richard Schwab
no flags Details
handle -N with ControlPersist (2.66 KB, patch)
2021-05-07 14:35 AEST, Damien Miller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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