fix(libkernel): fail fchmod on a pipe with EINVAL like FreeBSD #9502

Merged
GitamarT045T3R merged 1 commit from upstream-pr/9502 into main 2026-10-25 20:03:23 +00:00
GitamarT045T3R commented 2026-10-21 23:33:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-21T23:33:38Z.


What

fchmod and sceKernelFchmod on either end of a pipe failed with ENOENT on Windows, where the pipe has no path. On Linux they changed the pipe's mode. FreeBSD 11's pipe_chmod sends an unnamed pipe to invfo_chmod, which returns EINVAL. Both calls now return EINVAL (SCE_KERNEL_ERROR_EINVAL) for a pipe, as they already do for a socket. The check uses the existing IsPipeDescriptor. The guest has no mkfifo, so every pipe it holds is unnamed.

Tested

Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, on main 0c6a5bd59:

  • guest_filesystem now checks both calls on both ends of a pipe, next to the existing fsync and fdatasync checks there. It fails with main's Stdio.cpp and passes with this change.
  • python tools/check_conventions.py --base origin/main passes.
  • Not built or run on Linux or macOS. There IsPipeDescriptor uses fstat and S_ISFIFO.

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
  • 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:4959776383 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9502). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-21T23:33:38Z. --- ### What `fchmod` and `sceKernelFchmod` on either end of a pipe failed with `ENOENT` on Windows, where the pipe has no path. On Linux they changed the pipe's mode. FreeBSD 11's [`pipe_chmod`](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/sys/kern/sys_pipe.c#L1579-L1590) sends an unnamed pipe to [`invfo_chmod`](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/sys/kern/kern_descrip.c#L4027-L4032), which returns `EINVAL`. Both calls now return `EINVAL` (`SCE_KERNEL_ERROR_EINVAL`) for a pipe, as they already do for a socket. The check uses the existing `IsPipeDescriptor`. The guest has no `mkfifo`, so every pipe it holds is unnamed. ### Tested Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, on `main` `0c6a5bd59`: - `guest_filesystem` now checks both calls on both ends of a pipe, next to the existing `fsync` and `fdatasync` checks there. It fails with `main`'s `Stdio.cpp` and passes with this change. - `python tools/check_conventions.py --base origin/main` passes. - Not built or run on Linux or macOS. There `IsPipeDescriptor` uses `fstat` and `S_ISFIFO`. ### 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) - [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
jotitadev commented 2026-10-22 00:03:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T00:03:44Z.

Review: COMMENTED


Linux run of the current change, since the description only lists Windows ("Not built or run on Linux or macOS").

Machine: Linux x86_64, i7-8700 (6 cores / 12 threads), Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON. Head 9f05f4777 merged onto main a6dcea927 (the merge touches only Stdio.cpp and GuestFilesystem.cpp).

  • Build ok. guest_filesystem passes with the change.
  • Restoring libkernel/File/src/Stdio.cpp to main and keeping the test aborts guest_filesystem. The only added assertions are the two new pipe checks, and on Linux main's fchmod/sceKernelFchmod on a pipe end return 0 (they change the pipe's mode through fchmod/S_ISFIFO) instead of EINVAL/0x80020016, so the test covers the change on this host as well.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607700835 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9502#pullrequestreview-5607700835). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-22T00:03:44Z. **Review:** COMMENTED --- Linux run of the current change, since the description only lists Windows ("Not built or run on Linux or macOS"). Machine: Linux x86_64, i7-8700 (6 cores / 12 threads), Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`. Head `9f05f4777` merged onto `main` `a6dcea927` (the merge touches only `Stdio.cpp` and `GuestFilesystem.cpp`). - Build ok. `guest_filesystem` passes with the change. - Restoring `libkernel/File/src/Stdio.cpp` to `main` and keeping the test aborts `guest_filesystem`. The only added assertions are the two new pipe checks, and on Linux `main`'s `fchmod`/`sceKernelFchmod` on a pipe end return 0 (they change the pipe's mode through `fchmod`/`S_ISFIFO`) instead of `EINVAL`/`0x80020016`, so the test covers the change on this host as well. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-22 01:29:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:29:45Z.

Review: CHANGES_REQUESTED


I reviewed the one-line guard and the added assertions. The cited FreeBSD source routes pipe chmod through pipe_chmod to the invalid-operation handler, and the existing Linux run independently confirms that host fchmod would otherwise succeed on these pipe endpoints. The new test covers both fchmod and sceKernelFchmod for the tested pipe end; hosted eligibility, conventions, intake, labels and report checks pass. Product and relinker jobs were skipped by the workflow, and I did not run a local build.

The required overlap scan reports an exact shared sceKernelFchmod region with open #8520. I inspected that patch: it adds a virtual-directory error guard immediately before the existing socket guard in the same function, so both changes need to be retained and composed. Please coordinate with #8520’s author on merge order and record the agreed order in the checklist (Depends on: #8520 if this must follow it, otherwise none after confirming the rebase will compose). The present Depends on: none does not document the flagged overlap.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608230662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9502#pullrequestreview-5608230662). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T01:29:45Z. **Review:** CHANGES_REQUESTED --- I reviewed the one-line guard and the added assertions. The cited FreeBSD source routes pipe `chmod` through `pipe_chmod` to the invalid-operation handler, and the existing Linux run independently confirms that host `fchmod` would otherwise succeed on these pipe endpoints. The new test covers both `fchmod` and `sceKernelFchmod` for the tested pipe end; hosted eligibility, conventions, intake, labels and report checks pass. Product and relinker jobs were skipped by the workflow, and I did not run a local build. The required overlap scan reports an exact shared `sceKernelFchmod` region with open #8520. I inspected that patch: it adds a virtual-directory error guard immediately before the existing socket guard in the same function, so both changes need to be retained and composed. Please coordinate with #8520’s author on merge order and record the agreed order in the checklist (`Depends on: #8520` if this must follow it, otherwise `none` after confirming the rebase will compose). The present `Depends on: none` does not document the flagged overlap.
xXPBSXx commented 2026-10-22 04:11:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T04:11:55Z.


