Algorithm Search⌘K

Techniquecore

Software fault isolation

Also called SFI, address sandboxing.

Rewrites untrusted machine code so that every store and jump is masked or checked to stay inside its own region of memory.

Software fault isolation (SFI) runs untrusted code in the same address space as trusted code, but confines it to its own region of memory, called a fault domain, without help from the hardware's memory protection. A rewriter changes the untrusted machine code so that every store and every indirect jump uses an address that is first forced into the domain or checked against it, and a verifier checks the rewritten code before it is loaded. Wahbe, Lucco, Anderson and Graham (SOSP 1993) introduced the idea for RISC processors. A fault domain is a code segment and a data segment, each a range of addresses whose upper bits are the segment identifier. Segment matching checks the upper bits of each unsafe address and traps on a mismatch. Address sandboxing does not check: it sets the upper bits to the segment identifier with an AND and an OR, two instructions before each unsafe store or jump, so a wrong address is moved into the domain instead. The key design point is a dedicated register that only the sandboxing code may write: since it always holds an address in the domain, the code stays safe even if a jump lands right after the check. They measured an average overhead of 4 percent on a test suite that included the C SPEC92 benchmarks, far below the cost of switching hardware address spaces for each call. Native Client (2009) later applied the method to x86 code in a browser, and SFI is the classic example of an inline reference monitor.

In plain words

Suppose a program must run a plug-in that it does not trust. The usual answer is to put the plug-in in a separate process, but then every call between them is slow.

SFI keeps the plug-in in the same process and gives it one area of memory. Before the plug-in is loaded, its code is changed: in front of every instruction that writes memory or jumps through a pointer, a small step is added that forces the address into the plug-in's area. A checker then reads the changed code and refuses it if any write or jump could skip that step.

Now even a broken or hostile plug-in can only damage its own area. The checks cost a few instructions each, much less than switching between processes.

When it applies

  • The threat is an untrusted module in the same address space: a plug-in, a driver, a database extension or code from the web. The module may be buggy or hostile, and it controls every value it computes.
  • Calls across the boundary are frequent, so separate address spaces with hardware protection would cost too much.
  • The code can be rewritten and verified before it runs, by a compiler that emits sandboxed code, by a binary rewriter, or by a loader that rejects code that does not follow the rules.
  • The instruction set allows a reliable verifier. On RISC processors, instructions have one length and one alignment, so the verifier sees every instruction. On x86, instructions have many lengths, so the system must restrict where jumps may land, as Native Client does with aligned bundles.
  • Code cannot be changed after verification. The code segment is not writable and data is not executable, as data execution prevention provides.

The template

The defense has a rewriter that inserts the sandboxing steps and a verifier that the loader runs. The named holes are the choices of each system. The block shows the confinement of stores; indirect jumps are confined in the same way, with the code segment and a second dedicated register.

  1. REWRITE(module M, segment identifier g, offset bits m)
  2. 1reserve a dedicated register d that M does not use; the loader sets d to an address in the domain
  3. 2for each store through a register a in M whose address is not known to be in the domain do
  4. 3⟨address sandboxing⟩: d ← (a AND (2^m - 1)) OR (g · 2^m) ▷ two instructions, no branch
  5. 4or ⟨segment matching⟩: if a >> m ≠ g then trap; d ← a ▷ a compare and a branch
  6. 5store through d instead of a
  7. VERIFY(rewritten module M′)
  8. 6if any instruction of M′ other than a sandboxing step writes d then reject
  9. 7if any store goes through a register other than d, or a direct jump leaves M′, then reject
  10. 8accept

Walk-through. Line L1 reserves the dedicated register. Lines L2 to L5 rewrite each unsafe store. Address sandboxing at line L3 keeps the low mm bits of the address and replaces the upper bits by gg, so the result is in the domain whatever the value of aa. Segment matching at line L4 checks the upper bits instead, which costs a branch but reports the error. Line L5 makes the store use the dedicated register. Lines L6 and L7 are the verifier: it does not trust the rewriter, so a module from any source is safe once it passes. Wahbe et al. used four dedicated registers for segment matching and five for address sandboxing, for data and code addresses and their segment values.

