Skip to content

Commit 3063625

Browse files
Heng Qikuba-moo
authored andcommitted
virtio_net: fix missing lock protection on control_buf access
Refactored the handling of control_buf to be within the cvq_lock critical section, mitigating race conditions between reading device responses and new command submissions. Fixes: 6f45ab3 ("virtio_net: Add a lock for the command VQ.") Signed-off-by: Heng Qi <[email protected]> Reviewed-by: Hariprasad Kelam <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Xuan Zhuo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d8ec198 commit 3063625

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/net/virtio_net.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2686,6 +2686,7 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
26862686
{
26872687
struct scatterlist *sgs[5], hdr, stat;
26882688
u32 out_num = 0, tmp, in_num = 0;
2689+
bool ok;
26892690
int ret;
26902691

26912692
/* Caller should know better */
@@ -2731,8 +2732,9 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
27312732
}
27322733

27332734
unlock:
2735+
ok = vi->ctrl->status == VIRTIO_NET_OK;
27342736
mutex_unlock(&vi->cvq_lock);
2735-
return vi->ctrl->status == VIRTIO_NET_OK;
2737+
return ok;
27362738
}
27372739

27382740
static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,

0 commit comments

Comments
 (0)