Quellcode durchsuchen

Kernel: Return -ENOTDIR for non-directory mount target

The absence of this check allowed silly things like this:

    # touch file
    # mount /dev/hda file
Linus Groh vor 4 Jahren
Ursprung
Commit
b7b09470ca
2 geänderte Dateien mit 4 neuen und 0 gelöschten Zeilen
  1. 1 0
      Base/usr/share/man/man2/mount.md
  2. 3 0
      Kernel/Syscalls/mount.cpp

+ 1 - 0
Base/usr/share/man/man2/mount.md

@@ -89,6 +89,7 @@ launch the initial userspace process.
 * `EBADF`: If the `source_fd` is not valid, and either `fs_type` specifies a
   file-backed filesystem (and not a pseudo filesystem), or `MS_BIND` is
   specified in flags.
+* `ENOTDIR`: If `target` is not a directory.
 
 All of the usual path resolution errors may also occur.
 

+ 3 - 0
Kernel/Syscalls/mount.cpp

@@ -67,6 +67,9 @@ int Process::sys$mount(Userspace<const Syscall::SC_mount_params*> user_params)
 
     auto& target_custody = custody_or_error.value();
 
+    if (!target_custody->inode().is_directory())
+        return -ENOTDIR;
+
     if (params.flags & MS_REMOUNT) {
         // We're not creating a new mount, we're updating an existing one!
         return VFS::the().remount(target_custody, params.flags & ~MS_REMOUNT);