[PATCH -next] virtio: fix possible memory leak in virtqueue_add()

Subsystems: the rest, virtio core

STALE3666d

4 messages, 2 authors, 2016-08-03 · open the first message on its own page

[PATCH -next] virtio: fix possible memory leak in virtqueue_add()

From: Wei Yongjun <hidden>
Date: 2016-08-02 13:59:20

desc may malloced in virtqueue_add() and should be freed before
leaving from the error handling cases, otherwise it will cause
memory leak.

Signed-off-by: Wei Yongjun <redacted>
---
 drivers/virtio/virtio_ring.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 114a0c8..bda71ef 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -328,6 +328,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 		if (out_sgs)
 			vq->notify(&vq->vq);
 		END_USE(vq);
+		kfree(desc);
 		return -ENOSPC;
 	}

Re: [PATCH -next] virtio: fix possible memory leak in virtqueue_add()

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2016-08-02 14:05:07

On Tue, Aug 02, 2016 at 01:59:05PM +0000, Wei Yongjun wrote:
quoted hunk
desc may malloced in virtqueue_add() and should be freed before
leaving from the error handling cases, otherwise it will cause
memory leak.

Signed-off-by: Wei Yongjun <redacted>
---
 drivers/virtio/virtio_ring.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 114a0c8..bda71ef 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -328,6 +328,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 		if (out_sgs)
 			vq->notify(&vq->vq);
 		END_USE(vq);
+		kfree(desc);
I think only if indirect is true, otherwise you will free
vq->vring.desc.
 		return -ENOSPC;
 	}

[PATCH -next v2] virtio: fix possible memory leak in virtqueue_add()

From: Wei Yongjun <hidden>
Date: 2016-08-02 14:17:06

'desc' is malloced in virtqueue_add() and should be freed before
leaving from the error handling cases, otherwise it will cause
memory leak.

Signed-off-by: Wei Yongjun <redacted>
---
 drivers/virtio/virtio_ring.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 114a0c8..e4be912 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -328,6 +328,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 		if (out_sgs)
 			vq->notify(&vq->vq);
 		END_USE(vq);
+		if (indirect)
+			kfree(desc);
 		return -ENOSPC;
 	}

Re: [PATCH -next v2] virtio: fix possible memory leak in virtqueue_add()

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2016-08-03 04:22:15

On Tue, Aug 02, 2016 at 02:16:31PM +0000, Wei Yongjun wrote:
'desc' is malloced in virtqueue_add() and should be freed before
leaving from the error handling cases, otherwise it will cause
memory leak.

Signed-off-by: Wei Yongjun <redacted>
Appliecd except I moved this to before END_USE - seems
cleaner as alloc is caller after START_USE.
quoted hunk
---
 drivers/virtio/virtio_ring.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 114a0c8..e4be912 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -328,6 +328,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 		if (out_sgs)
 			vq->notify(&vq->vq);
 		END_USE(vq);
+		if (indirect)
+			kfree(desc);
 		return -ENOSPC;
 	}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help