Prevent Make from talking to public Internet

This change introduces the nointernet() function which may be called to
prevent a process and its descendants from communicating with publicly
routable Internet addresses. GNU Make has been modified to always call
this function. In the future Landlock Make will have a way to whitelist
subnets to override this behavior, or disable it entirely. Support is
available for Linux only. Our firewall does not require root access.

Calling nointernet() will return control to the caller inside a new
process that has a SECCOMP BPF filter installed, which traps network
related system calls. Your original process then becomes a permanent
ptrace() supervisor that monitors all processes and threads descending
from the returned child. Whenever a networking system call happens the
kernel will stop the process and wakes up the monitor, which then peeks
into the child memory to read the sockaddr_in to determine if it's ok.

The downside to doing this is that there can be only one supervisor at a
time using ptrace() on a process. So this firewall won't be enabled if
you run make under strace or inside gdb. It also makes testing tricky.
This commit is contained in:
Justine Tunney 2022-08-12 05:17:06 -07:00
parent 8a0a2c0c36
commit 7cf66bc161
48 changed files with 4924 additions and 2046 deletions

View file

@ -2,6 +2,7 @@
#define COSMOPOLITAN_TOOL_BUILD_LIB_MACHINE_H_
#include "libc/runtime/runtime.h"
#include "third_party/xed/x86.h"
#include "tool/build/lib/bits.h"
#include "tool/build/lib/fds.h"
#define kMachineHalt -1
@ -138,6 +139,7 @@ struct Machine {
uint64_t idt_base;
uint16_t gdt_limit;
uint16_t idt_limit;
uint32_t mxcsr;
struct MachineRealFree {
uint64_t i;
uint64_t n;
@ -161,12 +163,26 @@ struct Machine {
jmp_buf onhalt;
int64_t faultaddr;
bool dlab;
bool isfork;
bool ismetal;
struct MachineFds fds;
uint8_t stash[4096];
uint8_t icache[1024][40];
void (*onbinbase)(struct Machine *);
void (*onlongbranch)(struct Machine *);
void (*redraw)(void);
struct sigaction_bits sighand[28];
uint8_t sigmask[8];
int sig;
uint64_t siguc;
uint64_t sigfp;
struct {
int i, n;
struct {
int sig;
int code;
} p[64];
} signals;
} forcealign(64);
struct Machine *NewMachine(void) dontdiscard;