fix(libkernel): map app0.zar files with execute access on Windows #27906
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27906"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Ducengarth on 2026-11-27T19:38:39Z.
What
A shared
PROT_EXECmapping of a file read fromapp0.zarreopens the file on Windows to get execute access. When that reopen is refused, the mapping fails withEACCESwhere the same mapping of the loose file succeeds. This change maps through the handle the backing already has, so the mapping no longer depends on the reopen.Scope (corrected after the first review round): the refusal I measured happens only when the process runs inside an MSIX package with virtualized AppData, here the Claude desktop app (
Claude_pzs8sxrjxfjjc), whose child processes ranctest. A plain PowerShell started from Explorer on the same machine and folder accepts the reopen. So this does not fix a failure that users launching AnyPS5 normally would see. What it does fix:guest_kernel_app_archive_mmapfailing onmainfor anyone who runs the tests from a packaged app withTMPin%LOCALAPPDATA%\Temp. InMappingProtections, protection 4 withMAP_SHAREDgivesEACCESfor/app0/Mapped/196685.binand a mapping for/app0/Reference/196685.bin.How it fails. The mapping of an archived file goes through a temporary backing (
AppArchiveBacking.cpp) in%TEMP%. Its writer is created withFILE_FLAG_DELETE_ON_CLOSEand closed whenAppArchiveMaterialize_nid_no_patchreturns, so the file is delete-pending once only the read-only descriptor is left.DoMapFileBacked_nid_no_patchthen reopens that handle withGENERIC_READ | GENERIC_EXECUTE. Under the package's AppData virtualization, that reopen fails withSTATUS_DELETE_PENDING(0xC0000056,ERROR_ACCESS_DENIED): "map file: reopen the file with execute access: Permission denied".The change:
GENERIC_READ | GENERIC_EXECUTE, while the writer is still open. It still grants no write access.DoMapFileBacked_nid_no_patchreuses the descriptor's handle when it already grantsFILE_EXECUTE, and reopens it only otherwise, as before.docs/dev/debt/changes/fix-libkernel-app-archive-exec-map.md) updates the "Regular file mappings" entry oflibkernel.md, which said everyPROT_EXECmapping reopens the file. Plain files still do, since libkernel opens them without execute access.Tests (
GuestKernelAppArchive.cpp, Windows only):MappingBackingWindowschecks that every backing handle grants read and execute access and no write access.MappingExecutableHandleWindowsopens a file with read and execute access, then sets a DACL that grants only read and delete, so a reopen with execute access is refused (the test checks that). Shared mappings with protections 4 and 5 through that descriptor must succeed and read the file's bytes; a writable shared mapping still givesEACCES. This fails onmainon any Windows host, packaged or not, because it does not rely on delete-pending files.Standalone probe (create with
FILE_FLAG_DELETE_ON_CLOSE, reopen for read, close the writer, thenReOpenFilethe reader), same machine and folders:pwshstarted from Explorer%LOCALAPPDATA%\TempSTATUS_DELETE_PENDINGC:\Windows\TempThe same environment explains six
select_tests*failures listed below: creating a directory through a junction inside AppData fails there withERROR_ALREADY_EXISTS, and outside the package it works. They are not related to this change.Tested
Windows 11 (26300), WinLibs GCC, Release,
BUILD_TESTING=ON, clean build ofmain6653a47801and of this branch on top of it.ctestran from the Claude desktop app, so inside its MSIX package.guest_kernel_app_archive_*(5 tests), withTMP/TEMPin%LOCALAPPDATA%\Tempand in a D: folder:main:mmapfails in%LOCALAPPDATA%\Tempat theMappingProtectionscheck; passes in the D: folder.DirectMemory.cppchangeMappingExecutableHandleWindowsfails; without theAppArchiveBacking.cppchange theMappingBackingWindowsaccess check fails.ReOpenFilewith execute is denied. The newMappingBackingWithoutExecuteWindowspointsTMPat a folder whose ACL grants read, write and delete but not execute, materializes a page and checks that the backing reads it without execute or write access. Onmain6b222c7ccdcwith this branch merged, Windows 11, all 5guest_kernel_app_archive_*tests pass. Without the fallbackguest_kernel_app_archive_mmapaborts withmaterialize app0.zar backing: Permission denied.ctest(7,320 tests,-j10, same machine, Intel i9-9900K):main10 failures, this PR 8.guest_kernel_app_archive_mmap;windows_guest_main_stack_entry(timeout) andagc_driver_store_pending_identity, which pass when rerun alone onmain(3 of 3).agc_driver_linear_target_import_creation(#26650) and sixselect_tests*cases, caused by the package's AppData virtualization (above); they pass withTMPoutside AppData.agc_driver_draw_cache_capacity, which passes when rerun alone (5 of 5). It does not map files.python tools/check_conventions.py: passed.tools/pr_overlap.py --branch: no overlapping lines among the 17 it compared. Of the 10 it could not compare, #6936, #7149, #15040, #24034, #27330, #27445, #27543 and #27590 change other functions of the same files. My #28006 and #28013 move the sameReOpenFileline ofDoMapFileBacked_nid_no_patchinto anif, so whichever merges second needs a one-line rebase.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T19:40:19Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ff7d85a9f9:tools/check_conventions.pypassed.guest_kernel_app_archive_testsbuilt cleanly.guest_kernel_app_archive_archive,guest_kernel_app_archive_plain,guest_kernel_app_archive_mmap,guest_kernel_app_archive_mmap-failure,guest_kernel_app_archive_mmap-damaged):core/libs/prx/libc/src/AppArchiveBacking.cpp,core/libs/prx/libkernel/DirectMemory/DirectMemory.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T19:49:43Z.
Review: APPROVED
Reviewed — looks good
The change at head
ff7d85a9f9d22404b2c890a437fdd24896e1fd4caddresses the described Windows executable mapping failure, and the inspected implementation and tests show no verified blocking defect.What I ran
Read the prepared description, commit summary, manifest, diff, and all three changed files at the pinned head. Used
repo_read.pyto inspect the relevant Windows backing, mapping, access-query, and test code. No build or test commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Builds, tests, runtime behavior, and Windows volume behavior were not independently verified. The description reports Windows 11 build and test results, but these were not run for this review.
files.jsonwas not available through the reader; the manifest lists three changed files, all included and read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T20:48:45Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
5ed81dc5ed:tools/check_conventions.pypassed.guest_kernel_app_archive_testsbuilt cleanly.guest_kernel_app_archive_archive,guest_kernel_app_archive_plain,guest_kernel_app_archive_mmap,guest_kernel_app_archive_mmap-failure,guest_kernel_app_archive_mmap-damaged):core/libs/prx/libc/src/AppArchiveBacking.cpp,core/libs/prx/libkernel/DirectMemory/DirectMemory.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T20:55:48Z.
Review: COMMENTED
Reviewed — comments
The changed mapping paths and focused Windows test additions were inspected at head
5ed81dc5ed76799fb0d7a581085c2dc2a5218d02; tests were not run, so a formal approval is not justified.What I ran
Read the prepared description, commits, manifest, diff, and targeted code through
repo_read.pytools at the pinned head. No build or test command was run.Results
Negative control
Not run; the reported negative controls are author-provided results, not runs performed in this review.
Findings
Blocking
None identified in the inspected changed lines.
Non-blocking
None.
Not verified
The full contents of the changed source files were not read; only targeted ranges around changed behavior and its helpers were inspected. Build, test results, and the author-reported Windows behavior were not independently verified. The changed files listed in the manifest are
core/libs/prx/libc/src/AppArchiveBacking.cpp,core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp,core/libs/tests/GuestKernelAppArchive.cpp, anddocs/dev/debt/changes/fix-libkernel-app-archive-exec-map.md; all were included, and the relevant changed lines were inspected.To get this to a good state
Nothing is required. Optional: run the reported Windows test set on the pinned head and provide the results.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T10:16:21Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes appear consistent with the stated Windows mapping fix, but this review is incomplete because the full text of one changed file was not read.
What I ran
Reviewed head
6adabce61c616eb08d70979d7f0c1af990473389using the prepared diff andrepo_read.py; no commands or tests were run.Results
Findings
Blocking
None in the inspected code.
Non-blocking
None.
Sources
Not verified
The full 1,242-line
GuestKernelAppArchive.cppwas not read; only its changed sections and includes were inspected. No tests were run. All four changed files are included in the review folder; the two implementation files, the debt fragment, and the changed test sections were read. The remaining unchanged portions of the test file were not reviewed.To get this to a good state
Nothing is required. Optional: complete review of the remaining test file and run the Windows archive mapping tests.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T10:21:40Z.
Review: COMMENTED
Actionable comments posted: 1
9f17aab7-ec5d-4378-b613-68cc32716d28Reviewing files that changed from the base of the PR and between
5ed81dc5edand6adabce61c.core/libs/prx/libc/src/AppArchiveBacking.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-29T13:39:05Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
909b68fcd4:tools/check_conventions.pypassed.guest_kernel_app_archive_testsbuilt cleanly.guest_kernel_app_archive_archive,guest_kernel_app_archive_plain,guest_kernel_app_archive_mmap,guest_kernel_app_archive_mmap-failure,guest_kernel_app_archive_mmap-damaged):core/libs/prx/libc/src/AppArchiveBacking.cpp,core/libs/prx/libkernel/DirectMemory/DirectMemory.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T13:58:25Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected code and reported Windows behavior support merging.
What I ran
Reviewed head
909b68fcd425886625d376f808f2c8e5332dbf9d. Read the prepared description, commits, manifest, diff, and full text for all four changed files inreview/manifest.json. Usedrepo_read.pyto inspect the changed mapping and backing functions and the access-query helper. No build or tests were run during this review; test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, tests, or runtime checks were run. The reported Windows 11 tests and negative controls were not independently verified. The repository files read were
core/libs/prx/libc/src/AppArchiveBacking.cpp,core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp,core/libs/tests/GuestKernelAppArchive.cpp, anddocs/dev/debt/changes/fix-libkernel-app-archive-exec-map.md;review/files.jsonwas not available/read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T10:36:48Z.
Review: APPROVED
I read the diff at
909b68fcd4. Windows 11, GCC 15.2, merged intomainatb97867d3ce6together with other open PRs (so not an isolated build).guest_kernel_app_archivetests: pass.main's):guest_kernel_app_archive_mmapfails with "check failed at line 588".The red macOS check fails only in
frame_capture_minimize_replay, whichmainhas fixed since.Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T15:59:41Z.
Review: COMMENTED
I ran the five kernel app-archive CTests with the patch applied on Linux. All passed. The mmap fixture exercised the missing-directory backing case and skipped its noexec-filesystem subcase. The Windows executable permissions are outside this run.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.