netvsp: bounds-check RX buffer writes#3335
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds explicit bounds-checking for receive-buffer writes in netvsp to prevent panics from out-of-range offsets/lengths, returning a typed error and logging rate-limited warnings when writes would overflow.
Changes:
- Introduces
RxBufferWriteOverflow+check_rx_write_boundsto validateoffset + lensafely. - Updates
GuestBuffers::write_atto returnResultand validates against locked-page total size before writing. - Adds a unit test covering
check_rx_write_boundsedge cases.
chris-oo
left a comment
There was a problem hiding this comment.
LGTM other than question about what the guest should see
|
|
||
| fn write_data(&mut self, id: RxId, data: &[u8]) { | ||
| self.buffers.write_at(self.offset(id) + RX_HEADER_LEN, data); | ||
| if let Err(err) = self.buffers.write_at(self.offset(id) + RX_HEADER_LEN, data) { |
There was a problem hiding this comment.
does something need to get reported to the guest, or it's expected we just drop it on the floor?
There was a problem hiding this comment.
We wouldn't drop the packet, the Guest would see an packet with an empty buffer. Better than crashing.
In practice, this won't happen unless OpenHCL is misconfigured. This is defense in depth, caught by a fuzzer test that does not check capacity before calling write_packet.
GuestBuffers::write_at previously indexed into locked_pages without validating that offset + buf.len() fit within the locked page range. A misconfigured sub_allocation_size or an out-of-range RxId would panic.