XGameRuntime: QueryApiImpl forwarding classes can read past PC vtable and leak COM refs #2389

Open
opened 2026-11-25 17:48:29 +00:00 by ahmetbagci8 · 2 comments
ahmetbagci8 commented 2026-11-25 17:48:29 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by ahmetbagci8 on 2026-11-25T17:48:29Z.


Summary

In crates/xcl/src/hle/xgameruntime/api.rs (QueryApiImpl, lines 278-289):

let target = if !o.iface.forward.is_empty() {
    if known {
        if o.pc.load(Ordering::Acquire) == 0 {
            o.pc.store(pc_object(&c, &i).unwrap_or(0), Ordering::Release);
        }
        o
    } else {
        forward_alias_obj(o, c, i)
    }
} else {
    o
};
  1. layout() merges multiple known IIDs of a class (from different GDK versions with different PC vtable lengths) into a single Obj. Because forward_alias_obj is only used when !known, querying an older known IID of a forwarding class (such as XGameUi) caches that shorter PC COM object in o.pc. A subsequent query for a newer known IID in o.iface.iids reuses o with the older PC object, so calling any newer forwarded slot in forward() (*(*(o as *const *const usize)).add(slot)) reads past the end of the PC vtable.
  2. The o.pc.load followed by o.pc.store is also a TOCTOU race: concurrent QueryApiImpl calls both call pc_object(&c, &i) and one overwrites and leaks the other's COM reference.

Suggested fix

Always route forwarding classes through forward_alias_obj(o, c, i) regardless of known:

let target = if !o.iface.forward.is_empty() {
    forward_alias_obj(o, c, i)
} else {
    o
};

Not tested

  • Read from commit 082944135cd2b96288470a595861fa608eee08dc without a new runtime test.

AI use

  • Antigravity harness (Gemini 4 Neon) audited api.rs and drafted this report; the author reviewed it before posting.
<!-- greyfinch-sync:ivall/xcl:issue:6610355652 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2399). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-25T17:48:29Z. --- ### Summary In `crates/xcl/src/hle/xgameruntime/api.rs` (`QueryApiImpl`, lines 278-289): ```rust let target = if !o.iface.forward.is_empty() { if known { if o.pc.load(Ordering::Acquire) == 0 { o.pc.store(pc_object(&c, &i).unwrap_or(0), Ordering::Release); } o } else { forward_alias_obj(o, c, i) } } else { o }; ``` 1. `layout()` merges multiple known IIDs of a class (from different GDK versions with different PC vtable lengths) into a single `Obj`. Because `forward_alias_obj` is only used when `!known`, querying an older known IID of a forwarding class (such as `XGameUi`) caches that shorter PC COM object in `o.pc`. A subsequent query for a newer known IID in `o.iface.iids` reuses `o` with the older PC object, so calling any newer forwarded slot in `forward()` (`*(*(o as *const *const usize)).add(slot)`) reads past the end of the PC vtable. 2. The `o.pc.load` followed by `o.pc.store` is also a TOCTOU race: concurrent `QueryApiImpl` calls both call `pc_object(&c, &i)` and one overwrites and leaks the other's COM reference. ### Suggested fix Always route forwarding classes through `forward_alias_obj(o, c, i)` regardless of `known`: ```rust let target = if !o.iface.forward.is_empty() { forward_alias_obj(o, c, i) } else { o }; ``` ### Not tested - Read from commit `082944135cd2b96288470a595861fa608eee08dc` without a new runtime test. ### AI use - Antigravity harness (Gemini 4 Neon) audited `api.rs` and drafted this report; the author reviewed it before posting.
oni-swr commented 2026-11-26 19:06:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-26T19:06:27Z.


Claiming this issue: fixing QueryApiImpl forwarding-class routing in crates/xcl/src/hle/xgameruntime/api.rs so each IID gets its own PC object (preventing PC vtable over-reads and o.pc TOCTOU COM ref leaks), with CPU regression tests.
AI use: Claude Code (Claude Sonnet 5.5) implementing and testing on Windows; coordinated by Antigravity.

<!-- greyfinch-sync:ivall/xcl:comment:7201202201 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2399#issuecomment-7201202201). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T19:06:27Z. --- Claiming this issue: fixing `QueryApiImpl` forwarding-class routing in `crates/xcl/src/hle/xgameruntime/api.rs` so each IID gets its own PC object (preventing PC vtable over-reads and `o.pc` TOCTOU COM ref leaks), with CPU regression tests. AI use: Claude Code (Claude Sonnet 5.5) implementing and testing on Windows; coordinated by Antigravity.
oni-swr commented 2026-11-26 19:30:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-26T19:30:38Z.


Releasing my claim above — open PR #2623 already implements the per-IID clone fix for forwarding classes in api.rs.

<!-- greyfinch-sync:ivall/xcl:comment:7201667871 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2399#issuecomment-7201667871). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T19:30:38Z. --- Releasing my claim above — open PR #2623 already implements the per-IID clone fix for forwarding classes in `api.rs`.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl#2389
No description provided.