From fc45a7c8ed3b279a803dd8daad81329920b0493e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 00:15:56 -0300 Subject: dump: a load refused after the core reads none of the namespace's opens again: they are what the load read, freed by the rollback, and their count may be the damaged one the load refused: a refused load's teardown (`p.fs.deinit` after `l.rollback()` in loadKnowing and loadImage) walked `opens[0..opens_len]` as the dump gave them; found by the 40,000-seed fuzz on the walk UI's merged tree M1 (xvnytwqm); RUN FIRST: fuzz.zig "a dump and an image cut ..." at join seed 31554: `panic: index out of bounds: index 255, len 64` (fs.zig:1029, Namespace.deinit, from dump.zig:402's errdefer: the dump's opens_len past the 64 slots, refused by walk.holdTo, then read that far by the teardown); and dump.zig's new test, a session with a script's open holding a half-written line (`pending`) whose load is refused after the core (a mount of the same name dialled elsewhere: error.MountConflict, dump.zig:432): `panic: double free` of the open's 9 bytes, the first free `l.rollback()` (dump.zig:401), the second Open.deinit through Namespace.deinit; THE CAUSE: the errdefer of both loaders tears the namespace down for what Pardes.create made (its log, its out, its mounts), and Namespace.deinit frees its opens too, which the load had read in place: the rollback's to free; THE FIX: the errdefer sets `p.fs.opens_len = 0` before `p.fs.deinit` (both loaders); a user could hit the double free with no damage at all: a Restore or a join of a dump taken while a script held an open with something in it (a half-written line, a frozen listing, a run's output) into a process started with a mount of the same name dialled elsewhere; the index past the slots only with a damaged or hostile dump; TESTS: dump.zig 'a load refused after the core frees what a script's open held once: the rollback's, not the namespace's' (fails before: double free), fuzz.zig checks join seed 31554 by name (fails before: index out of bounds); the fuzz at 40,000 join and 1,779 image seeds green in 158 s Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/dump.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'core/dump.zig') diff --git a/core/dump.zig b/core/dump.zig index 683f043a..06a3eae5 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -399,6 +399,9 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: errdefer { if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {}; l.rollback(); + // Its opens are what the load read: the rollback's, freed (and + // their count may be a damaged one, refused). + p.fs.opens_len = 0; p.fs.deinit(gpa); gpa.destroy(p); } @@ -475,6 +478,9 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* errdefer { if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {}; l.rollback(); + // Its opens are what the load read: the rollback's, freed (and + // their count may be a damaged one, refused). + p.fs.opens_len = 0; p.fs.deinit(gpa); gpa.destroy(p); } @@ -1417,3 +1423,20 @@ test "optional GPU addon reload generation survives a replica dump" { try std.testing.expectEqual(original.gen, restored.gen); try std.testing.expectEqual(walk.digest(Kind.Slot, &original), walk.digest(Kind.Slot, &restored)); } + +test "a load refused after the core frees what a script's open held once: the rollback's, not the namespace's" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .mounts = &.{.{ .name = "peer", .dial = "/tmp/peer.sock" }} }); + defer p.deinit(); + _ = try p.setTestFile("x\n"); + // A script's open of a file of command lines, its last line half + // written: bytes the load makes. + p.fs.opens[0] = .{ .node = 1, .what = .lines }; + try p.fs.opens[0].pending.appendSlice(gpa, "Look half"); + p.fs.opens_len = 1; + const bytes = try byteDump(p); + defer gpa.free(bytes); + // The mounts are read after the core: the same name dialled elsewhere + // refuses the load there. + try std.testing.expectError(error.MountConflict, load(gpa, .{ .mounts = &.{.{ .name = "peer", .dial = "/tmp/other.sock" }} }, bytes, null)); +} -- cgit v1.3