mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-29 08:42:28 +00:00
Add seccomp bpf sandboxing to redbean
It's now possible to pass the `-S` or `-SS` flags to sandbox redbean worker proecsses after they've been forked. The first `-S` flag is intended to be a permissive builtin policy that limits system calls to only that which the various parts of redbean serving need. The second `-SS` flag is intended to be more restrictive, preventing things like the Lua extensions you download off the web from using the HTTP client or sockets APIs. In upcoming changes you'll be able to implement your own Berkeley Packet Filter sandbox programs and load them via Lua.
This commit is contained in:
parent
7166679620
commit
5a132f9652
79 changed files with 2271 additions and 651 deletions
|
@ -17,15 +17,29 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/issandboxed.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/struct/seccomp.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/sysv/consts/pr.h"
|
||||
#include "libc/sysv/consts/seccomp.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static const char *DescribeSeccompOperation(int x) {
|
||||
switch (x) {
|
||||
case SECCOMP_SET_MODE_STRICT:
|
||||
return "SECCOMP_SET_MODE_STRICT";
|
||||
case SECCOMP_SET_MODE_FILTER:
|
||||
return "SECCOMP_SET_MODE_FILTER";
|
||||
case SECCOMP_GET_ACTION_AVAIL:
|
||||
return "SECCOMP_GET_ACTION_AVAIL";
|
||||
case SECCOMP_GET_NOTIF_SIZES:
|
||||
return "SECCOMP_GET_NOTIF_SIZES";
|
||||
default:
|
||||
return "SECCOMP_???";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tunes Linux security policy.
|
||||
*
|
||||
|
@ -63,7 +77,7 @@ int seccomp(unsigned operation, unsigned flags, void *args) {
|
|||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
STRACE("seccomp(%s, %#x, %p) → %d% m",
|
||||
DescribeSeccompOperationFlags(operation), flags, args, rc);
|
||||
STRACE("seccomp(%s, %#x, %p) → %d% m", DescribeSeccompOperation(operation),
|
||||
flags, args, rc);
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue