Kernel: Take path+length in the unlink() and umount() syscalls

This commit is contained in:
Andreas Kling 2020-01-09 12:41:15 +01:00
parent 76c20642f0
commit 4b4d369c5d
Notes: sideshowbarker 2024-07-19 10:14:49 +09:00
3 changed files with 18 additions and 16 deletions

View file

@ -2550,16 +2550,14 @@ int Process::sys$link(const char* old_path, const char* new_path)
return VFS::the().link(StringView(old_path), StringView(new_path), current_directory());
}
int Process::sys$unlink(const char* pathname)
int Process::sys$unlink(const char* user_path, size_t path_length)
{
String path;
{
SmapDisabler disabler;
if (!validate_read_str(pathname))
return -EFAULT;
path = pathname;
}
return VFS::the().unlink(path, current_directory());
if (!validate_read(user_path, path_length))
return -EFAULT;
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().unlink(path.value(), current_directory());
}
int Process::sys$symlink(const char* target, const char* linkpath)
@ -3591,15 +3589,19 @@ int Process::sys$mount(const char* device_path, const char* mountpoint, const ch
return result;
}
int Process::sys$umount(const char* mountpoint)
int Process::sys$umount(const char* user_mountpoint, size_t mountpoint_length)
{
if (!is_superuser())
return -EPERM;
if (!validate_read_str(mountpoint))
if (!validate_read(user_mountpoint, mountpoint_length))
return -EFAULT;
auto metadata_or_error = VFS::the().lookup_metadata(mountpoint, current_directory());
auto mountpoint = get_syscall_path_argument(user_mountpoint, mountpoint_length);
if (mountpoint.is_error())
return mountpoint.error();
auto metadata_or_error = VFS::the().lookup_metadata(mountpoint.value(), current_directory());
if (metadata_or_error.is_error())
return metadata_or_error.error();

View file

@ -177,11 +177,11 @@ public:
clock_t sys$times(tms*);
int sys$utime(const char* pathname, size_t path_length, const struct utimbuf*);
int sys$link(const char* old_path, const char* new_path);
int sys$unlink(const char* pathname);
int sys$unlink(const char* pathname, size_t path_length);
int sys$symlink(const char* target, const char* linkpath);
int sys$rmdir(const char* pathname, size_t path_length);
int sys$mount(const char* device, const char* mountpoint, const char* fstype);
int sys$umount(const char* mountpoint);
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);
int sys$chown(const char* pathname, uid_t, gid_t);

View file

@ -319,7 +319,7 @@ int link(const char* old_path, const char* new_path)
int unlink(const char* pathname)
{
int rc = syscall(SC_unlink, pathname);
int rc = syscall(SC_unlink, pathname, strlen(pathname));
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@ -572,7 +572,7 @@ int mount(const char* device, const char* mountpoint, const char* fstype)
int umount(const char* mountpoint)
{
int rc = syscall(SC_umount, mountpoint);
int rc = syscall(SC_umount, mountpoint, strlen(mountpoint));
__RETURN_WITH_ERRNO(rc, rc, -1);
}