Skip to content

Commit 060423b

Browse files
yongduanmstsirkin
authored andcommitted
vhost: make sure log_num < in_num
The code assumes log_num < in_num everywhere, and that is true as long as in_num is incremented by descriptor iov count, and log_num by 1. However this breaks if there's a zero sized descriptor. As a result, if a malicious guest creates a vring desc with desc.len = 0, it may cause the host kernel to crash by overflowing the log array. This bug can be triggered during the VM migration. There's no need to log when desc.len = 0, so just don't increment log_num in this case. Fixes: 3a4d5c9 ("vhost_net: a kernel-level virtio server") Cc: [email protected] Reviewed-by: Lidong Chen <[email protected]> Signed-off-by: ruippan <[email protected]> Signed-off-by: yongduan <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Tyler Hicks <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent a89db44 commit 060423b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/vhost/vhost.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ static int get_indirect(struct vhost_virtqueue *vq,
21802180
/* If this is an input descriptor, increment that count. */
21812181
if (access == VHOST_ACCESS_WO) {
21822182
*in_num += ret;
2183-
if (unlikely(log)) {
2183+
if (unlikely(log && ret)) {
21842184
log[*log_num].addr = vhost64_to_cpu(vq, desc.addr);
21852185
log[*log_num].len = vhost32_to_cpu(vq, desc.len);
21862186
++*log_num;
@@ -2321,7 +2321,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
23212321
/* If this is an input descriptor,
23222322
* increment that count. */
23232323
*in_num += ret;
2324-
if (unlikely(log)) {
2324+
if (unlikely(log && ret)) {
23252325
log[*log_num].addr = vhost64_to_cpu(vq, desc.addr);
23262326
log[*log_num].len = vhost32_to_cpu(vq, desc.len);
23272327
++*log_num;

0 commit comments

Comments
 (0)