rootfs probe: a mountinfo line short of the super options fails closed
parseMountinfo accepted a line whose fields stopped after the source, because it required len(f) >= sep+3 where the type, the source and the super options need sep+4. Such a line is now an error, like any other line that is not a mount. Astra noted this in its review of the root-image fix.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+9
−1
internal/instanceexec/probe_rootfs.go+1 −1internal/instanceexec/probe_rootfs_test.go+8 −0
diff --git a/internal/instanceexec/probe_rootfs.go b/internal/instanceexec/probe_rootfs.go| index be45fdaff..cc43cc1f6 100644 |
| --- a/internal/instanceexec/probe_rootfs.go |
| +++ b/internal/instanceexec/probe_rootfs.go |
| @@ -159,7 +159,7 @@ 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]) |
diff --git a/internal/instanceexec/probe_rootfs_test.go b/internal/instanceexec/probe_rootfs_test.go| index 19de176fd..b816de6b8 100644 |
| --- a/internal/instanceexec/probe_rootfs_test.go |
| +++ b/internal/instanceexec/probe_rootfs_test.go |
| @@ -662,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 |