Commit 26057621 authored by yongduan's avatar yongduan Committed by Juerg Haefliger

UBUNTU: SAUCE: 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: 3a4d5c94 ("vhost_net: a kernel-level virtio server")
Reviewed-by: default avatarLidong Chen <lidongchen@tencent.com>
Signed-off-by: default avatarruippan <ruippan@tencent.com>
Signed-off-by: default avataryongduan <yongduan@tencent.com>
Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Reviewed-by: default avatarTyler Hicks <tyhicks@canonical.com>

CVE-2019-14835

(backported from email patch attachment)
[juergh: Adjusted context.]
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
parent fc75e4ae
...@@ -1324,7 +1324,7 @@ static int get_indirect(struct vhost_virtqueue *vq, ...@@ -1324,7 +1324,7 @@ static int get_indirect(struct vhost_virtqueue *vq,
/* If this is an input descriptor, increment that count. */ /* If this is an input descriptor, increment that count. */
if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_WRITE)) { if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_WRITE)) {
*in_num += ret; *in_num += ret;
if (unlikely(log)) { if (unlikely(log && ret)) {
log[*log_num].addr = vhost64_to_cpu(vq, desc.addr); log[*log_num].addr = vhost64_to_cpu(vq, desc.addr);
log[*log_num].len = vhost32_to_cpu(vq, desc.len); log[*log_num].len = vhost32_to_cpu(vq, desc.len);
++*log_num; ++*log_num;
...@@ -1453,7 +1453,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, ...@@ -1453,7 +1453,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
/* If this is an input descriptor, /* If this is an input descriptor,
* increment that count. */ * increment that count. */
*in_num += ret; *in_num += ret;
if (unlikely(log)) { if (unlikely(log && ret)) {
log[*log_num].addr = vhost64_to_cpu(vq, desc.addr); log[*log_num].addr = vhost64_to_cpu(vq, desc.addr);
log[*log_num].len = vhost32_to_cpu(vq, desc.len); log[*log_num].len = vhost32_to_cpu(vq, desc.len);
++*log_num; ++*log_num;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment