diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-21 16:33:09 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-21 16:33:09 +0200 |
commit | 51318d51a4836753ea61e595c8e845858569ddc4 (patch) | |
tree | fc46e63fa084613e9bf1386e0950a4ab45578a45 | |
parent | 8d0bd3f225786c0ee36e0ec4297b8115290b709a (diff) | |
download | serenity-51318d51a4836753ea61e595c8e845858569ddc4.zip |
Kernel: Make Socket::bind() take credentials as input
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 6 | ||||
-rw-r--r-- | Kernel/Net/IPv4Socket.h | 2 | ||||
-rw-r--r-- | Kernel/Net/LocalSocket.cpp | 4 | ||||
-rw-r--r-- | Kernel/Net/LocalSocket.h | 2 | ||||
-rw-r--r-- | Kernel/Net/Socket.h | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/socket.cpp | 2 |
6 files changed, 9 insertions, 9 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 7f21ea5159..439cc89e37 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -94,7 +94,7 @@ void IPv4Socket::get_peer_address(sockaddr* address, socklen_t* address_size) *address_size = sizeof(sockaddr_in); } -ErrorOr<void> IPv4Socket::bind(Userspace<sockaddr const*> user_address, socklen_t address_size) +ErrorOr<void> IPv4Socket::bind(Credentials const& credentials, Userspace<sockaddr const*> user_address, socklen_t address_size) { VERIFY(setup_state() == SetupState::Unstarted); if (address_size != sizeof(sockaddr_in)) @@ -107,9 +107,9 @@ ErrorOr<void> IPv4Socket::bind(Userspace<sockaddr const*> user_address, socklen_ return set_so_error(EINVAL); auto requested_local_port = ntohs(address.sin_port); - if (!Process::current().is_superuser()) { + if (!credentials.is_superuser()) { if (requested_local_port > 0 && requested_local_port < 1024) { - dbgln("UID {} attempted to bind {} to port {}", Process::current().uid(), class_name(), requested_local_port); + dbgln("UID {} attempted to bind {} to port {}", credentials.uid(), class_name(), requested_local_port); return set_so_error(EACCES); } } diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h index 1eb3a9cca5..1376944f03 100644 --- a/Kernel/Net/IPv4Socket.h +++ b/Kernel/Net/IPv4Socket.h @@ -32,7 +32,7 @@ public: virtual ~IPv4Socket() override; virtual ErrorOr<void> close() override; - virtual ErrorOr<void> bind(Userspace<sockaddr const*>, socklen_t) override; + virtual ErrorOr<void> bind(Credentials const&, Userspace<sockaddr const*>, socklen_t) override; virtual ErrorOr<void> connect(OpenFileDescription&, Userspace<sockaddr const*>, socklen_t) override; virtual ErrorOr<void> listen(size_t) override; virtual void get_local_address(sockaddr*, socklen_t*) override; diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index a31c16e242..9415bb7ab1 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -122,7 +122,7 @@ void LocalSocket::get_peer_address(sockaddr* address, socklen_t* address_size) get_local_address(address, address_size); } -ErrorOr<void> LocalSocket::bind(Userspace<sockaddr const*> user_address, socklen_t address_size) +ErrorOr<void> LocalSocket::bind(Credentials const& credentials, Userspace<sockaddr const*> user_address, socklen_t address_size) { VERIFY(setup_state() == SetupState::Unstarted); if (address_size > sizeof(sockaddr_un)) @@ -139,7 +139,7 @@ ErrorOr<void> LocalSocket::bind(Userspace<sockaddr const*> user_address, socklen mode_t mode = S_IFSOCK | (m_prebind_mode & 0777); UidAndGid owner { m_prebind_uid, m_prebind_gid }; - auto result = VirtualFileSystem::the().open(Process::current().credentials(), path->view(), O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current().current_directory(), owner); + auto result = VirtualFileSystem::the().open(credentials, path->view(), O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current().current_directory(), owner); if (result.is_error()) { if (result.error().code() == EEXIST) return set_so_error(EADDRINUSE); diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index 51f57c76b5..9b112aeca4 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -36,7 +36,7 @@ public: ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const& description) const override; // ^Socket - virtual ErrorOr<void> bind(Userspace<sockaddr const*>, socklen_t) override; + virtual ErrorOr<void> bind(Credentials const&, Userspace<sockaddr const*>, socklen_t) override; virtual ErrorOr<void> connect(OpenFileDescription&, Userspace<sockaddr const*>, socklen_t) override; virtual ErrorOr<void> listen(size_t) override; virtual void get_local_address(sockaddr*, socklen_t*) override; diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index df17360dee..22fc939346 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -72,7 +72,7 @@ public: ErrorOr<void> shutdown(int how); - virtual ErrorOr<void> bind(Userspace<sockaddr const*>, socklen_t) = 0; + virtual ErrorOr<void> bind(Credentials const&, Userspace<sockaddr const*>, socklen_t) = 0; virtual ErrorOr<void> connect(OpenFileDescription&, Userspace<sockaddr const*>, socklen_t) = 0; virtual ErrorOr<void> listen(size_t) = 0; virtual void get_local_address(sockaddr*, socklen_t*) = 0; diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index f0491f1096..bd45d54e7b 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -56,7 +56,7 @@ ErrorOr<FlatPtr> Process::sys$bind(int sockfd, Userspace<sockaddr const*> addres return ENOTSOCK; auto& socket = *description->socket(); REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain()); - TRY(socket.bind(address, address_length)); + TRY(socket.bind(credentials(), address, address_length)); return 0; } |