diff options
author | Brian Gianforcaro <b.gianfo@gmail.com> | 2020-08-07 00:18:20 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-07 16:18:36 +0200 |
commit | 6920d5f4230ebcd4f1d29dc5d9288cf79861906f (patch) | |
tree | 823a2dc3d061f4ef9d4dbf5478004d99cf8d5dc6 | |
parent | 9f685ac30a4bc2ec55e581b5779e4a9c7172f1d1 (diff) | |
download | serenity-6920d5f4230ebcd4f1d29dc5d9288cf79861906f.zip |
Kernel: Use Userspace<T> for the setsockopt syscall
-rw-r--r-- | Kernel/API/Syscall.h | 2 | ||||
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 4 | ||||
-rw-r--r-- | Kernel/Net/IPv4Socket.h | 2 | ||||
-rw-r--r-- | Kernel/Net/Socket.cpp | 9 | ||||
-rw-r--r-- | Kernel/Net/Socket.h | 2 | ||||
-rw-r--r-- | Kernel/Process.h | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/socket.cpp | 2 |
7 files changed, 12 insertions, 11 deletions
diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index 7e2f031f52..3f676921f8 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -314,7 +314,7 @@ struct SC_setsockopt_params { int sockfd; int level; int option; - const void* value; + Userspace<const void*> value; socklen_t value_size; }; diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 1ed96d4bb0..6ae59ebad1 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -429,7 +429,7 @@ String IPv4Socket::absolute_path(const FileDescription&) const return builder.to_string(); } -KResult IPv4Socket::setsockopt(int level, int option, const void* user_value, socklen_t user_value_size) +KResult IPv4Socket::setsockopt(int level, int option, Userspace<const void*> user_value, socklen_t user_value_size) { if (level != IPPROTO_IP) return Socket::setsockopt(level, option, user_value, user_value_size); @@ -439,7 +439,7 @@ KResult IPv4Socket::setsockopt(int level, int option, const void* user_value, so if (user_value_size < sizeof(int)) return KResult(-EINVAL); int value; - if (!Process::current()->validate_read_and_copy_typed(&value, (const int*)user_value)) + if (!Process::current()->validate_read_and_copy_typed(&value, static_ptr_cast<const int*>(user_value))) return KResult(-EFAULT); if (value < 0 || value > 255) return KResult(-EINVAL); diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h index 4b22dc97b8..28b4c07500 100644 --- a/Kernel/Net/IPv4Socket.h +++ b/Kernel/Net/IPv4Socket.h @@ -60,7 +60,7 @@ public: virtual bool can_write(const FileDescription&, size_t) const override; virtual KResultOr<size_t> sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override; virtual KResultOr<size_t> recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override; - virtual KResult setsockopt(int level, int option, const void*, socklen_t) override; + virtual KResult setsockopt(int level, int option, Userspace<const void*>, socklen_t) override; virtual KResult getsockopt(FileDescription&, int level, int option, void*, socklen_t*) override; virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override; diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index 7cb4f6cdab..1c303373fc 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -101,24 +101,25 @@ KResult Socket::queue_connection_from(NonnullRefPtr<Socket> peer) return KSuccess; } -KResult Socket::setsockopt(int level, int option, const void* user_value, socklen_t user_value_size) +KResult Socket::setsockopt(int level, int option, Userspace<const void*> user_value, socklen_t user_value_size) { ASSERT(level == SOL_SOCKET); switch (option) { case SO_SNDTIMEO: if (user_value_size != sizeof(timeval)) return KResult(-EINVAL); - copy_from_user(&m_send_timeout, (const timeval*)user_value); + copy_from_user(&m_send_timeout, static_ptr_cast<const timeval*>(user_value)); return KSuccess; case SO_RCVTIMEO: if (user_value_size != sizeof(timeval)) return KResult(-EINVAL); - copy_from_user(&m_receive_timeout, (const timeval*)user_value); + copy_from_user(&m_receive_timeout, static_ptr_cast<const timeval*>(user_value)); return KSuccess; case SO_BINDTODEVICE: { if (user_value_size != IFNAMSIZ) return KResult(-EINVAL); - auto ifname = Process::current()->validate_and_copy_string_from_user((const char*)user_value, user_value_size); + auto user_string = static_ptr_cast<const char*>(user_value); + auto ifname = Process::current()->validate_and_copy_string_from_user(user_string, user_value_size); if (ifname.is_null()) return KResult(-EFAULT); auto device = NetworkAdapter::lookup_by_name(ifname); diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index e85cc6050e..f5481dac7f 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -110,7 +110,7 @@ public: virtual KResultOr<size_t> sendto(FileDescription&, const void*, size_t, int flags, const sockaddr*, socklen_t) = 0; virtual KResultOr<size_t> recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) = 0; - virtual KResult setsockopt(int level, int option, const void*, socklen_t); + virtual KResult setsockopt(int level, int option, Userspace<const void*>, socklen_t); virtual KResult getsockopt(FileDescription&, int level, int option, void*, socklen_t*); pid_t origin_pid() const { return m_origin.pid; } diff --git a/Kernel/Process.h b/Kernel/Process.h index 9ad270c60d..b086926a8d 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -296,7 +296,7 @@ public: ssize_t sys$sendto(const Syscall::SC_sendto_params*); ssize_t sys$recvfrom(const Syscall::SC_recvfrom_params*); int sys$getsockopt(const Syscall::SC_getsockopt_params*); - int sys$setsockopt(const Syscall::SC_setsockopt_params*); + int sys$setsockopt(Userspace<const Syscall::SC_setsockopt_params*>); int sys$getsockname(Userspace<const Syscall::SC_getsockname_params*>); int sys$getpeername(Userspace<const Syscall::SC_getpeername_params*>); int sys$sched_setparam(pid_t pid, Userspace<const struct sched_param*>); diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index 89535c0798..234fe56e16 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -348,7 +348,7 @@ int Process::sys$getsockopt(const Syscall::SC_getsockopt_params* params) return socket.getsockopt(*description, level, option, value, value_size); } -int Process::sys$setsockopt(const Syscall::SC_setsockopt_params* user_params) +int Process::sys$setsockopt(Userspace<const Syscall::SC_setsockopt_params*> user_params) { Syscall::SC_setsockopt_params params; if (!validate_read_and_copy_typed(¶ms, user_params)) |