Skip to content

Adopt #555: constrain tar driver paths to image root#3

Merged
thomasdesr merged 1 commit into
mainfrom
thomas/adopt-555-tar-path-confinement
Jun 29, 2026
Merged

Adopt #555: constrain tar driver paths to image root#3
thomasdesr merged 1 commit into
mainfrom
thomas/adopt-555-tar-path-confinement

Conversation

@thomasdesr

Copy link
Copy Markdown

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) and pkg/drivers/tar_driver.go now route their path handling through it.

The tests in internal/pkgutil/tar_utils_test.go cover 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.go is added alongside.

Verified against the go1.26.4 Nix toolchain: go build ./... clean, all six new pkgutil tests pass, and go test ./internal/pkgutil/... ./pkg/drivers/... reports ok for both. go vet ./... surfaces only two findings, both in pkg/drivers/host_driver.go:90 and pkg/types/v1/file_existence.go:59, both pre-existing and untouched by this change.

…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>
@thomasdesr thomasdesr marked this pull request as ready for review June 29, 2026 19:38
@thomasdesr thomasdesr merged commit c024eed into main Jun 29, 2026
8 of 10 checks passed
@thomasdesr thomasdesr deleted the thomas/adopt-555-tar-path-confinement branch June 29, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant