fix: address external issues #158 + #159#161
Merged
Merged
Conversation
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>
This was referenced May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
`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.
`(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:
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