Omniglot

Building Bridges: Safe Interactions with Foreign Languages through Omniglot
Leon Schuermann and colleagues · OSDI 2025
Operating Systems and Computer Networks · Presented by Stephen Singer

Rust has memory and type safety

Memory safety

Ownership, borrowing and bounds checks keep access within live storage.

Type safety

Every value must satisfy its type’s rules.

Rust Book §§3.2, 4.2 · Rust Reference, Behavior considered undefined · Paper §3

Rust can share data without transferring ownership

let bytes = vec![0_u8, 1, 2];
let view: &[u8] = &bytes;
A Vec owns the allocated bytes. A slice reference borrows those same bytes.
Rust Book §§4.1–4.2 · Paper §2

Rust combines compile-time rules with runtime checks

let view: &[u8] = &[0, 1, 2];
let byte: u8 = view[2];  // third element

Compile time

Types and borrowing rules constrain the program.

At execution

Runtime checks enforce rules that depend on actual values.

Rust Book §§3.2, 4.2 · Paper §§2–3

Can safe code remain safe when it calls unsafe code?

Schuermann et al. · OSDI ’25 · §1

Rust applications can reuse existing C libraries

A Rust application can reuse libpng for PNG decoding, LwIP for networking, or CryptoLib for cryptography.
Schuermann et al. · OSDI ’25 · §1 · §§6.1–6.2

How a Rust call reaches foreign code

Foreign function interface

The FFI lets Rust declare and call a function implemented in another language.

Application binary interface

The ABI specifies how compiled code passes arguments and returns results.

Schuermann et al. · OSDI ’25 · §2.1, Listing 1 · §3, Fig. 2 · §5.3

Rust trusts the return type in a foreign declaration

unsafe extern "C" {
    fn f() -> bool;
}
extern "C"Declare an external symbol using the C ABI. unsafeThe declaration must match the external function. → boolThe caller expects a valid Rust Boolean.
Schuermann et al. · OSDI ’25 · §2.1, Listing 1 · §3, Fig. 2 · Rust Reference, External blocks

A raw pointer carries fewer guarantees than a reference

let byte = 1_u8;
let shared: &u8 = &byte;
let raw: *const u8 = shared;
A shared reference and a raw pointer identify the same byte. The shared reference carries a live, valid borrow.
Schuermann et al. · OSDI ’25 · §4.3, Fig. 3 · Rust Reference, Pointer types

A read must fit and be aligned

Assume a four-byte value requiring four-byte alignment. Addresses 100–103 are allocated.

100
101
102
103
104
Start Four bytes inside this allocation? Four-byte aligned?
100 Yes, 100–103 Yes
101 No, needs 101–104 No
104 No, starts outside Yes
Schuermann et al. · OSDI ’25 · §3 · §4.3, Fig. 3 · Illustrative addresses

A foreign function returns the byte 2

Illustrative example · Adapted from Figure 2

0Rust false
1Rust true
2Valid u8 · invalid bool
Schuermann et al. · OSDI ’25 · §2.4 and §3, Fig. 2

Validate before constructing a Rust bool

Conventional binding

A foreign byte of 2 returned through a binding declared as bool already produces an invalid Rust value.

Omniglot wrapper ?bool is research pseudocode

Receive unchecked bits. For 0 or 1, construct a Rust bool. For any other byte, including 2, return an error.
Schuermann et al. · OSDI ’25 · §3, Fig. 2, p. 598 · Conceptual pseudocode

Memory isolation is not type safety.

A library can stay inside its memory region and still return the byte 2 where Rust expects a Boolean.

Schuermann et al. · OSDI ’25 · §3, Fig. 2

How Omniglot protects a Rust caller

Isolation

Confine the library to permitted memory.

Validation

Check the storage and the value before a read.

Scopes

Keep those checks valid while Rust uses the view.

Schuermann et al. · OSDI ’25 · §§3–4.4

Omniglot uses a platform runtime for isolation

Omniglot’s bindings, wrappers and scopes use a platform runtime, which uses hardware and OS protection.
Schuermann et al. · OSDI ’25 · §§4.1–4.2 · §§5.1–5.3

Rust can read across the isolation boundary

Rust owns host-private memory and can use checked foreign memory. Foreign code is confined to its own memory.

A strong runtime keeps the library out of host-private memory.

Schuermann et al. · OSDI ’25 · §§4.1–4.3

Pointer upgrade checks the storage

Successful upgrade from a raw pointer to OGMutRef of T.

Check allocation, range, and alignment. The wrapper may still hold invalid bytes.

Schuermann et al. · OSDI ’25 · §4.3, Fig. 3 · §4.4, Table 1

The bytes still have to represent a valid value

Successful validation produces an OGVal from an OGMutRef. The host can borrow a shared reference through that validated view.

Validation establishes that the foreign bytes represent a valid T, allowing a scoped shared borrow.

Schuermann et al. · OSDI ’25 · §3 and §4.3, Fig. 3

A check can go stale

Check byte 1, write 2 through an alias, then the attempted read has a stale view.

A second pointer can change the value after validation, making the original check unreliable.

Schuermann et al. · OSDI ’25 · §§4.3–4.4, pp. 601–602

Rust permits shared reads or an exclusive write

let mut byte = 1_u8;
let a = &byte;
let b = &byte;
assert_eq!(*a, *b);    // last use of both readers
let writer = &mut byte;
*writer = 0;

Both shared readers finish using the byte before Rust permits an exclusive write.

Rust Book §4.2 · Paper §4.4

The allocation outlives its borrows

