3. 한도 조정

샌드박스 정책은 Sandboxee가 특정 syscall을 호출하지 못하도록 방지하여 공격 표면을 줄입니다. 그러나 공격자는 프로세스를 무기한 실행하거나 RAM 및 기타 리소스를 소진하여 원치 않는 결과를 일으킬 수 있습니다.

이러한 위협을 해결하기 위해 Sandboxee는 기본적으로 엄격한 실행 제한을 적용해 실행됩니다. 이러한 기본 제한으로 인해 프로그램의 적법한 실행에 문제가 발생하는 경우 실행자 객체에서 limits()를 호출하여 sandbox2::Limits 클래스를 사용하여 제한을 조정할 수 있습니다.

아래의 코드 스니펫은 한도 조정의 몇 가지 예를 보여줍니다. 사용 가능한 모든 옵션은 limits.h 헤더 파일에 설명되어 있습니다.

// Restrict the address space size of the sandboxee to 4 GiB.
executor->limits()->set_rlimit_as(4ULL << 30);
// Kill sandboxee with SIGXFSZ if it writes more than 1 GiB to the filesystem.
executor->limits()->set_rlimit_fsize(1ULL << 30);
// Number of file descriptors which can be used by the sandboxee.
executor->limits()->set_rlimit_nofile(1ULL << 10);
// The sandboxee is not allowed to create core files.
executor->limits()->set_rlimit_core(0);
// Maximum 300s of real CPU time.
executor->limits()->set_rlimit_cpu(300);
// Maximum 120s of wall time.
executor->limits()->set_walltime_limit(absl::Seconds(120));

sandbox2::Limits 클래스 사용 예는 도구 예를 참고하세요.