embeddedfs/vdi: add bounds check for BlocksInImage before slice allocation#1994
Open
adilburaksen wants to merge 2 commits intogoogle:mainfrom
Open
embeddedfs/vdi: add bounds check for BlocksInImage before slice allocation#1994adilburaksen wants to merge 2 commits intogoogle:mainfrom
adilburaksen wants to merge 2 commits intogoogle:mainfrom
Conversation
…ation convertVDIToRaw called make([]uint32, hdr.BlocksInImage) with no bounds check on the untrusted header field. A 512-byte crafted VDI with BlocksInImage=0x3FFFFFFF triggers a ~4 GB heap allocation before any I/O is attempted. With BlocksInImage=0xFFFFFFFF the request reaches ~16 GB. Fix: reject BlocksInImage values above 64M blocks (covers disks ≥64 TiB at the minimum 1 MiB block size) before the allocation. Add TestConvertVDIOOMRejected to confirm the malicious header is rejected.
Author
|
Hi! Just a friendly ping — all CI checks are passing. Happy to address any review feedback whenever you get a chance. Thanks for your time! |
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.
Summary
convertVDIToRawcallsmake([]uint32, hdr.BlocksInImage)with no boundscheck on the untrusted
BlocksInImageheader field (vdi.go:197).BlocksInImageis auint32read directly from the file. Setting it to0x3FFFFFFFrequests a ~4 GB slice;0xFFFFFFFFrequests ~16 GB. Theallocation occurs before any I/O — a 512-byte file is sufficient to trigger it.
Before fix (512-byte input):
On systems with overcommit disabled (common in containers with
vm.overcommit_memory=2), themake()call panics the process immediately.Fix
Add a hard cap of
64 << 20blocks (67,108,864) before the allocation.This covers disks ≥ 64 TiB at the minimum 1 MiB VDI block size — far beyond
any realistic disk image a scanner would encounter.
Testing
TestConvertVDIOOMRejectedconstructs a minimal 512-byte VDI header withBlocksInImage=0x3FFFFFFFin pure Go and confirms the fixed code returnsan error with zero heap allocation.
After fix:
TotalAlloc delta: 0 MB, immediate error.