fix(libkernel): fail unlink and rmdir of a path that ends in a dot component with EINVAL #8797
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8797"
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 xXPBSXx on 2026-10-21T00:57:03Z.
What
FreeBSD 11.4 refuses "." and ".." as the last component of a delete lookup with
EINVALbefore any other check (lookup(), sys/kern/vfs_lookup.c:750-754, 823-826).unlink/sceKernelUnlinkansweredEPERM,rmdir/sceKernelRmdiransweredENOTEMPTYfor "..", andunlinkatwithoutAT_REMOVEDIRansweredEPERM. They now run theRenameDotcheck from #8174 first, so a missing or non-directory parent still reportsENOENT/ENOTDIR.remove(libc) is not touched. Theunlinkat(base, ".", 0)expectation inGuestKernelSys.cppchanges fromEPERMtoEINVALfor the same source line; I did not measure a console.Fixes #8796
Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on upstream/main
57fdffd915+ this commit:guest_kernel_sys(line 549, guest errno 1) andguest_filesystem(line 243, guest errno 1) fail with the three source files taken back and the new cases in place; both pass with the change.python tools/check_conventions.py --base upstream/main: passes.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)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T00:57:38Z.
Review: CHANGES_REQUESTED
The conventions check is failing because the PR body does not fill in the required
### Whatsection. Please move the implementation summary currently above### Testedunder### What(keeping the remaining template headings), then rerun the check. No code issue identified in this review.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T00:59:04Z.
Review: APPROVED
I independently ran
python3 tools/check_conventions.py --base upstream/mainon the current head864baa17d4382da3575e6331ea3f2009dec0ea2f; it passes. The Windows test results are documented in the PR. I could not run a fresh local build here because the workspace filesystem has only 141 MB free. The hosted build/test jobs were skipped on this PR head. I found no additional code issue in this review.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T00:59:10Z.
Follow-up: I ran the repository script locally, and it passes against upstream/main. The hosted conventions check is a separate PR-template validation and remains failed because
### Whatis not filled; please fix that section and rerun checks. My approval only covers the code review, not the failing required check.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T00:59:47Z.
Review: CHANGES_REQUESTED
I am maintaining the request to fill the required
### Whatsection. The earlier approval was only for the code review and does not apply while the hosted conventions check still fails; please move the summary under### Whatand rerun checks.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T02:03:08Z.
@xXPBSXx the new case at
GuestFilesystem.cpp:248fails on Linux in our CI:unlink("/parent-test-mount/present.txt/.")returnsENOENT(2) instead ofENOTDIR(20). Windows passes.The cause is in
RenameDotError_nid_no_patch. The parent isstd::string(path, start), which keeps the trailing separator (.../present.txt/). On Linux the resolver keeps a trailing/, andstd::filesystem::exists("present.txt/")is false there, with no error code. So the helper takes the "missing parent" branch. On Windows the slash is dropped, which is why it passes.Trimming trailing separators from
parentbefore resolving (keeping a lone/) fixes it, e.g.while (parent.size() > 1 && separator(parent.back())) parent.pop_back();. That also correctsrename("file/.", ...)on Linux, which goes through the same helper and has the same wrong answer onmaintoday.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T02:31:14Z.
Thanks, that was the cause.
RenameDotError_nid_no_patchresolved the parent with its trailing separator, andstd::filesystem::exists("present.txt/")is false on Linux, sofile/.took the missing-parent branch. I now trim trailing separators fromparentbefore resolving (a lone/stays), as you suggested. This also correctsrename("file/.", ...)on Linux, soguest_filesystemgets two more cases:renameofpresent.txt/.andpresent.txt/..returns ENOTDIR.Checked on Linux (WSL2 Ubuntu 24.04, GCC 13.3, Release, so not a bare-metal CI run): at the old head 864baa17d4
guest_filesystemfails with "Filesystem check failed at line 248 (guest errno 2, host errno 2)"; at the new head 2f82e47f5f it passes. The tests that callunlink/rmdir/rename/unlinkatalso pass on Linux (guest_filesystem, guest_kernel_sync, guest_kernel_sys, guest_kqueue, guest_path_name_length, guest_poll, guest_posix_scalar_io, guest_rename_dot, guest_select, guest_select_wait, guest_truncate_extend), and on Windows 10 (MinGW GCC 15.2, Release)guest_filesystem,guest_kernel_sysandguest_rename_dotpass.check_conventionspasses. Not tested: macOS, a console.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:18:26Z.
Review: COMMENTED
The Linux fix looks right, but this trimming also strips a Windows drive root: for
C:\\.,parentisC:\\, then the loop changes it toC:. On WindowsC:is drive-relative to that drive’s current directory, not the rootC:\\; the check can inspect the wrong directory (and UNC share roots have the same root-preservation concern). Could you trim only whileparent.size() > std::filesystem::path(parent).root_path().native().size()(or otherwise preserveroot_path()), and add a Windows-root regression if this helper is meant to cover drive-root paths?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T06:08:56Z.
Follow-up to my root-path review: I prepared commit
d68de63527on a branch based on this PR head. It trims trailing separators only until the candidate reachesstd::filesystem::path::root_path(), and adds Windows checks forC:\\, repeated root separators and a non-root trailing separator. The commit is authored by MarcZX10 and passescheck_conventions,git diff --check, MinGW syntax checking ofGuestFilesystem.cpp(with a define for this package’s missingFILE_CS_FLAG_CASE_SENSITIVE_DIRSDK constant), and a native Linux root/trailing-separator smoke test. I tried to push it to this PR’s branch, but GitHub denied write access to the head fork (403), so the commit is available on my fork for cherry-picking.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T06:39:23Z.
I checked the updated head
0de8266c6f4f.TrimTrailingSeparators_nid_no_patchnow stops atroot_path(), andGuestFilesystem.cppadds Windows cases forC:\\,C:/, repeated drive-root separators, and non-root trailing separators. That addresses the root-preservation concern I raised. The current conventions check passes; Windows and macOS x86_64 relinker jobs are still in progress, so I will recheck those results before concluding review.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T06:40:36Z.
Review: APPROVED
Reviewed the updated head
0de8266c6f4f: the Linux trailing-separator fix is retained, trimming now preservesroot_path(), and the added Windows drive-root cases cover the concern I raised. The PR body now satisfies the required### Whatsection. All applicable hosted relinker, sanitizer, register-context, write-watch, conventions, and intake checks are passing; Linux/windows full-build jobs are skipped by workflow design. Approved.