Correctness. The verifier gives the invariant that dd always holds an address in the domain. At load time the loader sets dd in the domain. Only a sandboxing step may write dd (line L6), and every such step leaves an address in the domain or traps. Jumps change no register. So the invariant holds at every instruction, even at a store that a jump reached directly, skipping the step before it. Since every store goes through dd (line L7), every store writes inside the domain, whatever values the module computes. A second theorem says that the rewriting is transparent: a run of the original module whose stores were all in the domain makes the same stores after rewriting. The full proofs are in the proof file.

Example. Take w=16w = 16-bit words, m=10m = 10 offset bits and segment identifier g=5g = 5, so the domain is the addresses 5120 to 6143. A module sets a←3a \leftarrow 3 and b←7b \leftarrow 7 and stores bb at the address in aa. Address 3 is outside the domain. After rewriting with address sandboxing, the store goes through d=(3∧1023)∨5120=5123d = (3 \wedge 1023) \vee 5120 = 5123, inside the domain; the module wrote the wrong cell of its own domain, but no cell of anyone else. With segment matching, the step at line L4 sees that 3≫10=0≠53 \gg 10 = 0 \ne 5 and traps before the store.

Cost. In the word RAM model each sandboxed store costs O(1)O(1) extra operations, and the rewriter and the verifier each take O(n)O(n) time for nn instructions. The measured cost is in the lead: an average of 4 percent in the 1993 study, on a DECstation and an Alpha. A call across the boundary costs a jump through a trusted stub, which is why SFI beats separate processes when calls are frequent.

Code. The Python file impl/python/software_fault_isolation.py has the rewriter, the verifier and an interpreter for an abstract register machine with stores, loads, direct and indirect jumps. The tests run random verified modules with random registers and check every store address against the domain, and compare rewritten and original runs.

Classic examples

  • The original design (1993). Wahbe et al. rewrote code for MIPS and Alpha processors, used segment matching or address sandboxing with dedicated registers, and gave a verifier that checks the rewritten object code. Their goal was fast communication between modules in one address space.
  • Native Client (2009). Yee et al. ran untrusted x86 code in a web browser. Since x86 instructions have variable length, the validator requires that code be split into fixed-size aligned bundles, that no instruction cross a bundle boundary, and that indirect jumps go only to bundle starts. Then the validator's disassembly sees every instruction that can run. Data accesses were confined with the segment registers of 32-bit x86.
  • SFI on top of CFI. Abadi et al. showed that control-flow integrity makes SFI simpler: if every jump is known to follow the control flow graph, a check before a store cannot be skipped, so no dedicated register is needed for that purpose.
  • An inline reference monitor. SFI enforces a safety property (no store outside the domain) by checks inserted into the code itself, which is the general pattern of inline monitors and of policies given as a security automaton.
  • Safer extensions in other forms. Proof-carrying code replaces the rewriter by a proof that the code is safe, checked by the loader. The goal is the same: let untrusted code run at full speed in a trusted process.

Variations

  • Stores and jumps only, or loads too. Confining only stores and jumps protects integrity, which was the cheaper choice in the 1993 study. Confining loads as well also protects secrecy, at a higher cost.
  • Guard zones. If a store adds a small constant offset to a sandboxed register, the result may fall just outside the domain. Placing unmapped guard pages around the domain makes such stores fault, so the constant need not be sandboxed.
  • Hardware assistance. Segment registers on 32-bit x86, memory protection keys, or large reserved regions of a 64-bit address space with guard pages can replace some of the software checks.
  • Verified and formally proved sandboxes. Later work proved the safety of an SFI design for x86 with a mechanical proof, and modern sandboxes for portable bytecode compile it to native code with the same kind of address confinement.
  • Isolation for other defenses. Code-pointer integrity needs its safe region to be out of reach of regular accesses; SFI-style masking of those accesses is one way to provide it.

