nutanix / libvfio-user

framework for emulating devices in userspace
BSD 3-Clause "New" or "Revised" License
162 stars 51 forks source link

Possible data race problems for tran_sock_msg_iovec #657

Closed ycaibb closed 2 years ago

ycaibb commented 2 years ago

Hi, it seems the tran_sock_msg_iovec should be protected by locks. https://github.com/nutanix/libvfio-user/blob/17769cf1af093dfb4b9bc3347ae39324029989ac/samples/client.c#L483-L488

However, the method is not guarded in the blow places. https://github.com/nutanix/libvfio-user/blob/17769cf1af093dfb4b9bc3347ae39324029989ac/samples/client.c#L1066-L1078

https://github.com/nutanix/libvfio-user/blob/17769cf1af093dfb4b9bc3347ae39324029989ac/samples/client.c#L427-L437

tmakatos commented 2 years ago

I should have added a more detailed description in the original commit, looking at the code I think I did this to protect the migration region as it's written by the fake guest thread: https://github.com/nutanix/libvfio-user/blob/17769cf1af093dfb4b9bc3347ae39324029989ac/samples/client.c#L821-L834 while it's being read by do_migrate.

ycaibb commented 2 years ago

@tmakatos OK, thank you for your clarification.