diff options
author | Jason Wang <jasowang@redhat.com> | 2025-07-14 16:47:53 +0800 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2025-08-01 09:11:09 -0400 |
commit | b4ba1207d45adaafa2982c035898b36af2d3e518 (patch) | |
tree | a47e9d84639c4c20605bfb4ce5e9f616da12e4a1 | |
parent | 7d9896e9f6d02d8aa85e63f736871f96c59a5263 (diff) |
vhost: fail early when __vhost_add_used() fails
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>
-rw-r--r-- | drivers/vhost/vhost.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index f4c1bc6adeda..b38e39242fb9 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -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)) { |