-
Notifications
You must be signed in to change notification settings - Fork 167
virtio: validate descriptor index from avail ring #2780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
virtio: validate descriptor index from avail ring #2780
Conversation
There was a problem hiding this comment.
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 the virtio queue implementation against malicious or buggy guests by validating that descriptor indices read from the guest-provided avail ring are within the configured queue size, returning a specific error on violation.
Changes:
- Add a new
QueueError::InvalidDescriptorIndex(u16)error variant for invalid avail-ring descriptor indices. - Validate the descriptor index read from the avail ring against
queue_sizebefore using it.
88b7723 to
4ca3965
Compare
The descriptor index read from the guest's available ring was used directly without checking it against queue_size. A malicious or buggy guest could supply an out-of-range index. Add an explicit bounds check with a clear error message.
A queue_size of 0 causes division-by-zero panics in get_available_descriptor_index and set_used_descriptor, which both compute modulo queue_size. Reject it early in QueueCore::new.
4ca3965 to
0c6fd95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
| #[error("descriptor index {0} is out of range")] | ||
| InvalidDescriptorIndex(u16), |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The InvalidDescriptorIndex error message doesn’t include the queue size / valid range, which makes debugging guest issues harder. Consider including queue_size in the variant (e.g., store both the index and queue_size) and mention the valid range in the error text.
| mem: GuestMemory, | ||
| params: QueueParams, | ||
| ) -> Result<Self, QueueError> { | ||
| if params.size == 0 { |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new params.size == 0 check is redundant with QueueCoreGetWork::new’s is_power_of_two() validation (which already rejects 0), and it only checks for 0 (not other invalid sizes). To avoid inconsistent validation if SplitQueueGetWork::new is ever called directly, either remove this check (rely on the outer validation) or validate the full invariant here (non-zero power-of-two).
| if params.size == 0 { | |
| if !params.size.is_power_of_two() { |
The descriptor index read from the guest's available ring was used directly without checking it against queue_size. A malicious or buggy guest could supply an out-of-range index. Add an explicit bounds check with a clear error message.