Skip to content

Commit

Permalink
Kernel: Add pledge() syscall :^)
Browse files Browse the repository at this point in the history
This patch implements basic support for OpenBSD-style pledge().
pledge() allows programs to incrementally reduce their set of allowed
syscalls, which are divided into categories that each make up a subset
of POSIX functionality.

If a process violates one of its pledged promises by attempting to call
a syscall that it previously said it wouldn't call, the process is
immediately terminated with an uncatchable SIGABRT.

This is by no means complete, and we'll need to add more checks in
various places to ensure that promises are being kept.

But it is pretty cool! :^)
  • Loading branch information
awesomekling committed Jan 11, 2020
1 parent 529a65c commit 41c504a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Libraries/LibC/unistd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,16 @@ int chroot(const char* path)
int rc = syscall(SC_chroot, path, strlen(path));
__RETURN_WITH_ERRNO(rc, rc, -1);
}

int pledge(const char* promises, const char* execpromises)
{
Syscall::SC_pledge_params params {
{ promises, promises ? strlen(promises) : 0 },
{ execpromises, execpromises ? strlen(execpromises) : 0 }
};
int rc = syscall(SC_pledge, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
}

}

1 change: 1 addition & 0 deletions Libraries/LibC/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ int halt();
int reboot();
int mount(const char* source, const char* target, const char* fs_type, int flags);
int umount(const char* mountpoint);
int pledge(const char* promises, const char* execpromises);

enum {
_PC_NAME_MAX,
Expand Down

0 comments on commit 41c504a

Please sign in to comment.