Skip to contentSkip to conversation

tools: Fixes for 4.4

PATCH Applied Ian Jackson 3 participants 6 messages Jan 21, 2014 – Jan 28, 2014

lore
Share & tools
lore
#0 lore raw

v2 cover tools: Fixes for 4.4

I think these three bugfixes are clear 4.4 material.

a 1/3 libxl: events: Pass correct nfds to poll
a 2/3 xl: Free optdata_begin when saving domain config a 3/3 xenstore: xs_suspend_evtchn_port: always free portstr

They have all been acked by Ian Campbell.

Thanks,
Ian.

#1 lore raw

PATCH v2 1/3 libxl: events: Pass correct nfds to poll

libxl_event.c:eventloop_iteration would pass the allocated pollfds array size, rather than the used size, to poll (and to afterpoll_internal).

The effect is that if the number of fds to poll on reduces, libxl will poll on stale entries. Because of the way the return value from poll is processed these stale entries are often harmless because any events coming back from poll ignored by libxl. However, it could cause malfunctions:

It could result in unwanted SIGTTIN/SIGTTOU/SIGPIPE, for example, if the fd has been reused to refer to an object which can generate those signals. Alternatively, it could result in libxl spinning if the stale entry refers to an fd which happens now to be ready for the previously-requested operation.

I have tested this with a localhost migration and inspected the strace output.

---
 tools/libxl/libxl_event.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
tools/libxl/libxl_event.c +4 -5
index bdef7ac..1c48fee 100644
@@ -1386,7 +1386,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) {
      * can unlock it when it polls.
      */
     EGC_GC;
-    int rc;
+    int rc, nfds;
     struct timeval now;
     
     rc = libxl__gettimeofday(gc, &now);
@@ -1395,7 +1395,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) {
     int timeout;
 
     for (;;) {
-        int nfds = poller->fd_polls_allocd;
+        nfds = poller->fd_polls_allocd;
         timeout = -1;
         rc = beforepoll_internal(gc, poller, &nfds, poller->fd_polls,
                                  &timeout, now);
@@ -1413,7 +1413,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) {
     }
 
     CTX_UNLOCK;
-    rc = poll(poller->fd_polls, poller->fd_polls_allocd, timeout);
+    rc = poll(poller->fd_polls, nfds, timeout);
     CTX_LOCK;
 
     if (rc < 0) {
@@ -1428,8 +1428,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) {
     rc = libxl__gettimeofday(gc, &now);
     if (rc) goto out;
 
-    afterpoll_internal(egc, poller,
-                       poller->fd_polls_allocd, poller->fd_polls, now);
+    afterpoll_internal(egc, poller, nfds, poller->fd_polls, now);
 
     rc = 0;
  out:
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v2 2/3 xl: Free optdata_begin when saving domain config

In reply to Ian Jackson

This makes valgrind a bit happier.

It is also
Coverity-CID: 1055903

---
 tools/libxl/xl_cmdimpl.c |    2 ++
 1 file changed, 2 insertions(+)
tools/libxl/xl_cmdimpl.c +2 -0
index d93e01b..aff6f90 100644
@@ -3442,6 +3442,8 @@ static void save_domain_core_writeconfig(int fd, const char *source,
                      ctx, fd, optdata_begin, hdr.optional_data_len,
                      source, "header"));
 
+    free(optdata_begin);
+
     fprintf(stderr, "Saving to %s new xl format (info"
             " 0x%"PRIx32"/0x%"PRIx32"/%"PRIu32")\n",
             source, hdr.mandatory_flags, hdr.optional_flags,
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v2 3/3 xenstore: xs_suspend_evtchn_port: always free portstr

In reply to Ian Jackson

If portstr!=NULL but plen==0 this function would leak portstr.

---
v2: Fix whitespace error.

---
 tools/xenstore/xs.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tools/xenstore/xs.c +6 -3
index a636498..dd03a85 100644
@@ -1095,12 +1095,15 @@ int xs_suspend_evtchn_port(int domid)
     portstr = xs_read(xs, XBT_NULL, path, &plen);
     xs_daemon_close(xs);
 
-    if (!portstr || !plen)
-        return -1;
+    if (!portstr || !plen) {
+        port = -1;
+        goto out;
+    }
 
     port = atoi(portstr);
-    free(portstr);
 
+out:
+    free(portstr);
     return port;
 }
 
Signature · 1 line
1.7.10.4
#4 lore raw
In reply to Ian Jackson
Quoted 7 lines · Ian Jackson

I think these three bugfixes are clear 4.4 material.

a 1/3 libxl: events: Pass correct nfds to poll
a 2/3 xl: Free optdata_begin when saving domain config a 3/3 xenstore: xs_suspend_evtchn_port: always free portstr

They have all been acked by Ian Campbell.

All three:

Applied
#5 lore raw
Quoted 7 lines · George Dunlap
Quoted 6 lines · Ian Jackson

I think these three bugfixes are clear 4.4 material.

a 1/3 libxl: events: Pass correct nfds to poll
a 2/3 xl: Free optdata_begin when saving domain config a 3/3 xenstore: xs_suspend_evtchn_port: always free portstr

Quoted 5 lines
Quoted 1 line

They have all been acked by Ian Campbell.

All three:

Applied.