]> git.baikalelectronics.ru Git - kernel.git/commit
virtio_ring: Fix mem leak with vring_new_virtqueue()
authorSuman Anna <s-anna@ti.com>
Mon, 24 Feb 2020 21:26:43 +0000 (15:26 -0600)
committerMichael S. Tsirkin <mst@redhat.com>
Sun, 8 Mar 2020 09:35:23 +0000 (05:35 -0400)
commitdaa561ab3031e62b57e0aa1bd2cea8589b79699b
treed5d6a5dc5f4df13d7a1bdae3a79176f6d772fae3
parentfa91a3b5a2e53a995f641241b83c1d4bd4799307
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 79e407a3ffa8 ("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: 79e407a3ffa8 ("virtio_ring: allocate desc state for split ring separately")
Signed-off-by: Suman Anna <s-anna@ti.com>
Link: https://lore.kernel.org/r/20200224212643.30672-1-s-anna@ti.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
drivers/virtio/virtio_ring.c