Repository navigation
pkg/archive: reject out-of-range device numbers in layer headers - #13792
Conversation
Signed-off-by: Aysha Afrah Ziya <[email protected]>
There was a problem hiding this comment.
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.DevminorinhandleTarTypeBlockCharFifoand returnerrInvalidArchiveon out-of-range values. - Add a focused non-Windows unit test covering negative and
> MaxUint32device numbers to ensure the new validation triggers before attemptingmknod.
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.
|
/cherry-pick release/2.3 |
|
@AkihiroSuda: once the present PR merges, I will cherry-pick it on top of DetailsIn response to this:
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. |
|
@AkihiroSuda: new pull request created: #13793 DetailsIn response to this:
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. |
|
@AkihiroSuda: new pull request created: #13794 DetailsIn response to this:
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. |
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.