From 8997c6a4d1f1047e53d640982568e1e45ed8f171 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Aug 2022 16:35:03 +0200 Subject: [PATCH] Kernel: Make Socket::connect() take credentials as input --- Kernel/Net/IPv4Socket.cpp | 2 +- Kernel/Net/IPv4Socket.h | 2 +- Kernel/Net/LocalSocket.cpp | 4 ++-- Kernel/Net/LocalSocket.h | 2 +- Kernel/Net/Socket.h | 2 +- Kernel/Syscalls/socket.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 439cc89e37..1a1aa8750d 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -138,7 +138,7 @@ ErrorOr IPv4Socket::listen(size_t backlog) return protocol_listen(result.did_allocate); } -ErrorOr IPv4Socket::connect(OpenFileDescription& description, Userspace address, socklen_t address_size) +ErrorOr IPv4Socket::connect(Credentials const&, OpenFileDescription& description, Userspace address, socklen_t address_size) { if (address_size != sizeof(sockaddr_in)) return set_so_error(EINVAL); diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h index 1376944f03..fa3a7c9e59 100644 --- a/Kernel/Net/IPv4Socket.h +++ b/Kernel/Net/IPv4Socket.h @@ -33,7 +33,7 @@ public: virtual ErrorOr close() override; virtual ErrorOr bind(Credentials const&, Userspace, socklen_t) override; - virtual ErrorOr connect(OpenFileDescription&, Userspace, socklen_t) override; + virtual ErrorOr connect(Credentials const&, OpenFileDescription&, Userspace, socklen_t) override; virtual ErrorOr listen(size_t) override; virtual void get_local_address(sockaddr*, socklen_t*) override; virtual void get_peer_address(sockaddr*, socklen_t*) override; diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 9415bb7ab1..d5820aad41 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -160,7 +160,7 @@ ErrorOr LocalSocket::bind(Credentials const& credentials, Userspace LocalSocket::connect(OpenFileDescription& description, Userspace user_address, socklen_t address_size) +ErrorOr LocalSocket::connect(Credentials const& credentials, OpenFileDescription& description, Userspace user_address, socklen_t address_size) { VERIFY(!m_bound); @@ -179,7 +179,7 @@ ErrorOr LocalSocket::connect(OpenFileDescription& description, Userspaceview(), O_RDWR, 0, Process::current().current_directory())); + auto file = SOCKET_TRY(VirtualFileSystem::the().open(credentials, path->view(), O_RDWR, 0, Process::current().current_directory())); auto inode = file->inode(); m_inode = inode; diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index 9b112aeca4..8174b235fd 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -37,7 +37,7 @@ public: // ^Socket virtual ErrorOr bind(Credentials const&, Userspace, socklen_t) override; - virtual ErrorOr connect(OpenFileDescription&, Userspace, socklen_t) override; + virtual ErrorOr connect(Credentials const&, OpenFileDescription&, Userspace, socklen_t) override; virtual ErrorOr listen(size_t) override; virtual void get_local_address(sockaddr*, socklen_t*) override; virtual void get_peer_address(sockaddr*, socklen_t*) override; diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index 22fc939346..4e0de6ec11 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -73,7 +73,7 @@ public: ErrorOr shutdown(int how); virtual ErrorOr bind(Credentials const&, Userspace, socklen_t) = 0; - virtual ErrorOr connect(OpenFileDescription&, Userspace, socklen_t) = 0; + virtual ErrorOr connect(Credentials const&, OpenFileDescription&, Userspace, socklen_t) = 0; virtual ErrorOr listen(size_t) = 0; virtual void get_local_address(sockaddr*, socklen_t*) = 0; virtual void get_peer_address(sockaddr*, socklen_t*) = 0; diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index bd45d54e7b..70eded6dc4 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -152,7 +152,7 @@ ErrorOr Process::sys$connect(int sockfd, Userspace use return ENOTSOCK; auto& socket = *description->socket(); REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain()); - TRY(socket.connect(*description, user_address, user_address_size)); + TRY(socket.connect(credentials(), *description, user_address, user_address_size)); return 0; }