From: yongduan <yongd...@tencent.com>

commit 060423bfdee3f8bc6e2c1bac97de24d5415e2bc4 upstream.

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: 3a4d5c94e959 ("vhost_net: a kernel-level virtio server")
Cc: sta...@vger.kernel.org
Reviewed-by: Lidong Chen <lidongc...@tencent.com>
Signed-off-by: ruippan <ruip...@tencent.com>
Signed-off-by: yongduan <yongd...@tencent.com>
Acked-by: Michael S. Tsirkin <m...@redhat.com>
Reviewed-by: Tyler Hicks <tyhi...@canonical.com>
Signed-off-by: Michael S. Tsirkin <m...@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>

---
 drivers/vhost/vhost.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2075,7 +2075,7 @@ static int get_indirect(struct vhost_vir
                /* If this is an input descriptor, increment that count. */
                if (access == VHOST_ACCESS_WO) {
                        *in_num += ret;
-                       if (unlikely(log)) {
+                       if (unlikely(log && ret)) {
                                log[*log_num].addr = vhost64_to_cpu(vq, 
desc.addr);
                                log[*log_num].len = vhost32_to_cpu(vq, 
desc.len);
                                ++*log_num;
@@ -2218,7 +2218,7 @@ int vhost_get_vq_desc(struct vhost_virtq
                        /* If this is an input descriptor,
                         * increment that count. */
                        *in_num += ret;
-                       if (unlikely(log)) {
+                       if (unlikely(log && ret)) {
                                log[*log_num].addr = vhost64_to_cpu(vq, 
desc.addr);
                                log[*log_num].len = vhost32_to_cpu(vq, 
desc.len);
                                ++*log_num;


Reply via email to