]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
vhost: fail early when __vhost_add_used() fails
authorJason Wang <jasowang@redhat.com>
Mon, 14 Jul 2025 08:47:53 +0000 (16:47 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Aug 2025 16:41:21 +0000 (18:41 +0200)
[ Upstream commit b4ba1207d45adaafa2982c035898b36af2d3e518 ]

This patch fails vhost_add_used_n() early when __vhost_add_used()
fails to make sure used idx is not updated with stale used ring
information.

Reported-by: Eugenio Pérez <eperezma@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20250714084755.11921-2-jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/vhost/vhost.c

index 84c9bdf9aeddaf4c10c2cab5253931ccefd12952..478eca3cf113bcd4ae7f5e51b62b10aa4f892392 100644 (file)
@@ -2983,6 +2983,9 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
        }
        r = __vhost_add_used_n(vq, heads, count);
 
+       if (r < 0)
+               return r;
+
        /* Make sure buffer is written before we update index. */
        smp_wmb();
        if (vhost_put_used_idx(vq)) {