2022-10-02 16:06:27 +08:00
|
|
|
#include "resource.h"
|
2022-10-02 14:09:25 +08:00
|
|
|
#include "rules/lang.h"
|
|
|
|
#include "sandbox.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
|
2022-10-09 12:44:09 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-10-02 14:09:25 +08:00
|
|
|
static __attribute__((constructor)) void inject(void) {
|
2022-10-20 15:44:03 +08:00
|
|
|
char comm[64];
|
|
|
|
int fd = open("/proc/self/comm", O_RDONLY);
|
|
|
|
ssize_t len = read(fd, comm, sizeof(comm));
|
|
|
|
len = len > 0 ? len - 1 : 0;
|
|
|
|
comm[len] = '\0';
|
2022-10-09 12:44:09 +08:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
LOG_INFO("Setting up sandbox for %s(%d)", comm, getpid());
|
|
|
|
|
2022-10-09 20:19:25 +08:00
|
|
|
register_lang_c_cpp();
|
2022-10-02 16:06:27 +08:00
|
|
|
setup_rlimit();
|
2022-10-02 14:09:25 +08:00
|
|
|
setup_seccomp();
|
|
|
|
}
|