Skip to content

fix: address external issues #158 + #159#161

Merged
WaylandYang merged 3 commits into
mainfrom
fix/external-issues-158-159
May 25, 2026
Merged

fix: address external issues #158 + #159#161
WaylandYang merged 3 commits into
mainfrom
fix/external-issues-158-159

Conversation

@WaylandYang
Copy link
Copy Markdown
Contributor

Two community-reported quality bugs in one PR. Both reporters left concrete patches in their issues; I followed both closely with small tweaks for safety/testability.

#159 — `cgroup::ensure_parent` only enabled `memory`

Reporter: @mxz2007.

The module doc-comment promises future cpu/io/pids support, but the enable code only set `+memory` in subtree_control. A future PR adding `cpu.max` would silently fail because the child cgroup wouldn't expose the file — silent regression bait.

Fix (as reporter suggested): enable `{memory, cpu, io, pids}` on first use. Single-write of all "+ctrl" tokens. The kernel ignores subtree_control tokens for controllers not compiled in, so no error.

Also tightened the module doc-comment to match the new behavior.

#158 — Audit RFC3339 formatter had two latent bugs

Reporter: @pardcomper (Ziyu Wang).

The hand-rolled formatter avoided pulling in chrono, but:

  1. `SystemTime::duration_since(UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0)` silently collapsed pre-epoch clocks (dead CMOS battery boot) to `1970-01-01T00:00:00Z`. Two audit records back-to-back in this state would have identical timestamps, with no signal anywhere.

  2. `(y + ...) as i32` overflowed for `secs > ~4×10^17`. A corrupted `state.json` with a bogus future `created_at_unix` would silently render a wrong year.

Fix: replaced the hand-rolled formatter with the `time` crate (`default-features = false`, features = `["formatting", "macros"]`). For in-range timestamps, output is bit-identical to the old formatter. Out-of-range now returns a `"outside-time-range"` sentinel rather than overflowing.

Added three regression tests:

  • `rfc3339_format_negative_pre_epoch`: `-1 → "1969-12-31T23:59:59Z"` (the actual prior date, not a misleading zero)
  • `rfc3339_format_far_future_does_not_overflow`: year 9999 renders correctly
  • `rfc3339_format_out_of_range_returns_sentinel`: `1e18 → "outside-time-range"`

Test results (dev box, kernel 6.14)

```
test audit::tests::rfc3339_format_epoch_zero ... ok
test audit::tests::rfc3339_format_far_future_does_not_overflow ... ok
test audit::tests::rfc3339_format_known_timestamp ... ok
test audit::tests::audit_sink_writes_and_persists ... ok
test audit::tests::rfc3339_format_negative_pre_epoch ... ok
test audit::tests::rfc3339_format_out_of_range_returns_sentinel ... ok
test result: ok. 6 passed; 0 failed
```

Closes #158. Closes #159.

🤖 Generated with Claude Code

WaylandYang and others added 2 commits May 25, 2026 14:30
Two community-reported quality bugs, both with concrete patches from
the reporters:

#159 (mxz2007): cgroup::ensure_parent only enabled the `memory`
controller in the forkd parent cgroup's subtree_control, despite the
module doc-comment promising future cpu/io/pids support. Future PRs
adding cpu.max would silently fail because the child cgroup wouldn't
expose the file. Now enables {memory, cpu, io, pids} at first use.
Kernels ignore unknown controllers in subtree_control, so write
errors don't fire when a controller isn't compiled in.

#158 (pardcomper / Ziyu Wang): audit log's hand-rolled RFC3339
formatter had two latent bugs:
  1. SystemTime::duration_since(UNIX_EPOCH).unwrap_or(0) silently
     collapsed pre-epoch clocks (e.g. dead CMOS battery boot) to
     1970-01-01 with no warning — two audit records could land on the
     same timestamp with no signal.
  2. `as i32` cast of the computed year overflowed for secs >
     ~4e17, which a corrupted state.json with a bogus future
     created_at_unix could feed into and silently render a wrong year.

Replace with `time` crate (~30 KiB, no-default-features). For
in-range timestamps, behavior is identical; out-of-range returns a
"outside-time-range" sentinel rather than a wrong year. Added
regression tests for pre-epoch, year-9999, and the overflow case.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@WaylandYang WaylandYang merged commit 36097b8 into main May 25, 2026
2 checks passed
@WaylandYang WaylandYang deleted the fix/external-issues-158-159 branch May 25, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cgroup::ensure_parent doesn't enable cpu/io/pids controllers RFC3339 formatter: y2262 + negative-epoch undefined behaviour

1 participant