Skip to content

Commit

Permalink
mount tests: take FORK_MTX when forking or unmounting
Browse files Browse the repository at this point in the history
unmounting can fail if a child process inherited a file a file descriptor
we opened in temporary mount point

Should fix #2369
  • Loading branch information
TheJonny committed Apr 22, 2024
1 parent f129095 commit 889e861
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/mount/test_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ fn test_mount_tmpfs_without_flags_allows_rwx() {
.unwrap_or_else(|e| panic!("read failed: {e}"));
assert_eq!(buf, SCRIPT_CONTENTS);

// while forking and unmounting prevent other child processes
let _m = FORK_MTX.lock();
// Verify execute.
assert_eq!(
EXPECTED_STATUS,
Expand Down Expand Up @@ -89,6 +91,8 @@ fn test_mount_rdonly_disallows_write() {
.unwrap()
);

// wait for child processes to prevent EBUSY
let _m = FORK_MTX.lock();
umount(tempdir.path()).unwrap_or_else(|e| panic!("umount failed: {e}"));
}

Expand Down Expand Up @@ -129,6 +133,8 @@ fn test_mount_noexec_disallows_exec() {
&test_path
);

// while forking and unmounting prevent other child processes
let _m = FORK_MTX.lock();
// EACCES: Permission denied
assert_eq!(
EACCES,
Expand Down Expand Up @@ -168,6 +174,8 @@ fn test_mount_bind() {
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
.unwrap_or_else(|e| panic!("write failed: {e}"));

// wait for child processes to prevent EBUSY
let _m = FORK_MTX.lock();
umount(mount_point.path())
.unwrap_or_else(|e| panic!("umount failed: {e}"));
}
Expand Down

0 comments on commit 889e861

Please sign in to comment.