]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
virtio: fix memory leak in virtqueue_add()
authorWei Yongjun <weiyj.lk@gmail.com>
Tue, 2 Aug 2016 14:16:31 +0000 (14:16 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Sep 2016 06:34:44 +0000 (08:34 +0200)
commit 58625edf9e2515ed41dac2a24fa8004030a87b87 upstream.

When using the indirect buffers feature, 'desc' is allocated in
virtqueue_add() but isn't freed before leaving on a ring full error,
causing a memory leak.

For example, it seems rather clear that this can trigger
with virtio net if mergeable buffers are not used.

Signed-off-by: Wei Yongjun <weiyj.lk@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/virtio/virtio_ring.c

index ca6bfddaacad2beeb1897a0e397bd5300ccff30d..2ebf30e57eec8b0128d6b10cc7dc3cbdfff10125 100644 (file)
@@ -316,6 +316,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
                 * host should service the ring ASAP. */
                if (out_sgs)
                        vq->notify(&vq->vq);
+               if (indirect)
+                       kfree(desc);
                END_USE(vq);
                return -ENOSPC;
        }