Skip to content

test: Grab FORK_MTX when unmounting or forking in the mount tests #2386

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

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this lock necessary, this test does not open file descriptors, so theoretically no one could access the file system mounted at tempdir

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the File::create has to fail, so this is not necessary

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
3 changes: 2 additions & 1 deletion test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ fn read_exact<Fd: AsFd>(f: Fd, buf: &mut [u8]) {
}

/// Any test that creates child processes must grab this mutex, regardless
/// of what it does with those children.
/// of what it does with those children. It must hold the mutex until the
/// child processes are waited upon.
pub static FORK_MTX: Mutex<()> = Mutex::new(());
/// Any test that changes the process's current working directory must grab
/// the RwLock exclusively. Any process that cares about the current
Expand Down