qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_xattrcreate
@ 2016-10-10 10:41 Li Qiang
  2016-10-10 11:20 ` Greg Kurz
  0 siblings, 1 reply; 5+ messages in thread
From: Li Qiang @ 2016-10-10 10:41 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: Li Qiang

From: Li Qiang <liqiang6-s@360.cn>

The 'fs.xattr.value' field in V9fsFidState object doesn't consider the
situation that this field has been allocated previously. Every time, it
will be allocated directly. This leads a host memory leak issue. This
patch fix this.

Signed-off-by: Li Qiang <liqiang6-s@360.cn>
---
 hw/9pfs/9p.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 8751c19..e4040dc 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3282,6 +3282,7 @@ static void v9fs_xattrcreate(void *opaque)
     xattr_fidp->fs.xattr.flags = flags;
     v9fs_string_init(&xattr_fidp->fs.xattr.name);
     v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
+    g_free(xattr_fidp->fs.xattr.value);
     xattr_fidp->fs.xattr.value = g_malloc0(size);
     err = offset;
     put_fid(pdu, file_fidp);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_xattrcreate
  2016-10-10 10:41 [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_xattrcreate Li Qiang
@ 2016-10-10 11:20 ` Greg Kurz
  2016-10-10 11:28   ` Greg Kurz
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kurz @ 2016-10-10 11:20 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, Li Qiang

On Mon, 10 Oct 2016 03:41:38 -0700
Li Qiang <liq3ea@gmail.com> wrote:

> From: Li Qiang <liqiang6-s@360.cn>
> 
> The 'fs.xattr.value' field in V9fsFidState object doesn't consider the
> situation that this field has been allocated previously. Every time, it
> will be allocated directly. This leads a host memory leak issue. This
> patch fix this.
> 
> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> ---

I'll add to the changelog that this may happen if the client sends a
Txattrcreate message with the same fid number before the fid was
clunked.

Reviewed-by: Greg Kurz <groug@kaod.org>

>  hw/9pfs/9p.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 8751c19..e4040dc 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -3282,6 +3282,7 @@ static void v9fs_xattrcreate(void *opaque)
>      xattr_fidp->fs.xattr.flags = flags;
>      v9fs_string_init(&xattr_fidp->fs.xattr.name);
>      v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
> +    g_free(xattr_fidp->fs.xattr.value);
>      xattr_fidp->fs.xattr.value = g_malloc0(size);
>      err = offset;
>      put_fid(pdu, file_fidp);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_xattrcreate
  2016-10-10 11:20 ` Greg Kurz
@ 2016-10-10 11:28   ` Greg Kurz
  2016-10-10 11:54     ` Li Qiang
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kurz @ 2016-10-10 11:28 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, Li Qiang

On Mon, 10 Oct 2016 13:20:51 +0200
Greg Kurz <groug@kaod.org> wrote:

> On Mon, 10 Oct 2016 03:41:38 -0700
> Li Qiang <liq3ea@gmail.com> wrote:
> 
> > From: Li Qiang <liqiang6-s@360.cn>
> > 
> > The 'fs.xattr.value' field in V9fsFidState object doesn't consider the
> > situation that this field has been allocated previously. Every time, it
> > will be allocated directly. This leads a host memory leak issue. This
> > patch fix this.
> > 
> > Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> > ---  
> 
> I'll add to the changelog that this may happen if the client sends a
> Txattrcreate message with the same fid number before the fid was
> clunked.
> 
> Reviewed-by: Greg Kurz <groug@kaod.org>
> 

Oops I may have answered to fast... what about xattr_fidp->fs.xattr.name ?
It looks like it is leaked the same way...

