mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00

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.
2.1 KiB
2.1 KiB
Name
pledge - reduce process capabilities
Synopsis
#include <unistd.h>
int pledge(const char* promises, const char* execpromises);
Description
pledge()
makes a promise to the kernel that from this moment on, the calling process will only use a subset of system functionality.
Functionality is divided into a curated set of promises (described below), which can be combined to cover the program's needs. Both arguments are space-separated lists of promises.
Note that pledge()
can be called repeatedly to remove previously-pledged promises, but it can never regain capabilities once lost.
promises
are applied to the current process, and will also be inherited by children created by fork
(2).
execpromises
are applied if/when a new process image is created with exec(2)
.
If promises
or execpromises
is null, the corresponding value is unchanged.
Promises
stdio
: Basic I/O, memory allocation, information about self, various non-destructive syscallsthread
: The POSIX threading APIid
: Ability to change UID/GIDtty
: TTY related functionalityproc
: Process and scheduling related functionalityexec
: Theexec(2)
syscallunix
: UNIX local domain socketsinet
: IPv4 domain socketsaccept
: May useaccept(2)
to accept incoming socket connections on already listening sockets. It also allowsgetsockopt(2)
withSOL_SOCKET
andSO_PEERCRED
on local socketsrpath
: "Read" filesystem accesswpath
: "Write" filesystem accesscpath
: "Create" filesystem accessdpath
: Creating new device fileschown
: Changing file owner/groupfattr
: Changing file attributes/permissionsshared_buffer
: Shared memory bufferschroot
: Thechroot(2)
syscallvideo
: May useioctl(2)
andmmap(2)
on framebuffer video devices
Errors
EFAULT
:promises
and/orexecpromises
are not null and not in readable memory.EINVAL
: One or more invalid promises were specified.EPERM
: An attempt to increase capabilities was rejected.