3. 上限を調整する
サンドボックス ポリシーにより、サンドボックス化されたプロセスが特定のシステムコールを呼び出すことができなくなり、攻撃対象領域が縮小されます。ただし、攻撃者はプロセスを無期限に実行したり、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
クラスの使用例については、ツールの例をご覧ください。