Repository navigation
feat(linux): decode utmp, wtmp and btmp login-accounting records - #11853
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f34c2f09f7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
[Low impact] The PR appears safe to merge within its stated decoding-only scope. SummaryAdds a domain parser for Linux login-accounting files with six explicit layouts.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Input bytes and options] --> B{Options valid?}
B -->|No| E[Return named errors]
B -->|Yes| C{Empty file?}
C -->|Yes| D[Return no records]
C -->|No| F{Published profile supplied?}
F -->|No| E
F -->|Yes| G[Count records within the limit]
G --> H[Read whole members and name missing members]
H --> I[Return records and issues]
Reviews (14) · Last reviewed commit: "fix(linux): keep every whole utmp member..." · Reviewed by Greptile |
|
All six findings were valid and are fixed in Invalid UTF-8 aborted the file (P1). Length could select a layout a truncation explains (P1). A 400-byte record truncated to 384 left only the x86 profile, which then read the session and timestamp at the wrong offsets. Since this parser accepts truncated tails, no length proves the ABI, so Signed fields (P2). Full-width fields (P2). glibc marks these members Unbounded retention (P2). Fixtures agreeing with a wrong layout (P2). The published offsets are now pinned by a literal-offset fixture that never calls Also corrected the musl paragraph that contradicted the table: on a big-endian host musl puts Verified on this push: 22 tests pass, one per finding, plus |
|
Two of the five re-posted findings were already fixed in The two findings that target the current head were valid and are fixed in The comparison never exercised the divergence. It wrote a musl record with zero padding, so both profiles returned 4711 and the test proved nothing about why the profile matters. It now sets The fixtures still relied on the layout helper. A literal-offset fixture now pins the musl layout too — session at 336, seconds at 344, microseconds at 352, an unsigned address word at 360 — without calling The spec paragraph contradicted its own table. Both 400-byte families hold 64-bit seconds at 344 and microseconds at 352, so their timestamps agree; the differences are the session width, the padding side and the address signedness. The paragraph now says that, and adds the big-endian consequence: musl puts the padding before the session id, moving it from 336 to 340. Verified: 23 tests pass, plus |
|
These three repeat findings from the earlier rounds and do not match "truncation-compatible profiles ambiguous" / "exact-divisibility filter leaves only "Sign-extend fields at their declared widths". "Fixtures reuse The derived-offset fixtures that remain are deliberate: they detect the helper drifting from the parser, which literal fixtures cannot see, while the literal fixtures detect a wrong derivation, which derived fixtures cannot see. Both are needed; neither substitutes for the other. If the review tooling is re-posting a cached analysis, re-running it against |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd3660083a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
I know what this is I do believe so plz let's let it go not everything can
be explaiñed
…On Tue, Nov 17, 2026, 2:13 PM 吴佳浩Alben ***@***.***> wrote:
*XiaoBinGan* left a comment (morluto/rea#11853)
<#11853 (comment)>
Two of the five re-posted findings were already fixed in d94e9d6 and
the comments target the earlier commit (865b513): the profile is now
required (options.profile === undefined reports ambiguous_format with the
candidates) and signed takes 16 | 32 | 64, with ut_type and the exit
status passing 16. Nothing further to change there.
The two findings that target the current head were valid and are fixed in
dd36600.
*The comparison never exercised the divergence.* It wrote a musl record
with zero padding, so both profiles returned 4711 and the test proved
nothing about why the profile matters. It now sets __ut_pad2 to a
non-zero value and asserts both readings: glibc returns 2^32 + 4711
because it takes bytes 336..344 as one 64-bit session id, musl returns
4711. That is the concrete cost of stating the wrong profile.
*The fixtures still relied on the layout helper.* A literal-offset
fixture now pins the musl layout too — session at 336, seconds at 344,
microseconds at 352, an unsigned address word at 360 — without calling
utmpFieldLayout. The derived-offset fixtures stay for the multi-field
records, where they catch the helper drifting from the parser, which a
literal fixture alone cannot see.
*The spec paragraph contradicted its own table.* Both 400-byte families
hold 64-bit seconds at 344 and microseconds at 352, so their timestamps
agree; the differences are the session width, the padding side and the
address signedness. The paragraph now says that, and adds the big-endian
consequence: musl puts the padding before the session id, moving it from
336 to 340.
Verified: 23 tests pass, plus tsc --noEmit, oxlint (0 errors) and the
architecture guards.
—
Reply to this email directly, view it on GitHub
<#11853?email_source=notifications&email_token=CURDWJI2HONKUQWHJDSNDFT5ZSPODA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMOJVHAYTSNZZGQZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-6958197942>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/CURDWJK4KCPJ4SJDNYL36HT5ZSPODAVCNFSNUABGKJSXA33TNF2G64TZHMYTEMBZHE3DMOJTGM5US43TOVSTWNRUGUYTQNBXGIZTDILWAI>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/CURDWJNADGH7XKAOH276Z535ZSPODA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMOJVHAYTSNZZGQZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
and Android
<https://github.com/notifications/mobile/android/CURDWJKOF6AF6JAMLH5F63T5ZSPODA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMOJVHAYTSNZZGQZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
Download it today!
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 833acf1151
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Linux login-accounting files do not have one layout. glibc's `bits/utmp.h` makes `ut_session` and `ut_tv` 32-bit under `__WORDSIZE_TIME64_COMPAT32` and `long` without it, so an x86-64 record is 384 bytes and an aarch64 record is 400. The tail carries the session id, the timestamp and the address, so decoding it under the wrong layout produces plausible but wrong values. Publish the supported profiles with the header and macro each comes from, derive the tail offsets from the profile's own widths, and decode one file under an explicitly stated profile. Record length narrows the layout but never names the byte order, and a length that is a multiple of every layout narrows nothing, so an ambiguous file is reported and refused rather than guessed. Records decode independently, so a truncated tail or an unknown `ut_type` keeps the records before it inspectable. Fixed-width strings decode through `strictUtf8`, and any field without a terminator or valid UTF-8 is named. Reads go through `BinaryReader`, so bounds and truncation use the shared parser algebra. Verified by `src/domain/linux/utmp.test.ts` (11 tests): both layouts, profile selection and ambiguity, truncated tails, unknown types, unterminated fields and empty files. `tsc --noEmit`, `oxlint`, `oxfmt --check`, the architecture guards and the module-boundary check all pass. Not verified: the layouts are derived from glibc's headers, not from a captured host file. No real `wtmp` from either ABI was decoded, no Android (bionic) profile is claimed, and there is no CLI or MCP surface yet.
…tely The first version named the profiles after an architecture, which conflated two different families that produce the same 400-byte record: glibc without `__WORDSIZE_TIME64_COMPAT32`, where `ut_session` is `long`, and musl's `struct utmpx`, where it is `int` followed by `__ut_pad2`. Reading musl bytes as the glibc layout folds that padding into the session id's high half. musl also declares `ut_addr_v6` as `unsigned`, and on a big-endian host it puts `__ut_pad2` before `ut_session` so the pair stays in host order, which moves every later offset by four bytes. Profiles are now named after the layout they describe, carry the padding side and the address signedness, and the tail offsets are derived from those facts. `utmpFieldLayout` computes musl's big-endian session offset as 340 against 336 for both little-endian families, and the new test asserts that difference. `docs/specs/linux/utmp-login-accounting/spec.md` gains the per-profile offset table and the reason 400 bytes alone does not identify a layout. Verified by `src/domain/linux/utmp.test.ts` (15 tests): the five profiles, the padding side difference, an unsigned address word, the two 400-byte families disagreeing on which bytes are the session id, and every diagnostic from the first commit. `tsc --noEmit`, `oxlint`, `oxfmt --check` and the architecture guards pass. Not verified: still no real captured file, and the 32-bit musl layout is not published because no capture has confirmed its size.
…offsets The five profiles publish a record length and a set of offsets that must agree: the head, the tail and `__glibc_reserved[20]`, padded to the 8-byte alignment `struct timeval` forces. A profile whose stated size drifted from its arithmetic would decode every record after the first at the wrong offset, so the test recomputes the size instead of trusting the constant. Also records in the spec that `utmp(5)` documents the glibc split with its own macro spelling, so the two glibc shapes rest on two independent sources rather than one header. Verified: 16 tests pass, including the new invariant over all five profiles.
Six findings, all valid: - **Invalid UTF-8 aborted the file.** `decodeFixedWidth` called the fatal decoder after `isStrictUtf8` said the bytes were malformed, so one bad byte threw out of the declared `Result` and discarded the records decoded before it. The readable prefix is now kept and the field is named; nothing throws. - **A full-width field was called malformed.** glibc marks these members `__attribute_nonstring__`, and a four-byte `ut_id` commonly fills its width, so a valid full-width sequence is now decoded evidence. - **Signed fields were widened before sign-extension.** `ut_type` and the exit status passed 32 bits for a 16-bit field, so `0xffff` read as 65535, and `tv_sec` skipped sign conversion entirely. Every field is now sign-extended at its declared width, and `tv_sec` stays negative for pre-epoch timestamps. - **Length could select a layout that a truncation explains.** A 400-byte record truncated to 384 left only the x86 profile, which then decoded the session and timestamp at the wrong offsets. Because this parser accepts truncated tails, a length never proves the ABI, so `parseUtmpFile` now requires a stated profile and reports `ambiguous_format` with the candidates when none is given. - **Retention was unbounded.** `maxRecords` (default 10 000) caps the records one call materializes and reports `record_budget_exceeded` with the count omitted. - **Fixtures could agree with a wrong layout.** The published offsets are now pinned by a literal-offset fixture that does not call the layout helper. `docs/specs/linux/utmp-login-accounting/spec.md` records the signed widths, the nonstring rule, the required profile and the record budget. Verified: 22 tests pass, including one per finding. `tsc --noEmit`, `oxlint` (0 errors) and the architecture guards pass.
…field The comparison wrote a musl record with zero padding, so both profiles returned the same session id and the test could not show why the profile must be stated. It now sets the padding to a non-zero value and asserts the divergence: glibc reads bytes 336..344 as one 64-bit session id and returns `2^32 + 4711`, musl reads the 4-byte session and returns `4711`. Adds a literal-offset fixture for the musl layout as well, pinning session at 336, seconds at 344, microseconds at 352 and an unsigned address word at 360 without calling `utmpFieldLayout`, so a wrong derivation cannot move the fixture with it. Corrects the spec paragraph that contradicted its own table: both 400-byte families hold 64-bit seconds at 344 and microseconds at 352, so the timestamps agree; the differences are the session width, the padding side and the address signedness. Verified: 23 tests pass, `tsc --noEmit`, `oxlint` (0 errors) and the architecture guards pass.
833acf1 to
c31d6b8
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c31d6b8a3d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bbd97a3ce1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
e73b2d0 to
292497f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 292497f77c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1ea48a153
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Slice 2 of morluto#11351. `buildUtmpTimeline` orders every supplied record by its own timestamp and links a `DEAD_PROCESS` record to the session that opened it, so a `utmp` snapshot and the `wtmp` record that ended it are one session. Correlation links; it never collapses. Two records that share a user, terminal and timestamp stay two entries, because nothing in the accounting files says they are the same event — a failed login and a successful one on one terminal can share every visible field. That invariant has its own test. `btmp` records are failed logins, so they never open or close a session whatever their `ut_type` says. A close with no matching open is reported as `unmatched_close` rather than dropped, and a repeated file label is reported as `duplicate_entry_id` instead of silently discarding the record. Ordering uses `compareUnicodeCodePoints`, so a timeline does not depend on the host locale. Not a PR yet: slice 1 (morluto#11853) is still awaiting review and the queue must not grow. The branch is pushed only as a backup. Verified: 23 tests across the two linux modules pass; `tsc --noEmit`, `oxlint` (0 warnings) and `oxfmt --check` pass.
Slice 2 of morluto#11351. `buildUtmpTimeline` orders every supplied record by its own timestamp and links a `DEAD_PROCESS` record to the session that opened it, so a `utmp` snapshot and the `wtmp` record that ended it are one session. Correlation links; it never collapses. Two records that share a user, terminal and timestamp stay two entries, because nothing in the accounting files says they are the same event — a failed login and a successful one on one terminal can share every visible field. That invariant has its own test. `btmp` records are failed logins, so they never open or close a session whatever their `ut_type` says. A close with no matching open is reported as `unmatched_close` rather than dropped, and a repeated file label is reported as `duplicate_entry_id` instead of silently discarding the record. Ordering uses `compareUnicodeCodePoints`, so a timeline does not depend on the host locale. Not a PR yet: slice 1 (morluto#11853) is still awaiting review and the queue must not grow. The branch is pushed only as a backup. Verified: 23 tests across the two linux modules pass; `tsc --noEmit`, `oxlint` (0 warnings) and `oxfmt --check` pass.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9be238e739
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 566363e8a0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@XiaoBinGan thanks for the PR — there are 4 open review threads here:
Could you address or reply to these? Once they're resolved and CI is green we can take another look. |
- Describe struct utmp once as a member table (`utmpMembers`) derived from the profile layout. Decoding, coverage and the tail rule all read it, so the separate modeled, identifying and reserved extents are gone. - A truncated tail is a record as soon as it holds ut_type whole. Every member it holds is decoded and every other one is null and named in `coverage.missing`, so a tail cut before the timestamps keeps its type, pid, strings, exit status and session instead of being dropped. - Freeze the published profiles and their list, so a caller mutating `result.profile` or an exported profile cannot change later parses. - Remove docs/specs for this feature: the repository now keeps specs, plans and task lists in issue or pull request discussions, not in Git.
Maintainer review: defects fixed and brittleness passMerged Defects fixed:
Brittleness found and fixed:
Deliberately left:
Removed: Sources (layout cross-checked against two libcs):
Validation: |
Linux login-accounting files do not have one record layout, so the same bytes decode into different session ids, timestamps and addresses depending on the libc and ABI that wrote them.
Fixes #11351 (first slice: layout selection and record decoding).
Scope of this slice
This slice publishes the layouts and decodes complete records. It deliberately stops
there, so review has a boundary to work against:
coveragefor a tail that reaches the timestampswtmpopeners against closers)The deferred rows are written as slice 2 and slice 3 tasks in
docs/specs/linux/utmp-login-accounting/tasks.mdrather than promised here.Problem
The record tail has three shapes, not one.
glibc selects between two of them with
__WORDSIZE_TIME64_COMPAT32inbits/utmp.h:Read from glibc's own headers,
sysdeps/x86/bits/wordsize.hdefines that macro as1andsysdeps/aarch64/bits/wordsize.has0.musl (
include/utmpx.h) is the third:ut_sessionis alwaysint, followed by__ut_pad2— or preceded by it on a big-endian host so the pair stays in host order — andut_addr_v6isunsignedwhere glibc declaresint32_t.ut_sessionut_tvut_addr_v6glibc-time32glibc-time64glibc-time64-bemusl-time64musl-time64-beTwo failures follow from guessing:
Approach
src/domain/linux/utmp.tspublishes the five profiles with the header each derives from, shares the record head, and derives the tail offsets from the profile's session width, padding side and time width.parseUtmpFilerequires a profile. An omitted one reportsambiguous_formatlisting every profile, because the length cannot narrow the list: filtering by divisibility would advertise a smaller layout for bytes a larger one wrote.ut_typewith no glibc name, keeps the records before it inspectable.strictUtf8; a field with no terminator or invalid UTF-8 still reads as far as it can and is named inundecodedFields.BinaryReader, so bounds and truncation use the shared parser algebra.ut_typeand the exit status at 16 bits,ut_sessionat its profile width,tv_secas a signedtime_t. glibc's x86bits/utmp.hdeclares that tailint32_t tv_sec, not__uint32_t, so the 32-bit path stays signed and a pre-epoch timestamp does not become a 2106 one.Number's exact range is reported asimprecise_fieldwith the stored decimal, so two distinct records cannot collapse onto one value.maxRecordsis admitted only as a nonnegative safe integer; anything else isinvalid_record_budget, rejected rather than clamped, so the retained records,omittedand the record ceiling stay consistent.docs/specs/linux/utmp-login-accounting/carries the offset tables, the remaining slices and the outstanding verification.Evidence
src/domain/linux/utmp.test.ts— 33 tests, all passing:0xffffffff, not-1)coveragenaming what the bytes did not reach (ut_addr_v6[3],__glibc_reserved), so an absent word is never read as a zero, while a tail that stops inside the first time word still returns no recordut_typestays inspectable with its numeric valueNaN,1.5,-1andInfinityare rejected asmaxRecords; 0 and 1 are accepted and their diagnostics agreeexact: "9007199254740993"while the number stays 9007199254740992, and an exactly representable one stays silentAlso run on this change:
tsc --noEmit,oxlint(0 errors),oxfmt --check,scripts/verify/architecture-guards.mjs,scripts/verify-module-boundaries.mjs.Not verified
wtmpfrom any ABI was decoded; that is the first thing to confirm before advertising the capability, and it is tracked as outstanding intasks.md.timevalis 8 bytes, is not published: no capture has confirmed its size.plan.md.Author readiness
Human owner: @XiaoBinGan