Adopt #555: constrain tar driver paths to image root#3
Merged
Conversation
…ontainerTools#555) Adopt upstream security fix that confines tar driver path resolution to the extracted image root, preventing tar-slip and symlink-escape attacks where archive entries reference paths outside the image filesystem. Upstream-PR: GoogleContainerTools#555 Co-authored-by: Francesco Sabiu <fsabiu@users.noreply.github.com>
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.
Adopts upstream googlecontainertools/container-structure-test#555 ("Constrain tar driver paths to image root", by Francesco Sabiu) as a single commit.
The tar driver previously let archive entries resolve to paths outside the extracted image root. A file, symlink, or hardlink entry could point past the root and the driver would follow it, so a crafted image could read or write host paths during a structure test. That is the tar-slip / symlink-escape class of bug.
The fix adds
internal/pkgutil/root_path.go, a resolver that pins every entry path to the image root and rejects anything that escapes, including escapes that only show up after following a symlink or hardlink chain.internal/pkgutil/tar_utils.go(the unpack path) andpkg/drivers/tar_driver.gonow route their path handling through it.The tests in
internal/pkgutil/tar_utils_test.gocover both halves: entries that escape the root are rejected, entries that stay inside resolve normally. Cases include plain files, symlinks, hardlinks, a hardlink pointing at a symlink (which must not be followed), and a hardlink whose source symlink escapes.pkg/drivers/tar_driver_test.gois added alongside.Verified against the go1.26.4 Nix toolchain:
go build ./...clean, all six new pkgutil tests pass, andgo test ./internal/pkgutil/... ./pkg/drivers/...reportsokfor both.go vet ./...surfaces only two findings, both inpkg/drivers/host_driver.go:90andpkg/types/v1/file_existence.go:59, both pre-existing and untouched by this change.