-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix failure with rw bind mount of a ro fuse
As reported in [1], in a case where read-only fuse (sshfs) mount is used as a volume without specifying ro flag, the kernel fails to remount it (when adding various flags such as nosuid and nodev), returning EPERM. Here's the relevant strace line: > [pid 333966] mount("/tmp/bats-run-PRVfWc/runc.RbNv8g/bundle/mnt", "/proc/self/fd/7", 0xc0001e9164, MS_NOSUID|MS_NODEV|MS_REMOUNT|MS_BIND|MS_REC, NULL) = -1 EPERM (Operation not permitted) I was not able to reproduce it with other read-only mounts as the source (tried tmpfs, read-only bind mount, and an ext2 mount), so somehow this might be specific to fuse. The fix is to check whether the source has RDONLY flag, and retry the remount with this flag added. A test case (which was kind of hard to write) is added, and it fails without the fix. Note that rootless user need to be able to ssh to rootless@localhost in order to sshfs to work -- amend setup scripts to make it work, and skip the test if the setup is not working. [1] containers/podman#12205 Signed-off-by: Kir Kolyshkin <[email protected]>
- Loading branch information
Showing
6 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bats | ||
|
||
load helpers | ||
|
||
function setup() { | ||
# Create a ro fuse-sshfs mount; skip the test if it's not working. | ||
local sshfs="sshfs | ||
-o UserKnownHostsFile=/dev/null | ||
-o StrictHostKeyChecking=no | ||
-o PasswordAuthentication=no" | ||
|
||
DIR="$BATS_RUN_TMPDIR/fuse-sshfs" | ||
mkdir -p "$DIR" | ||
|
||
if ! $sshfs -o ro rootless@localhost: "$DIR"; then | ||
skip "test requires working sshfs mounts" | ||
fi | ||
|
||
setup_hello | ||
} | ||
|
||
function teardown() { | ||
# New distros (Fedora 35) do not have fusermount installed | ||
# as a dependency of fuse-sshfs, and good ol' umount works. | ||
fusermount -u "$DIR" || umount "$DIR" | ||
|
||
teardown_bundle | ||
} | ||
|
||
@test "runc run [rw bind mount of a ro fuse sshfs mount]" { | ||
update_config ' .mounts += [{ | ||
type: "bind", | ||
source: "'"$DIR"'", | ||
destination: "/mnt", | ||
options: ["rw", "rprivate", "nosuid", "nodev", "rbind"] | ||
}]' | ||
|
||
runc run test_busybox | ||
[ "$status" -eq 0 ] | ||
} |