summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 00:15:56 -0300
committerGabriel Schneider <[email protected]>2026-11-25 00:20:24 -0300
commitfc45a7c8ed3b279a803dd8daad81329920b0493e (patch)
treed904db7d43fc9dd9fdaa9171ea0657879e3fcaee /core
parent7bac0f3d594b029a3631687ec3d8dd3626e0f447 (diff)
downloadpardes-fc45a7c8ed3b279a803dd8daad81329920b0493e.tar.gz
pardes-fc45a7c8ed3b279a803dd8daad81329920b0493e.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
-rw-r--r--core/dump.zig23
-rw-r--r--core/fuzz.zig3
2 files changed, 26 insertions, 0 deletions
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));
+}
diff --git a/core/fuzz.zig b/core/fuzz.zig
index c68c7810..dc3e8e07 100644
--- a/core/fuzz.zig
+++ b/core/fuzz.zig
@@ -790,6 +790,9 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan
// Join seed 19224: the theme read after the core a reference to a
// slice the core holds, freed by hand and again by the rollback.
try loadSeed(bytes, .join, 19224);
+ // Join seed 31554: the namespace's opens_len past its 64 slots, refused,
+ // and the rollback's teardown of the namespace read that far.
+ try loadSeed(bytes, .join, 31554);
for ([_][]const u8{ bytes, image }, [_]Road{ .join, .restore }, [_]u64{ 2048, 1024 }) |whole, road, n| {
try loadSeed(whole, road, 0);
for (1..n + 1) |seed| try loadSeed(whole, road, seed);