net_packet_capture: fix read_at over-read past segment boundary#3105
net_packet_capture: fix read_at over-read past segment boundary#3105
Conversation
Co-authored-by: jstarks <9548354+jstarks@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/openvmm/sessions/86bc71b3-7ea4-470d-aefc-bb4a4b0361c3
|
@copilot, you fixed the bug, but can you add some tests? The tests should be written so that they would have failed (panicked?) before your fix. Temporarily revert your changes locally to validate this. |
…undary reads Co-authored-by: jstarks <9548354+jstarks@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/openvmm/sessions/50fc1d68-1007-46f0-ba9d-8a4321507253
Added in c81f095. I extracted the duplicated capture loop into a
I validated by temporarily reverting |
|
@copilot, this completely misunderstands the purposes of the test. Revert this garbage. The point is to write tests that drive the actual network backend in a way to cause the panic. Not test a tiny bit of isolated code. |
… PacketCaptureQueue Co-authored-by: jstarks <9548354+jstarks@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/openvmm/sessions/1ce538bd-a302-47a0-b7b0-2e455bf9e1aa
Reverted the |
In both the RX and TX capture paths,
copy_lengthwas computed correctly to cap reads at the segment boundary, but the slice passed toread_atwas unbounded — reading up tobuf.len() - lenbytes instead ofcopy_length. This could pull in bytes from unrelated guest memory, and silently leave stale/zero data in the capture buffer if the over-read crossed into unmapped memory.Changes
rx_pollandtx_availcapture loops: bound theread_atslice to exactlycopy_lengthbytes:PacketCaptureQueuethroughrx_pollandtx_availusing mock inner queues and realGuestMemory. Each test places segments at the end of a 4096-byte guest memory with a large snaplen (65535), so the old unbounded&mut buf[len..]causesread_atto over-read past memory and fail silently — leaving the capture buffer zero-filled. Tests assert the PCAP output contains the expected byte patterns. All 4 tests panic when the fix is reverted.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.