Skip to content

Commit

Permalink
drop too small ethernet frames
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes authored and mkroening committed Nov 9, 2023
1 parent af01ca5 commit 1b8fe72
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/drivers/net/virtio_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,21 @@ impl NetworkDriver for VirtioNetDriver {
if recv_data.len() == 1 {
let mut vec_data: Vec<u8> = Vec::with_capacity(self.mtu.into());
let num_buffers = {
const HEADER_SIZE: usize = mem::size_of::<VirtioNetHdr>();
let packet = recv_data.pop().unwrap();

// drop packets with invalid packet size
if packet.len() < HEADER_SIZE {
transfer
.reuse()
.unwrap()
.provide()
.dispatch_await(Rc::clone(&self.recv_vqs.poll_queue), false);

return None;
}

let header = unsafe {
const HEADER_SIZE: usize = mem::size_of::<VirtioNetHdr>();
core::mem::transmute::<[u8; HEADER_SIZE], VirtioNetHdr>(
packet[..HEADER_SIZE].try_into().unwrap(),
)
Expand Down

0 comments on commit 1b8fe72

Please sign in to comment.