fix(libkernel): refuse O_CREAT on an existing directory with EISDIR on macOS #10853
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10853"
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 krishalivaibhav on 2026-10-25T05:12:47Z.
What
On macOS,
open()of an existing directory withO_CREAT(withoutO_EXCL) succeeds, while FreeBSD and Linux fail withEISDIR. libkernel'sOpenNativehandled this only on Windows, so on macOSsceKernelOpen/openreturned a descriptor where the guest expectsEISDIR(guest_filesystemaborted atGuestFilesystem.cpp:1290).Under
__APPLE__, after the native open: ifO_CREATwas set withoutO_EXCLandfstatreports a directory, the descriptor is closed andEISDIRis returned. Linux and Windows are unchanged.The change matches the hunk in iamthehimansh's
feat/macos-port(#8658), who is credited as co-author.Tested
macOS: Apple Silicon M2, macOS 27.2, AppleClang, x86_64 Release, on a local integration of
main+ #10419 + #10366 + #10369 + #7631 + #7804 + #4630 + #10552 (libkernel does not build on macOS without these) + this commit:guest_filesystempasses (it aborted before at line 1290);guest_fdopendir,guest_kernel_sys,guest_statvfsandguest_file_timestampspass.Darwin's behaviour was also checked with a small C program:
open(dir, O_CREAT)succeeds.Linux/Windows: not built locally; the change is
__APPLE__-only.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🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T05:14:46Z.
Review: APPROVED
Reviewed exact head
ed61cbd11bcc0adc9446884ea25e9a5bf8b6eeeb. The Apple-only branch checks the opened descriptor withfstat, so it tests the object actually opened rather than re-resolving a path; it only changes theO_CREATwithoutO_EXCLcase, closes the descriptor and restoreserrno = EISDIR.GuestFilesystem.cppalready coverscreaton the existing root directory and expects EISDIR. The matching prior hunk is credited to iamthehimansh as co-author in the PR metadata; #8658 is closed, and the current intake/conventions checks pass. I could not independently run the macOS test; the M2 integration results in the description are author-reported. Product test jobs are skipped by repository policy. I found no blocker in this focused change.Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-25T07:16:08Z.
Review: APPROVED
Tested head
ed61cbd11bon Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2. The tree ismain61fc572ceeplus the open macOS build PRs (libkernel doesn't build on macOS without them); the patch applies cleanly there. I swapped onlyOpen.cppand ranguest_filesystem,guest_fdopendir,guest_kernel_sys,guest_path_case,guest_statvfsandguest_file_timestampstwice each:main'sOpen.cpp,guest_filesystemaborts, at theopen(dir, O_CREAT)check atGuestFilesystem.cpp:1218on the currentmain. The other five pass.f4704da5b8, carried by #7201), which usesstd::filesystem::is_directoryon the path. This PR'sfstaton the opened descriptor checks the same object that was opened, so I'd keep this one. If this is merged first, that hunk can be dropped from the series.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-25T10:19:35Z.
Review: APPROVED
The fix is correct and passes a swap A/B on a second macOS tree. The notes below are non-blocking.
Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)
Tested at
ed61cbd11bon mugurc's macOS series (27e968974) merged withmainat2742004ed2, with other open macOS fixes. The patch does not apply there because the series already has its ownstd::filesystem::is_directorycheck at the same place inOpenNative. I did a swap A/B instead:#ifdef __APPLE__block afterNativeOpen.Both sides were rebuilt, and each test ran 3 times per side with the same results every time.
guest_filesystemguest_fdopendir,guest_kernel_sys,guest_path_case,guest_statvfs,guest_file_timestampsGuestFilesystem.cpp:1218(1290 at this PR's head), theopen(dir, O_CREAT)check that expectsEISDIR(lldb)GuestFilesystem.cpp:1245(1317 at this PR's head; see 1)The stop at 1245 is a separate gap, not caused by this PR. The check there calls
sceKernelGetdentson a regular file and expectsEINVAL. This tree's macOSsceKernelGetdirentriescomes from the series;maindoes not have it. The tree with the series' original check stops at the same line, which fits with imellag'smain-based tree passing the whole test. I did not capture the error the call returned. No open PR other than #7201 touches it.The body says FreeBSD fails
O_CREATon a directory withEISDIR. FreeBSD 11.4vn_open_cred(sys/kern/vfs_vnops.c:204-270) confirms that, including through a symlink and a trailing slash. But it takes the create path only when(fmode & (O_CREAT | O_DIRECTORY)) == O_CREAT. SoO_CREAT | O_DIRECTORYon an existing directory is a plain lookup there and returns a descriptor. Darwin fails the same open withEINVAL; I checked this with a small C probe on macOS 27. The new block runs only whenfd >= 0, so it does not make this worse, but it does not fix it either. A follow-up or a line indocs/dev/debt/libkernel.mdwould cover it.Open.cpp:238:NativeClose(fd)instead of::close(fd)would match the rest of the file. The two are identical on POSIX today. This is optional.Body: the
Depends online reads "none to review; building libkernel on macOS needs #10552 and the PRs above". CONTRIBUTING asks forDepends on: #Nwhen another PR is needed first. imellag already points out that #7201 carries the same check in the series. The checklist line "no other open PR implements the same functions" should name it. The overlap rule in CONTRIBUTING asks for the order to be agreed and stated inDepends on.AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).