Pitfalls

  • A verifier that trusts the rewriter. The point of the design is that the loader checks the code itself. A verifier must reject any store or jump that does not use a dedicated register, whoever produced the code.
  • Jumps into the middle of instructions. On variable-length instruction sets, a jump to an unintended offset can decode as a different instruction stream that the verifier never saw. Alignment rules for jump targets, as in Native Client, close this.
  • Writable code. If the module can write its own code segment, it can remove the checks after verification. Code must be non-writable, and code generated at run time must be verified before it can run.
  • Forgetting the boundary. The calls from the module into trusted code, and the values passed across, are part of the attack surface. Trusted stubs must check their arguments.
  • Leaks through loads. A design that confines only stores lets the module read the rest of the process. If the process holds secrets, confine loads too.
  • Side channels. SFI confines architectural accesses. Speculative execution can read outside the domain without any store or architectural load; see the Spectre attack.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

software_fault_isolation.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/software-fault-isolation/. The authors are listed in prov/BDGPFB.jsonl.

"""Software fault isolation of stores on an abstract register machine.

The model has no real machine code. A module is a list of instructions on
registers that hold w-bit words. Its fault domain is the segment of addresses
whose upper w - m bits equal the segment identifier g. The rewriter puts a
sandboxing step before every store, the verifier checks the result, and the
interpreter runs a module with any initial registers, which models an
attacker who controls every value the module computes.

Instructions:
    ("li", r, k)          r <- k
    ("add", r, a, b)      r <- (a + b) mod 2**w
    ("load", r, a)        r <- mem[a]          (loads are not confined here)
    ("store", a, v)       mem[a] <- v
    ("sandbox", d, a)     d <- (a AND (2**m - 1)) OR (g * 2**m)
    ("check", d, a)       fault unless a >> m == g; then d <- a
    ("jnz", c, k)         if c != 0 then go to instruction k
    ("ijump", a)          go to instruction a, fault if a is not an index
    ("halt",)
"""

from collections.abc import Mapping, Sequence

Instr = tuple

_WRITES_FIRST = {"li", "add", "load", "sandbox", "check"}


class SFIError(Exception):
    """Raised by rewrite when the module already uses the dedicated register."""


def sandbox_address(a: int, g: int, m: int) -> int:
    """Force the address a into segment g: keep the low m bits, set the segment bits."""
    return (a & ((1 << m) - 1)) | (g << m)


def in_segment(a: int, g: int, m: int) -> bool:
    return a >> m == g


def rewrite(module: Sequence[Instr], d: str, mode: str = "mask") -> list[Instr]:
    """Insert a sandboxing step before each store that does not use d.

    mode "mask" is address sandboxing and mode "check" is segment matching.
    Direct jump targets are renumbered. Time O(n) for n instructions.
    Precondition: the module does not mention the dedicated register d.
    """
    if mode not in ("mask", "check"):
        raise ValueError("mode must be 'mask' or 'check'")
    for ins in module:
        if d in ins[1:]:
            raise SFIError(f"the module uses the dedicated register {d!r}")  # @line L1
    new_index: list[int] = []
    pos = 0
    for ins in module:
        new_index.append(pos)
        pos += 2 if ins[0] == "store" else 1
    out: list[Instr] = []
    for ins in module:  # @line L2
        if ins[0] == "store":  # @line L2
            _, a, v = ins
            if mode == "mask":
                out.append(("sandbox", d, a))  # @line L3
            else:
                out.append(("check", d, a))  # @line L4
            out.append(("store", d, v))  # @line L5
        elif ins[0] == "jnz":
            out.append(("jnz", ins[1], new_index[ins[2]] if ins[2] < len(module) else pos))
        else:
            out.append(ins)
    return out


def verify(module: Sequence[Instr], d: str) -> bool:
    """Accept only modules in which every store goes through d and only a
    sandboxing step writes d. Time O(n). This is the check a loader runs
    before it trusts a module, so it must not depend on the rewriter."""
    n = len(module)
    for ins in module:
        op = ins[0]
        if op in _WRITES_FIRST and ins[1] == d and op not in ("sandbox", "check"):
            return False  # @line L6
        if op == "store" and ins[1] != d:
            return False  # @line L7
        if op == "jnz" and not 0 <= ins[2] <= n:
            return False  # @line L7
    return True  # @line L8


