Explorar o código

virtio: fix memory leak in virtqueue_add()

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.

Cc: stable@vger.kernel.org
Signed-off-by: Wei Yongjun <weiyj.lk@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Wei Yongjun %!s(int64=9) %!d(string=hai) anos
pai
achega
58625edf9e
Modificáronse 1 ficheiros con 2 adicións e 0 borrados
  1. 2 0
      drivers/virtio/virtio_ring.c

+ 2 - 0
drivers/virtio/virtio_ring.c

@@ -327,6 +327,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;
 	}