A protocol is reached by name now, not by a compile-time integer. Init is PID 1 and already knows which binary it started, so init serves /protocol as a vfs backend: bind claims a contract with the provider's endpoint attached, open answers with that endpoint as the reply's capability, and readdir lists what is bound with the task and binary behind it. The kernel reserves the prefix — nothing may mount over it, under it, or unmount it — and ServiceId, ipc_register and ipc_lookup are gone, their syscall numbers left vacant. A bind is authorized by who the caller *is*: the kernel-stamped binary together with the supervising task's identity, matched against /system/configuration/protocol.csv. Identity, not spelling — spawn is ungated, so an attacker can run any bundled binary, and a name-only rule would have let it launder grants through an init of its own making. A name a live process holds is refused to everyone else; a dead one's is released. Three review rounds against a hostile ring-3 process found what 108 green tests could not, because the suite contains no attacker. Publishing init's supervision endpoint as the registry put PID 1's mailbox in every process's hands, where two forged bytes reached the shutdown path: privileged traffic is now believed only from the task that holds the contract it speaks for. A capability arriving on a request outlived every path that ignored it, one handle per call until the table was full — in init, and in the harness ten services share — so the arriving capability is owned by the turn and released unless a handler says otherwise. And the kernel let anyone holding an endpoint handle aim signals, timers, exit notices and interrupts at it: binding now requires having created it. Suite 108/108. The new protocol-registry case asserts eleven properties, each one an attack that must fail.
48 lines
1.7 KiB
Zig
48 lines
1.7 KiB
Zig
//! test/system/services/shared-memory-client — the creating half of the shared-memory test (docs/display-v2.md V2).
|
|
//! It `shared_memory_create`s a shared region, writes a known pattern into it, and hands the region's
|
|
//! capability to `shared-memory-server` as an `ipc_call` send_cap. The server maps that capability and
|
|
//! confirms the pattern is visible — proving cross-process shared memory over the extended
|
|
//! capability-passing path.
|
|
|
|
|
|
const channel = @import("channel");
|
|
const ipc = @import("ipc");
|
|
const time = @import("time");
|
|
const memory = @import("memory");
|
|
const logging = @import("logging");
|
|
const pattern_len = 4096;
|
|
|
|
/// The pattern the server checks — must match shared-memory-server.zig.
|
|
fn expected(i: usize) u8 {
|
|
return @truncate(i *% 7 +% 3);
|
|
}
|
|
|
|
fn lookupServer() ?ipc.Handle {
|
|
var attempts: usize = 0;
|
|
while (attempts < 100) : (attempts += 1) {
|
|
if (channel.openEndpoint("test/shared-memory")) |h| return h;
|
|
time.sleepMillis(50);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
pub fn main() void {
|
|
const region = memory.sharedCreate(pattern_len) orelse {
|
|
_ = logging.write("shared-memory: create failed\n");
|
|
return;
|
|
};
|
|
var i: usize = 0;
|
|
while (i < pattern_len) : (i += 1) region.ptr[i] = expected(i);
|
|
|
|
const server = lookupServer() orelse {
|
|
_ = logging.write("shared-memory: no server\n");
|
|
return;
|
|
};
|
|
// A non-empty message (so it reaches on_message, not the ping path), carrying the shared-memory
|
|
// region's capability. The reply is empty; we just need the round trip.
|
|
var reply: [64]u8 = undefined;
|
|
_ = ipc.callCap(server, "shared-memory", &reply, region.handle) catch {
|
|
_ = logging.write("shared-memory: call failed\n");
|
|
};
|
|
}
|