proot-me / proot

chroot, mount --bind, and binfmt_misc without privilege/setup for Linux
https://proot-me.github.io
GNU General Public License v2.0
2.02k stars 378 forks source link

-R and -S fail to chdir to / when $PWD does not exist in the guest rootfs #307

Open parke opened 3 years ago

parke commented 3 years ago

Expected Behavior

I expect -r and -R (and -S) to behave similarly.

Actual Behavior

When the directory $PWD does not exist inside the guest rootfs:

-r will print a warning and chdir() to / -R fails to print a warning and fails to chdir() -S fails just like -R

Steps to Reproduce the Problem

I am running in this directory.

$  pwd
/home/hack/20211018_ubuntu_rootfs

$  ls
proot-v5.2.0-x86_64-static  squashfs-root

squashfs-root is an Ubuntu 21.04 userland extracted from the official Ubuntu 21.04 installation .iso file. However, you should be able to reproduce this problem with just about any userland.

We now make sure that $PWD does not exist inside squashfs-root:

$  mkdir  -p  squashfs-root/$PWD
$  rmdir      squashfs-root/$PWD

Now we can reproduce the difference between -r and -R:

$  ./proot-v5.2.0-x86_64-static  -r squashfs-root/  pwd
proot warning: can't chdir("/home/hack/20211018_ubuntu_rootfs/./.") in the guest rootfs: No such file or directory
proot info: default working directory is now "/"
/

$  ./proot-v5.2.0-x86_64-static  -R squashfs-root/  pwd
/home/hack/20211018_ubuntu_rootfs

$  ./proot-v5.2.0-x86_64-static  -r squashfs-root/  ls
proot warning: can't chdir("/home/hack/20211018_ubuntu_rootfs/./.") in the guest rootfs: No such file or directory
proot info: default working directory is now "/"
bin   dev  home  lib32  libx32  mnt  proc  run   snap  sys  usr
boot  etc  lib   lib64  media   opt  root  sbin  srv   tmp  var

$  ./proot-v5.2.0-x86_64-static  -R squashfs-root/  ls
proot-v5.2.0-x86_64-static  squashfs-root

Note that -R fails to print the warning that $PWD does not exist.

Note that -R runs the pwd and ls commands in the host's file-system, rather than in the guest's file-system. IMO, this is a bug.

Specifications

Command Output

The command output is listed above in the steps-to-reproduce section.

oxr463 commented 3 years ago

@parke thanks for the bug report!