Skip to content
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

devices/vsock: check the packet length before use #38

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/devices/vsock/src/transport/virtio_pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ impl VirtioVsock {
.ok_or(VsockTransportError::DmaAllocation)?;
}

let packet_hdr = Packet::new_unchecked(&hdr_buf[..]);
let packet_hdr = Packet::new_checked(&hdr_buf[..])
.map_err(|_| VsockTransportError::InvalidVsockPacket)?;
let data_len = packet_hdr.data_len();
if data_len != 0 {
if data_len > pkt[1].len {
Expand Down
3 changes: 3 additions & 0 deletions src/devices/vsock/src/transport/vmcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use alloc::boxed::Box;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use core::arch::asm;

Check warning on line 19 in src/devices/vsock/src/transport/vmcall.rs

View workflow job for this annotation

GitHub Actions / Build final migtd

unused import: `core::arch::asm`
use core::convert::TryInto;
use core::sync::atomic::{AtomicBool, Ordering};
use td_payload::{eoi, interrupt_handler_template};
Expand Down Expand Up @@ -94,6 +94,9 @@
let mut header = Vec::new();
let mut data = Vec::new();

if pkt.len() < HEADER_LEN {
return Err(VsockTransportError::InvalidVsockPacket);
}
// Read out the packet header into a safe place
header.extend_from_slice(&pkt[..HEADER_LEN]);

Expand Down
Loading