JFLib

plat/sandbox.rs#

Source: lib/plat/sandbox.rs

sandbox -- OS-level confinement that mirrors the permission manifest (docs/PERMISSIONS.md
"OS sandbox"), as defence in depth for the in-process policy (policy.rs): a bug or native
code can bypass `plat`, the kernel cannot be bypassed.  Opt in with a `sandbox` (best effort)
or `sandbox strict` (refuse to start when the OS cannot enforce it) line in the manifest.

  apply()          install the sandbox for the active policy, once, at start-up (boot.rs,
                   before the app's own code runs); nothing without a `sandbox` line
  status() -> Status   what was applied (tests, a diagnostics page)

Linux: Landlock restricts the filesystem to the folders the manifest grants plus the system
paths the library reads (ABI detected, best effort on older kernels), and TCP bind / connect
to the manifest's ports (ABI 4+); seccomp-bpf denies a list of dangerous syscalls (ptrace,
process_vm_*, kexec, module loading, mount, bpf, perf_event_open, userfaultfd, keyctl ...)
and execve when no program is allowed.  Windows: process mitigation policies (image load,
extension points, dynamic code; strict adds child-process creation, strict handle checks are
deliberately not set: win_sandbox.rs).  The browser and Android have no such API; apply() does
nothing there.
  • struct Status what [apply] installed (the fields not relevant to this OS stay false / -1)
    • level: u8 -- 0 none, 1 sandbox, 2 sandbox strict
    • landlock_abi: i32 -- Linux: the Landlock ABI the kernel reports (-1 = no Landlock)
    • landlock_fs: bool -- Linux: the filesystem ruleset is enforced
    • landlock_net: bool -- Linux: TCP bind / connect is restricted (Landlock ABI 4+)
    • seccomp: bool -- Linux: the seccomp filter is installed
    • exec_denied: bool -- execve is denied (no program allowed): Linux seccomp, Windows child-process policy
    • win_mitigations: bool -- Windows: the process mitigation policies were set
    • win_dynamic_code: bool -- Windows: dynamic code is prohibited (no native plugins)

impl Status

  • const NONE: Status = Status { level: 0, landlock_abi: -1, landlock_fs: false, ... nothing applied

  • fn apply() (Linux) install the OS sandbox the active policy asks for (nothing without a sandbox line); call once, before the app's own code and before any worker thread is started

  • fn apply() (Windows) install the OS sandbox the active policy asks for (nothing without a sandbox line)

  • fn apply() the browser and Android have no such API

  • fn status() -> Status what [apply] installed

  • fn status() -> Status the browser and Android install nothing

  • fn denied_syscalls() -> &'static [usize] (Linux) (Linux) the system calls the seccomp filter answers with EPERM; execve and execveat come on top when the manifest allows no program (sandboxtest calls every one of them)

Source: docs/API.md in the JFLib repository.