Linux data point for 9f05f47775: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main; its merge-base is 0c6a5bd59).

  • With the PR: ctest -R '^guest_filesystem$' passes 3 of 3.
  • With libkernel/File/src/Stdio.cpp restored to the merge-base (the PR's tests kept): fails (Subprocess aborted).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332496938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9502#issuecomment-6332496938). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-22T04:11:55Z. --- Linux data point for `9f05f47775`: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`; its merge-base is `0c6a5bd59`). - With the PR: `ctest -R '^guest_filesystem$'` passes 3 of 3. - With `libkernel/File/src/Stdio.cpp` restored to the merge-base (the PR's tests kept): fails (`Subprocess aborted`). Not tested: macOS, Windows, a title run. AI-assisted (Claude Code).
MarcZX10 commented 2026-10-22 04:25:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:25:20Z.

Review: DISMISSED


The pipe behavior and regression assertions are well supported by the FreeBSD path and the reported Linux/WSL red-green runs. The open overlap with #8520 remains unresolved: its virtual-directory guard and this pipe guard both modify sceKernelFchmod, and the checklist still says Depends on: none without recording an author-agreed order. In addition, this branch is based on 0c6a5bd593, while upstream main is now ab347d144d. Please coordinate with #8520’s author, document the order/dependency, rebase onto current main, recheck shared hunks including #6044’s test-file changes, and rerun the focused filesystem test and conventions check on the rebased result. Hosted product jobs are skipped. I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609249109 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9502#pullrequestreview-5609249109). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:25:20Z. **Review:** DISMISSED --- The pipe behavior and regression assertions are well supported by the FreeBSD path and the reported Linux/WSL red-green runs. The open overlap with #8520 remains unresolved: its virtual-directory guard and this pipe guard both modify `sceKernelFchmod`, and the checklist still says `Depends on: none` without recording an author-agreed order. In addition, this branch is based on 0c6a5bd593, while upstream main is now ab347d144d88fae054d9770cf0db8d3565735c02. Please coordinate with #8520’s author, document the order/dependency, rebase onto current main, recheck shared hunks including #6044’s test-file changes, and rerun the focused filesystem test and conventions check on the rebased result. Hosted product jobs are skipped. I did not run local tests.
GitamarT045T3R commented 2026-10-22 08:10:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-22T08:10:33Z.


Rebased onto main d6eafa54d (7350b1cfc). The pipe check is now its own line after File::RefuseArchivedFile, and the socket line is left as it was. A pipe is never an archived file, so the order changes nothing, and two unchanged lines now separate it from #8520's new first line in sceKernelFchmod. git merge-tree of this head with #8520 is clean in Stdio.cpp. Its only conflict is DirectoryDescriptor.cpp, which #8520 already has with main. With #6044 it is clean in both files this PR touches. guest_filesystem passes on Windows, and check_conventions passes.

Landing order with #8520 (@qpavyros): neither depends on the other, and either order merges without conflict in these lines. With both in, fchmod on a virtual directory answers EISDIR and on a pipe EINVAL. So Depends on stays none.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6335988831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9502#issuecomment-6335988831). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-22T08:10:33Z. --- Rebased onto `main` `d6eafa54d` (7350b1cfc). The pipe check is now its own line after `File::RefuseArchivedFile`, and the socket line is left as it was. A pipe is never an archived file, so the order changes nothing, and two unchanged lines now separate it from #8520's new first line in `sceKernelFchmod`. `git merge-tree` of this head with #8520 is clean in `Stdio.cpp`. Its only conflict is `DirectoryDescriptor.cpp`, which #8520 already has with `main`. With #6044 it is clean in both files this PR touches. `guest_filesystem` passes on Windows, and `check_conventions` passes. Landing order with #8520 (@qpavyros): neither depends on the other, and either order merges without conflict in these lines. With both in, `fchmod` on a virtual directory answers `EISDIR` and on a pipe `EINVAL`. So `Depends on` stays none.
GitamarT045T3R commented 2026-10-22 12:15:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-22T12:15:44Z.


Rebased onto current main (89f99c2f5) and moved the pipe check one line up, between the socket check and File::RefuseArchivedFile. #7299 (@qpavyros) inserts its Windows shared-memory branch right after RefuseArchivedFile, at the same place this check was. git merge-tree of this head is now clean against #7299. Against #8520 it is clean in Stdio.cpp, and #8520's one conflict is DirectoryDescriptor.cpp, which it already has with main. A pipe is neither a socket, an archived file nor shared memory, so the order changes nothing. guest_filesystem passes on Windows, and check_conventions passes. Depends on stays none.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6340496445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9502#issuecomment-6340496445). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-22T12:15:44Z. --- Rebased onto current `main` (89f99c2f5) and moved the pipe check one line up, between the socket check and `File::RefuseArchivedFile`. #7299 (@qpavyros) inserts its Windows shared-memory branch right after `RefuseArchivedFile`, at the same place this check was. `git merge-tree` of this head is now clean against #7299. Against #8520 it is clean in `Stdio.cpp`, and #8520's one conflict is `DirectoryDescriptor.cpp`, which it already has with `main`. A pipe is neither a socket, an archived file nor shared memory, so the order changes nothing. `guest_filesystem` passes on Windows, and `check_conventions` passes. `Depends on` stays none.
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!9502
No description provided.