Skip to content
Open
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
16 changes: 16 additions & 0 deletions vm/devices/net/netvsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,8 @@ enum WorkerError {
RndisMessageTooSmall,
#[error("unsupported rndis behavior")]
UnsupportedRndisBehavior,
#[error("invalid lso packet")]
InvalidLsoPacket(&'static str),
#[error("vmbus queue error")]
Queue(#[from] queue::Error),
#[error("too many control messages")]
Expand Down Expand Up @@ -2467,6 +2469,20 @@ impl<T: RingMem> NetChannel<T> {
});
}

if metadata.offload_tcp_segmentation {
if segments.len() < 2 {
return Err(WorkerError::InvalidLsoPacket(
"LSO requires at least two SGEs",
));
}
let first_segment_size = segments.first().unwrap().len;
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using unwrap() is unsafe here even though the length check exists above. If segments is empty, this will panic. Consider using segments[0].len instead since the length check guarantees at least 2 elements, or use a safer pattern like let first_segment = &segments[0];.

Suggested change
let first_segment_size = segments.first().unwrap().len;
let first_segment_size = segments[0].len;

Copilot uses AI. Check for mistakes.

if first_segment_size > 256 {
return Err(WorkerError::InvalidLsoPacket(
"LSO requires first SGE to be <= 256 bytes",
));
}
}

metadata.segment_count = segments.len() - start;

stats.tx_packets.increment();
Expand Down