Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sshfs hangs when the target directory matches $OLDPWD #206

Closed
Maelan opened this issue Feb 19, 2020 · 4 comments · Fixed by #227
Closed

sshfs hangs when the target directory matches $OLDPWD #206

Maelan opened this issue Feb 19, 2020 · 4 comments · Fixed by #227

Comments

@Maelan
Copy link

Maelan commented Feb 19, 2020

Description

When OLDPWD (the shell variable containing the last visited directory) contains the path of the local directory we are trying to mount into, then sshfs hangs in a read(2) syscall.

This happens quite often, to me at least.

Versions tested

$ env -i bash --noprofile --norc
$ ssh srv uname -a
Linux srv 5.2.1-arch1-1-ARCH #1 SMP PREEMPT Sun Jul 14 14:52:52 UTC 2019 x86_64 GNU/Linux
$ ssh srv ssh -V
OpenSSH_8.0p1, OpenSSL 1.1.1d  10 Sep 2019
$ uname -a
Linux mylaptop 5.2.11-arch1-1-ARCH #1 SMP PREEMPT Thu Aug 29 08:09:36 UTC 2019 x86_64 GNU/Linux
$ ssh -V
OpenSSH_8.1p1, OpenSSL 1.1.1d  10 Sep 2019
$ sshfs -V
SSHFS version 3.7.0
FUSE library version 3.9.0
using FUSE kernel interface version 7.31
fusermount3 version: 3.9.0

Steps to reproduce

$ env -i bash --noprofile --norc
$ mkdir d
$ sshfs srv:/ d
(mounting successful)
$ umount d
$ OLDPWD=/home/mine/d  sshfs srv:/ d
(sshfs hangs)
^Cread: Interrupted system call
$ OLDPWD=  sshfs srv:/ d
(mounting successful)
$ umount d

Debug info

debug output (-d -f -s)

$ OLDPWD=  sshfs -d -f -s srv:/ d
SSHFS version 3.7.0
executing <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-2> <srv> <-s> <sftp>
Server version: 3
Extension: [email protected] <1>
Extension: [email protected] <2>
Extension: [email protected] <2>
Extension: [email protected] <1>
Extension: [email protected] <1>
Extension: [email protected] <1>
[00001] LSTAT
  [00001]          ATTRS       41bytes (9ms)

sent:               1 messages, 14 bytes
received:           1 messages, 41 bytes
rtt min/max/avg:    9ms/9ms/9ms
num connect:        1
$ OLDPWD=/home/mine/d  sshfs -d -f -s srv:/ d
SSHFS version 3.7.0
executing <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-2> <srv> <-s> <sftp>
(sshfs hangs)
^C

strace

$ OLDPWD=  strace /bin/sshfs srv:/ d
(see trace attached)
$ OLDPWD=/home/mine/d  strace /bin/sshfs srv:/ d
(see trace attached)

log-strace-ok.txt
log-strace-fail.txt

gdb backtrace

I fear that one is not terribly helpful.

$ OLDPWD=/home/mine/d  sshfs srv:/ d
(then, as sshfs hangs, type in another terminal:)
$ sudo gdb -p <pid_of_sshfs>
GNU gdb (GDB) 9.1
Attaching to process <pid_of_sshfs>
Reading symbols from /usr/bin/sshfs...
(No debugging symbols found in /usr/bin/sshfs)
Reading symbols from /usr/lib/libc.so.6...
(No debugging symbols found in /usr/lib/libc.so.6)
Reading symbols from /usr/lib/libfuse3.so.3...
(No debugging symbols found in /usr/lib/libfuse3.so.3)
Reading symbols from /usr/lib/libpthread.so.0...
(No debugging symbols found in /usr/lib/libpthread.so.0)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Reading symbols from /usr/lib/libglib-2.0.so.0...
(No debugging symbols found in /usr/lib/libglib-2.0.so.0)
Reading symbols from /lib64/ld-linux-x86-64.so.2...
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
Reading symbols from /usr/lib/libdl.so.2...
(No debugging symbols found in /usr/lib/libdl.so.2)
Reading symbols from /usr/lib/libpcre.so.1...
(No debugging symbols found in /usr/lib/libpcre.so.1)
0x00007fdb27a3c3f2 in read () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007fdb27a3c3f2 in read () from /usr/lib/libc.so.6
#1  0x00005564c99969f7 in ?? ()
#2  0x00005564c999751f in ?? ()
#3  0x00005564c9997688 in ?? ()
#4  0x00005564c9997d67 in ?? ()
#5  0x00005564c999cd9d in ?? ()
#6  0x00005564c999de26 in ?? ()
#7  0x00007fdb27973153 in __libc_start_main () from /usr/lib/libc.so.6
#8  0x00005564c99948ae in ?? ()

Reproducibility

Apparently it depends on the remote server. Although sshfs hangs with my server srv above, it does not with this other server:

$ ssh othersrv uname -a
Linux othersrv 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux
$ ssh othersrv ssh -V
OpenSSH_7.9p1 Raspbian-6, OpenSSL 1.1.1a  20 Nov 2018

So it may be tied to some piece of configuration for SSH on my server srv. I may take time to investigate this later if necessary.

@Nikratio
Copy link
Contributor

That's probably because we first open the mountpoint and then fork SSH. So if the shell or ssh tries to access the mountpoint, everything hangs.

@Nikratio
Copy link
Contributor

Thank you for the report! Do you think you could work on this (or do you know someone who could)?

SSHFS is a fully volunteer driven project. This means that new features and bugfixes are implemented only when someone has a personal interest in them and therefore also does the necessary
work. So if someone (that probably means you) is interested in working on this, then I'd be happy to give guidance and review patches. If not, I will close this issue in a few days (since the purpose of the issue tracker is to coordinate ongoing and planned work, rather than enumerate all the work that could possibly be done).

@Nikratio
Copy link
Contributor

This is probably a duplicate of #196

@nomis
Copy link
Contributor

nomis commented Sep 2, 2020

The easiest way to fix this particular issue would be to unset the environment variable OLDPWD before starting ssh. That would stop bash or other process from trying to access it.

nomis added a commit to nomis/sshfs that referenced this issue Sep 2, 2020
If ssh is configured to use "Match exec" and the previous working
directory is the mount point, then the shell (bash) hangs calling
stat() on OLDPWD.

Unset OLDPWD so that this doesn't happen.

Fixes libfuse#206.
Nikratio pushed a commit that referenced this issue Sep 3, 2020
If ssh is configured to use "Match exec" and the previous working
directory is the mount point, then the shell (bash) hangs calling
stat() on OLDPWD.

Unset OLDPWD so that this doesn't happen.

Fixes #206.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants