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: 3a4d5c94e959 ("vhost_net: a kernel-level virtio server")
Cc: stable@vger.kernel.org
Reviewed-by: Lidong Chen <lidongchen@tencent.com>
Signed-off-by: ruippan <ruippan@tencent.com>
Signed-off-by: yongduan <yongduan@tencent.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by yongduan and committed by Michael S. Tsirkin 060423bf a89db445

Changed files
+2 -2
drivers
vhost
+2 -2
drivers/vhost/vhost.c
··· 2180 2180 /* If this is an input descriptor, increment that count. */ 2181 2181 if (access == VHOST_ACCESS_WO) { 2182 2182 *in_num += ret; 2183 - if (unlikely(log)) { 2183 + if (unlikely(log && ret)) { 2184 2184 log[*log_num].addr = vhost64_to_cpu(vq, desc.addr); 2185 2185 log[*log_num].len = vhost32_to_cpu(vq, desc.len); 2186 2186 ++*log_num; ··· 2321 2321 /* If this is an input descriptor, 2322 2322 * increment that count. */ 2323 2323 *in_num += ret; 2324 - if (unlikely(log)) { 2324 + if (unlikely(log && ret)) { 2325 2325 log[*log_num].addr = vhost64_to_cpu(vq, desc.addr); 2326 2326 log[*log_num].len = vhost32_to_cpu(vq, desc.len); 2327 2327 ++*log_num;