Skip to content
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

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

Merged
merged 4 commits into from
Apr 24, 2024

Conversation

TheJonny
Copy link
Contributor

@TheJonny TheJonny commented Apr 22, 2024

fork() duplicates all open file descriptors, which then could prevent a successful umount().

So either when creating file descriptors or when requiring a file descriptor to be closed, we must make sure that no child processes have copies. since wile descriptors are created all over the place, It is more practical to wait for all child processes before unlock.

TODO:

  • verify the semantic of FORK_MTX: how long must it be held? This PR assumes that the mutex is locked until all child processes have exited.

unmounting can fail if a child process inherited a file a file descriptor
we opened in temporary mount point

Should fix nix-rust#2369
@SteveLauC
Copy link
Member

Hi, thanks for working on this!

What about we set the close-on-exec flag for the test files in that bind-mount fs (as well as the fds in other mount tests), I kinda think this would be more straightforward, thoughts?

@TheJonny
Copy link
Contributor Author

The close-on exec-flag will not prevent the issue, because the issue is not exec, but fork: it copies any opened file descriptors and then they live until exit or exec. if a file descriptor to something on the mountpoint is forked, unmount will fail.

@SteveLauC
Copy link
Member

it copies any opened file descriptors and then they live until exit or exec.

You are right, there is still a timespan between fork() and execxxx() that could theoretically make the test fail

@@ -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

test/test.rs Outdated Show resolved Hide resolved
Copy link
Member

@SteveLauC SteveLauC left a comment

Choose a reason for hiding this comment

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

Thanks!

@SteveLauC SteveLauC added this pull request to the merge queue Apr 24, 2024
@SteveLauC SteveLauC linked an issue Apr 24, 2024 that may be closed by this pull request
Merged via the queue into nix-rust:master with commit 395906e Apr 24, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Debug mount::test_mount::test_mount_bind on Linux
2 participants