* [PATCH -next] virtio: fix possible memory leak in virtqueue_add()
@ 2016-08-02 13:59 Wei Yongjun
2016-08-02 14:04 ` Michael S. Tsirkin
2016-08-02 14:16 ` [PATCH -next v2] " Wei Yongjun
0 siblings, 2 replies; 4+ messages in thread
From: Wei Yongjun @ 2016-08-02 13:59 UTC (permalink / raw)
To: Michael S . Tsirkin; +Cc: Wei Yongjun, linux-kernel, virtualization
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 <weiyj.lk@gmail.com>
---
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;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next] virtio: fix possible memory leak in virtqueue_add()
2016-08-02 13:59 [PATCH -next] virtio: fix possible memory leak in virtqueue_add() Wei Yongjun
@ 2016-08-02 14:04 ` Michael S. Tsirkin
2016-08-02 14:16 ` [PATCH -next v2] " Wei Yongjun
1 sibling, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2016-08-02 14:04 UTC (permalink / raw)
To: Wei Yongjun; +Cc: linux-kernel, virtualization
On Tue, Aug 02, 2016 at 01:59:05PM +0000, Wei Yongjun wrote:
> 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 <weiyj.lk@gmail.com>
> ---
> 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;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH -next v2] virtio: fix possible memory leak in virtqueue_add()
2016-08-02 13:59 [PATCH -next] virtio: fix possible memory leak in virtqueue_add() Wei Yongjun
2016-08-02 14:04 ` Michael S. Tsirkin
@ 2016-08-02 14:16 ` Wei Yongjun
2016-08-03 4:22 ` Michael S. Tsirkin
1 sibling, 1 reply; 4+ messages in thread
From: Wei Yongjun @ 2016-08-02 14:16 UTC (permalink / raw)
To: Michael S . Tsirkin; +Cc: Wei Yongjun, linux-kernel, virtualization
'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 <weiyj.lk@gmail.com>
---
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;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next v2] virtio: fix possible memory leak in virtqueue_add()
2016-08-02 14:16 ` [PATCH -next v2] " Wei Yongjun
@ 2016-08-03 4:22 ` Michael S. Tsirkin
0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2016-08-03 4:22 UTC (permalink / raw)
To: Wei Yongjun; +Cc: linux-kernel, virtualization
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 <weiyj.lk@gmail.com>
Appliecd except I moved this to before END_USE - seems
cleaner as alloc is caller after START_USE.
> ---
> 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;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-08-03 4:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-02 13:59 [PATCH -next] virtio: fix possible memory leak in virtqueue_add() Wei Yongjun
2016-08-02 14:04 ` Michael S. Tsirkin
2016-08-02 14:16 ` [PATCH -next v2] " Wei Yongjun
2016-08-03 4:22 ` Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).