virtio-win / kvm-guest-drivers-windows

Windows paravirtualized drivers for QEMU\KVM
https://www.linux-kvm.org/page/WindowsGuestDrivers
BSD 3-Clause "New" or "Revised" License
1.92k stars 377 forks source link

viosock: fix NtReadFile/NtWriteFile; fix sending large packet sg list #957

Closed Jing118 closed 10 months ago

Jing118 commented 11 months ago

This PR fixes 2 issues:

  1. Wait on a Event instead of the socket itself after calling NtWriteFile()/NtReadFile(), otherwise WaitForSingleObject() may return before the write/read completes, thus returning wrong status to caller. This issue can be reproduced by having a sender thread and a receiver thread running on a socket at the same time, and sometimes send() may return 0 bytes sent, even though the other side can receive the packet.

  2. If the first element in SgList is not 4KB, there will be 17 element in SgList for 64KB data, which will cause a stack buffer overrun BSOD. This issue can be reproduced by sending more then 64KB data in one send().

YanVugenfirer commented 10 months ago

Hi @Jing118 ,

  1. Please split the patches.
  2. Please add Signed-off-by line to the end of the commit message. Check contribution guidelines: https://github.com/virtio-win/kvm-guest-drivers-windows/blob/master/contributing.md
  3. For the TX fix, it is a bad practice to allocate memory on stack for SG in any case. I suggest to make a real fix that will allocate memory properly (also with consideration of probable usage of IOMMU) and not workaround.

Thanks, Yan.