Skip to content

Commit f13f09a

Browse files
sumanannamstsirkin
authored andcommitted
virtio_ring: Fix mem leak with vring_new_virtqueue()
The functions vring_new_virtqueue() and __vring_new_virtqueue() are used with split rings, and any allocations within these functions are managed outside of the .we_own_ring flag. The commit cbeedb7 ("virtio_ring: allocate desc state for split ring separately") allocates the desc state within the __vring_new_virtqueue() but frees it only when the .we_own_ring flag is set. This leads to a memory leak when freeing such allocated virtqueues with the vring_del_virtqueue() function. Fix this by moving the desc_state free code outside the flag and only for split rings. Issue was discovered during testing with remoteproc and virtio_rpmsg. Fixes: cbeedb7 ("virtio_ring: allocate desc state for split ring separately") Signed-off-by: Suman Anna <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent 98d54f8 commit f13f09a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/virtio/virtio_ring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,10 +2203,10 @@ void vring_del_virtqueue(struct virtqueue *_vq)
22032203
vq->split.queue_size_in_bytes,
22042204
vq->split.vring.desc,
22052205
vq->split.queue_dma_addr);
2206-
2207-
kfree(vq->split.desc_state);
22082206
}
22092207
}
2208+
if (!vq->packed_ring)
2209+
kfree(vq->split.desc_state);
22102210
list_del(&_vq->list);
22112211
kfree(vq);
22122212
}

0 commit comments

Comments
 (0)