def run(
    module: Sequence[Instr],
    regs: Mapping[str, int],
    g: int,
    m: int,
    w: int = 16,
    budget: int = 200,
) -> tuple[str, list[tuple[int, int]]]:
    """Run a module and return (status, stores), with stores as (address, value).

    status is "halt", "fault" or "budget". The memory starts as all zeros and
    a register that was never set reads 0. Time O(budget).
    """
    r = dict(regs)
    mem: dict[int, int] = {}
    stores: list[tuple[int, int]] = []
    word = (1 << w) - 1
    pc = 0
    n = len(module)
    for _ in range(budget):
        if not 0 <= pc < n:
            return "halt", stores
        ins = module[pc]
        op = ins[0]
        pc += 1
        if op == "li":
            r[ins[1]] = ins[2] & word
        elif op == "add":
            r[ins[1]] = (r.get(ins[2], 0) + r.get(ins[3], 0)) & word
        elif op == "load":
            r[ins[1]] = mem.get(r.get(ins[2], 0), 0)
        elif op == "store":
            a, v = r.get(ins[1], 0), r.get(ins[2], 0)
            mem[a] = v
            stores.append((a, v))
        elif op == "sandbox":
            r[ins[1]] = sandbox_address(r.get(ins[2], 0), g, m)
        elif op == "check":
            a = r.get(ins[2], 0)
            if not in_segment(a, g, m):
                return "fault", stores
            r[ins[1]] = a
        elif op == "jnz":
            if r.get(ins[1], 0) != 0:
                pc = ins[2]
        elif op == "ijump":
            t = r.get(ins[1], 0)
            if not 0 <= t < n:
                return "fault", stores
            pc = t
        elif op == "halt":
            return "halt", stores
        else:
            raise ValueError(f"unknown instruction {op!r}")
    return "budget", stores
test_software_fault_isolation.py 165 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/software-fault-isolation/. The authors are listed in prov/BDGPFB.jsonl.

import random

import pytest

from software_fault_isolation import SFIError, rewrite, run, sandbox_address, verify

G, M, W = 5, 10, 16
REGS = ["a", "b", "c"]
D = "d"


def in_domain(address: int) -> bool:
    """Independent oracle: the address lies in [G * 2**M, (G + 1) * 2**M)."""
    return G * 2**M <= address < (G + 1) * 2**M


def random_module(rng: random.Random, allow_ijump: bool = True, allow_load: bool = True) -> list:
    n = rng.randint(1, 10)
    ops = ["li", "add", "store", "store", "jnz", "halt"]
    if allow_ijump:
        ops.append("ijump")
    if allow_load:
        ops.append("load")
    module = []
    for _ in range(n):
        op = rng.choice(ops)
        r1, r2, r3 = (rng.choice(REGS) for _ in range(3))
        if op == "li":
            module.append(("li", r1, rng.randrange(2**W)))
        elif op == "add":
            module.append(("add", r1, r2, r3))
        elif op == "load":
            module.append(("load", r1, r2))
        elif op == "store":
            module.append(("store", r1, r2))
        elif op == "jnz":
            module.append(("jnz", r1, rng.randint(0, n)))
        elif op == "ijump":
            module.append(("ijump", r1))
        else:
            module.append(("halt",))
    return module


def random_regs(rng: random.Random) -> dict:
    regs = {r: rng.randrange(2**W) for r in REGS}
    regs[D] = G * 2**M + rng.randrange(2**M)
    return regs


EXAMPLE = [("li", "a", 3), ("li", "b", 7), ("store", "a", "b"), ("halt",)]


def test_example_of_the_page() -> None:
    assert run(EXAMPLE, {}, G, M) == ("halt", [(3, 7)])
    masked = rewrite(EXAMPLE, D, "mask")
    assert masked == [("li", "a", 3), ("li", "b", 7), ("sandbox", D, "a"), ("store", D, "b"), ("halt",)]
    assert run(masked, {D: G * 2**M}, G, M) == ("halt", [(5123, 7)])
    checked = rewrite(EXAMPLE, D, "check")
    assert run(checked, {D: G * 2**M}, G, M) == ("fault", [])


