fix(libSceGLSlimVSH): copy EGL attribute lists in through checked reads #20802

Merged
milescoviello merged 1 commit from upstream-pr/20802 into main 2026-11-17 07:43:51 +00:00
milescoviello commented 2026-11-15 15:47:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-15T15:47:39Z.


What

eglChooseConfig, eglCreateContext and eglCreatePbufferSurface walked the guest attributes list in place (for (auto p = attributes; *p != EGL_NONE; p += 2)). A list that pointed at unmapped memory, or ran into it before EGL_NONE, faulted the host. The library's debt file already lists this.

The three loops now read through a small Attributes reader in Egl.cpp. It copies the list with GuestCopyIn_nid_no_patch, up to 64 words per copy, and never crosses a 4 KiB boundary. A short list costs one checked copy rather than one per word, and the reader never touches a page the in-place loop would not have read.

Each value is still read only after its key is accepted. An unknown key therefore still returns EGL_BAD_ATTRIBUTE (0x3004) even when the word after it is unmapped, as before. An unreadable key or value returns EGL_BAD_PARAMETER (0x300c), which is the code the debt entry names. Valid lists behave exactly as before.

The existing debt entry is rewritten through a ## change fragment under docs/dev/debt/changes/. It records 0x300c as a host-safety fallback, since console behaviour here is not measured. These are setup calls, so the per-list copy sits off any per-draw path.

Tested

Linux (Ubuntu 26.04.1), GCC 15.2, Release.

  • New guest_glslim_attributes test. Each list is placed so it ends on the last word of a page, followed by a PROT_NONE page (PAGE_NOACCESS on Windows).
    • Valid lists still succeed for all three functions: criteria {SURFACE_TYPE, 1, RENDERABLE_TYPE, 4, NONE}, context {CONTEXT_CLIENT_VERSION, 2, NONE}, and pbuffer {WIDTH, 4, HEIGHT, 2, NONE}. The pbuffer then reports width 4.
    • An unmapped list (0x10) returns EGL_FALSE / EGL_NO_CONTEXT / EGL_NO_SURFACE with error 0x300c.
    • A list whose last mapped word is a valid key, with its value on the protected page, returns the same.
  • guest_glslim_query_surface, guest_glslim_state, guest_glslim_eglgetconfigs and guest_glslim_ipc_returns still pass.
  • Negative control: Egl.cpp from main with the new test dies with SIGSEGV at address 0x10. The page-end valid cases run before that point and pass on main too.
  • tools/check_conventions.py passes on the branch and this body. tools/debt_fold.py --check passes with the fragment applied.
  • git merge-tree against main, against #14212 (debt-file formatting for this library) and against #20798 (eglInitialize outputs, same file) is clean.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5324384796 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20802). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-15T15:47:39Z. --- ### What `eglChooseConfig`, `eglCreateContext` and `eglCreatePbufferSurface` walked the guest `attributes` list in place (`for (auto p = attributes; *p != EGL_NONE; p += 2)`). A list that pointed at unmapped memory, or ran into it before `EGL_NONE`, faulted the host. The library's debt file already lists this. The three loops now read through a small `Attributes` reader in `Egl.cpp`. It copies the list with `GuestCopyIn_nid_no_patch`, up to 64 words per copy, and never crosses a 4 KiB boundary. A short list costs one checked copy rather than one per word, and the reader never touches a page the in-place loop would not have read. Each value is still read only after its key is accepted. An unknown key therefore still returns `EGL_BAD_ATTRIBUTE` (0x3004) even when the word after it is unmapped, as before. An unreadable key or value returns `EGL_BAD_PARAMETER` (0x300c), which is the code the debt entry names. Valid lists behave exactly as before. The existing debt entry is rewritten through a `## change` fragment under `docs/dev/debt/changes/`. It records 0x300c as a host-safety fallback, since console behaviour here is not measured. These are setup calls, so the per-list copy sits off any per-draw path. ### Tested Linux (Ubuntu 26.04.1), GCC 15.2, Release. - New `guest_glslim_attributes` test. Each list is placed so it ends on the last word of a page, followed by a `PROT_NONE` page (`PAGE_NOACCESS` on Windows). - Valid lists still succeed for all three functions: criteria `{SURFACE_TYPE, 1, RENDERABLE_TYPE, 4, NONE}`, context `{CONTEXT_CLIENT_VERSION, 2, NONE}`, and pbuffer `{WIDTH, 4, HEIGHT, 2, NONE}`. The pbuffer then reports width 4. - An unmapped list (`0x10`) returns `EGL_FALSE` / `EGL_NO_CONTEXT` / `EGL_NO_SURFACE` with error 0x300c. - A list whose last mapped word is a valid key, with its value on the protected page, returns the same. - `guest_glslim_query_surface`, `guest_glslim_state`, `guest_glslim_eglgetconfigs` and `guest_glslim_ipc_returns` still pass. - Negative control: `Egl.cpp` from `main` with the new test dies with SIGSEGV at address `0x10`. The page-end valid cases run before that point and pass on `main` too. - `tools/check_conventions.py` passes on the branch and this body. `tools/debt_fold.py --check` passes with the fragment applied. - `git merge-tree` against `main`, against #14212 (debt-file formatting for this library) and against #20798 (`eglInitialize` outputs, same file) is clean. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-15 16:11:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T16:11:40Z.

Review: COMMENTED


Reviewed — comments

This review is incomplete because I could not access the prepared review files or run the repository reader.

What I ran

No commands; the required reader and review folder were not accessible through the available tools.

Results

Check Result Note
Review materials not run Not accessible
Repository context not run Reader not run

Findings

Blocking

None verified.

Non-blocking

The change could not be assessed without the diff and targeted source context.

Not verified

The description, commits, diff, manifest, changed files, behavior, and tests were not read or verified.

To get this to a good state

Provide access to the prepared review folder and reader so the review can be completed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5911654139 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20802#pullrequestreview-5911654139). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-15T16:11:40Z. **Review:** COMMENTED --- # Reviewed — comments This review is incomplete because I could not access the prepared review files or run the repository reader. ## What I ran No commands; the required reader and review folder were not accessible through the available tools. ## Results | Check | Result | Note | |---|---|---| | Review materials | not run | Not accessible | | Repository context | not run | Reader not run | ## Findings ### Blocking None verified. ### Non-blocking The change could not be assessed without the diff and targeted source context. ## Not verified The description, commits, diff, manifest, changed files, behavior, and tests were not read or verified. ## To get this to a good state Provide access to the prepared review folder and reader so the review can be completed.
Sign in to join this conversation.
No reviewers
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
boykopovar/AnyPS5!20802
No description provided.