Algorithmresearch
Secure multi-execution
Also called SME.
Runs a program once per security level and gives each run only the inputs it may see. This gives termination-sensitive noninterference and keeps each ending run of a TSNI program.
- Time
- O(k (t n + v)) worst
- Space
- O(k v + n) extra
- Where
- k = the number of distinct levels of the variables; n = the number of nodes of the syntax tree of the program; t = the largest number of steps of one copy; v = the number of variables
- Model
- Word RAM
- Properties
- completedeterministicofflineiterativesound
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Dominique Devriese, Frank Piessens, 2010
Secure multi-execution (SME) enforces noninterference by running the program several times, once for each security level. The copy at level gets the true value of each input that may see and a fixed default value for every other input, and only this copy may produce the outputs of level . So a public output is computed from public inputs only, whatever the program does. Devriese and Piessens (2010) proved that SME is termination-sensitive noninterferent (TSNI) for every program, and that it does not change the ending runs of a program that is already TSNI. The price is one run for each level.
In plain words
Suppose a program reads a secret and a public number and writes a public result. You cannot know if the program leaks the secret into the result. So you do not ask. You run the program twice. The first copy gets the public number and a fake secret, for example 0, and you take only its public result. The second copy gets the real inputs, and you take only its secret results. The public result cannot depend on the real secret, because the copy that made it never saw the secret. If the program does not leak, both copies agree on everything public, and you lose nothing. If it leaks, the public result is the one computed from the fake secret. The cost is that you run the program once for each level.
The problem
The input is a program in a small while language, a security lattice in which means that information may flow from to , a level for each variable, an initial store and a default value . The initial values are the inputs and the final values are the outputs; the output on is visible to an observer at level if . Write for the final store of the plain run, or if it does not end.
The output is a value or "no output" for each variable, such that:
- Soundness. For each level and each two stores that agree on the inputs of level at most , the observer at sees the same outputs, including the same "no output".
- Precision. If is TSNI and the plain run ends, the outputs are those of the plain run.
TSNI is defined on the page TINI.
The algorithm
SME(c, s, Γ, d) ▷ an output or ⊥ for each variable- 1
K ← the levels Γ(x), each level after the levels below it - 2
for each k in K do - 3
s_k ← the store with s_k(x) = s(x) if Γ(x) ≤ k, and d otherwise - 4
t_k ← the plain run of c from s_k ▷ ⊥ if it does not end - 5
for each variable x do - 6
t ← t_Γ(x) - 7
out(x) ← ⊥ if t = ⊥, and t(x) otherwise - 8
return out
Line L3 is the whole defense. The copy at level cannot read an input above , because it has the default value in its place. Line L6 takes each output from the copy of its own level, and no other copy may produce it. No line of the algorithm looks at the program or its labels during the run, so explicit flows, implicit flows and flows through termination are all cut in the same way. Line L1 runs the lower copies first, so that a higher copy that does not end cannot delay a lower one. The copies are independent, and they can also run at the same time.
Example
Take the diamond lattice , with , , , , the default value , the initial store and the program
The program is not secure: it copies into , although and are not comparable, and it copies into the public .
| copy | input | final | output taken |
|---|---|---|---|
SME gives . The plain run is the last copy and gives . The public is now 0 for every value of , and , and no longer depends on . The top output is unchanged, because the top copy sees all inputs.
Correctness
The proof below shows two theorems for the batch form on this page, where the inputs are the initial store and the outputs are the final store.
Theorem 1 (soundness). Hypotheses: the plain semantics is deterministic. Statement: for every program , every level and every two stores that agree on each input of level at most , the outputs of SME of level at most are equal, and either both are "no output" or both are the same value. The reason: an output with comes from the copy at , whose input by line L3 is the same for and .
Theorem 2 (precision). Hypotheses: is TSNI at each level. Statement: if the plain run from ends in , SME gives . The reason: and agree on the inputs of level at most , so by TSNI the copy at ends and agrees with on each variable of level .
These are Theorems 1 and 2 of Devriese and Piessens, who prove them for programs with input and output channels during the run. The hypothesis of Theorem 2 cannot be weakened to TINI (Pitfalls).
Proof: Secure multi-execution is termination-sensitive noninterferent and precisefull
We use the language and the pseudocode of the page. Levels are in a finite lattice , and is the level of variable . The plain semantics is deterministic: is the final store of the run of from , or if the run does not end. For a store and a level , let be the store of line L3: if , and otherwise, with the fixed default value. Let be the result of the page, with when the copy for does not end.
What the observer sees. An observer at level sees the output for each with ; the value is the observation "no output". Two stores are -equivalent, , if they agree on each with . For final results, , and is not -equivalent to a store.
The code computes this result. Line L1 lists each level that occurs as . The loop of lines L2 to L4 runs once from for each such level, and stores . The loop of lines L5 to L7 sets to , or to when . The level is in the list of line L1, so is defined. So , read as when the run does not end.
Lemma 1. If and , then .
Proof. Take a variable . If , then , so . Otherwise both values are .
Theorem 1 (soundness). For every program , every level and every two stores : for each with , . So the observer at sees the same outputs, and in particular sees "no output" in one run exactly when it does in the other. SME is termination-sensitive noninterferent.
Proof. Let . By Lemma 1, . The plain semantics is deterministic, so : both are , or both are the same store. In both cases .
Theorem 2 (precision). Let be termination-sensitive noninterferent for each level: for each and each two stores , . Then for every store with , .
Proof. Take a variable and let . The stores and agree on each with , so . By the hypothesis, . Since , also , and the two final stores agree on , because . So .
If and is as in Theorem 2, the same argument shows that each copy does not end, so for every , as for the plain run.
The bound on steps. The code replaces "does not end" by "does not end within the fuel bound". Theorem 1 holds for this semantics with the same proof, because a run with a step bound is still deterministic. Theorem 2 holds for it when is termination-sensitive noninterferent for the semantics with the step bound.
The hypothesis of Theorem 2 is needed. The program "while do skip; " is termination-insensitive noninterferent but not termination-sensitive. From the plain run ends with , but the public copy sees and does not end, so .
Complexity
The model is the word-RAM. Let be the number of distinct levels in , the largest number of steps of one copy, the number of nodes of the syntax tree and the number of variables. Line L3 takes time for each level, and a copy of steps takes time, since each step evaluates at most one expression of size at most . Line L1 sorts levels. The time is : about times the plain run. Only the levels that occur in need a copy, not every level of the lattice. The stores of the copies take space and the stack of one run , so the extra space is . A version that keeps only the outputs of each copy needs less.
Properties
- Sound for TSNI. Every program, secure or not, gives TSNI outputs (Theorem 1). This is stronger than the TINI guarantee of no-sensitive-upgrade and of the security type system.
- Precise for TSNI programs. A TSNI program gives the same outputs as its plain run, also when that run does not end (Theorem 2 and the proof). There are no false alarms on such programs, and the property "complete" above means this.
- Not transparent for TINI programs. A TINI program that is not TSNI can lose its public outputs (Pitfalls).
- A black box. SME does not read the program. It needs only a way to run it and to control its inputs and outputs, so it works for any language and for code known only at run time.
- Cost. One run for each level, in time or in parallel hardware.
Variants and improvements
- Interactive programs. In the original form, the inputs and outputs are channels with levels, read and written during the run. The copy at level reads the inputs of levels at most and gets the default value for the others, and only the copy at level writes to the outputs of level . An input of a low level is read once and given to each higher copy that needs it. Devriese and Piessens also discuss the timing channel and the choice of a scheduler for the copies; this page does not model time.
- Shadow executions. Capizzi et al. (2008) run a public and a private copy of a process, which is the two-level case.
- Browsers. FlowFox (De Groef et al. 2012) runs the JavaScript of a web page with SME, to enforce information flow policies on the scripts of the page.
- Faceted execution. Faceted execution simulates the copies in one run: it keeps a value for each level only where the copies differ. Bielova and Rezk (2016) compare the two and show that they do not give the same guarantees in general.
- Declassification. Later work lets a release of selected data from a high copy to a low copy, so that SME can work with a declassification policy.
When to use it
Use SME when you cannot change or analyze the program, false alarms are not acceptable, and you can pay for one run per level, for example for scripts of a few origins in a browser. Use the security type system when the program is known in advance and TINI is enough. Use no-sensitive-upgrade when one run is all you can pay for and a stop is acceptable. Use faceted execution when most of the program does not depend on secrets, so that most of the work is shared. SME does not help when a public output is meant to depend on a secret, such as the result of a password check; the low copy computes it from the default value.
Pitfalls
- The true inputs at line L3. A copy that gets itself, and not , computes the public outputs from the secrets, and "" leaks. The right line L3 replaces each input above by the default value.
- The wrong copy at line L6. Taking all outputs from the top copy gives the plain run, with all its leaks. Taking an output from a copy above its level leaks too. The right line L6 takes the output on from the copy at .
- A high copy first at line L1. If the copies run one after the other and the high copy runs first and does not end, the low copy never runs. Then the public output exists or not depending on the secret. The right line L1 runs the lower copies first, or the copies run side by side.
- Expecting the plain result from a TINI program. For "while do skip; " and , the plain run gives , but the public copy sees and does not end, so SME gives no public output. This is correct for TSNI and is not a bug.
- A default value that depends on the secret. The default value at line L3 must be fixed in advance. A default value computed from the real input is the real input under another name.
Implementations
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/secure-multi-execution/. The authors are listed in prov/5EGZEC.jsonl.
"""Secure multi-execution (SME) of a small while language.
Programs are nested tuples:
expression: an int (a constant), a str (a variable), or (op, e1, e2)
with op one of "+", "-", "*", "<", "=="
command: ("skip",)
("assign", x, e)
("seq", c1, c2)
("if", e, c1, c2)
("while", e, c)
Values are integers modulo MOD. A nonzero value is true. A level is a
frozenset of category names, ordered by inclusion. The inputs of a run
are the initial values of the variables, and the outputs are the final
values; the output on a variable x is visible at level gamma[x].
"""
from typing import Optional, Union
Level = frozenset
Expr = Union[int, str, tuple]
Cmd = tuple
Store = dict[str, int]
MOD = 256
def evaluate(e: Expr, s: Store) -> int:
"""Return the value of e in the store s.
Precondition: every variable of e is a key of s.
Cost: O(size of e). Uses an explicit stack, no recursion.
"""
values: list[int] = []
work: list[tuple[bool, Expr]] = [(False, e)]
while work:
done, f = work.pop()
if done:
b = values.pop()
a = values.pop()
op = f[0]
if op == "+":
values.append((a + b) % MOD)
elif op == "-":
values.append((a - b) % MOD)
elif op == "*":
values.append((a * b) % MOD)
elif op == "<":
values.append(int(a < b))
elif op == "==":
values.append(int(a == b))
else:
raise ValueError(f"unknown operator {op!r}")
elif isinstance(f, int):
values.append(f % MOD)
elif isinstance(f, str):
values.append(s[f])
else:
work.append((True, f))
work.append((False, f[2]))
work.append((False, f[1]))
return values[0]
def run(c: Cmd, s: Store, fuel: int = 10_000) -> Optional[Store]:
"""Run c on a copy of s. Return the final store, or None after fuel steps.
Precondition: every variable of c is a key of s.
Cost: at most fuel steps, each O(1) plus the cost of its expression.
"""
s = dict(s)
work: list[Cmd] = [c]
while work:
fuel -= 1
if fuel < 0:
return None
d = work.pop()
tag = d[0]
if tag == "skip":
continue
if tag == "assign":
s[d[1]] = evaluate(d[2], s)
elif tag == "seq":
work.append(d[2])
work.append(d[1])
elif tag == "if":
work.append(d[2] if evaluate(d[1], s) != 0 else d[3])
elif tag == "while":
if evaluate(d[1], s) != 0:
work.append(d)
work.append(d[2])
else:
raise ValueError(f"unknown command {tag!r}")
return s
def sme(c: Cmd, s: Store, gamma: dict[str, Level], default: int = 0, fuel: int = 10_000) -> dict[str, Optional[int]]:
"""Run c once per level and give each output from the copy of its level.
The copy at level k sees the true input of x when gamma[x] <= k, and
the default value otherwise. The output on x comes from the copy at
level gamma[x]; it is None when that copy does not end within fuel
steps. The copies run one after the other, lowest level first.
Precondition: the keys of gamma are the keys of s and hold every
variable of c.
Cost: one run of c per distinct level, so at most k times the cost of
one run for k levels.
"""
levels = sorted(set(gamma.values()), key=len) # @line L1
finals: dict[Level, Optional[Store]] = {}
for k in levels: # @line L2
sk = {x: (s[x] if gamma[x] <= k else default) for x in s} # @line L3
finals[k] = run(c, sk, fuel) # @line L4
out: dict[str, Optional[int]] = {}
for x in s: # @line L5
t = finals[gamma[x]] # @line L6
out[x] = None if t is None else t[x] # @line L7
return out # @line L8
test_secure_multi_execution.py 230 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/secure-multi-execution/. The authors are listed in prov/5EGZEC.jsonl.
import itertools
import random
from secure_multi_execution import MOD, evaluate, run, sme
L = frozenset()
H = frozenset({"h"})
GAMMA = {"h": H, "l": L, "m": L}
VARS = ["h", "l", "m"]
DOMAIN = [0, 1, 2]
FUEL = 200
# Independent oracle: a recursive interpreter with the same step count.
class OutOfFuel(Exception):
pass
def o_eval(e, s):
if isinstance(e, int):
return e % MOD
if isinstance(e, str):
return s[e]
a, b = o_eval(e[1], s), o_eval(e[2], s)
return {"+": (a + b) % MOD, "-": (a - b) % MOD, "*": (a * b) % MOD,
"<": int(a < b), "==": int(a == b)}[e[0]]
def o_exec(c, s, fuel):
fuel[0] -= 1
if fuel[0] < 0:
raise OutOfFuel
tag = c[0]
if tag == "assign":
s[c[1]] = o_eval(c[2], s)
elif tag == "seq":
o_exec(c[1], s, fuel)
o_exec(c[2], s, fuel)
elif tag == "if":
o_exec(c[2] if o_eval(c[1], s) else c[3], s, fuel)
elif tag == "while":
if o_eval(c[1], s):
o_exec(c[2], s, fuel)
o_exec(c, s, fuel)
def o_run(c, s, fuel=FUEL):
s = dict(s)
try:
o_exec(c, s, [fuel])
except OutOfFuel:
return None
return s
def o_sme_two_point(c, s):
low_run = o_run(c, {"h": 0, "l": s["l"], "m": s["m"]})
high_run = o_run(c, s)
return {"h": None if high_run is None else high_run["h"],
"l": None if low_run is None else low_run["l"],
"m": None if low_run is None else low_run["m"]}
def stores():
for vals in itertools.product(DOMAIN, repeat=len(VARS)):
yield dict(zip(VARS, vals))
def low_in(s):
return (s["l"], s["m"])
def low_out(r):
# None stands for "no output": a run that does not end.
return None if r is None else (r["l"], r["m"])
def is_tsni_plain(c):
seen = {}
for s in stores():
out = low_out(o_run(c, s))
if seen.setdefault(low_in(s), out) != out:
return False
return True
def is_tini_plain(c):
seen = {}
for s in stores():
out = low_out(o_run(c, s))
if out is None:
continue
if seen.setdefault(low_in(s), out) != out:
return False
return True
def sme_is_tsni(c):
seen = {}
for s in stores():
r = sme(c, s, GAMMA, fuel=FUEL)
out = (r["l"], r["m"])
if seen.setdefault(low_in(s), out) != out:
return False
return True
def rand_expr(rng, depth=0):
r = rng.random()
if depth >= 2 or r < 0.35:
return rng.choice(VARS)
if r < 0.5:
return rng.randrange(3)
return (rng.choice(["+", "-", "*", "<", "=="]),
rand_expr(rng, depth + 1), rand_expr(rng, depth + 1))
def rand_cmd(rng, budget):
if budget <= 1:
return ("assign", rng.choice(VARS), rand_expr(rng)), 1
r = rng.random()
if r < 0.35:
return ("assign", rng.choice(VARS), rand_expr(rng)), 1
if r < 0.4:
return ("skip",), 1
if r < 0.65:
c1, n1 = rand_cmd(rng, budget // 2)
c2, n2 = rand_cmd(rng, budget - n1)
return ("seq", c1, c2), n1 + n2
if r < 0.88:
c1, n1 = rand_cmd(rng, (budget - 1) // 2)
c2, n2 = rand_cmd(rng, max(1, budget - 1 - n1))
return ("if", rand_expr(rng), c1, c2), 1 + n1 + n2
c1, n1 = rand_cmd(rng, budget - 1)
return ("while", rand_expr(rng), c1), 1 + n1
def seq(*cs):
out = cs[-1]
for c in reversed(cs[:-1]):
out = ("seq", c, out)
return out
def test_worked_example():
# l := h; m := l + 1; h := h + m with h = 2, l = 5, m = 7.
prog = seq(("assign", "l", "h"), ("assign", "m", ("+", "l", 1)),
("assign", "h", ("+", "h", "m")))
s = {"h": 2, "l": 5, "m": 7}
assert run(prog, {"h": 0, "l": 5, "m": 7}) == {"h": 1, "l": 0, "m": 1}
assert run(prog, s) == {"h": 5, "l": 2, "m": 3}
assert sme(prog, s, GAMMA) == {"h": 5, "l": 0, "m": 1}
def test_implicit_flow_is_cut():
prog = ("if", "h", ("assign", "l", 1), ("assign", "l", 0))
for hv in DOMAIN:
assert sme(prog, {"h": hv, "l": 9, "m": 0}, GAMMA)["l"] == 0
assert sme_is_tsni(prog)
def test_termination_channel_is_closed():
# The plain program leaks h = 0 through termination; SME does not.
prog = seq(("while", ("==", "h", 0), ("skip",)), ("assign", "l", 1))
assert not is_tsni_plain(prog)
assert is_tini_plain(prog)
assert sme_is_tsni(prog)
# The low copy sees the default h = 0 and does not end, so SME gives no
# public output even when the true run ends: SME is not transparent
# for this TINI program.
r = sme(prog, {"h": 1, "l": 0, "m": 0}, GAMMA, fuel=FUEL)
assert run(prog, {"h": 1, "l": 0, "m": 0}, FUEL)["l"] == 1
assert r["l"] is None and r["h"] == 1
def test_secure_program_is_unchanged():
prog = seq(("assign", "h", ("+", "h", "l")), ("assign", "m", ("*", "l", 2)))
for s in stores():
assert sme(prog, s, GAMMA) == run(prog, s)
def test_only_public_variables():
gamma = {"a": L, "b": L}
prog = ("assign", "a", ("+", "a", "b"))
assert sme(prog, {"a": 1, "b": 2}, gamma) == {"a": 3, "b": 2}
def test_diamond_lattice():
a, b = frozenset({"a"}), frozenset({"b"})
gamma = {"x": L, "y": a, "z": b, "w": a | b}
prog = seq(("assign", "y", ("+", "y", "z")), ("assign", "w", ("+", "y", "z")),
("assign", "x", "w"))
s = {"x": 1, "y": 2, "z": 3, "w": 4}
r = sme(prog, s, gamma, default=0)
# Copy a sees x, y; copy b sees x, z; copy a|b sees all.
assert r == {"x": 0, "y": 2, "z": 3, "w": 8}
def test_evaluate():
assert evaluate(("-", 1, 2), {}) == MOD - 1
assert evaluate(("<", "x", 3), {"x": 2}) == 1
def test_deep_program_no_recursion():
prog = ("assign", "l", 0)
for _ in range(3000):
prog = ("seq", ("assign", "l", ("+", "l", 1)), prog)
assert sme(prog, {"h": 1, "l": 0, "m": 0}, GAMMA)["l"] == 0
def test_random_against_oracle_soundness_precision():
rng = random.Random(2010)
tsni_programs = 0
for _ in range(500):
prog, _n = rand_cmd(rng, rng.randint(1, 10))
for s in stores():
assert run(prog, s, FUEL) == o_run(prog, s)
assert sme(prog, s, GAMMA, fuel=FUEL) == o_sme_two_point(prog, s)
assert sme_is_tsni(prog), prog
if is_tsni_plain(prog):
tsni_programs += 1
for s in stores():
t = o_run(prog, s)
if t is not None:
assert sme(prog, s, GAMMA, fuel=FUEL) == t, (prog, s)
assert tsni_programs >= 100
History
Capizzi, Longo, Venkatakrishnan and Sistla (2008) used a public and a private copy of a process to prevent leaks. Devriese and Piessens (2010) gave the general construction for a lattice of levels, with inputs and outputs during the run, named it secure multi-execution, and proved soundness for TSNI and precision for TSNI programs. De Groef et al. (2012) built FlowFox, a web browser that runs scripts with SME. Austin and Flanagan (2012) gave faceted execution, which shares the work of the copies, and Bielova and Rezk (2016) compared the two methods.
References
- Dominique Devriese and Frank Piessens, Noninterference through secure multi-execution, Proceedings of the 2010 IEEE Symposium on Security and Privacy, pp. 109 to 124, the construction, the soundness theorem (Theorem 1) and the precision theorem for termination-sensitive noninterferent programs (Theorem 2)
- Roberto Capizzi, Antonio Longo, V. N. Venkatakrishnan and A. Prasad Sistla, Preventing information leaks through shadow executions, Proceedings of the 2008 Annual Computer Security Applications Conference (ACSAC), pp. 322 to 331, a public and a private copy of a process
- Willem De Groef, Dominique Devriese, Nick Nikiforakis and Frank Piessens, FlowFox, a web browser with flexible and precise information flow control, Proceedings of the 2012 ACM Conference on Computer and Communications Security, pp. 748 to 759, secure multi-execution of JavaScript in a browser
- Nataliia Bielova and Tamara Rezk, Spot the difference, secure multi-execution and multiple facets, ESORICS 2016, LNCS 9878, pp. 501 to 519, the comparison of secure multi-execution with faceted execution
- Aslan Askarov, Sebastian Hunt, Andrei Sabelfeld and David Sands, Termination-insensitive noninterference leaks more than just a bit, ESORICS 2008, LNCS 5283, pp. 333 to 348, the leak through termination that termination-insensitive methods allow and secure multi-execution closes
Where this leads
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 5EGZEC Edit this page History Report an error Markdown