Skip to content

Commit dbd29e0

Browse files
YongjiXiemstsirkin
authored andcommitted
vringh: Fix loop descriptors check in the indirect cases
We should use size of descriptor chain to test loop condition in the indirect case. And another statistical count is also introduced for indirect descriptors to avoid conflict with the statistical count of direct descriptors. Fixes: f87d0fb ("vringh: host-side implementation of virtio rings.") Signed-off-by: Xie Yongji <[email protected]> Signed-off-by: Fam Zheng <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent f38b3c6 commit dbd29e0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/vhost/vringh.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ __vringh_iov(struct vringh *vrh, u16 i,
292292
int (*copy)(const struct vringh *vrh,
293293
void *dst, const void *src, size_t len))
294294
{
295-
int err, count = 0, up_next, desc_max;
295+
int err, count = 0, indirect_count = 0, up_next, desc_max;
296296
struct vring_desc desc, *descs;
297297
struct vringh_range range = { -1ULL, 0 }, slowrange;
298298
bool slow = false;
@@ -349,7 +349,12 @@ __vringh_iov(struct vringh *vrh, u16 i,
349349
continue;
350350
}
351351

352-
if (count++ == vrh->vring.num) {
352+
if (up_next == -1)
353+
count++;
354+
else
355+
indirect_count++;
356+
357+
if (count > vrh->vring.num || indirect_count > desc_max) {
353358
vringh_bad("Descriptor loop in %p", descs);
354359
err = -ELOOP;
355360
goto fail;
@@ -411,6 +416,7 @@ __vringh_iov(struct vringh *vrh, u16 i,
411416
i = return_from_indirect(vrh, &up_next,
412417
&descs, &desc_max);
413418
slow = false;
419+
indirect_count = 0;
414420
} else
415421
break;
416422
}

0 commit comments

Comments
 (0)