Kernel/VFS: Ensure Custodies' absolute path don't match before mounting

This ensures that the host mount point custody path is not the same like
the new to-be-mounted custody.

A scenario that could happen before adding this check is:
```
mkdir -p /tmp2
mount /dev/hda /tmp2/
mount /dev/hda /tmp2/
mount /dev/hda /tmp2/ # this will fail here
```

and after adding this check, the following scenario is now this:
```
mkdir -p /tmp2
mount /dev/hda /tmp2/
mount /dev/hda /tmp2/ # this will fail here
mount /dev/hda /tmp2/ # this will fail here too
```
This commit is contained in:
Liav A 2023-08-04 14:54:52 +03:00 committed by Jelle Raaijmakers
parent 8da7d84512
commit debbfe07fb
Notes: sideshowbarker 2024-07-16 23:34:44 +09:00
2 changed files with 30 additions and 9 deletions

View file

@ -115,7 +115,8 @@ private:
ErrorOr<void> traverse_directory_inode(Inode&, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>);
bool mount_point_exists_at_inode(InodeIdentifier inode);
static bool check_matching_absolute_path_hierarchy(Custody const& first_custody, Custody const& second_custody);
bool mount_point_exists_at_custody(Custody& mount_point);
// FIXME: These functions are totally unsafe as someone could unmount the returned Mount underneath us.
Mount* find_mount_for_host(InodeIdentifier);