Skip to content

virtio: skip redundant memory check #4723

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

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/vmm/src/devices/virtio/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ pub struct DescriptorChain<'a, M: GuestMemory = GuestMemoryMmap> {
}

impl<'a, M: GuestMemory> DescriptorChain<'a, M> {
/// Creates a new `DescriptorChain` from the given memory and descriptor table.
///
/// Note that the desc_table and queue_size are assumed to be validated by the caller.
fn checked_new(
mem: &'a M,
desc_table: GuestAddress,
Expand All @@ -106,8 +109,9 @@ impl<'a, M: GuestMemory> DescriptorChain<'a, M> {
return None;
}

let desc_head = mem.checked_offset(desc_table, (index as usize) * 16)?;
mem.checked_offset(desc_head, 16)?;
// There's no need for checking as we already validated the descriptor table and index
// bounds.
let desc_head = desc_table.unchecked_add(u64::from(index) * 16);

// These reads can't fail unless Guest memory is hopelessly broken.
let desc = match mem.read_obj::<Descriptor>(desc_head) {
Expand Down
Loading