Skip to contentSkip to conversation

libxc: fix segfault on uninitialized xch->fmem

PATCH Superseded Seraphime Kirkovski 2 participants 3 messages Apr 3, 2017 – Apr 4, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxc: fix segfault on uninitialized xch->fmem

Currently in xc_interface_open, xch->fmem is not initialized and in some rare case the code fails before ever assigning a value to it.

I got this in master:

   $ sudo ./xl/xl run
   xencall: error: Could not obtain handle on privileged command interface: No such file or directory
   Segmentation fault

This initializes xch->fmem to NULL

---
 tools/libxc/xc_private.c | 1 +
 1 file changed, 1 insertion(+)
tools/libxc/xc_private.c +1 -0
index 72e6242417..4ed46fde5f 100644
@@ -32,6 +32,7 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
 {
     struct xc_interface_core xch_buf, *xch = &xch_buf;
 
+    xch->fmem = NULL;
     xch->flags = open_flags;
     xch->dombuild_logger_file = 0;
     xc_clear_last_error(xch);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 22 lines · Seraphime Kirkovski

Currently in xc_interface_open, xch->fmem is not initialized and in some rare case the code fails before ever assigning a value to it.

I got this in master:

   $ sudo ./xl/xl run
   xencall: error: Could not obtain handle on privileged command interface: No such file or directory
   Segmentation fault

This initializes xch->fmem to NULL

---
 tools/libxc/xc_private.c | 1 +
 1 file changed, 1 insertion(+)
tools/libxc/xc_private.c +0 -0
index 72e6242417..4ed46fde5f 100644

tools/libxc/xc_private.c struct xc_interface_core *xc_interface_open(xentoollog_logger *logger, · line 35

Quoted 4 lines
tools/libxc/xc_private.c +1 -0
@@ -32,6 +32,7 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
 {
     struct xc_interface_core xch_buf, *xch = &xch_buf;
 
+    xch->fmem = NULL;

Since there are a few handles in xch, it would be better to initialise them all at once by doing:

    struct xc_interface_core xch_buf = { 0 }
Quoted 6 lines
tools/libxc/xc_private.c +0 -0
     xch->flags = open_flags;
     xch->dombuild_logger_file = 0;
     xc_clear_last_error(xch);
Signature · 1 line
2.11.0

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

#2 lore raw
Quoted 11 lines · Wei Liu

Since there are a few handles in xch, it would be better to initialise them all at once by doing:

    struct xc_interface_core xch_buf = { 0 }
Quoted 6 lines
     xch->flags = open_flags;
     xch->dombuild_logger_file = 0;
     xc_clear_last_error(xch);
Signature · 1 line
2.11.0

Hi, thanks for the reply.

Literally 10 minutes after sending this, I thought that a bzero would be better. Will send a V2 shortly.

(Sorry about the resend, mailer problems...)

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