Skip to content

fix(libc): refuse a macOS host write over a read-only watched page, as Windows does - #28075

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
magnub:fix/macos-host-write-refuse-read-only
Dec 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
magnub:fix/macos-host-write-refuse-read-only

Conversation

@magnub

@magnub magnub commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What

On macOS the write watch cannot see host writes, so GuestWriteWatchBeginHostWrite_nid_postfix marks every page of the range written as soon as a host write opens. Windows refuses the open instead when any page of the range is not writable (WindowsMappings::BeginHostWrite), and callers already treat a refused open as an unwritable destination.

GuestArenaBeginHostWrite_nid_postfix now does the same on macOS: when the write watch records a page of the range without PROT_WRITE, it returns false before marking anything. A host write could not land on such a page anyway, because opening it restores the recorded protection, which has no write bit.

This is what broke guest_videodec2_hevc_aliases on macOS. The upfront frame and output check from #21081 opens a host write over the read-only frame, and over an output that crosses into the read-only page, so pages were reported dirty although nothing was written. The code change is under __APPLE__; Linux and Windows are unchanged.

Tested

Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2, on main 29b14e4. #17425, #11049, #26739 and #25331 were merged locally only so that main builds on macOS.

  • guest_videodec2_hevc_aliases: fails 2/2 on main ("read-only frame dirtied watched output page"), passes 3/3 with this change.
  • The 116 tests that open guest memory for writing, including write_watch_* and guest_arena_*, before and after: the only difference is that guest_videodec2_hevc_aliases now passes. guest_kernel_sys fails both before and after.

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

🤖 Generated with Claude Code

https://claude.ai/code/session_012LL9hfx4BY6MbUCYMduDAQ

Summary by CodeRabbit

  • Bug Fixes
    • On Apple, host writes to memory regions reported as non-writable are now rejected. Other platforms are unchanged.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b6938e7-e0d5-46d8-a8b1-bbaf58b51c3f
Commits

Reviewing files that changed from the base of the PR and between 54e22cc and 93edeb5.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Changes: Guest Arena host writes

Layer / File(s) Summary
Check protections before host writes
core/libs/prx/libc/src/GuestArena.cpp
The Apple host-write entry point scans eligible ranges and returns false when a successful protection query reports a run without PROT_WRITE. Zero-length and overflowing ranges skip the check.

Suggested reviewers: milescoviello, leandrolp23, marczx10

Change: Bug fix

Merge Risk: Minimal · previous review 54e22

On macOS, opening a host write over a read-only watched page is now refused, as on Windows. The scan terminates and the decoder callers handle the refusal, so no concrete merge-blocking risk remains.

Security architecture risk: Minimal · up to 54e22

The change prevents a refused write from marking guest pages as modified. It adds no write permissions, and the existing cleanup rules still apply when a write is refused.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed behavior is confined to macOS host-write admission for guest-memory ranges. It refuses some writes previously admitted to setup and does not grant new host or guest permissions.

Trust Boundaries and Controls

  • observed — The control checks recorded permissions for the requested address and length. Each query takes its own lock, so admission is not atomic with setup; when there is no protection record, the check does not make a new authorization decision.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ade17fa0-f95a-4752-ba4d-82a94830e882
Commits

Reviewing files that changed from the base of the PR and between 045b7d7 and 54e22cc.

Files selected for processing: 1

  • core/libs/prx/libc/src/GuestArena.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

Nothing blocks this change; the read-only protection check runs before the write watch marks any pages dirty.

What I ran

Reviewed head 54e22cc7d934e5bbc74ffee7df92ad8183ec081f from the prepared diff and reader-pinned source. No commands or tests were run.

Results

Check Result Note
Diff and source review passed One changed source file read
Tests not run No tests run in this review

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author-reported macOS test results were not independently verified. No test files were changed. The review bundle’s files.json was not available, so I could not compare the read file count against its reviewed list. GuestArena.cpp was the only changed file listed in the manifest and was read; the remaining repository files were not read.

To get this to a good state

