mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-22 23:55:12 +00:00
Kernel: Add "accept" pledge promise for accepting incoming connections
This patch adds a new "accept" promise that allows you to call accept() on an already listening socket. This lets programs set up a socket for for listening and then dropping "inet" and/or "unix" so that only incoming (and existing) connections are allowed from that point on. No new outgoing connections or listening server sockets can be created. In addition to accept() it also allows getsockopt() with SOL_SOCKET and SO_PEERCRED, which is used to find the PID/UID/GID of the socket peer. This is used by our IPC library when creating shared buffers that should only be accessible to a specific peer process. This allows us to drop "unix" in WindowServer and LookupServer. :^) It also makes the debugging/introspection RPC sockets in CEventLoop based programs work again.
This commit is contained in:
@@ -3091,6 +3091,7 @@ int Process::sys$listen(int sockfd, int backlog)
|
||||
|
||||
int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* address_size)
|
||||
{
|
||||
REQUIRE_PROMISE(accept);
|
||||
if (!validate_write_typed(address_size))
|
||||
return -EFAULT;
|
||||
SmapDisabler disabler;
|
||||
@@ -3105,7 +3106,6 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a
|
||||
if (!accepting_socket_description->is_socket())
|
||||
return -ENOTSOCK;
|
||||
auto& socket = *accepting_socket_description->socket();
|
||||
REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain());
|
||||
if (!socket.can_accept()) {
|
||||
if (accepting_socket_description->is_blocking()) {
|
||||
if (current->block<Thread::AcceptBlocker>(*accepting_socket_description) != Thread::BlockResult::WokeNormally)
|
||||
@@ -3348,7 +3348,12 @@ int Process::sys$getsockopt(const Syscall::SC_getsockopt_params* params)
|
||||
if (!description->is_socket())
|
||||
return -ENOTSOCK;
|
||||
auto& socket = *description->socket();
|
||||
REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain());
|
||||
|
||||
if (has_promised(Pledge::accept) && socket.is_local() && level == SOL_SOCKET && option == SO_PEERCRED) {
|
||||
// We make an exception for SOL_SOCKET::SO_PEERCRED on local sockets if you've pledged "accept"
|
||||
} else {
|
||||
REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain());
|
||||
}
|
||||
return socket.getsockopt(*description, level, option, value, value_size);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user