Skip to content

Commit e8f0a89

Browse files
vittyvkdavem330
authored andcommitted
hv_netvsc: fix a race between netvsc_send() and netvsc_init_buf()
Fix in commit 8809883 ("hv_netvsc: set nvdev link after populating chn_table") turns out to be incomplete. A crash in netvsc_get_next_send_section() is observed on mtu change when the device is under load. The race I identified is: if we get to netvsc_send() after we set net_device_ctx->nvdev link in netvsc_device_add() but before we finish netvsc_connect_vsp()->netvsc_init_buf() send_section_map is not allocated and we crash. Unfortunately we can't set net_device_ctx->nvdev link after the netvsc_init_buf() call as during the negotiation we need to receive packets and on the receive path we check for it. It would probably be possible to split nvdev into a pair of nvdev_in and nvdev_out links and check them accordingly in get_outbound_net_device()/ get_inbound_net_device() but this looks like an overkill. Check that send_section_map is allocated in netvsc_send(). Signed-off-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9e58c5d commit e8f0a89

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/net/hyperv/netvsc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,13 @@ int netvsc_send(struct hv_device *device,
888888
if (!net_device)
889889
return -ENODEV;
890890

891+
/* We may race with netvsc_connect_vsp()/netvsc_init_buf() and get
892+
* here before the negotiation with the host is finished and
893+
* send_section_map may not be allocated yet.
894+
*/
895+
if (!net_device->send_section_map)
896+
return -EAGAIN;
897+
891898
out_channel = net_device->chn_table[q_idx];
892899

893900
packet->send_buf_index = NETVSC_INVALID_INDEX;

0 commit comments

Comments
 (0)