-
Couldn't load subscription status.
- Fork 157
netvsp: adding LSO validation logic to handle_rndis_packet_message #2148
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?
netvsp: adding LSO validation logic to handle_rndis_packet_message #2148
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 adds LSO (Large Send Offload) packet validation logic to the netvsp driver's packet handling function to ensure guest-provided LSO packets meet required constraints.
Key changes:
- Adds validation for LSO packets to verify they have at least two SGEs (Scatter-Gather Elements)
- Validates that the first SGE is no larger than 256 bytes (header size constraint)
- Introduces a new error type for invalid LSO packets
vm/devices/net/netvsp/src/lib.rs
Outdated
| "LSO requires at least two SGEs", | ||
| )); | ||
| } | ||
| let first_segment_size = segments.first().unwrap().len; |
Copilot
AI
Oct 10, 2025
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.
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];.
| let first_segment_size = segments.first().unwrap().len; | |
| let first_segment_size = segments[0].len; |
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.
+1 to this
vm/devices/net/netvsp/src/lib.rs
Outdated
|
|
||
| if metadata.offload_tcp_segmentation { | ||
| if segments.len() < 2 { | ||
| return Err(WorkerError::InvalidLsoPacket( |
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.
should this be two different error types, and we log in the error how many segments we actually got?
vm/devices/net/netvsp/src/lib.rs
Outdated
| } | ||
| let first_segment_size = segments.first().unwrap().len; | ||
| if first_segment_size > 256 { | ||
| return Err(WorkerError::InvalidLsoPacket( |
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.
same with this below as above?
vm/devices/net/netvsp/src/lib.rs
Outdated
| "LSO requires at least two SGEs", | ||
| )); | ||
| } | ||
| let first_segment_size = segments.first().unwrap().len; |
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.
+1 to this
011988b to
7fe50de
Compare
7fe50de to
a92d91d
Compare
vm/devices/net/netvsp/src/lib.rs
Outdated
| )); | ||
| } | ||
| let first_segment_size = segments[0].len; | ||
| if first_segment_size > 256 { |
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 is a MANA requirement, but I dont see this as a (R)NDIS requirement here https://learn.microsoft.com/en-us/windows-hardware/drivers/network/offloading-the-segmentation-of-large-tcp-packets
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.
Ok, I'll remove this check.
vm/devices/net/netvsp/src/lib.rs
Outdated
| } | ||
|
|
||
| if metadata.offload_tcp_segmentation { | ||
| if segments.len() < 2 { |
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.
Lets define a constant for the min segment count and also use the same constant for the ndis_offload min_segement_count property for IPv4/v6
For reference, here is the spec https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddndis/ns-ntddndis-_ndis_tcp_large_send_offload_v2
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.
.
…nt count constant
netvsp should be validating the LSO packets coming from the guest