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 CurrentCb BytesToRead setting #963

Closed Jing118 closed 10 months ago

Jing118 commented 10 months ago

We should set pCurrentCb->BytesToRead to 0 before calling VIOSockRxCbPushLocked(). Consider following scenario:

  1. thread 1 calls VIOSockRxCbPushLocked(), add CurrentCb to RxCbBuffers
  2. thread 2 calls VIOSockRxPktInsert(), get the CurrentCb from RxCbBuffers, and uses virtqueue_add_buf() to add the CurrentCb to RxVq
  3. thread 2 calls VIOSockRxVqProcess(), get the CurrentCb from virtqueue_get_buf(), and ready to be read from user recv() call
  4. thread 1 sets pCurrentCb->BytesToRead to 0, so it modifies the CurrentCb used by thread 2
Jing118 commented 10 months ago

Rebased.