Loader: IAT thunk and TLS-index writes don't reject targets inside the headers (hardening parity with leonida#501) #830
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-24T06:32:39Z.
What this is: a small, unit-testable hardening parity gap in the manual-mapping path. No game data; the title's own images are well-formed — this is defense-in-depth against crafted images (and cheap to close).
The gap. Two writes into a manually-mapped image skip the one validation that matters — target must not be inside the headers:
crates/xcl/src/loader.rs:178—((base + e.iat_rva) as *mut u64).write_unaligned(..): resolves an import and writes the thunk at the IAT RVA without checkingiat_rva >= size_of_headers. A malformed image whose import directory RVA points into the headers gets its own PE headers overwritten (or the write faults inside xcl if the headers page is mapped RX — either is a loader bug, not the image's).crates/xcl/src/tls.rs, "write that slot's index into the game's_tls_index") takes the target from the image'sAddressOfIndex(read attls.rs:268style deref) with the same missing bound check.pe.rsalready parses and storessize_of_headers(pe.rs:200) and uses it to clamp reads (pe.rs:335/357) — the write side just needs the same invariant: directory-derived write targets ∈ [size_of_headers,SizeOfImage).Precedent: the sibling project just closed the identical class — ubiquitarianism/leonida#501 ("refuse an import address table or TLS index in the headers"). Two independent projects finding the same loader invariant within an hour is the usual evidence it belongs in the parse step rather than at each write site: reject once in
pe.rs(PeError::HeaderWriteTarget), and the write sites keep working unguarded on already-vetted images.Test sketch: craft a minimal PE in
tests/data/(synthetic, allowed) withSizeOfHeaders=0x400and an import-directory (and TLSAddressOfIndex) RVA of0x80; assertPe::parse/mapping returns the new error instead of writing.Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-24T06:34:24Z.
Class weight update within the hour: the sibling project independently closed the same invariant — Marvisak/VIctory#670 ("loader: use checked offsets and sizes in image preparation"). Third project, one day, no coordination: when three independent manual-mapping loaders each find that directory-derived write targets need the
size_of_headersbound, the natural home is the parse step once (as proposed here), not per-write-site checks forever.Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-24T15:24:13Z.
Fourth instance within a day, same class: the sibling runtime just opened Marvisak/VIctory#1047 ("fix 4 bounds and cleanup bugs in
windows.rs" — their loader image preparation) on top of their #670, this repo's parse-step work referenced here, and the leonida original. Four independent finds in one day across three manual-mapping loaders is no longer a coincidence to fix per-site — it is evidence that the invariant (directory-derived targets and table bounds must be validated once, at parse) belongs inPe::parseso every future write site inherits it. Leaving the proposal as filed; the class keeps making its own argument.Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-24T15:37:07Z.
Status update on this proposal, same day: it got implemented while we were filing examples for it — #1367 now validates directory descriptors and block sizes in the parser (
imports/delay_imports/relocations,Err(BadRva)at parse time) and #1397 boundsrva_to_offsetat EOF on the consumer side. If the exports-directory coverage question I left on #1367 comes back clean, this issue can be closed as done after those two merge — the five-instance class (both sibling runtimes + leonida + today's two PRs) is the receipts.upstream-sync referenced this issue2026-11-24 19:06:45 +00:00
upstream-sync referenced this issue2026-11-26 09:06:34 +00:00