Nothing is required.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1835 core/libs/prx/libc/src/GuestArena.cpp
PR 16372 core/libs/prx/libc/src/GuestArena.cpp
PR 28264 core/libs/prx/libc/src/GuestArena.cpp
PR 28470 core/libs/prx/libc/src/GuestArena.cpp
PR 29072 core/libs/prx/libc/src/GuestArena.cpp

@magnub
magnub force-pushed the fix/macos-host-write-refuse-read-only branch from 54e22cc to 93edeb5 Compare November 29, 2026 00:15

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the inspected code supports rejecting macOS host writes that span a watched page without write permission.

What I ran

Reviewed head 93edeb564a305a6effd4244931d7f59b3a4a35c using the prepared diff and pinned reader repo_read.py. No tests or builds were run.

Results

Check Result Note
Diff and description passed One source file changed
Targeted source review passed Protection lookup and write-watch path inspected
Tests and build not run No local execution

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests reported in the PR description were not run independently. Only the changed GuestArena.cpp and targeted portions of GuestWriteWatch.cpp and GuestWriteWatch.hpp were read. No other changed files were listed in the manifest; files.json was not available from the reader.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot added the libc label Nov 29, 2026
@NobleBrains

Copy link
Copy Markdown
Contributor

Tested on Apple silicon: Apple M4, macOS 15.7.9, Apple clang 17.0.0, CMAKE_OSX_ARCHITECTURES=x86_64 (Rosetta), Release, BUILD_TESTING=ON. Tree: main at 611e7805f4 with the diffs of #27201, #27739, #27843, #27767, #17425 and #27827 applied so that it builds.

Without this PR, guest_videodec2_hevc_aliases failed (read-only frame dirtied watched output page); with it (93edeb564a), the test passed.

AI-assisted: yes (Claude Code)

@NobleBrains NobleBrains left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on macOS 15.

Setup: Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, BUILD_TESTING=ON. These are the OS and compiler generation of the macos-15 runner; the description tested macOS 27.
Tree: main 93d64f2d1e + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (main does not build on macOS without them, see #28168) + #22091 + #28369, then #28075, #28076 and #28284 merged one after another. Each merged cleanly.

guest_videodec2_hevc_aliases failures
before this PR (same tree) 3/3
with this PR at 93edeb564a 0/5

Full ctest -j 6 with all of them merged: 7038/7066 pass. Compared with the same tree before these PRs, no test fails that passed before. jsc_wtf_cpu_time aborted once under the parallel load, then passed 5/5 on its own; it is unrelated JavaScriptCore CPU-time code.

AI-assisted: yes (Claude Code)

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the Darwin range walk into GuestWriteWatchProtection_nid_postfix. It advances through watched runs and unwatched gaps up to the requested end, so a range that starts writable and crosses into a watched read-only page is rejected before the write watch is opened. The Apple-specific implementation was reviewed from source because this checkout runs on Linux.

AI-assisted: yes.

@NobleBrains

Copy link
Copy Markdown
Contributor

Host: macOS 15.7.9, Apple M4, x86_64 Release build under Rosetta 2, BUILD_TESTING=ON. The tree was main e8f09d2877 plus the open macOS build fixes #27201, #27767, #27739 and #27843, so it is not a build of this branch alone. This PR's diff (gh pr diff, head 93edeb564a) was applied on top. The other two PRs I was testing in the same tree touch different files.

guest_videodec2_hevc_aliases: fails without this PR (read-only frame dirtied watched output page), passes with it. I removed only this diff again to check, and the test failed again.

The full ctest -j2 run (7152 tests) had no other new failure from this change. guest_main_stack_move failed once in that run, but it is flaky here with and without this diff (5 of 30 runs fail without it, 3 of 20 with it). I did not test natively on arm64 or on Intel hardware, and no title was run.

AI-assisted: yes (Claude Code)

@ycbuzi

ycbuzi commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Tested 93edeb564a merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 2 tests failed out of 7616; 99% tests passed, 2 tests failed out of 7616. 2 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 7616; 100% tests passed, 0 tests failed out of 7616. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@oneandonlydean
oneandonlydean merged commit 04ffc25 into boykopovar:main Dec 5, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants