]> www.infradead.org Git - users/hch/misc.git/commitdiff
vhost: vringh: Fix copy_to_iter return value check
authorMichael S. Tsirkin <mst@redhat.com>
Tue, 23 Sep 2025 21:44:26 +0000 (17:44 -0400)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 1 Oct 2025 11:24:31 +0000 (07:24 -0400)
The return value of copy_to_iter can't be negative, check whether the
copied length is equal to the requested length instead of checking for
negative values.

Fixes: 309bba39c945 ("vringh: iterate on iotlb_translate to handle large translations")
Cc: "Stefano Garzarella" <sgarzare@redhat.com>
Cc: zhang jiao <zhangjiao2@cmss.chinamobile.com>
Link: https://lore.kernel.org/all/20250910091739.2999-1-zhangjiao2@cmss.chinamobile.com
Message-ID: <cd637504a6e3967954a9e80fc1b75e8c0978087b.1758723310.git.mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vhost/vringh.c

index 0c8a17cbb22ea7068e7cb6bbdf0bbf750c770d56..925858cc60964b46019c41ef1cc6286de46fbfa3 100644 (file)
@@ -1162,6 +1162,7 @@ static inline int copy_to_iotlb(const struct vringh *vrh, void *dst,
                struct iov_iter iter;
                u64 translated;
                int ret;
+               size_t size;
 
                ret = iotlb_translate(vrh, (u64)(uintptr_t)dst,
                                      len - total_translated, &translated,
@@ -1179,9 +1180,9 @@ static inline int copy_to_iotlb(const struct vringh *vrh, void *dst,
                                      translated);
                }
 
-               ret = copy_to_iter(src, translated, &iter);
-               if (ret < 0)
-                       return ret;
+               size = copy_to_iter(src, translated, &iter);
+               if (size != translated)
+                       return -EFAULT;
 
                src += translated;
                dst += translated;