Skip to content

pkg/archive: reject out-of-range device numbers in layer headers - #13792

Merged
mxpv merged 1 commit into
containerd:mainfrom
aysha-afrah26:tar-device-number-range
Jul 14, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
aysha-afrah26:tar-device-number-range

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

handleTarTypeBlockCharFifo takes the device major and minor straight from the layer's tar header, where they are int64, and hands them to unix.Mkdev as uint32. The header comes from image content, so those numbers are attacker-controlled, and nothing checks that they fit in 32 bits before the cast. A layer that declares a major or minor at or above 2^32 gets silently truncated, so the block or character device that lands on disk carries a different major/minor than the header states (for example 0x100000008 becomes 8). I came across it while reading the block/char/fifo path for that narrowing cast. Range-checking the two fields against 0..MaxUint32 in that helper keeps the created node matching the header and leaves every real device, which fits in 32 bits, untouched. I kept the check inside handleTarTypeBlockCharFifo so the extraction loop stays as it was.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Unix layer extraction for special device entries (block/char/fifo) by rejecting tar headers that specify device major/minor numbers outside the representable uint32 range, preventing silent truncation when calling unix.Mkdev.

Changes:

  • Add explicit range checks for hdr.Devmajor / hdr.Devminor in handleTarTypeBlockCharFifo and return errInvalidArchive on out-of-range values.
  • Add a focused non-Windows unit test covering negative and > MaxUint32 device numbers to ensure the new validation triggers before attempting mknod.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/archive/tar_unix.go Validates device major/minor from tar headers before narrowing to uint32 for unix.Mkdev, returning errInvalidArchive on invalid values.
pkg/archive/tar_unix_test.go Adds a regression test ensuring invalid device numbers are rejected with errInvalidArchive.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AkihiroSuda

Copy link
Copy Markdown
Member

/cherry-pick release/2.3
/cherry-pick release/2.2

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: once the present PR merges, I will cherry-pick it on top of release/2.2, release/2.3 in new PRs and assign them to you.

Details

In response to this:

/cherry-pick release/2.3
/cherry-pick release/2.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jul 14, 2026
@mxpv
mxpv added this pull request to the merge queue Jul 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 14, 2026
@mxpv
mxpv added this pull request to the merge queue Jul 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 14, 2026
@mxpv
mxpv added this pull request to the merge queue Jul 14, 2026
Merged via the queue into containerd:main with commit 9e70782 Jul 14, 2026
51 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jul 14, 2026
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: new pull request created: #13793

Details

In response to this:

/cherry-pick release/2.3
/cherry-pick release/2.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: new pull request created: #13794

Details

In response to this:

/cherry-pick release/2.3
/cherry-pick release/2.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants