libc: guest paths resolve ".." lexically, so stat/open/unlink/rmdir act on "missing/../file" instead of failing; fix branch ready #3117

Closed
opened 2026-10-10 22:35:11 +00:00 by milescoviello · 1 comment
milescoviello commented 2026-10-10 22:35:11 +00:00 (Migrated from github.com)
Contributor

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


Resolve in libc/src/General.cpp normalizes the guest path with lexically_normal() before the host sees it, so the component before .. is never checked. On main (Linux), with dd/file a file and dd/victim a directory:

  • stat("dd/missing/../file") and open(...) succeed;
  • stat("dd/file/..") succeeds;
  • unlink("dd/missing/../file") deletes dd/file;
  • rmdir("dd/missing/../victim") deletes dd/victim.

FreeBSD's lookup() (sys/kern/vfs_lookup.c) resolves .. with VOP_LOOKUP in the directory reached so far, so these fail with ENOENT (missing component) or ENOTDIR (file component), and POSIX pathname resolution (XBD 4.13) says the same.

Fix on my fork: milescoviello/AnyPS5:fix/dotdot-path-resolution (one commit, 98a5a999, on main 4d27834f; the 12 commits on main since then don't touch these files): .. is still collapsed when the path before it is an existing directory, so aliases and case-insensitive matching behave as before. Otherwise the rest of the path goes to the host unchanged, and Linux reports ENOENT/ENOTDIR as FreeBSD does. On Windows, Win32 collapses .. itself, so results there are unchanged (not fixed, no regression). guest_filesystem gains checks (the negative ones inside its existing non-Windows block) that fail on main and pass with the fix. Windows was not built or tested.

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:5795892723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3117). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-10T22:35:11Z. --- `Resolve` in `libc/src/General.cpp` normalizes the guest path with `lexically_normal()` before the host sees it, so the component before `..` is never checked. On main (Linux), with `dd/file` a file and `dd/victim` a directory: - `stat("dd/missing/../file")` and `open(...)` succeed; - `stat("dd/file/..")` succeeds; - `unlink("dd/missing/../file")` deletes `dd/file`; - `rmdir("dd/missing/../victim")` deletes `dd/victim`. FreeBSD's `lookup()` (`sys/kern/vfs_lookup.c`) resolves `..` with `VOP_LOOKUP` in the directory reached so far, so these fail with ENOENT (missing component) or ENOTDIR (file component), and POSIX pathname resolution (XBD 4.13) says the same. Fix on my fork: [`milescoviello/AnyPS5:fix/dotdot-path-resolution`](https://github.com/milescoviello/AnyPS5/tree/fix/dotdot-path-resolution) (one commit, `98a5a999`, on `main` 4d27834f; the 12 commits on `main` since then don't touch these files): `..` is still collapsed when the path before it is an existing directory, so aliases and case-insensitive matching behave as before. Otherwise the rest of the path goes to the host unchanged, and Linux reports ENOENT/ENOTDIR as FreeBSD does. On Windows, Win32 collapses `..` itself, so results there are unchanged (not fixed, no regression). `guest_filesystem` gains checks (the negative ones inside its existing non-Windows block) that fail on main and pass with the fix. Windows was not built or tested. **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:44 +00:00 (Migrated from github.com)
Author
Contributor

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


Windows run, since the issue says it wasn't built or tested there: Windows 11, WinLibs GCC 15.2.0 r7, Release, fix/dotdot-path-resolution (98a5a999) merged onto main 06da1176 together with #3116, #3181 and #3169.

  • It builds, guest_filesystem passes (including the new viaParent check outside the non-Windows block), and all 421 non-GPU tests (ctest -E "^agc_") pass with the four branches merged. So no regression, as you expected.
  • As you said, Windows isn't fixed by it. I ran your negative checks on Windows with a temporary print: stat and open of root/missing/../present.txt still succeed, stat of present.txt/.. returns 0, and sceKernelStat of present.txt/../present.txt returns 0, since Win32 collapses the .. the branch hands it.
  • One possible way to fix Windows in the same branch: in the case where the part before .. isn't a directory, a \?\ path makes Windows keep the .. instead of collapsing it. I checked with os.stat here: \?\<dir>\missing\..\present.txt fails with ERROR_PATH_NOT_FOUND (3), which would give ENOENT. But \?\<dir>\present.txt\.. fails with the same error 3, not a "not a directory" one, so the ENOTDIR cases would need their own check (for example, whether the part before .. exists as a file).

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104126980 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3117#issuecomment-6104126980). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T01:18:44Z. --- Windows run, since the issue says it wasn't built or tested there: Windows 11, WinLibs GCC 15.2.0 r7, Release, `fix/dotdot-path-resolution` (`98a5a999`) merged onto `main` 06da1176 together with #3116, #3181 and #3169. - It builds, `guest_filesystem` passes (including the new `viaParent` check outside the non-Windows block), and all 421 non-GPU tests (`ctest -E "^agc_"`) pass with the four branches merged. So no regression, as you expected. - As you said, Windows isn't fixed by it. I ran your negative checks on Windows with a temporary print: `stat` and `open` of `root/missing/../present.txt` still succeed, `stat` of `present.txt/..` returns 0, and `sceKernelStat` of `present.txt/../present.txt` returns 0, since Win32 collapses the `..` the branch hands it. - One possible way to fix Windows in the same branch: in the case where the part before `..` isn't a directory, a `\?\` path makes Windows keep the `..` instead of collapsing it. I checked with `os.stat` here: `\?\<dir>\missing\..\present.txt` fails with ERROR_PATH_NOT_FOUND (3), which would give ENOENT. But `\?\<dir>\present.txt\..` fails with the same error 3, not a "not a directory" one, so the ENOTDIR cases would need their own check (for example, whether the part before `..` exists as a file). AI-assisted (Claude Code); I ran all of 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#3117
No description provided.