Repository navigation
fix(libc): resolve ".." in guest paths against the directory before it - #3892
Closed
renzipego-cpu wants to merge 1 commit into
Closed
renzipego-cpu wants to merge 1 commit into
renzipego-cpu wants to merge 1 commit into
Conversation
Guest paths were normalized lexically before they reached the host, so "missing/../file" and "file/../x" dropped the component before "..": stat and open succeeded on the file, unlink deleted it and rmdir removed a directory, where FreeBSD's lookup() resolves ".." with VOP_LOOKUP in the directory reached so far and fails with ENOENT for a missing component and ENOTDIR for a file. POSIX path resolution (XBD 4.13) says the same. ".." is still collapsed lexically when the path before it is an existing directory, so case-insensitive matching and aliases behave as before. When it is not, the rest of the path is passed to the host unchanged and the host resolves it. Linux then reports ENOENT or ENOTDIR as FreeBSD does; Windows collapses ".." itself, so its results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYhZu5HokHMo9mfi8QU83m
Contributor
|
Thanks for carrying it, @renzipego-cpu. A heads-up so it isn't reviewed twice: #3485 (@santhoshkumar-dev) already carries this same commit as its first one (21d1698, identical patch), together with the Windows half of #3117, and its checks pass. Either way is fine by me; just pointing out the overlap. |
Author
|
ok thanks |
9 tasks done
Contributor
+1 |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Carries the branch from #3117 (
milescoviello:fix/dotdot-path-resolution@98a5a999), rebased onto current main and rebuilt here. Fixes #3117.What
Resolveinlibc/src/General.cppnormalizes the guest path withlexically_normal()before the host sees it, so the component before..is never checked. Onmain(Linux), withdd/filea file anddd/victima directory:stat("dd/missing/../file")andopen(...)succeed;stat("dd/file/..")succeeds;unlink("dd/missing/../file")deletesdd/file;rmdir("dd/missing/../victim")deletesdd/victim.FreeBSD's
lookup()(sys/kern/vfs_lookup.c) resolves..withVOP_LOOKUPin the directory reached so far, so these fail withENOENT(missing component) orENOTDIR(file component), and POSIX pathname resolution (XBD 4.13) says the same. With this change,..is still collapsed when the path before it is an existing directory (aliases and case-insensitive matching keep behaving as before); otherwise the rest of the path reaches the host unchanged and reports the right error.Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release,
BUILD_TESTING=ON, full build includinglibs:guest_path_caseandguest_realpathpass on the rebased branch. (guest_filesystemaborts on this machine without Windows Developer Mode for symlinks — same on cleanmain.)python tools/check_conventions.py --base upstream/mainpasses; no new test registration needed (the branch extends the existingGuestFilesystem.cppcases).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)