3. התאמת המגבלות

מדיניות Sandbox מונעת מ-Sandboxee לקרוא ל-syscalls ספציפיים ולכן מצמצמת את שטח ההתקפה. עם זאת, תוקף עלול עדיין לגרום להשפעות לא רצויות על ידי הפעלת תהליך ללא הגבלת זמן או מיצוי של ה-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 זמינה בכלי לדוגמה.