]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
virtio_net: fix missing lock protection on control_buf access
authorHeng Qi <hengqi@linux.alibaba.com>
Thu, 30 May 2024 03:41:43 +0000 (11:41 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 1 Jun 2024 22:09:56 +0000 (15:09 -0700)
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: 6f45ab3e0409 ("virtio_net: Add a lock for the command VQ.")
Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
Reviewed-by: Hariprasad Kelam <hkelam@marvell.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240530034143.19579-1-hengqi@linux.alibaba.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/virtio_net.c

index 4a802c0ea2cbc381ecc8a48c7ca28bc75c4808f8..1ea8e6a24286ef029ac67ea6abb8ad5e30ff7f31 100644 (file)
@@ -2686,6 +2686,7 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
 {
        struct scatterlist *sgs[5], hdr, stat;
        u32 out_num = 0, tmp, in_num = 0;
+       bool ok;
        int ret;
 
        /* Caller should know better */
@@ -2731,8 +2732,9 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
        }
 
 unlock:
+       ok = vi->ctrl->status == VIRTIO_NET_OK;
        mutex_unlock(&vi->cvq_lock);
-       return vi->ctrl->status == VIRTIO_NET_OK;
+       return ok;
 }
 
 static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,