fix: stop hard links escaping the codemodule extraction dir#6803
Open
knQzx wants to merge 1 commit into
Open
Conversation
the hard link check validated linkname against the entry path, but os.Link resolves it relative to the extraction root, so a crafted archive could pass the check and link to a file outside the target dir - validate against the root to match os.Link
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.
problem
hard link extraction in the codemodule gzip unpacker checks the wrong base path
extractLinkvalidates withisSafeToLink(header.Linkname, targetDir, target)butos.Linkresolves the source asfilepath.Join(targetDir, header.Linkname)the check uses
target(the deeptargetDir/header.Name) while os.Link usestargetDirtar hard link linknames are relative to the archive root so os.Link is right and the check is wrong - the extra depth in
targeteats leading../so a layer entry with a deep name and a matching
../linkname passes the check but links outside the extraction dirimpact
extraction runs in the privileged csi provisioner and the unpacked dir is renamed into the codemodule dir mounted into pods
a malicious or compromised codemodule image can hard link to a file outside the extraction root on the same csi volume - cross pod disclosure
bounded by exdev so not arbitrary host files
the symlink branch is fine - only the hard link base was wrong
fix
validate the linkname against
targetDir- the same base os.Link usestest
extract gzip with malicious hard link blocks escaping linkfails on main and passes hereplus a positive case so legit in archive hard links still work