def test_sandbox_address_values() -> None:
    assert sandbox_address(3, G, M) == 5123
    assert sandbox_address(5123, G, M) == 5123
    assert sandbox_address(2**W - 1, G, M) == G * 2**M + 2**M - 1


def test_verifier_decisions() -> None:
    assert not verify(EXAMPLE, D)
    assert verify(rewrite(EXAMPLE, D), D)
    assert not verify([("li", D, 3), ("store", D, "b")], D)
    assert not verify([("add", D, "a", "b")], D)
    assert not verify([("load", D, "a")], D)
    assert not verify([("jnz", "a", 9)], D)
    assert verify([("store", D, "b"), ("sandbox", D, "a"), ("halt",)], D)


def test_rewrite_rejects_module_using_dedicated_register() -> None:
    with pytest.raises(SFIError):
        rewrite([("li", D, 1)], D)
    with pytest.raises(ValueError):
        rewrite(EXAMPLE, D, "other")


def test_jump_past_the_sandbox_step_stays_in_domain() -> None:
    # Jump straight to the store, skipping the sandbox step: d still holds a domain address.
    module = rewrite([("li", "a", 0), ("store", "a", "b"), ("halt",)], D)
    module = [("li", "c", 4), ("ijump", "c")] + module
    assert module[4] == ("store", D, "b")
    assert verify(module, D)
    status, stores = run(module, {D: G * 2**M + 17, "b": 9}, G, M)
    assert status == "halt"
    assert stores == [(G * 2**M + 17, 9)]


def test_rewritten_modules_store_only_in_domain() -> None:
    rng = random.Random(1993)
    for _ in range(800):
        module = random_module(rng)
        for mode in ("mask", "check"):
            out = rewrite(module, D, mode)
            assert verify(out, D)
            for _ in range(3):
                _, stores = run(out, random_regs(rng), G, M)
                assert all(in_domain(a) for a, _ in stores)


def test_any_verified_module_stores_only_in_domain() -> None:
    rng = random.Random(2009)
    checked = 0
    while checked < 600:
        module = random_module(rng)
        # Turn some stores into stores through d and scatter sandbox steps at random places.
        mixed = []
        for ins in module:
            if ins[0] == "store" and rng.random() < 0.8:
                ins = ("store", D, ins[2])
            if rng.random() < 0.3:
                mixed.append(("sandbox", D, rng.choice(REGS)))
            mixed.append(ins)
        mixed = [("jnz", i[1], min(i[2], len(mixed))) if i[0] == "jnz" else i for i in mixed]
        if not verify(mixed, D):
            assert any(i[0] == "store" and i[1] != D for i in mixed)
            continue
        checked += 1
        for _ in range(3):
            _, stores = run(mixed, random_regs(rng), G, M)
            assert all(in_domain(a) for a, _ in stores)


def test_transparent_when_stores_are_already_in_domain() -> None:
    rng = random.Random(1308)
    compared = 0
    for _ in range(3000):
        module = random_module(rng, allow_ijump=False)
        regs = random_regs(rng)
        status, stores = run(module, regs, G, M, budget=100)
        if status != "halt" or not all(in_domain(a) for a, _ in stores):
            continue
        compared += 1
        for mode in ("mask", "check"):
            assert run(rewrite(module, D, mode), regs, G, M, budget=200) == (status, stores)
    assert compared >= 500


def test_mask_maps_stores_and_check_faults_without_loads() -> None:
    rng = random.Random(4242)
    for _ in range(800):
        module = random_module(rng, allow_ijump=False, allow_load=False)
        regs = random_regs(rng)
        status, stores = run(module, regs, G, M, budget=100)
        if status != "halt":
            continue
        masked = run(rewrite(module, D, "mask"), regs, G, M, budget=200)
        assert masked == ("halt", [(sandbox_address(a, G, M), v) for a, v in stores])
        checked = run(rewrite(module, D, "check"), regs, G, M, budget=200)
        bad = [k for k, (a, _) in enumerate(stores) if not in_domain(a)]
        if bad:
            assert checked == ("fault", stores[: bad[0]])
        else:
            assert checked == ("halt", stores)

