diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 9bdd497d6c..7b625d2ca4 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -3575,28 +3575,35 @@ int Process::sys$reboot() return ESUCCESS; } -int Process::sys$mount(const char* device_path, const char* mountpoint, const char* fstype) +int Process::sys$mount(const Syscall::SC_mount_params* user_params) { if (!is_superuser()) return -EPERM; - SmapDisabler disabler; + if (!validate_read_typed(user_params)) + return -EFAULT; + Syscall::SC_mount_params params; + copy_from_user(¶ms, user_params); - if (!validate_read_str(device_path) || !validate_read_str(mountpoint) || !validate_read_str(fstype)) + auto source = validate_and_copy_string_from_user(params.source); + auto target = validate_and_copy_string_from_user(params.target); + auto fs_type = validate_and_copy_string_from_user(params.fs_type); + + if (source.is_null() || target.is_null() || fs_type.is_null()) return -EFAULT; - dbg() << "mount " << fstype << ": device " << device_path << " @ " << mountpoint; + dbg() << "mount " << fs_type << ": source " << source << " @ " << target; - auto custody_or_error = VFS::the().resolve_path(mountpoint, current_directory()); + auto custody_or_error = VFS::the().resolve_path(target, current_directory()); if (custody_or_error.is_error()) return custody_or_error.error(); - auto& mountpoint_custody = custody_or_error.value(); + auto& target_custody = custody_or_error.value(); - RefPtr fs { nullptr }; + RefPtr fs; - if (strcmp(fstype, "ext2") == 0 || strcmp(fstype, "Ext2FS") == 0) { - auto metadata_or_error = VFS::the().lookup_metadata(device_path, current_directory()); + if (fs_type == "ext2" || fs_type == "Ext2FS") { + auto metadata_or_error = VFS::the().lookup_metadata(source, current_directory()); if (metadata_or_error.is_error()) return metadata_or_error.error(); @@ -3616,25 +3623,26 @@ int Process::sys$mount(const char* device_path, const char* mountpoint, const ch auto& disk_device = static_cast(*device); - dbg() << "mount: attempting to mount device (" << major << "," << minor << ") on " << mountpoint; + dbg() << "mount: attempting to mount device (" << major << "," << minor << ") on " << target; fs = Ext2FS::create(disk_device); - } else if (strcmp(fstype, "proc") == 0 || strcmp(fstype, "ProcFS") == 0) + } else if (fs_type == "proc" || fs_type == "ProcFS") { fs = ProcFS::create(); - else if (strcmp(fstype, "devpts") == 0 || strcmp(fstype, "DevPtsFS") == 0) + } else if (fs_type == "devpts" || fs_type == "DevPtsFS") { fs = DevPtsFS::create(); - else if (strcmp(fstype, "tmp") == 0 || strcmp(fstype, "TmpFS") == 0) + } else if (fs_type == "tmp" || fs_type == "TmpFS") { fs = TmpFS::create(); - else - return -ENODEV; - - if (!fs->initialize()) { - dbg() << "mount: failed to initialize " << fstype << " filesystem on " << device_path; + } else { return -ENODEV; } - auto result = VFS::the().mount(fs.release_nonnull(), mountpoint_custody); - dbg() << "mount: successfully mounted " << device_path << " on " << mountpoint; + if (!fs->initialize()) { + dbg() << "mount: failed to initialize " << fs_type << " filesystem on " << source; + return -ENODEV; + } + + auto result = VFS::the().mount(fs.release_nonnull(), target_custody); + dbg() << "mount: successfully mounted " << source << " on " << target; return result; } diff --git a/Kernel/Process.h b/Kernel/Process.h index 50f36ee6e4..5e05f3a175 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -179,7 +179,7 @@ public: int sys$unlink(const char* pathname, size_t path_length); int sys$symlink(const Syscall::SC_symlink_params*); int sys$rmdir(const char* pathname, size_t path_length); - int sys$mount(const char* device, const char* mountpoint, const char* fstype); + int sys$mount(const Syscall::SC_mount_params*); int sys$umount(const char* mountpoint, size_t mountpoint_length); int sys$chmod(const char* pathname, size_t path_length, mode_t); int sys$fchmod(int fd, mode_t); diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 57899c3883..8d0fe0566f 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -355,6 +355,12 @@ struct SC_rename_params { StringArgument new_path; }; +struct SC_mount_params { + StringArgument source; + StringArgument target; + StringArgument fs_type; +}; + void initialize(); int sync(); diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index ece2124a88..30e1bf13cf 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -610,9 +610,14 @@ int reboot() __RETURN_WITH_ERRNO(rc, rc, -1); } -int mount(const char* device, const char* mountpoint, const char* fstype) +int mount(const char* source, const char* target, const char* fs_type) { - int rc = syscall(SC_mount, device, mountpoint, fstype); + if (!source || !target || !fs_type) { + errno = EFAULT; + return -1; + } + Syscall::SC_mount_params params { { source, strlen(source) }, { target, strlen(target) }, { fs_type, strlen(fs_type) } }; + int rc = syscall(SC_mount, ¶ms); __RETURN_WITH_ERRNO(rc, rc, -1); } diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index fb5b6d09bd..feafa57f3b 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -111,7 +111,7 @@ int fchown(int fd, uid_t, gid_t); int ftruncate(int fd, off_t length); int halt(); int reboot(); -int mount(const char* device, const char* mountpoint, const char* fstype); +int mount(const char* source, const char* target, const char* fs_type); int umount(const char* mountpoint); enum {