fix: use lstat() in CreateTarget to prevent symlink traversal outside sandbox_root#29645
Open
Ashutosh0x wants to merge 1 commit into
Open
fix: use lstat() in CreateTarget to prevent symlink traversal outside sandbox_root#29645Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit into
Conversation
This was referenced May 26, 2026
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.
Fixes #28515
Summary
CreateTarget()inlinux-sandbox-pid1.ccusesstat()to check whether a path already exists before creating mount targets undersandbox_root. Sincestat()follows symlinks, a pre-seeded symlink undersandbox_rootcauses subsequentmkdir()/link()calls to operate on the host filesystem outsidesandbox_root.This is a robustness/hardening issue: hermetic sandbox setup code runs before
pivot_root/chrootand performs host filesystem operations. Ifsandbox_root/<component>is unexpectedly a symlink, mount target creation can write outside the intended sandbox directory.Root Cause
Fix
Two changes to
CreateTarget():Replaced
stat()withlstat()--lstat()does not follow symlinks, so it reports the symlink itself rather than its target.Added explicit symlink rejection -- if
lstat()detects a symlink (S_ISLNK),CreateTarget()now returns-1witherrno = ELOOP, preventing any further operations on the path.Reproduction (from #28515)
Related
/cc @meisterT