Conversation
vm_guest_to_host validates only the start address, so a guest descriptor whose addr sits near the top of RAM with a length running off the end yields a host-side OOB read/write. Add vm_guest_buf(v, guest, len) that checks guest+len <= RAM_BASE+RAM_SIZE with a __builtin_add_overflow guard, returning NULL otherwise, and migrate every length-driven access in the virtio fast paths to it. virtio-blk also gains a backing-store bounds check and overflow guards on the sector arithmetic. sector*512 + data_size must fit in diskimg->size; both __builtin_mul_overflow on the shift and __builtin_add_overflow on the addition reject malicious offsets before issuing I/O. Short reads/writes from diskimg_read/diskimg_write now map to VIRTIO_BLK_S_IOERR rather than the previous "io_bytes < 0" check that silently reported a stale guest buffer as success. On error, used.len reports only the 1-byte status so the guest does not consume the unwritten tail. The status descriptor is now required to advertise at least one device-writable byte before the device clobbers it. virtio-net rx and tx snapshot desc->len into a local before the bounds check, then use only that snapshot for the read/writev byte count. The descriptor lives in guest-writable memory, so a concurrent guest write could otherwise enlarge len after the check and walk the host kernel past the validated guest range.
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.
vm_guest_to_host validates only the start address, so a guest descriptor whose addr sits near the top of RAM with a length running off the end yields a host-side OOB read/write. Add vm_guest_buf(v, guest, len) that checks guest+len <= RAM_BASE+RAM_SIZE with a __builtin_add_overflow guard, returning NULL otherwise, and migrate every length-driven access in the virtio fast paths to it.
virtio-blk also gains a backing-store bounds check and overflow guards on the sector arithmetic. sector*512 + data_size must fit in diskimg->size; both __builtin_mul_overflow on the shift and __builtin_add_overflow on the addition reject malicious offsets before issuing I/O. Short reads/writes from diskimg_read/diskimg_write now map to VIRTIO_BLK_S_IOERR rather than the previous "io_bytes < 0" check that silently reported a stale guest buffer as success. On error, used.len reports only the 1-byte status so the guest does not consume the unwritten tail. The status descriptor is now required to advertise at least one device-writable byte before the device clobbers it.
virtio-net rx and tx snapshot desc->len into a local before the bounds check, then use only that snapshot for the read/writev byte count. The descriptor lives in guest-writable memory, so a concurrent guest write could otherwise enlarge len after the check and walk the host kernel past the validated guest range.
Summary by cubic
Add length-checked guest buffer validation across virtio paths to prevent host out-of-bounds access. Tightens virtio-blk bounds and status handling and snapshots virtio-net descriptor lengths to block TOCTOU.
Written for commit 33b400e. Summary will update on new commits. Review in cubic