vhost: fix dead loop in enqueue path
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Sun, 22 Jan 2017 08:46:58 +0000 (16:46 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Sat, 28 Jan 2017 13:25:23 +0000 (14:25 +0100)
commitcc7301908c031a288eeb6c12db21b938755b67ee
tree60bd3952abcc85abd2aa5663608fe5fe6cf1eef7
parent30712b214b5d469f6fc988af130811a9f5710841
vhost: fix dead loop in enqueue path

If a malicious guest forges a dead loop desc chain (let desc->next point
to itself) and desc->len is zero, this could lead to a dead loop in
copy_mbuf_to_desc(following is a simplified code to show this issue
clearly):

    while (mbuf_is_not_totally_consumed) {
        if (desc_avail == 0) {
            desc = &descs[desc->next];
            desc_avail = desc->len;
        }

        COPY(desc, mbuf, desc_avail);
    }

I have actually fixed a same issue before: commit a436f53ebfeb ("vhost:
avoid dead loop chain"); it fixes the dequeue path though, leaving the
enqueue path still vulnerable.

The fix is the same. Add a var nr_desc to avoid the dead loop.

Fixes: f1a519ad981c ("vhost: fix enqueue/dequeue to handle chained vring descriptors")
Cc: stable@dpdk.org
Reported-by: Xieming Katty <katty.xieming@huawei.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
lib/librte_vhost/virtio_net.c