Repository navigation
chroot_realpath: do not add a separator after expanding a symlink - #2422
Merged
Merged
Conversation
|
Ephemeral COPR build failed. @containers/packit-build please check. |
1 similar comment
|
Ephemeral COPR build failed. @containers/packit-build please check. |
Collaborator
Author
|
CI is being fixed by #2423 |
After a symlink is expanded, new_path already points right after a separator: the root one for an absolute symlink, and the parent directory one for a relative symlink (since commit 513d3ce). When the symlink is not the last component, the code then appends another separator, so the result gets a "//" in it. This has two effects: * a ".." that follows (e.g. coming from a "sym -> ../escaped" target) backs up to the duplicate separator only, so it is silently dropped: "/dir/sym/file" resolves to "<root>/dir/escaped/file" instead of "<root>/escaped/file"; * an absolute intermediate symlink yields "<root>//target/file", so callers stripping the rootfs prefix get "//target/file". The result stays under the rootfs in all cases, only the path inside it may differ from what the kernel would resolve. Since the expanded symlink contents become the remaining path to process, there is nothing left to do in the current iteration, so just continue with the loop. Add test cases for intermediate symlinks. Fixes: 513d3ce ("chroot_realpath: keep separator when expanding a relative symlink") Reported-by: Inanna Malick <inanna@recursion.wtf> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin
force-pushed
the
chroot-realpath-dup-sep
branch
from
October 30, 2026 19:08
e38f17c to
cb66e4d
Compare
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.
After expanding a symlink that is not the last path component,
chroot_realpath()appends an extra separator, resulting in//in the resolved path. This has two effects:..that follows (e.g. from asym -> ../escapedtarget) is silently dropped, so/dir/sym/fileresolves to<root>/dir/escaped/fileinstead of<root>/escaped/file(a regression since 513d3ce);<root>//target/file, and callers stripping the rootfs prefix get//target/file.The result always stays under the rootfs; only the path inside it may differ from what the kernel would resolve. This is reachable via the
safe_openat()fallback (noopenat2(2)) and the CRIU external bind mount handling.The fix is to
continueright after the symlink expansion, sincenew_pathalready points after a separator.Unit tests for intermediate symlinks are added (they fail without the fix).
Reported-by: @inanna-malick