startup: ring_copy reads guest memory with an unguarded memcpy after the probe #3468

Closed
opened 2026-11-29 15:56:55 +00:00 by Leyukaka · 0 comments
Leyukaka commented 2026-11-29 15:56:55 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T15:56:55Z.


On main cf0c30af, with X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT=1 (#2862), src/startup_stubs/d3d12_draw.inl:2684-2687 probes the input range with readable_window and then calls ring_copy(..., true).

ring_copy (src/startup_stubs/d3d12_xs_device.cpp:2885) copies with a plain std::memcpy. A page that is decommitted or protected between the probe and the copy faults inside the stand-in instead of taking the existing "could not be copied" refusal.

x2w_local::guarded_memcpy (src/startup_stubs/local_log.h:176) already covers this case: it returns false on an access violation or an in-page error. copy_title_bytes (d3d12_draw.inl:728) and guarded_copy (linear_buffer_backing.h:248) use it.

ring_copy has three call sites, all probe-then-copy:

Call site Probe
d3d12_draw.inl:2686, compute input snapshot readable_window at :2684
d3d12_draw.inl:2065, texture upload readable_window on the whole range at :1960, same function
d3d12_xs_device.cpp:2897, upload_from_title, called at :4603 readable_window at :4602

Measurement

One long local run of the application, switch off and then on, over the comparable window:

off on
translated compute dispatches 10 3,189
"placed buffer that does not alias" input refusals 4,693 0

With the switch on, 5,000 inputs were snapshotted (about 8.7 MiB). No snapshot refusal and no new fault was logged. This is one run, and output correctness was not checked.

Proposal

  • Copy with guarded_memcpy(dest, source, bytes, false) in ring_copy and return false on a fault. The snapshot caller then refuses on its existing path, so the opt-in fails closed. The other two callers already handle a false return.
  • A synthetic test that reserves a page without committing it (as tests/startup_local_log_check.cpp:574 does) and checks the refusal and the absence of a crash.
  • No default change in this issue.

I'm working on this.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6680841884 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3468). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T15:56:55Z. --- On main cf0c30af, with `X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT=1` (#2862), `src/startup_stubs/d3d12_draw.inl:2684-2687` probes the input range with `readable_window` and then calls `ring_copy(..., true)`. `ring_copy` (`src/startup_stubs/d3d12_xs_device.cpp:2885`) copies with a plain `std::memcpy`. A page that is decommitted or protected between the probe and the copy faults inside the stand-in instead of taking the existing "could not be copied" refusal. `x2w_local::guarded_memcpy` (`src/startup_stubs/local_log.h:176`) already covers this case: it returns false on an access violation or an in-page error. `copy_title_bytes` (`d3d12_draw.inl:728`) and `guarded_copy` (`linear_buffer_backing.h:248`) use it. `ring_copy` has three call sites, all probe-then-copy: | Call site | Probe | | --- | --- | | `d3d12_draw.inl:2686`, compute input snapshot | `readable_window` at `:2684` | | `d3d12_draw.inl:2065`, texture upload | `readable_window` on the whole range at `:1960`, same function | | `d3d12_xs_device.cpp:2897`, `upload_from_title`, called at `:4603` | `readable_window` at `:4602` | ### Measurement One long local run of the application, switch off and then on, over the comparable window: | | off | on | | --- | --- | --- | | translated compute dispatches | 10 | 3,189 | | "placed buffer that does not alias" input refusals | 4,693 | 0 | With the switch on, 5,000 inputs were snapshotted (about 8.7 MiB). No snapshot refusal and no new fault was logged. This is one run, and output correctness was not checked. ### Proposal - Copy with `guarded_memcpy(dest, source, bytes, false)` in `ring_copy` and return false on a fault. The snapshot caller then refuses on its existing path, so the opt-in fails closed. The other two callers already handle a false return. - A synthetic test that reserves a page without committing it (as `tests/startup_local_log_check.cpp:574` does) and checks the refusal and the absence of a crash. - No default change in this issue. I'm working on this.
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
R0Y00/Xbox2Windows#3468
No description provided.