libkernel/libc: rmdir, sceKernelRmdir and remove delete the directory for "dir/." instead of failing with EINVAL; fix branch ready #3116

Closed
opened 2026-10-10 22:35:07 +00:00 by milescoviello · 4 comments
milescoviello commented 2026-10-10 22:35:07 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-10T22:35:07Z.


Guest paths are normalized lexically (Resolve in libc/src/General.cpp), so dir/. reaches the host as dir/ and the directory is removed. FreeBSD's kern_rmdirat rejects a final . with EINVAL ("No rmdir "." please."), and POSIX requires rmdir to fail with EINVAL when the last component is dot. remove calls rmdir for a directory (FreeBSD lib/libc/stdio/remove.c).

On main (Linux), each of these returns 0 and the directory is gone: rmdir("probe_dir/."), sceKernelRmdir("probe_dir/."), remove("probe_dir/.").

Fix on my fork: milescoviello/AnyPS5:fix/rmdir-dot-component (one commit, 9aaf6240, rebased onto main ec77a616 after #3395): sceKernelRmdir (and therefore rmdir) and remove return EINVAL (0x80020016) and keep the directory. A missing path or a file before the dot keeps its current error. guest_filesystem gains checks that fail on main and pass with the fix. Linux only; Windows was not built or tested. The check runs on the guest path before any host call, so the code is portable.

Setup: Gentoo, Linux 7.2.8, GCC 15.3.0, Release with CI's configure flags, main 4d27834f.

Tested: the new checks fail on main and pass with the fix. Full ctest with the fix on Linux (RTX 5090 Laptop GPU): no new failures; the only failures are the known agc_driver_dcc_keys_first_write (#2767) and two guest_video_out_* tests that time out with the displays powered off. tools/check_conventions.py passes. All five fixes I am filing today also pass their tests merged together on the current main.

Not opened as a PR because intake is paused for new contributors; a maintainer is welcome to carry the commit.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5795892281 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3116). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-10T22:35:07Z. --- Guest paths are normalized lexically (`Resolve` in `libc/src/General.cpp`), so `dir/.` reaches the host as `dir/` and the directory is removed. FreeBSD's `kern_rmdirat` rejects a final `.` with `EINVAL` ("No rmdir "." please."), and POSIX requires `rmdir` to fail with `EINVAL` when the last component is dot. `remove` calls `rmdir` for a directory (FreeBSD `lib/libc/stdio/remove.c`). On main (Linux), each of these returns 0 and the directory is gone: `rmdir("probe_dir/.")`, `sceKernelRmdir("probe_dir/.")`, `remove("probe_dir/.")`. Fix on my fork: [`milescoviello/AnyPS5:fix/rmdir-dot-component`](https://github.com/milescoviello/AnyPS5/tree/fix/rmdir-dot-component) (one commit, `9aaf6240`, rebased onto `main` ec77a616 after #3395): `sceKernelRmdir` (and therefore `rmdir`) and `remove` return `EINVAL` (0x80020016) and keep the directory. A missing path or a file before the dot keeps its current error. `guest_filesystem` gains checks that fail on main and pass with the fix. Linux only; Windows was not built or tested. The check runs on the guest path before any host call, so the code is portable. **Setup:** Gentoo, Linux 7.2.8, GCC 15.3.0, Release with CI's configure flags, `main` 4d27834f. **Tested:** the new checks fail on `main` and pass with the fix. Full `ctest` with the fix on Linux (RTX 5090 Laptop GPU): no new failures; the only failures are the known `agc_driver_dcc_keys_first_write` (#2767) and two `guest_video_out_*` tests that time out with the displays powered off. `tools/check_conventions.py` passes. All five fixes I am filing today also pass their tests merged together on the current `main`. Not opened as a PR because intake is paused for new contributors; a maintainer is welcome to carry the commit. AI-assisted: yes
Silverash-i8 commented 2026-10-11 01:18:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:18:43Z.


Windows run, since the issue says it wasn't built or tested there: Windows 11, WinLibs GCC 15.2.0 r7, Release, fix/rmdir-dot-component (a43ccf41) merged onto main 06da1176 together with #3117, #3181 and #3169 (#3169 is needed here because guest_filesystem otherwise stops at the symlink checks on a machine without the symlink privilege).

  • The bug is on Windows too: RemoveDirectoryW collapses the dot itself, so a plain rmdir of dir\. removes dir (checked directly with Python's os.rmdir).
  • With the branch, the new checks in guest_filesystem sit outside the non-Windows block and pass: rmdir, sceKernelRmdir and remove of dir/. and dir/./ return EINVAL (0x80020016 for sceKernelRmdir) and the directory stays. The backslash paths the test builds on Windows work since FinalPathComponentIsDot_nid_no_patch splits on both separators.
  • All 421 non-GPU tests (ctest -E "^agc_") pass with the four branches merged.

AI-assisted (Claude Code); I ran this on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104126860 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3116#issuecomment-6104126860). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T01:18:43Z. --- Windows run, since the issue says it wasn't built or tested there: Windows 11, WinLibs GCC 15.2.0 r7, Release, `fix/rmdir-dot-component` (`a43ccf41`) merged onto `main` 06da1176 together with #3117, #3181 and #3169 (#3169 is needed here because `guest_filesystem` otherwise stops at the symlink checks on a machine without the symlink privilege). - The bug is on Windows too: `RemoveDirectoryW` collapses the dot itself, so a plain `rmdir` of `dir\.` removes `dir` (checked directly with Python's `os.rmdir`). - With the branch, the new checks in `guest_filesystem` sit outside the non-Windows block and pass: `rmdir`, `sceKernelRmdir` and `remove` of `dir/.` and `dir/./` return EINVAL (0x80020016 for `sceKernelRmdir`) and the directory stays. The backslash paths the test builds on Windows work since `FinalPathComponentIsDot_nid_no_patch` splits on both separators. - All 421 non-GPU tests (`ctest -E "^agc_"`) pass with the four branches merged. AI-assisted (Claude Code); I ran this on my machine.
milescoviello commented 2026-10-11 01:21:10 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T01:21:10Z.


Thanks @Silverash-i8 for the Windows runs on this and #3117, and for checking RemoveDirectoryW directly. Good to know the dot case is fixed on Windows too. The \\?\ idea for .. on Windows is useful as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104144105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3116#issuecomment-6104144105). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-11T01:21:10Z. --- Thanks @Silverash-i8 for the Windows runs on this and #3117, and for checking `RemoveDirectoryW` directly. Good to know the dot case is fixed on Windows too. The `\\?\` idea for `..` on Windows is useful as well.
milescoviello commented 2026-10-11 09:58:44 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T09:58:44Z.


Rebased onto main ec77a616: #3395 changed the same lines of sceKernelRmdir. The dot check now runs right after its ENOTDIR/ENOENT block, which keeps FreeBSD's order (lookup errors first, then EINVAL, then ENOTEMPTY). New commit 9aaf6240. The 33 file, path and save-data tests pass, including #3395's new checks, and guest_filesystem fails with the check reverted.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107814197 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3116#issuecomment-6107814197). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-11T09:58:44Z. --- Rebased onto `main` ec77a616: #3395 changed the same lines of `sceKernelRmdir`. The dot check now runs right after its ENOTDIR/ENOENT block, which keeps FreeBSD's order (lookup errors first, then EINVAL, then ENOTEMPTY). New commit `9aaf6240`. The 33 file, path and save-data tests pass, including #3395's new checks, and `guest_filesystem` fails with the check reverted. AI-assisted: yes
Silverash-i8 commented 2026-10-11 10:09:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T10:09:38Z.


Windows recheck of the rebased 9aaf6240 on main ec77a616 (Windows 11, WinLibs GCC 15.2.0 r7, Release): guest_filesystem passes, now all the way through since #3169 is in, and the non-GPU suite (ctest -E "^agc_") is 453/454. The one failure is windows_exceptions, which fails the same way on plain main (#3411), so nothing from this branch.

AI-assisted (Claude Code); I ran this on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107924304 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3116#issuecomment-6107924304). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T10:09:38Z. --- Windows recheck of the rebased `9aaf6240` on `main` ec77a616 (Windows 11, WinLibs GCC 15.2.0 r7, Release): `guest_filesystem` passes, now all the way through since #3169 is in, and the non-GPU suite (`ctest -E "^agc_"`) is 453/454. The one failure is `windows_exceptions`, which fails the same way on plain `main` (#3411), so nothing from this branch. AI-assisted (Claude Code); I ran this on my machine.
Sign in to join this conversation.
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#3116
No description provided.