3. ปรับขีดจำกัด

นโยบายแซนด์บ็อกซ์จะป้องกันไม่ให้ Sandboxee เรียก Syscall ที่เฉพาะเจาะจงและ จึงช่วยลดพื้นที่ในการโจมตี อย่างไรก็ตาม ผู้โจมตียังคงอาจทำให้เกิดผลที่ไม่พึงประสงค์ได้โดยการเรียกใช้กระบวนการอย่างไม่มีกำหนด หรือใช้ RAM และ ทรัพยากรอื่นๆ จนหมด

Sandboxee จะทำงานภายใต้ขีดจำกัดการดำเนินการที่เข้มงวดโดยค่าเริ่มต้นเพื่อรับมือกับภัยคุกคามนี้ หากขีดจํากัดเริ่มต้นเหล่านี้ทําให้เกิดปัญหาในการเรียกใช้โปรแกรมของคุณอย่างถูกต้อง คุณสามารถปรับขีดจํากัดได้โดยใช้คลาส sandbox2::Limits โดยการเรียกใช้ 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 ได้ที่เครื่องมือตัวอย่าง