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

Open
opened 2026-11-26 05:29:51 +00:00 by github-bot · 0 comments
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-25 17:48 UTC · original

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.
**@⁠ahmetbagci8** on GitHub · 2026-11-25 17:48 UTC · [original](https://github.com/xcl-dev/xcl/issues/2399) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:29:51 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.