Exercises

  1. With w=16w = 16, m=10m = 10 and g=5g = 5, compute the result of address sandboxing at line L3 for the addresses 0, 5120, 6143, 6144 and 65535. Which of them does segment matching at line L4 accept?
  2. Prove Lemma 1 of the proof file: for every word aa, the value (a∧(2m−1))∨g⋅2m(a \wedge (2^m - 1)) \vee g \cdot 2^m lies in the domain when g<2w−mg < 2^{w - m}.
  3. A variant of the rewriter sandboxes the address into the register aa itself, a←(a∧(2m−1))∨g⋅2ma \leftarrow (a \wedge (2^m - 1)) \vee g \cdot 2^m, and then stores through aa. Give a module and a jump that store outside the domain under this variant, and explain which line of the verifier the dedicated register replaces.
  4. A store writes to d+kd + k for a constant kk with 0≤k<2120 \le k < 2^{12}. How large must the guard zones around the domain be so that every such store either lands in the domain or faults?
Proof: A verified module stores only inside its fault domain, whatever its data and its jumpsfull

The model. Words have ww bits. The fault domain of a module is the set of addresses aa with ⌊a/2m⌋=g\lfloor a / 2^m \rfloor = g, for a segment identifier gg with 0≤g<2w−m0 \le g < 2^{w - m}; write dom(a)\mathrm{dom}(a) for this condition. A module is a finite list of instructions on registers, with the instruction set of the code file: constant loads, additions, loads, stores, the two sandboxing steps SANDBOX(d,a)(d, a) (line L3) and CHECK(d,a)(d, a) (line L4), conditional direct jumps, indirect jumps and halt. The register dd is the dedicated register. A run starts with any values in the registers other than dd and any memory contents, which models an attacker who controls every value the module computes, and with dd set to some address in the domain by the trusted loader.

Lemma 1 (the sandboxing steps). For every word aa, dom((a∧(2m−1))∨g⋅2m)\mathrm{dom}\big((a \wedge (2^m - 1)) \vee g \cdot 2^m\big) holds. CHECK(d,a)(d, a) either faults or sets dd to a value aa with dom(a)\mathrm{dom}(a).

Proof. The value a∧(2m−1)a \wedge (2^m - 1) is below 2m2^m and has no bits at positions mm and above, and g⋅2mg \cdot 2^m has no bits below position mm. So their OR equals g⋅2m+(a∧(2m−1))g \cdot 2^m + (a \wedge (2^m - 1)), which lies in [g⋅2m,(g+1)⋅2m)[g \cdot 2^m, (g + 1) \cdot 2^m), and it is below 2w2^w because g<2w−mg < 2^{w - m}. CHECK writes dd only after it has tested ⌊a/2m⌋=g\lfloor a / 2^m \rfloor = g. □\square

Invariant (D). Let PP be a module that the verifier accepts (lines L6 to L8). At every step of every run of PP, the register dd holds an address in the domain.

Proof, by induction on the number of steps. At the start, the loader set dd to a domain address. Assume (D) before a step. If the step runs SANDBOX or CHECK with destination dd, then by Lemma 1 the new value of dd is in the domain, or the run faults and stops. If the step runs any other instruction that writes a register, then its destination is not dd, because line L6 rejects every module with such an instruction; so dd does not change. Stores, jumps and halt write no register. A jump changes only the position in the module, and (D) is a statement about dd alone, so it holds at every position, including a position that a run reaches by an indirect jump to the middle of a sandboxed pair. □\square

Theorem (confinement). If the verifier accepts PP, then every store that a run of PP executes writes an address in the domain, for every initial value of the other registers and of memory, and for every sequence of jumps.

