2020-01-12 16:11:12 +01:00
## Name
pledge - reduce process capabilities
## Synopsis
```**c++
#include <unistd.h>
int pledge(const char* promises, const char* execpromises);
```
## Description
2020-01-12 19:07:49 +01:00
`pledge()` makes a promise to the kernel that from this moment on, the calling process will only use a subset of system functionality.
2020-01-12 16:11:12 +01:00
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) ](fork.md ).
2021-09-11 14:06:29 +02:00
`execpromises` are applied if/when a new process image is created with [`exec`(2) ](exec.md ).
2020-01-12 16:11:12 +01:00
If `promises` or `execpromises` is null, the corresponding value is unchanged.
2020-05-26 14:09:56 +03:00
If the process later attempts to use any system functionality it has previously promised *not* to use, the process is instantly terminated. Note that a process that has not ever called `pledge()` is considered to not have made any promises, and is allowed use any system functionality (subject to regular permission checks).
`pledge()` is intended to be used in programs that want to sandbox themselves, either to limit the impact of a possible vulnerability exploitation, or before intentionally executing untrusted code.
2020-01-12 16:11:12 +01:00
## Promises
2020-01-13 17:38:41 -08:00
* `stdio` : Basic I/O, memory allocation, information about self, various non-destructive syscalls
2020-01-23 10:37:58 +01:00
* `thread` : The POSIX threading API (\*)
2020-01-12 16:11:12 +01:00
* `id` : Ability to change UID/GID
2020-01-13 17:38:41 -08:00
* `tty` : TTY related functionality
2020-01-12 16:11:12 +01:00
* `proc` : Process and scheduling related functionality
2021-09-11 14:06:29 +02:00
* `exec` : The [`exec`(2) ](exec.md ) syscall
2020-01-12 16:11:12 +01:00
* `unix` : UNIX local domain sockets
* `inet` : IPv4 domain sockets
2021-09-11 14:06:29 +02:00
* `accept` : May use [`accept`(2) ](accept.md ) to accept incoming socket connections on already listening sockets (\*)
2020-01-12 16:11:12 +01:00
* `rpath` : "Read" filesystem access
* `wpath` : "Write" filesystem access
* `cpath` : "Create" filesystem access
* `dpath` : Creating new device files
* `chown` : Changing file owner/group
* `fattr` : Changing file attributes/permissions
2021-09-11 14:06:29 +02:00
* `chroot` : The [`chroot`(2) ](chroot.md ) syscall (\*)
* `video` : May use [`ioctl`(2) ](ioctl.md ) and [`mmap`(2) ](mmap.md ) on framebuffer video devices
2020-05-08 22:54:17 +02:00
* `settime` : Changing the system time and date
2020-06-19 21:15:25 +02:00
* `setkeymap` : Changing the system keyboard layout (\*)
2020-05-26 14:09:56 +03:00
* `sigaction` : Change signal handlers and dispositions (\*)
2020-06-25 10:54:57 +02:00
* `sendfd` : Send file descriptors over a local socket
* `recvfd` : Receive file descriptors over a local socket
2021-09-11 14:06:29 +02:00
* `ptrace` : The [`ptrace`(2) ](ptrace.md ) syscall (\*)
* `prot_exec` : [`mmap`(2) ](mmap.md ) and [`mprotect`(2) ](mprotect.md ) with `PROT_EXEC`
* `map_fixed` : [`mmap`(2) ](mmap.md ) with `MAP_FIXED` (\*)
2020-01-12 16:11:12 +01:00
2020-01-23 10:37:58 +01:00
Promises marked with an asterisk (\*) are SerenityOS specific extensions not supported by the original OpenBSD `pledge()` .
2020-01-12 16:11:12 +01:00
## Errors
* `EFAULT` : `promises` and/or `execpromises` are not null and not in readable memory.
* `EINVAL` : One or more invalid promises were specified.
* `EPERM` : An attempt to increase capabilities was rejected.
2020-01-23 10:37:58 +01:00
## History
The `pledge()` system call was first introduced by OpenBSD. The implementation in SerenityOS differs in many ways and is by no means final.
2020-05-04 19:47:21 +03:00
## See also
* [`unveil`(2) ](unveil.md )
2021-05-05 02:44:25 -07:00
* [`Mitigations`(7) ](../man7/Mitigations.md )