diff --git a/Kernel/Process.h b/Kernel/Process.h index f212074fc2..64feb852a0 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -294,7 +294,7 @@ public: ErrorOr sys$open(Userspace); ErrorOr sys$close(int fd); ErrorOr sys$read(int fd, Userspace, size_t); - ErrorOr sys$pread(int fd, Userspace, size_t, off_t); + ErrorOr sys$pread(int fd, Userspace, size_t, Userspace); ErrorOr sys$readv(int fd, Userspace iov, int iov_count); ErrorOr sys$write(int fd, Userspace, size_t); ErrorOr sys$writev(int fd, Userspace iov, int iov_count); diff --git a/Kernel/Syscalls/read.cpp b/Kernel/Syscalls/read.cpp index 4dc7b0d15a..a001285925 100644 --- a/Kernel/Syscalls/read.cpp +++ b/Kernel/Syscalls/read.cpp @@ -90,7 +90,7 @@ ErrorOr Process::sys$read(int fd, Userspace buffer, size_t size) return TRY(description->read(user_buffer.value(), size)); } -ErrorOr Process::sys$pread(int fd, Userspace buffer, size_t size, off_t offset) +ErrorOr Process::sys$pread(int fd, Userspace buffer, size_t size, Userspace userspace_offset) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(stdio); @@ -98,6 +98,8 @@ ErrorOr Process::sys$pread(int fd, Userspace buffer, size_t size, return 0; if (size > NumericLimits::max()) return EINVAL; + off_t offset; + TRY(copy_from_user(&offset, userspace_offset)); if (offset < 0) return EINVAL; dbgln_if(IO_DEBUG, "sys$pread({}, {}, {}, {})", fd, buffer.ptr(), size, offset); diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index 88d28f759d..c08c377998 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -296,7 +296,7 @@ ssize_t read(int fd, void* buf, size_t count) ssize_t pread(int fd, void* buf, size_t count, off_t offset) { - int rc = syscall(SC_pread, fd, buf, count, offset); + int rc = syscall(SC_pread, fd, buf, count, &offset); __RETURN_WITH_ERRNO(rc, rc, -1); }