Proof. By line L7, every store of PP has the form STORE(d,v)(d, v), so it writes the address held in dd. By (D) that address is in the domain. □\square

The theorem is the point of the design of Wahbe et al.: the check is on the dedicated register, not on the path that led to the store. So an attacker who controls the values of the module, or who jumps over a sandboxing step, still cannot store outside the domain. The only thing that must be true at every moment is (D), and the verifier makes sure that only the sandboxing steps can change dd.

Lemma 2 (the rewriter's output passes the verifier). If a module QQ does not mention dd, then REWRITE(Q,d)(Q, d) is accepted by the verifier, in both modes.

Proof. REWRITE refuses a module that mentions dd (line L1). It replaces each store STORE(a,v)(a, v) by a sandboxing step with destination dd followed by STORE(d,v)(d, v) (lines L2 to L5), and copies every other instruction, with direct jump targets renumbered to the new position of their old target, or to the end of the new module if the old target was the end. The copied instructions do not mention dd, so line L6 finds no instruction that writes dd other than a sandboxing step. Every store of the output goes through dd, and every direct jump target is in range, so line L7 does not reject. Line L8 accepts. □\square

Theorem (transparency). Let QQ be a module without indirect jumps that does not mention dd. Take a run of QQ that halts and in which every store address is in the domain. Then the run of REWRITE(Q,d)(Q, d) from the same initial state, in either mode, halts with the same sequence of stores.

Proof. Match each step of the run of QQ at position ii with the step of the rewritten module at the new position of ii. Instructions other than stores and jumps are copied, so they compute the same values. A direct jump goes to the renumbered target, which is the new position of the old target. A store STORE(a,v)(a, v) at position ii becomes a sandboxing step and STORE(d,v)(d, v). By assumption the address in aa is in the domain, so the masking step leaves it unchanged (Lemma 1 with ⌊a/2m⌋=g\lfloor a / 2^m \rfloor = g gives back aa), and the checking step passes and copies it. So the store writes the same address and the same value. The register dd is not read by any other instruction of QQ, so its new value changes nothing else. By induction on the steps, the two runs make the same stores and halt together. □\square

What the theorems do not say. They are about stores. In this model loads are not confined, which matches the cheaper variant that protects only writes and jumps; confining reads needs a sandboxing step before each load as well. They say nothing about indirect jumps leaving the module, which a real system confines in the same way with a code segment and a second dedicated register. They need the loader to set dd at entry and the verifier to run on the exact code that will run, and they assume that the code cannot be changed after verification, as data execution prevention provides.

Termination and cost. REWRITE and the verifier each make a fixed number of passes over the nn instructions, so they take O(n)O(n) steps. The interpreter stops after at most its step budget. Each sandboxing step adds one instruction per store in this model and two machine instructions on a RISC processor in the paper of Wahbe et al. ■\blacksquare

References

  1. Robert Wahbe, Steven Lucco, Thomas E. Anderson and Susan L. Graham, Efficient software-based fault isolation, 14th ACM Symposium on Operating Systems Principles (SOSP 1993), pages 203-216, the section on the software encapsulation method (fault domains, segment matching and address sandboxing with dedicated registers, and the verifier of the object code), and the introduction for the average overhead of 4 percent on a test suite with the C SPEC92 benchmarks
  2. Bennet Yee, David Sehr, Gregory Dardyk, J. Bradley Chen, Robert Muth, Tavis Ormandy, Shiki Okasaka, Neha Narula and Nicholas Fullagar, Native Client, a sandbox for portable, untrusted x86 native code, 2009 IEEE Symposium on Security and Privacy, pages 79-93, the inner sandbox (the validator, the alignment rules for instructions and jump targets, and the use of segments for data) and the reported cost
  3. Martin Abadi, Mihai Budiu, Ulfar Erlingsson and Jay Ligatti, Control-flow integrity, principles, implementations, and applications, ACM Transactions on Information and System Security 13(1), article 4, 2009, the section on building software fault isolation on top of CFI

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH2 full proof
  • correctness: no review record reviews/BDGPFB/proof-correctness.yaml
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • five exercises