Files
reverse-engineering-anything/scripts/verify/baselines
3cfe8480c5 fix(elf): decode a 32-bit prpsinfo whose ABI gives pr_uid 32 bits (#10189)
* fix(elf): decode a 32-bit prpsinfo whose ABI gives pr_uid 32 bits

`decodeCorePrpsinfo` assumed every ELFCLASS32 core carries the i386/ARM `struct elf_prpsinfo`:
16-bit `pr_uid`/`pr_gid` and a 124-byte descriptor.

`pr_uid` is `__kernel_uid_t`, and its width is an ABI property, not an ELF-class one. Only
`arch/x86/include/uapi/asm/posix_types_32.h` and its ARM/m68k/sparc counterparts narrow it to
`unsigned short`; everything else takes `asm-generic/posix_types.h`'s `unsigned int`, so MIPS o32,
PowerPC-32, s390 and `compat_elf_prpsinfo` (`include/asm-generic/compat.h`:
`typedef u32 __compat_uid_t`) write a 128-byte struct with every member after `pr_flag` four bytes
later.

Reading a 128-byte descriptor with the 124-byte offsets published wrong values rather than null.
Measured through `parseElfNotes`, with `uid 70000, gid 80000, pid 4242, fname mips-proc`:

    before: {"pid":80000,"ppid":4242,"pgrp":1,"sid":4242,"uid":4464,"gid":1,
             "filename":"\u{10}","psargs":""}
    after:  {"pid":4242,"ppid":1,"pgrp":4242,"sid":4242,"uid":70000,"gid":80000,
             "filename":"mips-proc","psargs":"./mips-proc --serve"}

`pid` came out of the middle of `gid` and the two text fields came from the wrong offsets
entirely.

The kernel writes `sizeof(*psinfo)` as the descriptor — `fs/binfmt_elf.c`:
`fill_note(&info->psinfo, PRPSINFO, sizeof(*psinfo), psinfo)` — so the declared length already
carries the distinction and no machine table is needed. The 32-bit id width is now
`descriptor.length >= 128 ? 4 : 2`, and `pr_pid`/`pr_fname`/`pr_psargs` are derived from it. The
124-byte and 136-byte decodes are unchanged; the second new case pins that.

`src/native/elf` and `src/domain/native` — 535 passing. Forcing the 16-bit layout fails the new case.

* test(elf): produce the 32-bit prpsinfo layout from the shared note builder

Review finding: the regression hand-encoded a second NT_PRPSINFO layout while `corePrpsinfoNote` is
the repository's producer for this format, so nothing else could represent the MIPS/PowerPC/s390
ABI and the two encodings could drift.

`corePrpsinfoNote` takes `idWidth: 2 | 4` now. It allocates 124 or 128 bytes from it, writes
`pr_uid`/`pr_gid` at that width, and derives `pr_pid` through `pr_psargs` from `8 + idWidth * 2`
instead of the fixed 12/28/44 offsets. The option is ignored for a 64-bit image, whose layout is
fixed at 136.

Both new cases build their descriptor through the producer, so the test no longer carries offsets
the fixture does not know about.

* test(elf): drop the duplicate 124-byte prpsinfo case

The previous commit's rewrite left the original hand-built 124-byte block in place, so the same
regression ran twice — once through `corePrpsinfoNote`, once with the offsets written out again.
Keeping both is exactly the drift the shared producer was supposed to end.

* fix(elf): preserve SuperH PRPSINFO decoding

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
Co-authored-by: wunianze666-netizen <wunianze666@gmail.com>
2026-11-20 01:23:27 +00:00
..