> >  hw/9pfs/9p.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > index 8751c19..e4040dc 100644
> > --- a/hw/9pfs/9p.c
> > +++ b/hw/9pfs/9p.c
> > @@ -3282,6 +3282,7 @@ static void v9fs_xattrcreate(void *opaque)
> >      xattr_fidp->fs.xattr.flags = flags;
> >      v9fs_string_init(&xattr_fidp->fs.xattr.name);
> >      v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
> > +    g_free(xattr_fidp->fs.xattr.value);
> >      xattr_fidp->fs.xattr.value = g_malloc0(size);
> >      err = offset;
> >      put_fid(pdu, file_fidp);  
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_xattrcreate
  2016-10-10 11:28   ` Greg Kurz
@ 2016-10-10 11:54     ` Li Qiang
  2016-10-10 12:08       ` Greg Kurz
  0 siblings, 1 reply; 5+ messages in thread
From: Li Qiang @ 2016-10-10 11:54 UTC (permalink / raw)
  To: Greg Kurz; +Cc: qemu-devel, Li Qiang

I think the 'xattr_fidp->fs.xattr.name' will not leak as the
'v9fs_string_copy' will first free the fs.xattr.name.

Thanks.

2016-10-10 19:28 GMT+08:00 Greg Kurz <groug@kaod.org>:

> On Mon, 10 Oct 2016 13:20:51 +0200
> Greg Kurz <groug@kaod.org> wrote:
>
> > On Mon, 10 Oct 2016 03:41:38 -0700
> > Li Qiang <liq3ea@gmail.com> wrote:
> >
> > > From: Li Qiang <liqiang6-s@360.cn>
> > >
> > > The 'fs.xattr.value' field in V9fsFidState object doesn't consider the
> > > situation that this field has been allocated previously. Every time, it
> > > will be allocated directly. This leads a host memory leak issue. This
> > > patch fix this.
> > >
> > > Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> > > ---
> >
> > I'll add to the changelog that this may happen if the client sends a
> > Txattrcreate message with the same fid number before the fid was
> > clunked.
> >
> > Reviewed-by: Greg Kurz <groug@kaod.org>
> >
>
> Oops I may have answered to fast... what about xattr_fidp->fs.xattr.name ?
> It looks like it is leaked the same way...
>
> > >  hw/9pfs/9p.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > > index 8751c19..e4040dc 100644
> > > --- a/hw/9pfs/9p.c
> > > +++ b/hw/9pfs/9p.c
> > > @@ -3282,6 +3282,7 @@ static void v9fs_xattrcreate(void *opaque)
> > >      xattr_fidp->fs.xattr.flags = flags;
> > >      v9fs_string_init(&xattr_fidp->fs.xattr.name);
> > >      v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
> > > +    g_free(xattr_fidp->fs.xattr.value);
> > >      xattr_fidp->fs.xattr.value = g_malloc0(size);
> > >      err = offset;
> > >      put_fid(pdu, file_fidp);
> >
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_xattrcreate
  2016-10-10 11:54     ` Li Qiang
@ 2016-10-10 12:08       ` Greg Kurz
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2016-10-10 12:08 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, Li Qiang

On Mon, 10 Oct 2016 19:54:01 +0800
Li Qiang <liq3ea@gmail.com> wrote:

> I think the 'xattr_fidp->fs.xattr.name' will not leak as the
> 'v9fs_string_copy' will first free the fs.xattr.name.
> 

Indeed!

> Thanks.
> 

Cheers.

--
Greg

> 2016-10-10 19:28 GMT+08:00 Greg Kurz <groug@kaod.org>:
> 
> > On Mon, 10 Oct 2016 13:20:51 +0200
> > Greg Kurz <groug@kaod.org> wrote:
> >
> > > On Mon, 10 Oct 2016 03:41:38 -0700
> > > Li Qiang <liq3ea@gmail.com> wrote:
> > >
> > > > From: Li Qiang <liqiang6-s@360.cn>
> > > >
> > > > The 'fs.xattr.value' field in V9fsFidState object doesn't consider the
> > > > situation that this field has been allocated previously. Every time, it
> > > > will be allocated directly. This leads a host memory leak issue. This
> > > > patch fix this.
> > > >
> > > > Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> > > > ---
> > >
> > > I'll add to the changelog that this may happen if the client sends a
> > > Txattrcreate message with the same fid number before the fid was
> > > clunked.
> > >
> > > Reviewed-by: Greg Kurz <groug@kaod.org>
> > >
> >
> > Oops I may have answered to fast... what about xattr_fidp->fs.xattr.name ?
> > It looks like it is leaked the same way...
> >
> > > >  hw/9pfs/9p.c | 1 +
> > > >  1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > > > index 8751c19..e4040dc 100644
> > > > --- a/hw/9pfs/9p.c
> > > > +++ b/hw/9pfs/9p.c
> > > > @@ -3282,6 +3282,7 @@ static void v9fs_xattrcreate(void *opaque)
> > > >      xattr_fidp->fs.xattr.flags = flags;
> > > >      v9fs_string_init(&xattr_fidp->fs.xattr.name);
> > > >      v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
> > > > +    g_free(xattr_fidp->fs.xattr.value);
> > > >      xattr_fidp->fs.xattr.value = g_malloc0(size);
> > > >      err = offset;
> > > >      put_fid(pdu, file_fidp);
> > >
> >
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-10-10 12:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-10 10:41 [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_xattrcreate Li Qiang
2016-10-10 11:20 ` Greg Kurz
2016-10-10 11:28   ` Greg Kurz
2016-10-10 11:54     ` Li Qiang
2016-10-10 12:08       ` Greg Kurz

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).