Skip to contentSkip to conversation

9pfs: fix memory leak in v9fs_xattrcreate

PATCH In review Li Qiang 2 participants 5 messages Oct 10, 2016

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 9pfs: fix memory leak in v9fs_xattrcreate

From: Li Qiang <[email protected]>

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.

---
 hw/9pfs/9p.c | 1 +
 1 file changed, 1 insertion(+)
hw/9pfs/9p.c +1 -0
index 8751c19..e4040dc 100644
@@ -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);
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Mon, 10 Oct 2016 03:41:38 -0700 Li Qiang <[email protected]> wrote:

From: Li Qiang <[email protected]>

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.

---

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.

Quoted 15 lines
 hw/9pfs/9p.c | 1 +
 1 file changed, 1 insertion(+)
hw/9pfs/9p.c +1 -0
index 8751c19..e4040dc 100644
@@ -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);
#2 lore raw
Quoted 10 lines · On Mon, 10 Oct 2016 13:20:51 +0200 Greg Kurz <[email protected]> wrote:
Quoted 7 lines · On Mon, 10 Oct 2016 03:41:38 -0700 Li Qiang <[email protected]> wrote:

From: Li Qiang <[email protected]>

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.

Quoted 9 lines
Quoted 2 lines

---

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.

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

Quoted 16 lines
Quoted 15 lines
 hw/9pfs/9p.c | 1 +
 1 file changed, 1 insertion(+)
hw/9pfs/9p.c +1 -0
index 8751c19..e4040dc 100644
@@ -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);  
author
#3 lore raw

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 <[email protected]>:

Quoted 44 lines
Quoted 10 lines · On Mon, 10 Oct 2016 13:20:51 +0200 Greg Kurz <[email protected]> wrote:
Quoted 7 lines · On Mon, 10 Oct 2016 03:41:38 -0700 Li Qiang <[email protected]> wrote:

From: Li Qiang <[email protected]>

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.

Quoted 9 lines
Quoted 2 lines

---

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.

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

Quoted 16 lines
Quoted 15 lines
 hw/9pfs/9p.c | 1 +
 1 file changed, 1 insertion(+)
hw/9pfs/9p.c +1 -0
index 8751c19..e4040dc 100644
@@ -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);
#4 lore raw
Quoted 3 lines · On Mon, 10 Oct 2016 19:54:01 +0800 Li Qiang <[email protected]> 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!

Quoted 2 lines

Thanks.

Cheers.

--
Greg

Quoted 46 lines

2016-10-10 19:28 GMT+08:00 Greg Kurz <[email protected]>:

Quoted 44 lines
Quoted 10 lines · On Mon, 10 Oct 2016 13:20:51 +0200 Greg Kurz <[email protected]> wrote:
Quoted 7 lines · On Mon, 10 Oct 2016 03:41:38 -0700 Li Qiang <[email protected]> wrote:

From: Li Qiang <[email protected]>

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.

Quoted 9 lines
Quoted 2 lines

---

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.

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

Quoted 16 lines
Quoted 15 lines
 hw/9pfs/9p.c | 1 +
 1 file changed, 1 insertion(+)
hw/9pfs/9p.c +1 -0
index 8751c19..e4040dc 100644
@@ -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);