mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
Kernel: Use Userspace<T> for the setsockopt syscall
This commit is contained in:
parent
9f685ac30a
commit
6920d5f423
Notes:
sideshowbarker
2024-07-19 04:09:49 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/6920d5f4230 Pull-request: https://github.com/SerenityOS/serenity/pull/3039
7 changed files with 12 additions and 11 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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*>);
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue