Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1454479 > unrolled thread

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

Started byWei Yongjun <weiyj.lk@gmail.com>
First post2016-08-02 16:10 +0200
Last post2016-08-03 06:30 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH -next] virtio: fix possible memory leak in virtqueue_add() Wei Yongjun <weiyj.lk@gmail.com> - 2016-08-02 16:10 +0200
    Re: [PATCH -next] virtio: fix possible memory leak in virtqueue_add() "Michael S. Tsirkin" <mst@redhat.com> - 2016-08-02 16:10 +0200
    [PATCH -next v2] virtio: fix possible memory leak in virtqueue_add() Wei Yongjun <weiyj.lk@gmail.com> - 2016-08-02 16:20 +0200
      Re: [PATCH -next v2] virtio: fix possible memory leak in  virtqueue_add() "Michael S. Tsirkin" <mst@redhat.com> - 2016-08-03 06:30 +0200

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

FromWei Yongjun <weiyj.lk@gmail.com>
Date2016-08-02 16:10 +0200
Subject[PATCH -next] virtio: fix possible memory leak in virtqueue_add()
Message-ID<s1Iyl-5ut-5@gated-at.bofh.it>
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;
 	}

[toc] | [next] | [standalone]


#1454487

From"Michael S. Tsirkin" <mst@redhat.com>
Date2016-08-02 16:10 +0200
Message-ID<s1Iym-5ut-33@gated-at.bofh.it>
In reply to#1454479
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;
>  	}

[toc] | [prev] | [next] | [standalone]


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

FromWei Yongjun <weiyj.lk@gmail.com>
Date2016-08-02 16:20 +0200
Subject[PATCH -next v2] virtio: fix possible memory leak in virtqueue_add()
Message-ID<s1II3-5y4-61@gated-at.bofh.it>
In reply to#1454479
'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;
 	}

[toc] | [prev] | [next] | [standalone]


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

From"Michael S. Tsirkin" <mst@redhat.com>
Date2016-08-03 06:30 +0200
SubjectRe: [PATCH -next v2] virtio: fix possible memory leak in virtqueue_add()
Message-ID<s1VYB-5Um-1@gated-at.bofh.it>
In reply to#1454532
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;
>  	}

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web