Skip to content

Commit 4392633

Browse files
mstsirkinkuba-moo
authored andcommitted
vhost: vringh: Fix copy_to_iter return value check
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. Cc: zhang jiao <zhangjiao2@cmss.chinamobile.com> Link: https://lore.kernel.org/all/20250910091739.2999-1-zhangjiao2@cmss.chinamobile.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Simon Horman <horms@kernel.org> Fixes: 309bba3 ("vringh: iterate on iotlb_translate to handle large translations") Link: https://patch.msgid.link/cd637504a6e3967954a9e80fc1b75e8c0978087b.1758723310.git.mst@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e9f3529 commit 4392633

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/vhost/vringh.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ static inline int copy_to_iotlb(const struct vringh *vrh, void *dst,
11611161
struct iov_iter iter;
11621162
u64 translated;
11631163
int ret;
1164+
size_t size;
11641165

11651166
ret = iotlb_translate(vrh, (u64)(uintptr_t)dst,
11661167
len - total_translated, &translated,
@@ -1178,9 +1179,9 @@ static inline int copy_to_iotlb(const struct vringh *vrh, void *dst,
11781179
translated);
11791180
}
11801181

1181-
ret = copy_to_iter(src, translated, &iter);
1182-
if (ret < 0)
1183-
return ret;
1182+
size = copy_to_iter(src, translated, &iter);
1183+
if (size != translated)
1184+
return -EFAULT;
11841185

11851186
src += translated;
11861187
dst += translated;

0 commit comments

Comments
 (0)