containers / containers/bubblewrap
Bind mounting over symlinks attempts to create their targets and bind mount over them
- Dominant language
- C
- Stars
- 8.7k
- Forks
- 386
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 11
Description
### What I observe:
```
$ touch a_file
$ ln -s a_file rel_symlink
$ bwrap --bind / / --bind a_file $PWD/rel_symlink /usr/bin/env ls -l $PWD/rel_symlink
lrwxrwxrwx 1 robryk users 6 Sep 14 23:55 /home/robryk/zero-k/rel_symlink -> a_file
$ ln -s $PWD/a_file abs_symlink
$ bwrap --bind / / --bind a_file $PWD/abs_symlink /usr/bin/env ls -l $PWD/abs_symlink
bwrap: Can't create file at /home/robryk/zero-k/abs_symlink: No such file or directory
$ ls -l nonexistent
ls: cannot access 'nonexistent': No such file or directory
$ ln -s nonexistent broken_symlink
$ bwrap --bind / / --bind a_file $PWD/broken_symlink /usr/bin/env ls -l $PWD/broken_symlink
lrwxrwxrwx 1 robryk users 11 Sep 14 23:55 /home/robryk/zero-k/broken_symlink -> nonexistent
$ ls -l nonexistent
-rw-rw-rw- 1 robryk users 0 Sep 15 00:04 nonexistent
$ ln -s ../../../nonexistent another_broken_symlink
$ bwrap --bind / / --bind a_file $PWD/another_broken_symlink /usr/bin/env ls -l $PWD/another_broken_symlink
bwrap: Can't create file at /home/robryk/zero-k/another_broken_symlink: Permission denied
```
It seems that:
1. Mounting over an unbroken symlink caused `bwrap` to mount over the symlink's target.
2. Mounting over an unbroken, absolute symlink caused `bwrap` to fail.
3. Mounting over a broken symlink caused `bwrap` to create the symlink target and mount over it.
4. Mounting over a broken symlink that points into a directory that is not writeable caused bwrap to fail.
### What I expect:
Mounting over any kind of symlink to cause the resulting mount namespace to have the symlink replaced with the source of the mount. This did not happen in any of the four cases.
If doing that is impossible (quick skim of `man mount(2)` didn't yield an equivalent of `O_NOFOLLOW`, even though `umount2` does have the `UMOUNT_NOFOLLOW` flag), I expect bwrap to exit with an error. I also expect it not to mount anything over the symlink's target. This failed to happen in cases 1 and 3.
It would be nice if the "File not found" error was more descriptive. It's not obvious which file is "missing" (my first intuition was that the problem was with one of the directories in the target path).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.