mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52: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
|
@ -50,7 +50,12 @@ static int log_mask;
|
|||
static uint16_t log_id; /* Used for Windows EvtID */
|
||||
static int64_t log_fd = -1;
|
||||
|
||||
static const struct sockaddr_un log_addr = {AF_UNIX, "/dev/log"};
|
||||
static const char *const kLogPaths[] = {
|
||||
"/dev/log",
|
||||
// "/var/run/log", // TODO: Help with XNU and FreeBSD.
|
||||
};
|
||||
|
||||
static struct sockaddr_un log_addr = {AF_UNIX, "/dev/log"};
|
||||
|
||||
static int64_t Time(int64_t *tp) {
|
||||
struct timespec ts;
|
||||
|
@ -73,16 +78,20 @@ forceinline int is_lost_conn(int e) {
|
|||
}
|
||||
|
||||
static void __openlog() {
|
||||
int i;
|
||||
if (IsWindows()) {
|
||||
log_fd = RegisterEventSource(NULL, log_ident);
|
||||
} else {
|
||||
log_fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (log_fd >= 0) {
|
||||
int rc = connect(log_fd, (void *)&log_addr, sizeof(log_addr));
|
||||
if (rc < 0) {
|
||||
printf("ERR: connect(openlog) failed: %s (errno=%d)\n", strerror(errno),
|
||||
errno);
|
||||
for (i = 0; i < ARRAYLEN(kLogPaths); ++i) {
|
||||
strcpy(log_addr.sun_path, kLogPaths[i]);
|
||||
if (!connect(log_fd, (void *)&log_addr, sizeof(log_addr))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("ERR: connect(openlog) failed: %s (errno=%d)\n", strerror(errno),
|
||||
errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue