3. 한도 조정

샌드박스 정책은 샌드박스에서 특정 시스템 호출을 호출하는 것을 방지하므로 공격 노출 영역이 줄어듭니다. 하지만 공격자는 프로세스를 무기한 실행하거나 RAM 및 기타 리소스를 소진하여 원치 않는 효과를 유발할 수 있습니다.

이 위협에 대응하기 위해 샌드박스 앱은 기본적으로 엄격한 실행 제한을 적용받습니다. 이러한 기본 제한으로 인해 프로그램의 적법한 실행에 문제가 발생하는 경우 실행기 객체에서 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 클래스 사용 예는 tool 예시를 참고하세요.