Skip to content

Commit e4e1956

Browse files
Kernel: Disallow unmounting busy mounts
We use refcounting (which now is possible due to previous commits) to ensure nothing besides the mount table holds a reference to the Mount to be removed.
1 parent 2420bc3 commit e4e1956

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Kernel/FileSystem/VFSRootContext.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ ErrorOr<void> VFSRootContext::unmount(FileBackedFileSystem::List& file_backed_fi
225225
if (custody_path != mountpoint_path->view())
226226
continue;
227227

228+
auto mount_ref_count = mount.ref_count();
229+
// Technically, a reference count should be 2 under normal conditions (when the system is done booting
230+
// and userspace started), however, because during a shutdown the init process is dead, then the reference
231+
// count could be one.
232+
VERIFY(mount_ref_count >= 1);
233+
// The Mount object is referenced normally at the mount table
234+
// and also now, so if we have more than 2 in the refcounting, then
235+
// someone else uses the Mount, and we should refuse unmounting it.
236+
if (mount_ref_count > 2)
237+
return EBUSY;
238+
228239
TRY(VFSRootContext::validate_mount_not_immutable_while_being_used(details, mount));
229240
dbgln("VFSRootContext({}): Unmounting {}...", id(), custody_path);
230241
TRY(VFSRootContext::remove_mount(mount, file_backed_file_systems_list));

0 commit comments

Comments
 (0)