Rootfs probe: root-image judges the loop device, not the mount source string (#366). systemd 257 mounts a RootImage= loop device through /proc/self/fd/N, so the old /dev/loop prefix test refused every real box (rootfs_ready false everywhere, fail closed). rootIsImage now requires squashfs on loop major 7, a source of exactly /dev/loopN or /proc/self/fd/N, ro and the marker; parseMountinfo reads MAJ:MIN and refuses truncated lines. Census census-ruling-rootfs-root-image approved by Astra on #280.
Prompts:
<task-notification>
<task-id>a49708f9b9969c3d7</task-id>
<tool-use-id>toolu_018mQCLJR67tBbnfk3vVeUUw</tool-use-id>
<output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/723ae101-0fd7-40c3-a758-6adf1597efb2/tasks/a49708f9b9969c3d7.output</output-file>
<status>completed</status>
<summary>Agent "Fix rootfs root-image probe check" finished</summary>
<note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note>
<result>I merged main 7f79385e into the branch, re-ran the census with the same claim, and added Astra's field-count fix with its own census commit. The branch tip is 039dad15 and nothing is pushed.
- **ce3febde (merge):** the only conflict was `plan14-root-reads-chain.tsv`. Main's plans-6a-units and plans-6-checkout lines went in, and this branch's overlay stays last. This branch adds no record-write inventory, so nothing needed re-layering.
- **5b06d12f (census):** `make census-propose NAME=rootfs-root-image` with the same claim. The card still shows `rootIsImage` as `body` plus an `internal/instanceexec` package re-pin. The overlay file came out byte-identical and only the seal moved, to eedd10a4. Before this, the card showed one `other` ("changed legacy freeze"), which was the old seal from before the merge.
- **a7e2e346 (field-count fix):** `parseMountinfo` now needs `sep+4` fields, so a line that stops after the source is an error. The new `TestParseMountinfo` cases failed with `sep+3` and pass with `sep+4`.
- **039dad15 (census):** the fix did change the census, but only the `internal/instanceexec` package fingerprint (aa3f6500 → 6719ed26). The `rootIsImage` row, the claim and the seal are unchanged.
- **Checks after the merge:** census-card is clean, `go test ./internal/provision -run Census -count=1` and `./internal/instanceexec` pass, and vet and gofmt are clean. I did not re-run the darwin and windows builds after the merge.
- **Still open:** Astra's approval covered the code and census as they were before these commits. The field-count fix and the second package re-pin have not been reviewed.
I added these results to the end of `/home/paulca/.cache/rootfs-apps/root-image-fix-report.md`.</result>
<usage><subagent_tokens>129935</subagent_tokens><tool_uses>15</tool_uses><duration_ms>247655</duration_ms></usage>
</task-notification>
Squashed from rootfs-root-image-probe into main.
5 files changed,
+248
−13
docs/superpowers/notes/census-proposal-rootfs-root-image.md+19 −0internal/instanceexec/probe_rootfs.go+81 −10internal/instanceexec/probe_rootfs_test.go+142 −3internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-rootfs-root-image.tsv+5 −0
CI passed — run details
landed from rootfs-root-image-probe
diff --git a/docs/superpowers/notes/census-proposal-rootfs-root-image.md b/docs/superpowers/notes/census-proposal-rootfs-root-image.md| new file mode 100644 |
| index 000000000..b831eaeb6 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-rootfs-root-image.md |
| @@ -0,0 +1,19 @@ |
| +# Census approval: rootfs-root-image |
| + |
| +Ruling `census-ruling-rootfs-root-image`. Every change below keeps the disposition it already has, so it needs an approval, not a decision. |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/instanceexec/probe_rootfs.go` `rootIsImage` | body | unchanged (1) | body only: the same one read (Lstat of the probe marker); the mountinfo verdict now judges the root mount by its device (MAJ:MIN must be the loop major 7, which parseMountinfo now parses and refuses when malformed), squashfs and per-mount ro, and accepts only the sources /dev/loopN or /proc/self/fd/N (systemd 257 mounts RootImage= through the loop fd) where it took any /dev/loop prefix; a device-mapper root is refused; no read added, nothing a tenant names is opened | |
| + |
| +Envelopes re-pinned: `internal/instanceexec`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/instanceexec/probe_rootfs.go` `rootIsImage`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-2;identity=the rootfs probe (/opt/carlos/carlos instance-probe --rootfs, carlos-instance-rootfs-probe.service, started by instance control; user carlos inside the probe image's namespace; no tenant code runs there);basis=root-input (J4): new (rootfs Plan 2 Task 7): the root-image line: the mount at / is a squashfs on a loop device, and Lstat of the marker root wrote into the probe image is a regular file; no root process runs it; decides nothing for root |
| + |
| +Seal: `c6a920b27d3206e85ac923b308bdf287931954776681732937f7445dd88ec11b` → `eedd10a4727f2a562495cfd8ed7cffe23c568658858198ec7c8309b5f202ab5a`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-rootfs-root-image.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/instanceexec/probe_rootfs.go b/internal/instanceexec/probe_rootfs.go| index 0e089438e..cc43cc1f6 100644 |
| --- a/internal/instanceexec/probe_rootfs.go |
| +++ b/internal/instanceexec/probe_rootfs.go |
| @@ -75,8 +75,8 @@ func runRootfsChecks(e rootfsProbeEnv) instancectl.ProbeReport { |
| v := &verdicts{} |
| entries, merr := readMountinfo(e.mountinfo) |
| - // The root is the probe image: a squashfs on a loop device, carrying |
| - // the marker root wrote into it. |
| + // The root is the probe image: a read-only squashfs on a loop device, |
| + // carrying the marker root wrote into it. |
| if merr != nil { |
| v.add("root-image", "fail", merr.Error()) |
| } else { |
| @@ -123,8 +123,13 @@ func runRootfsChecks(e rootfsProbeEnv) instancectl.ProbeReport { |
| // mountEntry is one line of /proc/self/mountinfo: the mount point, the |
| // root of the mount within its file system, the file system type, the |
| -// source and the per-mount options. |
| -type mountEntry struct{ Point, Root, FSType, Source, Options string } |
| +// source, the per-mount options, and the device (field 3, MAJ:MIN), which |
| +// is st_dev of the mount's files and so names the block device whatever |
| +// the source field reads. |
| +type mountEntry struct { |
| + Point, Root, FSType, Source, Options string |
| + Major, Minor uint32 |
| +} |
| func readMountinfo(path string) ([]mountEntry, error) { |
| b, err := os.ReadFile(path) |
| @@ -137,7 +142,9 @@ func readMountinfo(path string) ([]mountEntry, error) { |
| // parseMountinfo reads proc_pid_mountinfo(5): six fields, optional fields |
| // up to a lone "-", then the type, the source and the super options. |
| // Paths carry octal escapes for space, tab, newline and backslash, which |
| -// are decoded. A line of another shape is an error, never skipped. |
| +// are decoded. A line of another shape, a device field among them that is |
| +// not two decimal numbers either side of one colon, is an error, never |
| +// skipped. |
| func parseMountinfo(b []byte) ([]mountEntry, error) { |
| var out []mountEntry |
| for i, line := range strings.Split(string(b), "\n") { |
| @@ -152,12 +159,17 @@ func parseMountinfo(b []byte) ([]mountEntry, error) { |
| break |
| } |
| } |
| - if sep < 0 || len(f) < sep+3 { |
| + if sep < 0 || len(f) < sep+4 { |
| return nil, fmt.Errorf("mountinfo line %d: %q is not a mount", i+1, line) |
| } |
| + major, minor, ok := parseDevice(f[2]) |
| + if !ok { |
| + return nil, fmt.Errorf("mountinfo line %d: device %q is not MAJ:MIN", i+1, f[2]) |
| + } |
| out = append(out, mountEntry{ |
| Root: unescapeMountinfo(f[3]), Point: unescapeMountinfo(f[4]), Options: f[5], |
| FSType: f[sep+1], Source: unescapeMountinfo(f[sep+2]), |
| + Major: major, Minor: minor, |
| }) |
| } |
| if len(out) == 0 { |
| @@ -166,6 +178,34 @@ func parseMountinfo(b []byte) ([]mountEntry, error) { |
| return out, nil |
| } |
| +// parseDevice reads mountinfo's MAJ:MIN field: decimal numbers, each |
| +// fitting the kernel's 32-bit dev_t halves. |
| +func parseDevice(s string) (major, minor uint32, ok bool) { |
| + a, b, found := strings.Cut(s, ":") |
| + if !found || !allDigits(a) || !allDigits(b) { |
| + return 0, 0, false |
| + } |
| + ma, err1 := strconv.ParseUint(a, 10, 32) |
| + mi, err2 := strconv.ParseUint(b, 10, 32) |
| + if err1 != nil || err2 != nil { |
| + return 0, 0, false |
| + } |
| + return uint32(ma), uint32(mi), true |
| +} |
| + |
| +// allDigits reports whether s is one or more ASCII decimal digits. |
| +func allDigits(s string) bool { |
| + if s == "" { |
| + return false |
| + } |
| + for i := 0; i < len(s); i++ { |
| + if s[i] < '0' || s[i] > '9' { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| // unescapeMountinfo decodes the kernel's \ooo escapes. |
| func unescapeMountinfo(s string) string { |
| if !strings.Contains(s, `\`) { |
| @@ -185,8 +225,23 @@ func unescapeMountinfo(s string) string { |
| return b.String() |
| } |
| -// rootIsImage: the mount on top at / is a squashfs on a loop device, and |
| -// the probe image's marker is a regular file at its root. |
| +// loopMajor is the loop block device's major number (LOOP_MAJOR, |
| +// include/uapi/linux/major.h). Every loop device has it, whatever its |
| +// minor; device-mapper (dm-verity among it) and disks have others. |
| +const loopMajor = 7 |
| + |
| +// rootIsImage: the mount on top at / is the probe image, a read-only |
| +// squashfs on a loop device, and the image's marker is a regular file at |
| +// its root. The device is judged, not the source string: mountinfo's |
| +// MAJ:MIN is the mount's st_dev, so it must be the loop major, while the |
| +// source only says how the device was named at mount time. systemd 257 |
| +// mounts RootImage= through the loop device's fd, so its source reads |
| +// /proc/self/fd/N (the v0.28.17 dev roll, 2026-10-26), where a mount by |
| +// path reads /dev/loopN; the source must be one of those two shapes and |
| +// nothing else. A dm-verity root is refused: the spec (C3) asks for the |
| +// image on a loop device and does not ask for verity. The per-mount "ro" |
| +// is the mount's own read-only flag; root-read-only (rootReadOnly) proves |
| +// the same from the other side, by a create answering EROFS. |
| func rootIsImage(entries []mountEntry, marker string) (string, bool) { |
| var root *mountEntry |
| for i := range entries { |
| @@ -198,8 +253,11 @@ func rootIsImage(entries []mountEntry, marker string) (string, bool) { |
| return "no mount at /", false |
| } |
| var bad []string |
| - if root.FSType != "squashfs" || !strings.HasPrefix(root.Source, "/dev/loop") { |
| - bad = append(bad, fmt.Sprintf("/ is %s on %s, not a squashfs on a loop device", root.FSType, root.Source)) |
| + if root.FSType != "squashfs" || root.Major != loopMajor || !loopSource(root.Source) { |
| + bad = append(bad, fmt.Sprintf("/ is %s on %s (device %d:%d), not a squashfs on a loop device", root.FSType, root.Source, root.Major, root.Minor)) |
| + } |
| + if !slices.Contains(strings.Split(root.Options, ","), "ro") { |
| + bad = append(bad, fmt.Sprintf("/ is mounted %s, not ro", root.Options)) |
| } |
| if fi, err := os.Lstat(marker); err != nil { |
| bad = append(bad, err.Error()) |
| @@ -209,6 +267,19 @@ func rootIsImage(entries []mountEntry, marker string) (string, bool) { |
| return strings.Join(bad, "; "), len(bad) == 0 |
| } |
| +// loopSource reports whether a mount source is one of the two shapes a |
| +// loop mount shows: /dev/loopN, or /proc/self/fd/N (a mount through the |
| +// loop device's fd). Nothing else passes: not /dev/loop-control, not |
| +// /dev/loopfoo, not a host path. |
| +func loopSource(s string) bool { |
| + for _, prefix := range []string{"/dev/loop", "/proc/self/fd/"} { |
| + if n, ok := strings.CutPrefix(s, prefix); ok && allDigits(n) { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| // mountsAllowlisted is C3's probe form: every mount point is / or one of |
| // the allowed points and trees, and no mount's root or source names the |
| // version store, the live links, the host's /var or root's credentials. |
diff --git a/internal/instanceexec/probe_rootfs_test.go b/internal/instanceexec/probe_rootfs_test.go| index edc854846..b816de6b8 100644 |
| --- a/internal/instanceexec/probe_rootfs_test.go |
| +++ b/internal/instanceexec/probe_rootfs_test.go |
| @@ -23,8 +23,11 @@ import ( |
| // sockets BindLogSockets= binds, /run/host/incoming and os-release, the |
| // host's /dev/pts, /dev/shm, /dev/mqueue and /dev/hugepages under the |
| // block's tmpfs mounts, ProtectKernelTunables= remounts, and ProtectHome= |
| -// over the image's /home and /root). |
| -const probeMountinfo = `600 550 7:3 / / ro,nosuid,nodev,relatime - squashfs /dev/loop3 ro,errors=continue |
| +// over the image's /home and /root). The root's source is the loop |
| +// device's fd path, which is what systemd 257 mounts RootImage= through |
| +// (the v0.28.17 dev roll, 2026-10-26: Debian 13, systemd 257.13); the |
| +// device is still the loop device, 7:3. |
| +const probeMountinfo = `600 550 7:3 / / ro,nosuid,nodev,relatime - squashfs /proc/self/fd/3 ro,errors=continue |
| 601 600 0:90 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw,hidepid=invisible,subset=pid |
| 602 601 0:90 /sys /proc/sys ro,nosuid,nodev,noexec,relatime - proc proc rw,hidepid=invisible,subset=pid |
| 603 601 0:24 /systemd/inaccessible/reg /proc/kallsyms ro,nosuid,nodev,noexec - tmpfs tmpfs rw,mode=755 |
| @@ -155,6 +158,24 @@ func (e rootfsProbeEnv) setMount(t *testing.T, point, fstype, source string) { |
| } |
| } |
| +// setRootLine replaces the fixture's line for the image root (mount ID |
| +// 600) with line. |
| +func (e rootfsProbeEnv) setRootLine(t *testing.T, line string) { |
| + t.Helper() |
| + b, err := os.ReadFile(e.mountinfo) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + lines := strings.Split(strings.TrimRight(string(b), "\n"), "\n") |
| + if !strings.HasPrefix(lines[0], "600 550 ") { |
| + t.Fatalf("the fixture's first line is not the root: %q", lines[0]) |
| + } |
| + lines[0] = line |
| + if err := os.WriteFile(e.mountinfo, []byte(strings.Join(lines, "\n")+"\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| func (e rootfsProbeEnv) addMountLine(t *testing.T, line string) { |
| t.Helper() |
| f, err := os.OpenFile(e.mountinfo, os.O_APPEND|os.O_WRONLY, 0) |
| @@ -196,6 +217,24 @@ func TestRootfsProbeFailsWhenTheRootIsNotTheImage(t *testing.T) { |
| if r := runRootfsChecks(e); r.Ready || verdict(r, "root-image") != "fail" { |
| t.Error("a squashfs root that is not on a loop device passed") |
| } |
| + // The device decides, through the whole report: squashfs on a disk |
| + // partition (8:1) or on device-mapper (253:0, dm-verity's shape) is |
| + // refused with the fd source systemd 257 shows, and the loop device |
| + // passes with either source form. |
| + for dev, want := range map[string]string{"8:1": "fail", "253:0": "fail", "7:3": "ok"} { |
| + for _, source := range []string{"/proc/self/fd/3", "/dev/loop3"} { |
| + e = goodRootfsEnv(t) |
| + e.setRootLine(t, "600 550 "+dev+" / / ro,nosuid,nodev,relatime - squashfs "+source+" ro,errors=continue") |
| + if r := runRootfsChecks(e); verdict(r, "root-image") != want || r.Ready != (want == "ok") { |
| + t.Errorf("squashfs on %s from %s: root-image %s (%s), ready %v; want %s", dev, source, verdict(r, "root-image"), detail(r, "root-image"), r.Ready, want) |
| + } |
| + } |
| + } |
| + e = goodRootfsEnv(t) |
| + e.setRootLine(t, "600 550 7:3 / / rw,nosuid,nodev,relatime - squashfs /proc/self/fd/3 ro,errors=continue") |
| + if r := runRootfsChecks(e); r.Ready || verdict(r, "root-image") != "fail" { |
| + t.Error("a root mounted read-write passed") |
| + } |
| e = goodRootfsEnv(t) |
| os.Remove(e.rootMarker) |
| if r := runRootfsChecks(e); r.Ready || verdict(r, "root-image") != "fail" { |
| @@ -209,6 +248,89 @@ func TestRootfsProbeFailsWhenTheRootIsNotTheImage(t *testing.T) { |
| } |
| } |
| +// rootIsImage judges the device, not the source string: the mount on top |
| +// at / is a squashfs, read-only, on the loop block major (7), with a |
| +// source of one of the two shapes a loop mount shows ("/dev/loopN", or |
| +// "/proc/self/fd/N" when systemd 257 mounts through the loop device's fd), |
| +// and the probe marker is a regular file. Each refused case is wrong in |
| +// one respect only, so each pins one requirement. |
| +func TestRootIsImage(t *testing.T) { |
| + marker := filepath.Join(t.TempDir(), ".carlos-rootfs-probe") |
| + if err := os.WriteFile(marker, []byte("carlos rootfs probe image\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + other := "601 600 0:90 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw\n" |
| + for name, c := range map[string]struct { |
| + root string |
| + ok bool |
| + }{ |
| + // What systemd 257 shows (dev roll, 2026-10-26). |
| + "systemd 257 fd source": {"600 550 7:3 / / ro,nosuid,nodev,relatime - squashfs /proc/self/fd/3 ro,errors=continue", true}, |
| + "loop device source": {"600 550 7:3 / / ro,nosuid,nodev,relatime - squashfs /dev/loop3 ro,errors=continue", true}, |
| + "a high loop minor": {"600 550 7:1048576 / / ro,relatime - squashfs /dev/loop1048576 ro", true}, |
| + "a two-digit fd": {"600 550 7:12 / / ro,relatime - squashfs /proc/self/fd/12 ro", true}, |
| + |
| + "host ext4 root": {"600 550 8:1 / / rw,relatime - ext4 /dev/root rw", false}, |
| + "host xfs root": {"600 550 259:1 / / rw,relatime - xfs /dev/nvme0n1p1 rw", false}, |
| + // A host directory bound at / shows the host disk's device, with a |
| + // root that is not the file system's own. |
| + "host directory bound at /": {"600 550 8:1 /srv/image / ro,relatime - ext4 /dev/root rw", false}, |
| + // Squashfs on a block device that is not a loop device: only the |
| + // major says so. |
| + "squashfs on a disk, fd source": {"600 550 8:1 / / ro,relatime - squashfs /proc/self/fd/3 ro", false}, |
| + "squashfs on a disk, loop source": {"600 550 259:0 / / ro,relatime - squashfs /dev/loop3 ro", false}, |
| + // The spec (C3) asks for the image on a loop device and did not |
| + // ask for verity, so a device-mapper root (dm-verity or any other |
| + // dm target, a dynamic major such as 253) is refused, whatever its |
| + // source reads. |
| + "dm-verity root": {"600 550 253:0 / / ro,relatime - squashfs /dev/mapper/probe-verity ro", false}, |
| + "dm root, fd source": {"600 550 253:0 / / ro,relatime - squashfs /proc/self/fd/3 ro", false}, |
| + "dm root, dm-N source": {"600 550 254:0 / / ro,relatime - squashfs /dev/dm-0 ro", false}, |
| + "loop major, ext4": {"600 550 7:3 / / ro,relatime - ext4 /dev/loop3 ro", false}, |
| + "loop major, erofs": {"600 550 7:3 / / ro,relatime - erofs /proc/self/fd/3 ro", false}, |
| + "loop major, overlay": {"600 550 7:3 / / ro,relatime - overlay overlay ro", false}, |
| + "a read-write root": {"600 550 7:3 / / rw,relatime - squashfs /dev/loop3 ro", false}, |
| + "source /dev/loopfoo": {"600 550 7:3 / / ro,relatime - squashfs /dev/loopfoo ro", false}, |
| + "source /dev/loop": {"600 550 7:3 / / ro,relatime - squashfs /dev/loop ro", false}, |
| + "source /dev/loop3/x": {"600 550 7:3 / / ro,relatime - squashfs /dev/loop3/x ro", false}, |
| + "source /dev/loop-control": {"600 550 7:3 / / ro,relatime - squashfs /dev/loop-control ro", false}, |
| + "source a host image path": {"600 550 7:3 / / ro,relatime - squashfs /data/image.squashfs ro", false}, |
| + "source /proc/self/fd/": {"600 550 7:3 / / ro,relatime - squashfs /proc/self/fd/ ro", false}, |
| + "source /proc/self/fd/3x": {"600 550 7:3 / / ro,relatime - squashfs /proc/self/fd/3x ro", false}, |
| + "source another pid's fd": {"600 550 7:3 / / ro,relatime - squashfs /proc/1/fd/3 ro", false}, |
| + "source a loop dir path": {"600 550 7:3 / / ro,relatime - squashfs /proc/self/fd/../../../srv ro", false}, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + entries, err := parseMountinfo([]byte(c.root + "\n" + other)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + d, ok := rootIsImage(entries, marker) |
| + if ok != c.ok { |
| + t.Errorf("rootIsImage = %v (%q), want %v", ok, d, c.ok) |
| + } |
| + }) |
| + } |
| + // The mount on top at / is the one judged: an image under a host |
| + // mount stacked over it is refused, and so is an image without the |
| + // marker. |
| + entries, err := parseMountinfo([]byte("600 550 7:3 / / ro - squashfs /proc/self/fd/3 ro\n700 600 8:1 / / rw - ext4 /dev/root rw\n")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if d, ok := rootIsImage(entries, marker); ok { |
| + t.Errorf("a host root stacked over the image passed: %q", d) |
| + } |
| + entries, _ = parseMountinfo([]byte("600 550 7:3 / / ro - squashfs /proc/self/fd/3 ro\n")) |
| + if d, ok := rootIsImage(entries, marker+".missing"); ok { |
| + t.Errorf("an image without the marker passed: %q", d) |
| + } |
| + entries, _ = parseMountinfo([]byte(other)) |
| + if d, ok := rootIsImage(entries, marker); ok { |
| + t.Errorf("no mount at / passed: %q", d) |
| + } |
| +} |
| + |
| // C3 from inside: a mount from another instance's directory, from the |
| // version store or from the live links fails the allowlist, whatever |
| // else is right. |
| @@ -507,10 +629,19 @@ func TestRealMmapWX(t *testing.T) { |
| } |
| func TestParseMountinfo(t *testing.T) { |
| - entries, err := parseMountinfo([]byte("36 35 7:3 / / ro,relatime - squashfs /dev/loop3 ro\n40 36 0:25 /.instances/_probe /data/instances/_probe rw,nosuid,nodev,noexec,nosymfollow - ext4 /dev/root rw\n")) |
| + entries, err := parseMountinfo([]byte("36 35 7:3 / / ro,relatime - squashfs /dev/loop3 ro\n40 36 259:65536 /.instances/_probe /data/instances/_probe rw,nosuid,nodev,noexec,nosymfollow - ext4 /dev/root rw\n")) |
| if err != nil || len(entries) != 2 { |
| t.Fatalf("%v %v", entries, err) |
| } |
| + // Field 3 is the device, MAJ:MIN. |
| + if entries[0].Major != 7 || entries[0].Minor != 3 || entries[1].Major != 259 || entries[1].Minor != 65536 { |
| + t.Errorf("devices %d:%d and %d:%d", entries[0].Major, entries[0].Minor, entries[1].Major, entries[1].Minor) |
| + } |
| + for _, dev := range []string{"7", "7:", ":3", "x:3", "7:y", "7:3:1", "-7:3", "4294967296:0"} { |
| + if _, err := parseMountinfo([]byte("36 35 " + dev + " / / ro - squashfs /dev/loop3 ro\n")); err == nil { |
| + t.Errorf("a device field %q parsed", dev) |
| + } |
| + } |
| if entries[0].FSType != "squashfs" || entries[0].Source != "/dev/loop3" || entries[1].Root != "/.instances/_probe" || entries[1].Point != "/data/instances/_probe" { |
| t.Errorf("parsed %+v", entries) |
| } |
| @@ -531,6 +662,14 @@ func TestParseMountinfo(t *testing.T) { |
| if _, err := parseMountinfo([]byte("1 0 0:1 / / rw tmpfs tmpfs rw\n")); err == nil { |
| t.Error("a line with no separator parsed") |
| } |
| + // After the separator come three fields: the type, the source and the |
| + // super options. A line that stops short of the super options is not a |
| + // mount either, and fails closed. |
| + for _, line := range []string{"1 0 0:1 / / rw - tmpfs tmpfs", "1 0 0:1 / / rw - tmpfs", "1 0 0:1 / / rw -"} { |
| + if _, err := parseMountinfo([]byte(line + "\n")); err == nil { |
| + t.Errorf("a line short of the super options parsed: %q", line) |
| + } |
| + } |
| } |
| // Outside a cgroup namespace (strict ignored), the probe's own cgroup is |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index a715c43f8..87553f704 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -47,3 +47,4 @@ plan14-root-reads-claims-cleanup-r1.tsv 9cef5e93a1e3520e02efe66455bf70c1170d380b |
| plan14-root-reads-claims-cleanup-r2.tsv 9cef5e93a1e3520e02efe66455bf70c1170d380b6d6a72ede02036ce3dd41924 |
| plan14-root-reads-plans-6a-units.tsv 9b27c8b855ca32a3f12119da92a7571542d2b0c4be4f3383e2ac482323b60ca8 |
| plan14-root-reads-plans-6-checkout.tsv c6a920b27d3206e85ac923b308bdf287931954776681732937f7445dd88ec11b |
| +plan14-root-reads-rootfs-root-image.tsv eedd10a4727f2a562495cfd8ed7cffe23c568658858198ec7c8309b5f202ab5a |
diff --git a/internal/provision/testdata/plan14-root-reads-rootfs-root-image.tsv b/internal/provision/testdata/plan14-root-reads-rootfs-root-image.tsv| new file mode 100644 |
| index 000000000..cf0262a45 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-rootfs-root-image.tsv |
| @@ -0,0 +1,5 @@ |
| +# Census overlay rootfs-root-image, written by census-propose (#369). census-ruling-rootfs-root-image, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-rootfs-root-image.md. |
| +# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy 2949b1ed103eca1dc2d43f35144653a4bf6da88a05ddaa1593a282ec0d60170f internal/instanceexec/probe_rootfs.go rootIsImage legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-2;identity=the rootfs probe (/opt/carlos/carlos instance-probe --rootfs, carlos-instance-rootfs-probe.service, started by instance control; user carlos inside the probe image's namespace; no tenant code runs there);basis=root-input (J4): new (rootfs Plan 2 Task 7): the root-image line: the mount at / is a squashfs on a loop device, and Lstat of the marker root wrote into the probe image is a regular file; no root process runs it; decides nothing for root;rev3=census-ruling-rootfs-root-image;basis=body only: the same one read (Lstat of the probe marker); the mountinfo verdict now judges the root mount by its device (MAJ:MIN must be the loop major 7, which parseMountinfo now parses and refuses when malformed), squashfs and per-mount ro, and accepts only the sources /dev/loopN or /proc/self/fd/N (systemd 257 mounts RootImage= through the loop fd) where it took any /dev/loop prefix; a device-mapper root is refused; no read added, nothing a tenant names is opened file:Lstat@643 15d3fe1256801ee8ce04d1859e3db35422e4b979ecd85c8316f54d43be6183eb |
| +internal/instanceexec/probe_rootfs.go rootIsImage legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-2;identity=the rootfs probe (/opt/carlos/carlos instance-probe --rootfs, carlos-instance-rootfs-probe.service, started by instance control; user carlos inside the probe image's namespace; no tenant code runs there);basis=root-input (J4): new (rootfs Plan 2 Task 7): the root-image line: the mount at / is a squashfs on a loop device, and Lstat of the marker root wrote into the probe image is a regular file; no root process runs it; decides nothing for root;rev3=census-ruling-rootfs-root-image;basis=body only: the same one read (Lstat of the probe marker); the mountinfo verdict now judges the root mount by its device (MAJ:MIN must be the loop major 7, which parseMountinfo now parses and refuses when malformed), squashfs and per-mount ro, and accepts only the sources /dev/loopN or /proc/self/fd/N (systemd 257 mounts RootImage= through the loop fd) where it took any /dev/loop prefix; a device-mapper root is refused; no read added, nothing a tenant names is opened file:Lstat@643 15d3fe1256801ee8ce04d1859e3db35422e4b979ecd85c8316f54d43be6183eb |
| +@coverage internal/instanceexec 6719ed2608dd3532961ee994795d4764ee0aea49df58518170287fc139753e67 |