blob: 89ac41e02e3b2a8e5910ef87beb338b38a509b19 [file] [log] [blame]
From 88b42855b404e6db92d083b0d4ba129417bc3d47 Mon Sep 17 00:00:00 2001
From: Suman Anna <>
Date: Mon, 24 Feb 2020 15:26:43 -0600
Subject: [PATCH] virtio_ring: Fix mem leak with vring_new_virtqueue()
commit f13f09a12cbd0c7b776e083c5d008b6c6a9c4e0b upstream.
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 cbeedb72b97a ("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: cbeedb72b97a ("virtio_ring: allocate desc state for split ring separately")
Signed-off-by: Suman Anna <>
Signed-off-by: Michael S. Tsirkin <>
Acked-by: Jason Wang <>
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 4ff48b8e5924..f1ce14ba186d 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -2199,10 +2199,10 @@ void vring_del_virtqueue(struct virtqueue *_vq)
- kfree(vq->split.desc_state);
+ if (!vq->packed_ring)
+ kfree(vq->split.desc_state);