#ifdef __linux__ #include "sandbox-internal.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static bool int_in(int* list, int len, int val) { for (int i=0;id_name, ".") == 0) continue; if (strcmp(dent->d_name, "..") == 0) continue; char* endp; long fd = strtol(dent->d_name, &endp, 10); if (dent->d_name==endp || *endp!='\0' || fd<0 || fd>=INT_MAX) { _exit(0); } if (fd != dirfd(dirp) && !int_in(allow_fd, n_allow_fd, (int)fd)) { close((int)fd); changed = true; } } closedir(dirp); } while (changed); } void sandbox_lockdown(int* allow_fd, int n_allow_fd) { prctl(PR_SET_DUMPABLE, false); prctl(PR_SET_TSC, PR_TSC_SIGSEGV); prctl(PR_SET_PDEATHSIG, SIGKILL); close_fds(allow_fd, n_allow_fd); //TODO: rlimit? prctl(PR_SET_NO_NEW_PRIVS, true); //TODO: seccomp //TODO: test vsyscall and vdso with seccomp enabled } #endif