* [Qemu-devel] [PATCH] 9pfs: fix potential host memory leak in v9fs_read
@ 2016-09-27 11:58 Li Qiang
2016-09-27 15:41 ` Greg Kurz
2016-10-10 11:16 ` Greg Kurz
0 siblings, 2 replies; 5+ messages in thread
From: Li Qiang @ 2016-09-27 11:58 UTC (permalink / raw)
To: aneesh.kumar, groug, qemu-devel; +Cc: Li Qiang
From: Li Qiang <liqiang6-s@360.cn>
In 9pfs read dispatch function, it doesn't free two QEMUIOVector
object thus causing potential memory leak. This patch avoid this.
Signed-off-by: Li Qiang <liqiang6-s@360.cn>
---
hw/9pfs/9p.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 119ee58..543a791 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1826,14 +1826,15 @@ static void v9fs_read(void *opaque)
if (len < 0) {
/* IO error return the error */
err = len;
- goto out;
+ goto out_free_iovec;
}
} while (count < max_count && len > 0);
err = pdu_marshal(pdu, offset, "d", count);
if (err < 0) {
- goto out;
+ goto out_free_iovec;
}
err += offset + count;
+out_free_iovec:
qemu_iovec_destroy(&qiov);
qemu_iovec_destroy(&qiov_full);
} else if (fidp->fid_type == P9_FID_XATTR) {
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] 9pfs: fix potential host memory leak in v9fs_read
2016-09-27 11:58 [Qemu-devel] [PATCH] 9pfs: fix potential host memory leak in v9fs_read Li Qiang
@ 2016-09-27 15:41 ` Greg Kurz
2016-10-10 11:16 ` Greg Kurz
1 sibling, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2016-09-27 15:41 UTC (permalink / raw)
To: Li Qiang; +Cc: aneesh.kumar, qemu-devel, Li Qiang
On Tue, 27 Sep 2016 04:58:46 -0700
Li Qiang <liq3ea@gmail.com> wrote:
> From: Li Qiang <liqiang6-s@360.cn>
>
> In 9pfs read dispatch function, it doesn't free two QEMUIOVector
> object thus causing potential memory leak. This patch avoid this.
>
> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> ---
When you post an updated version of a patch, you should:
- add a version in the subject
[PATCH v2] 9pfs: fix potential host memory leak in v9fs_read
- list the changes since the previous version under the --- after
your Signed-off-by
Anyway, the change is ok, I'll push this to my tree.
Thanks.
--
Greg
> hw/9pfs/9p.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 119ee58..543a791 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -1826,14 +1826,15 @@ static void v9fs_read(void *opaque)
> if (len < 0) {
> /* IO error return the error */
> err = len;
> - goto out;
> + goto out_free_iovec;
> }
> } while (count < max_count && len > 0);
> err = pdu_marshal(pdu, offset, "d", count);
> if (err < 0) {
> - goto out;
> + goto out_free_iovec;
> }
> err += offset + count;
> +out_free_iovec:
> qemu_iovec_destroy(&qiov);
> qemu_iovec_destroy(&qiov_full);
> } else if (fidp->fid_type == P9_FID_XATTR) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] 9pfs: fix potential host memory leak in v9fs_read
2016-09-27 11:58 [Qemu-devel] [PATCH] 9pfs: fix potential host memory leak in v9fs_read Li Qiang
2016-09-27 15:41 ` Greg Kurz
@ 2016-10-10 11:16 ` Greg Kurz
1 sibling, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2016-10-10 11:16 UTC (permalink / raw)
To: Li Qiang; +Cc: aneesh.kumar, qemu-devel, Li Qiang
On Tue, 27 Sep 2016 04:58:46 -0700
Li Qiang <liq3ea@gmail.com> wrote:
> From: Li Qiang <liqiang6-s@360.cn>
>
> In 9pfs read dispatch function, it doesn't free two QEMUIOVector
> object thus causing potential memory leak. This patch avoid this.
>
> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> ---
Reviewed-by: Greg Kurz <groug@kaod.org>
> hw/9pfs/9p.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 119ee58..543a791 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -1826,14 +1826,15 @@ static void v9fs_read(void *opaque)
> if (len < 0) {
> /* IO error return the error */
> err = len;
> - goto out;
> + goto out_free_iovec;
> }
> } while (count < max_count && len > 0);
> err = pdu_marshal(pdu, offset, "d", count);
> if (err < 0) {
> - goto out;
> + goto out_free_iovec;
> }
> err += offset + count;
> +out_free_iovec:
> qemu_iovec_destroy(&qiov);
> qemu_iovec_destroy(&qiov_full);
> } else if (fidp->fid_type == P9_FID_XATTR) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] 9pfs: fix potential host memory leak in v9fs_read
2016-09-27 4:42 Li Qiang
@ 2016-09-27 8:14 ` Greg Kurz
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2016-09-27 8:14 UTC (permalink / raw)
To: Li Qiang; +Cc: aneesh.kumar, qemu-devel, Li Qiang
On Mon, 26 Sep 2016 21:42:26 -0700
Li Qiang <liq3ea@gmail.com> wrote:
> From: Li Qiang <liqiang6-s@360.cn>
>
> In 9pfs read dispatch function, it doesn't free two QEMUIOVector
> object thus causing potential memory leak. This patch avoid this.
>
Good catch for the leak, but I'd prefer another fix. See below.
> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> ---
> hw/9pfs/9p.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index d960a2e..b1ff8e7 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -1830,12 +1830,16 @@ static void v9fs_read(void *opaque)
> } while (len == -EINTR && !pdu->cancelled);
> if (len < 0) {
> /* IO error return the error */
> + qemu_iovec_destroy(&qiov);
> + qemu_iovec_destroy(&qiov_full);
We already have these lines at the end of the code block for
type P9_FID_FILE.
Let's introduce an out_free_iovec: label and...
> err = len;
> goto out;
goto out_free_iovec;
> }
> } while (count < max_count && len > 0);
> err = pdu_marshal(pdu, offset, "d", count);
> if (err < 0) {
> + qemu_iovec_destroy(&qiov);
> + qemu_iovec_destroy(&qiov_full);
> goto out;
Same here.
> }
> err += offset + count;
As a valuable side effect, the error will be traced :)
Cheers.
--
Greg
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH] 9pfs: fix potential host memory leak in v9fs_read
@ 2016-09-27 4:42 Li Qiang
2016-09-27 8:14 ` Greg Kurz
0 siblings, 1 reply; 5+ messages in thread
From: Li Qiang @ 2016-09-27 4:42 UTC (permalink / raw)
To: aneesh.kumar, groug, qemu-devel; +Cc: Li Qiang
From: Li Qiang <liqiang6-s@360.cn>
In 9pfs read dispatch function, it doesn't free two QEMUIOVector
object thus causing potential memory leak. This patch avoid this.
Signed-off-by: Li Qiang <liqiang6-s@360.cn>
---
hw/9pfs/9p.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index d960a2e..b1ff8e7 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1830,12 +1830,16 @@ static void v9fs_read(void *opaque)
} while (len == -EINTR && !pdu->cancelled);
if (len < 0) {
/* IO error return the error */
+ qemu_iovec_destroy(&qiov);
+ qemu_iovec_destroy(&qiov_full);
err = len;
goto out;
}
} while (count < max_count && len > 0);
err = pdu_marshal(pdu, offset, "d", count);
if (err < 0) {
+ qemu_iovec_destroy(&qiov);
+ qemu_iovec_destroy(&qiov_full);
goto out;
}
err += offset + count;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-10-10 11:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-27 11:58 [Qemu-devel] [PATCH] 9pfs: fix potential host memory leak in v9fs_read Li Qiang
2016-09-27 15:41 ` Greg Kurz
2016-10-10 11:16 ` Greg Kurz
-- strict thread matches above, loose matches on Subject: below --
2016-09-27 4:42 Li Qiang
2016-09-27 8:14 ` Greg Kurz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.