Bug 2192395

Summary: sftp fails without -d (debugmode)
Product: [Fedora] Fedora Reporter: customercare
Component: opensshAssignee: Dmitry Belyavskiy <dbelyavs>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: medium    
Version: 37CC: crypto-team, dbelyavs, dwalsh, jjelen, lkundrak, mattias.ellert, tm
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description customercare 2023-05-01 19:40:09 UTC
Description of problem:

The server in question has a chroot env with a fake /proc to deny attackers, who gained control, to proceed further and check processid's etc. etc.

/opt/root/proc/
└── self
    └── fd
        ├── 0 -> /dev/pts/0
        ├── 1 -> /dev/pts/0
        ├── 2 -> /dev/pts/0
        └── 3
            ├── 0 -> /dev/null
            └── 9 -> /dev/null

4 directories, 5 files

sshd puts anyone except root in this chroot.

A none-root user with ssh as client can log into the system and start bash -> op success

A none-root user with sftp as client can not log into the system -> op fail

At this point we started sshd manually to use strace to dig into it.

As long as sshd is not started with at least one "-d" option, sftp keeps failing.
As soon as we start sshd with "-d" option, which means debug level 1, sftp can flawlessly log in and use the server inside the chroot as it should be -> op success

Conclusion:

something besides the obvious log_print() changes inside openssh-server changes to make sftp work. 

I can not verify IF this is a Fedora only bug due to the many downstream patches or a common bug in all releases.


Version-Release number of selected component (if applicable):

Name        : openssh-server
Version     : 8.8p1
Release     : 10.fc37
Architecture: x86_64
Install Date: Mo 01 Mai 2023 17:54:23 CEST


How reproducible:

- create a chroot with minimal system and bash
- mkdir /chroot/proc
        mkdir -p /chroot/proc/self/fd/3
        ln -s /dev/pts/0 /chroot/proc/self/fd/0
        ln -s /dev/pts/0 /chroot/proc/self/fd/1
        ln -s /dev/pts/0 /chroot/proc/self/fd/2
        ln -s /dev/null /chroot/proc/self/fd/3/0
        ln -s /dev/null /chroot/proc/self/fd/3/9
- mount dev to /chroot/dev

change your /etc/ssh/sshd_config and add:

ChrootDirectory /opt/root/
Match user root
 	ChrootDirectory none

now stop sshd and run it manually i.e. on another port:

$(which sshd) -D -p 22 
$(which sshd) -D -d -p 22 

and try sftp to log into your none-root account ( you may need to copy /etc/passwd etc. into the chroot env )  

it will fail.

O== Wanted solution

working sftp without enabling debug mode and without a /proc filesystem

(if you have a better idea than the described above, i'm all ear)

Comment 1 Dmitry Belyavskiy 2023-05-02 09:42:16 UTC
Could you please check it against upstream?

I don't recall any sftp patches that could cause such behavior.

Comment 2 customercare 2023-05-02 09:58:27 UTC
whats the best build source?

Comment 3 Dmitry Belyavskiy 2023-05-02 10:03:21 UTC
https://www.openssh.com/portable.html - the last one (9.3p1) from any mirrors.

Comment 4 customercare 2023-05-02 11:41:19 UTC
Server# /usr/src/openssh/openssh/sshd -V -D -p 30
OpenSSH_9.3, OpenSSL 3.0.8 7 Feb 2023
Server# /usr/src/openssh/openssh/sshd -D -p 30

Client# sftp -P 30 user@thatserver
Connected to thatserver.
sftp> ls -la /proc/
dr-xr-xr-x    3 root     root         4096 Apr 25 19:53 .
drwxr-xr-x   18 root     root         4096 Apr 25 14:31 ..
drwxr-xr-x    3 root     root         4096 Apr 19 15:03 self
sftp> exit

So the unpatched native openssh-server version works like a charm on a Fedora 37.

My Buildline looks like this:

./configure --with-md5-passwords --with-pam --with-selinux --sysconfdir=/etc/ssh

and for my stuff, it seems to work. So... do you finally upgrade to 9.3 or do I need to create a replacement rpm for my Fedora Cluster? :D