net_packet_capture: read_at over-reads past segment boundary in PCAP capture
@jstarks is already working on this.
Since Mar 23, 2026.
- Dominant language
- Rust
- Stars
- 1.9k
- Forks
- 238
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 100
Description
In net_packet_capture, both the RX and TX capture paths compute a copy_length to limit how many bytes to capture from each segment, but then pass an unbounded slice to read_at:
let copy_length = std::cmp::min(buf.len() - len, segment.len as usize);
let _ = pool.guest_memory().read_at(segment.gpa, &mut buf[len..]);
// ^^^^^^^^^ should be &mut buf[len..len + copy_length]
This reads buf.len() - len bytes from guest memory starting at segment.gpa, which can extend past the segment boundary into unrelated guest memory. The PCAP output happens to use the correct length (since len only advances by copy_length), but:
- Bytes beyond the segment are read into the capture buffer unnecessarily.
- If the over-read crosses into unmapped guest memory,
read_atfails and thelet _ =silently swallows the error, leaving stale/zero bytes in the buffer.
Fix: Change both sites to &mut buf[len..len + copy_length].
Affected code: vm/devices/net/net_packet_capture/src/lib.rs — the rx_poll capture loop and the tx_avail capture loop.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.