Skip to contentSkip to conversation

libxc: fix leak of t_info in xc_tbuf_get_size()

PATCH Superseded Harmandeep Kaur 3 participants 6 messages Feb 11, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libxc: fix leak of t_info in xc_tbuf_get_size()

Avoid leaking the memory mapping of the trace buffer

Coverity ID 1351228

---
v2: call to unmapping function reduced to one from two

---
 tools/libxc/xc_tbuf.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/libxc/xc_tbuf.c +5 -3
index 695939a..d96cc67 100644
@@ -70,11 +70,13 @@ int xc_tbuf_get_size(xc_interface *xch, unsigned long *size)
                     sysctl.u.tbuf_op.buffer_mfn);
 
     if ( t_info == NULL || t_info->tbuf_size == 0 )
-        return -1;
+        rc = -1;
+    else
+	*size = t_info->tbuf_size;
 
-    *size = t_info->tbuf_size;
+    xenforeignmemory_unmap(xch->fmem, t_info, *size);
 
-    return 0;
+    return rc;
 }
 
 int xc_tbuf_enable(xc_interface *xch, unsigned long pages, unsigned long *mfn,
Signature · 1 line
2.5.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Harmandeep Kaur

Avoid leaking the memory mapping of the trace buffer

Coverity ID 1351228

Thanks and Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Harmandeep Kaur

Copying George since he maintains xentrace which this relates to.

Quoted 24 lines · Harmandeep Kaur

Avoid leaking the memory mapping of the trace buffer

Coverity ID 1351228

---
v2: call to unmapping function reduced to one from two
---
 tools/libxc/xc_tbuf.c | 8 +++++---

 1 file changed, 5 insertions(+), 3 deletions(-)
tools/libxc/xc_tbuf.c +0 -0
index 695939a..d96cc67 100644
@@ -70,11 +70,13 @@ int xc_tbuf_get_size(xc_interface *xch, unsigned long
 *size)
                      sysctl.u.tbuf_op.buffer_mfn);


     if ( t_info == NULL || t_info->tbuf_size == 0 ) -        return -1;
+        rc = -1;
+    else

tools/libxc/xc_tbuf.c +1 -0
+	*size = t_info->tbuf_size;
Quoted 3 lines


-    *size = t_info->tbuf_size;
+    xenforeignmemory_unmap(xch->fmem, t_info, *size);

*size could be uninitialised here (in the error path) and even in the success case I don't think t_info->tbus_size is the right argument here, it needs to be the size which was passed to the map function, i.e. sysctl.u.tbuf_op.size.

Ian.

Quoted 7 lines


-    return 0;
+    return rc;
 }

 int xc_tbuf_enable(xc_interface *xch, unsigned long pages, unsigned long *mfn,

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 17 lines · Ian Campbell
Quoted 16 lines · Harmandeep Kaur

tools/libxc/xc_tbuf.c +0 -0
index 695939a..d96cc67 100644
@@ -70,11 +70,13 @@ int xc_tbuf_get_size(xc_interface *xch,

unsigned long
*size)
                     sysctl.u.tbuf_op.buffer_mfn);
     if ( t_info == NULL || t_info->tbuf_size == 0 ) -        return -1;
+        rc = -1;
+    else

tools/libxc/xc_tbuf.c +1 -0
+	*size = t_info->tbuf_size;

Quoted 9 lines
Quoted 2 lines

-    *size = t_info->tbuf_size;
+    xenforeignmemory_unmap(xch->fmem, t_info, *size);

*size could be uninitialised here (in the error path) and even in the success case I don't think t_info->tbus_size is the right argument here, it
needs to be the size which was passed to the map function, i.e. sysctl.u.tbuf_op.size.

And I think both are issues with the current code, and, more important, not what Coverity is complaining about in the referenced CID?

To be clear, I'm not arguing that they're not issues we should fix (I don't know about the tbuf_size vs. tbuf_op.size, but I can check). I'm genuinely asking whether we should do that here, as compared to in a pre or follow up patch, and let this one be the one that placates Coverity on that particular issue.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw
Quoted 27 lines · Dario Faggioli
Quoted 17 lines · Ian Campbell
Quoted 16 lines · Harmandeep Kaur

tools/libxc/xc_tbuf.c +0 -0
index 695939a..d96cc67 100644
@@ -70,11 +70,13 @@ int xc_tbuf_get_size(xc_interface *xch,

unsigned long
*size)
                     sysctl.u.tbuf_op.buffer_mfn);
     if ( t_info == NULL || t_info->tbuf_size == 0 ) -        return -1;
+        rc = -1;
+    else

tools/libxc/xc_tbuf.c +1 -0
+	*size = t_info->tbuf_size;

Quoted 9 lines
Quoted 2 lines

-    *size = t_info->tbuf_size;
+    xenforeignmemory_unmap(xch->fmem, t_info, *size);

*size could be uninitialised here (in the error path) and even in the success case I don't think t_info->tbus_size is the right argument here, it
needs to be the size which was passed to the map function, i.e. sysctl.u.tbuf_op.size.

Quoted 1 line

And I think both are issues with the current code,

I don't think so, the xenforeignmemory_unmap using *size as an argument (where it is either uninitialised or the wrong value) is added by this patch.

Quoted 8 lines

and, more important,
not what Coverity is complaining about in the referenced CID?

To be clear, I'm not arguing that they're not issues we should fix (I don't know about the tbuf_size vs. tbuf_op.size, but I can check). I'm genuinely asking whether we should do that here, as compared to in a pre or follow up patch, and let this one be the one that placates Coverity on that particular issue.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
Quoted 30 lines · Ian Campbell
Quoted 29 lines · Dario Faggioli
Quoted 28 lines · Ian Campbell
Quoted 15 lines · Harmandeep Kaur

tools/libxc/xc_tbuf.c +0 -0
index 695939a..d96cc67 100644
@@ -70,11 +70,13 @@ int xc_tbuf_get_size(xc_interface *xch,

unsigned long
*size)
                     sysctl.u.tbuf_op.buffer_mfn);
     if ( t_info == NULL || t_info->tbuf_size == 0 ) -        return -1;
+        rc = -1;
+    else

tools/libxc/xc_tbuf.c +1 -0
+	*size = t_info->tbuf_size;
Quoted 3 lines


-    *size = t_info->tbuf_size;
+    xenforeignmemory_unmap(xch->fmem, t_info, *size);

*size could be uninitialised here (in the error path) and even in the
success case I don't think t_info->tbus_size is the right argument
here, it
needs to be the size which was passed to the map function, i.e. sysctl.u.tbuf_op.size.

Quoted 8 lines
Quoted 1 line

And I think both are issues with the current code,

I don't think so, the xenforeignmemory_unmap using *size as an argument
(where it is either uninitialised or the wrong value) is added by this
patch.

Ah, that one! Yes, you're right, I had overlooked this, and thought you where referring to something else, sorry. I agree sysctl.u.tbuf_op.size is what should be used.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel