From: Jason Wang Date: Mon, 14 Jul 2025 08:47:53 +0000 (+0800) Subject: vhost: fail early when __vhost_add_used() fails X-Git-Tag: v6.12.43~173 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1a63d8a442d09ccc38af1618391f626c4fa0c49;p=thirdparty%2Fkernel%2Fstable.git vhost: fail early when __vhost_add_used() fails [ 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 Signed-off-by: Jason Wang Message-Id: <20250714084755.11921-2-jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin Tested-by: Lei Yang Signed-off-by: Sasha Levin --- diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 79b0b7cd28601..71604668e53f6 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2971,6 +2971,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)) {