Time runs left to right. The allocation spans two overlapping shared borrows, their common last read, and a later exclusive write. Release comes after all three borrows.

After the readers’ last use, the writer can borrow the same byte. Its owner releases it later.

Rust background · The Rust Book, §§4.2 and 10.3 · Schuermann et al., §4.4

Omniglot tracks storage lifetime and checked access separately

AllocScope

A storage wrapper can live only as long as its allocation.

AccessScope

A live validated view blocks writes through other wrappers.

Schuermann et al. · OSDI ’25 · §4.4, Table 1, pp. 602–603

A call conflicts with a live view

AllowedValidate, read for the last time, then call. RejectedValidate, call, then try to read the old view.

The call needs both scope markers exclusively.

Schuermann et al. · OSDI ’25 · §4.3 · §4.4, Table 1 · §4.5, Listing 3

Rust can read foreign output in place

The Rust reader borrows the decoded pixels in their existing foreign buffer.

Decoded PNG pixels are one example of a suitable foreign buffer.

Schuermann et al. · OSDI ’25 · §§4.2–4.4, 5.3 and 6.2

The security guarantee depends on the runtime

OGPMP · strong

RISC-V PMP confines lower-privilege code in Tock. The runtime controls when it runs.

OGMPK · weak

x86 protection keys limit page access in Linux. The prototype relies on library cooperation.

Schuermann et al. · OSDI ’25 · §4.1 and §§5.1–5.2

How much time do checks add beyond isolation?

Workload Unsafe FFI Isolation only
(% vs. unsafe FFI)
Full Omniglot
(% vs. isolation only)
LwIP · PMP 51.74 µs 78.71 µs (+52.1%) 81.4 µs (+3.4%)
CryptoLib · PMP 9105 µs 9145 µs (+0.44%) 9145 µs (+0%)
libpng · MPK 352.98 µs 397.93 µs (+12.7%) 401.25 µs (+0.8%)
Schuermann et al. · OSDI ’25 · §6, Table 2 · selected application workloads

How the paper evaluates zero-copy

PNG decoding produces a buffer of pixels. The researchers compare three ways to access that output.

Unsafe FFI

Call the decoder directly and access its output.

OGMPK

Check the buffer and read it in place.

Sandcrust

Serialize and copy the pixels across a process boundary.

Sandcrust isolates a separate process. OGMPK relies on library cooperation.

Schuermann et al. · OSDI ’25 · §6.2, p. 607 · §5.2, p. 604

Sandcrust falls behind as decoded PNG output grows

Figure 5 plots decode time in milliseconds against decoded image size in MB. Unsafe FFI and OGMPK track closely. Sandcrust rises more steeply.

The plot measures total decode time. The authors attribute the widening gap to serializing and copying pixels between processes.

Schuermann et al. · OSDI ’25 · §6.2, Fig. 5, p. 607 · original plot

What host soundness leaves open

CorrectnessThe library can return a valid true when the answer should be false. Side channelsTiming can still reveal private information.
Schuermann et al. · OSDI ’25 · §4.1, p. 600 · §5.2, p. 604

Some types need more evidence than their bytes

u8Every initialized byte pattern is a value. boolOnly byte patterns 0 and 1 are valid. ReferencesNeed evidence of origin, lifetime, and permitted access.
Schuermann et al. · OSDI ’25 · §3, p. 599 · §4.3, p. 601 · Rust Reference, Pointer types

Safe interoperability requires more than a sandbox

A strong runtime confines the library. Validation lets Rust read foreign data in place. Scopes keep that read valid through its last use.

Schuermann et al. · OSDI ’25 · §§3–4.4 and 9

Why isn’t OGMutRef<T> a Rust &mut T?

Two checked wrappers can point to the same byte.

A successful upgrade() proves the storage is usable. Writing through either wrapper still requires exclusive access to the library’s AccessScope.

Q&A backup · Schuermann et al. · §4.3, Fig. 3, p. 601 · §4.4, Table 1, p. 602

Why does Omniglot separate allocation and access scopes?

A write can change a checked value while its allocation stays live.

One conservative scopeCould block both writes and release while any wrapper is live. Omniglot’s two scopesAn upgraded wrapper keeps storage live. A validated view also blocks writes.
Q&A backup · Schuermann et al. · §4.4, Table 1, p. 602 · §4.5, Listing 3, p. 603

Can a malicious C library bypass Omniglot?

The Tock prototype can confine an adversarial library. The Linux prototype relies on its cooperation.

OGPMPLower privilege and restricted execution protect the host. OGMPKUncontrolled system calls or background threads can break the assumptions.
Q&A backup · Schuermann et al. · §4.1, p. 600 · §§5.1–5.2, p. 604

Why not copy foreign data into Rust-owned memory?

Copy when Rust needs to keep the result beyond the foreign allocation’s lifetime.

Keep a snapshot

Copy from readable storage, then validate the copied representation before using it as a typed value.

Use it now

Borrow the checked output in place. The view ends when its scope does.

Q&A backup · Schuermann et al. · §§4.2–4.4, pp. 600–602 · §6.2, Fig. 5, p. 607

What if the library crashes, hangs, or returns the wrong result?

Protecting Rust’s soundness still leaves the host responsible for handling failure.

FaultOGPMP reports a trapped library fault as an error. HangThe paper gives no guarantee that a call returns. Wrong resultA valid true can still be the wrong answer.
Q&A backup · Schuermann et al. · §§4.1–4.2, p. 600 · §5.1, p. 604

Thank you.

Safety requires boundaries.

Omniglot mediates between the Rust host and foreign code.

Questions?