Skip to contentSkip to conversation

Fixes for various minor Coverity issues

PATCH In review Matthew Daley 9 participants 25 messages Sep 10, 2013 – Sep 13, 2013

lore
Share & tools
lore
#0 lore raw

cover Fixes for various minor Coverity issues

These are fixes for various minor non-security-impacting issues discovered by Coverity. They have been build-tested, but not runtime-tested; they are hopefully all obvious fixes.

Matthew Daley (8):
x86: add missing va_end to hypercall_xlat_continuation sched/arinc653: check for guest data transfer failures
libxl: fix use-after-free in discard_events iteration
libxl: correctly handle readlink() errors
mini-os: fix use-after-free in xs_daemon_close event iteration
mini-os: handle possibly overlong _nodename in init_consfront
kdd: fix free of array-typed value
xenstored: fix possible, but unlikely, stack overflow

 extras/mini-os/console/xenbus.c  |    6 ++++--
 extras/mini-os/lib/xs.c          |    7 +++++--
 tools/debugger/kdd/kdd-xen.c     |    1 -
 tools/libxl/libxl.c              |    4 ++--
 tools/libxl/libxl_exec.c         |    2 +-
 tools/xenstore/xenstored_linux.c |    2 +-
 xen/arch/x86/domain.c            |    4 ++++
 xen/common/sched_arinc653.c      |   13 +++++++++++--
 8 files changed, 28 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/8 x86: add missing va_end to hypercall_xlat_continuation

Coverity-ID: 1056208

---
 xen/arch/x86/domain.c |    4 ++++
 1 file changed, 4 insertions(+)
xen/arch/x86/domain.c +4 -0
index f7b0308..316ef04 100644
@@ -1648,7 +1648,11 @@ int hypercall_xlat_continuation(unsigned int *id, unsigned int mask, ...)
     if ( test_bit(_MCSF_in_multicall, &mcs->flags) )
     {
         if ( !test_bit(_MCSF_call_preempted, &mcs->flags) )
+        {
+            va_end(args);
             return 0;
+        }
+
         for ( i = 0; i < 6; ++i, mask >>= 1 )
         {
             if ( mask & 1 )
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] x86: add missing va_end to hypercall_xlat_continuation

Quoted 2 lines · Matthew Daley

Coverity-ID: 1056208

Quoted 20 lines
---
 xen/arch/x86/domain.c |    4 ++++
 1 file changed, 4 insertions(+)
xen/arch/x86/domain.c +4 -0
index f7b0308..316ef04 100644
@@ -1648,7 +1648,11 @@ int hypercall_xlat_continuation(unsigned int *id, unsigned int mask, ...)
     if ( test_bit(_MCSF_in_multicall, &mcs->flags) )
     {
         if ( !test_bit(_MCSF_call_preempted, &mcs->flags) )
+        {
+            va_end(args);
             return 0;
+        }
+
         for ( i = 0; i < 6; ++i, mask >>= 1 )
         {
             if ( mask & 1 )
Acked-by on v1 1/8
#3 lore raw

Re: [PATCH 1/8] x86: add missing va_end to hypercall_xlat_continuation

In reply to Matthew Daley
Quoted 2 lines · Matthew Daley

Coverity-ID: 1056208

Quoted 21 lines
---
 xen/arch/x86/domain.c |    4 ++++
 1 file changed, 4 insertions(+)
xen/arch/x86/domain.c +4 -0
index f7b0308..316ef04 100644
@@ -1648,7 +1648,11 @@ int hypercall_xlat_continuation(unsigned int *id,
 unsigned int mask, ...)
     if ( test_bit(_MCSF_in_multicall, &mcs->flags) )
     {
         if ( !test_bit(_MCSF_call_preempted, &mcs->flags) )
+        {
+            va_end(args);
             return 0;
+        }
+
         for ( i = 0; i < 6; ++i, mask >>= 1 )
         {
             if ( mask & 1 )
#4 lore raw

PATCH 2/8 sched/arinc653: check for guest data transfer failures

In reply to Matthew Daley

Coverity-ID: 1055121
Coverity-ID: 1055122
Coverity-ID: 1055123
Coverity-ID: 1055124

---
 xen/common/sched_arinc653.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
xen/common/sched_arinc653.c +11 -2
index 63ddb82..2502192 100644
@@ -635,12 +635,21 @@ a653sched_adjust_global(const struct scheduler *ops,
     switch ( sc->cmd )
     {
     case XEN_SYSCTL_SCHEDOP_putinfo:
-        copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1);
+        if ( copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
         rc = arinc653_sched_set(ops, &local_sched);
         break;
     case XEN_SYSCTL_SCHEDOP_getinfo:
         rc = arinc653_sched_get(ops, &local_sched);
-        copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1);
+        if ( rc )
+            break;
+
+        if ( copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1) )
+            rc = -EFAULT;
         break;
     }
 
Signature · 1 line
1.7.10.4
Reviewed-by on v1 2/8
#5 lore raw

Re: [PATCH 2/8] sched/arinc653: check for guest data transfer failures

Quoted 5 lines · Matthew Daley

Coverity-ID: 1055121
Coverity-ID: 1055122
Coverity-ID: 1055123
Coverity-ID: 1055124

Quoted 32 lines
---
 xen/common/sched_arinc653.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
xen/common/sched_arinc653.c +11 -2
index 63ddb82..2502192 100644
@@ -635,12 +635,21 @@ a653sched_adjust_global(const struct scheduler *ops,
     switch ( sc->cmd )
     {
     case XEN_SYSCTL_SCHEDOP_putinfo:
-        copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1);
+        if ( copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
         rc = arinc653_sched_set(ops, &local_sched);
         break;
     case XEN_SYSCTL_SCHEDOP_getinfo:
         rc = arinc653_sched_get(ops, &local_sched);
-        copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1);
+        if ( rc )
+            break;
+
+        if ( copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1) )
+            rc = -EFAULT;
         break;
     }
 
Acked-by on v1 2/8
#6 lore raw

Re: [PATCH 2/8] sched/arinc653: check for guest data transfer failures

In reply to Matthew Daley
Quoted 5 lines · Matthew Daley

Coverity-ID: 1055121
Coverity-ID: 1055122
Coverity-ID: 1055123
Coverity-ID: 1055124

CC'ing the authors as well so they can ack / nack / backport as desired.

Quoted 40 lines
---
 xen/common/sched_arinc653.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
xen/common/sched_arinc653.c +11 -3
index 63ddb82..2502192 100644
@@ -635,12 +635,21 @@ a653sched_adjust_global(const struct scheduler *ops,
     switch ( sc->cmd )
     {
     case XEN_SYSCTL_SCHEDOP_putinfo:
-        copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1);
+        if ( copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
         rc = arinc653_sched_set(ops, &local_sched);
         break;
     case XEN_SYSCTL_SCHEDOP_getinfo:
         rc = arinc653_sched_get(ops, &local_sched);
-        copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1);
+        if ( rc )
+            break;
+
+        if ( copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1) )
+            rc = -EFAULT;
         break;
     }
 
--

1.7.10.4

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

Acked-by Acked-by George Dunlap
#7 lore raw

Re: [PATCH 2/8] sched/arinc653: check for guest data transfer failures

George,

This scheduler is now being maintained by Robert VanVossen <[email protected]> and Nate Studer <[email protected]>. Is there a way to make sure that future e-mails are sent to them instead of Josh and me?

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of George Dunlap
Sent: Tuesday, September 10, 2013 10:51 AM
To: Matthew Daley
Cc: [email protected]; Kathy Hadley; Josh Holtrop
Subject: Re: [Xen-devel] [PATCH 2/8] sched/arinc653: check for guest data transfer failures

Quoted 5 lines · Matthew Daley

Coverity-ID: 1055121
Coverity-ID: 1055122
Coverity-ID: 1055123
Coverity-ID: 1055124

CC'ing the authors as well so they can ack / nack / backport as desired.

Quoted 40 lines
---
 xen/common/sched_arinc653.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
xen/common/sched_arinc653.c +11 -3
index 63ddb82..2502192 100644
@@ -635,12 +635,21 @@ a653sched_adjust_global(const struct scheduler *ops,
     switch ( sc->cmd )
     {
     case XEN_SYSCTL_SCHEDOP_putinfo:
-        copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1);
+        if ( copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
         rc = arinc653_sched_set(ops, &local_sched);
         break;
     case XEN_SYSCTL_SCHEDOP_getinfo:
         rc = arinc653_sched_get(ops, &local_sched);
-        copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1);
+        if ( rc )
+            break;
+
+        if ( copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1) )
+            rc = -EFAULT;
         break;
     }
 
--

1.7.10.4

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

#8 lore raw

Re: [PATCH 2/8] sched/arinc653: check for guest data transfer failures

Quoted 4 lines · Kathy Hadley

This scheduler is now being maintained by Robert VanVossen
<[email protected]> and Nate Studer <[email protected]>. Is there a way to make sure that future e-mails are sent to them instead of Josh and me?

You (or they) can send a patch against the MAINTAINERS file at the top level of the Xen source tree.

Ian.

Acked-by on v1 2/8
#9 lore raw

Re: [PATCH 2/8] sched/arinc653: check for guest data transfer failures

In reply to Matthew Daley
Quoted 5 lines · Matthew Daley

Coverity-ID: 1055121
Coverity-ID: 1055122
Coverity-ID: 1055123
Coverity-ID: 1055124

Quoted 33 lines
---
 xen/common/sched_arinc653.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
xen/common/sched_arinc653.c +11 -2
index 63ddb82..2502192 100644
@@ -635,12 +635,21 @@ a653sched_adjust_global(const struct scheduler *ops,
     switch ( sc->cmd )
     {
     case XEN_SYSCTL_SCHEDOP_putinfo:
-        copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1);
+        if ( copy_from_guest(&local_sched, sc->u.sched_arinc653.schedule, 1)
 )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
         rc = arinc653_sched_set(ops, &local_sched);
         break;
     case XEN_SYSCTL_SCHEDOP_getinfo:
         rc = arinc653_sched_get(ops, &local_sched);
-        copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1);
+        if ( rc )
+            break;
+
+        if ( copy_to_guest(sc->u.sched_arinc653.schedule, &local_sched, 1) )
+            rc = -EFAULT;
         break;
     }
#10 lore raw

PATCH 3/8 libxl: fix use-after-free in discard_events iteration

In reply to Matthew Daley

We need to use the foreach variant which gets the next pointer before the loop body is executed.

Coverity-ID: 1056193

---
 tools/libxl/libxl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +2 -2
index 81785df..8f4a250 100644
@@ -122,8 +122,8 @@ static void free_disable_deaths(libxl__gc *gc,
 
 static void discard_events(struct libxl__event_list *l) {
     /* doesn't bother unlinking from the list, so l is corrupt on return */
-    libxl_event *ev;
-    LIBXL_TAILQ_FOREACH(ev, l, link)
+    libxl_event *ev, *next;
+    LIBXL_TAILQ_FOREACH_SAFE(ev, l, link, next)
         libxl_event_free(0, ev);
 }
 
Signature · 1 line
1.7.10.4
Acked-by on v1 3/8
#11 lore raw

Re: [PATCH 3/8] libxl: fix use-after-free in discard_events iteration

Matthew Daley writes ("[PATCH 3/8] libxl: fix use-after-free in discard_events iteration"):

Quoted 5 lines

We need to use the foreach variant which gets the next pointer before the loop body is executed.

Coverity-ID: 1056193

#12 lore raw

PATCH 4/8 libxl: correctly handle readlink() errors

In reply to Matthew Daley

readlink() returns a ssize_t with a negative value on failure.

Coverity-ID: 1055566

---
 tools/libxl/libxl_exec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_exec.c +1 -1
index 98bfd71..7eddaef 100644
@@ -33,7 +33,7 @@ static void check_open_fds(const char *what)
 
     for (i = 4; i < 256; i++) {
 #ifdef __linux__
-        size_t len;
+        ssize_t len;
         char path[PATH_MAX];
         char linkpath[PATH_MAX+1];
 #endif
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH 5/8 mini-os: fix use-after-free in xs_daemon_close event iteration

In reply to Matthew Daley

We need to get the next pointer before the freeing of the event.

Coverity-ID: 1056173

---
 extras/mini-os/lib/xs.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
extras/mini-os/lib/xs.c +5 -2
index a2a1220..c603d17 100644
@@ -29,9 +29,12 @@ struct xs_handle *xs_daemon_open()
 void xs_daemon_close(struct xs_handle *h)
 {
     int fd = _xs_fileno(h);
-    struct xenbus_event *event;
-    for (event = files[fd].xenbus.events; event; event = event->next)
+    struct xenbus_event *event, *next;
+    for (event = files[fd].xenbus.events; event; event = next)
+    {
+        next = event->next;
         free(event);
+    }
     files[fd].type = FTYPE_NONE;
 }
 
Signature · 1 line
1.7.10.4
#16 lore raw

PATCH 6/8 mini-os: handle possibly overlong _nodename in init_consfront

In reply to Matthew Daley

The only current user that passes a non-NULL _nodename limits it to 64 bytes anyway.

Coverity-ID: 1054993

---
 extras/mini-os/console/xenbus.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
extras/mini-os/console/xenbus.c +4 -2
index e65baf7..95d42a4 100644
@@ -70,8 +70,10 @@ struct consfront_dev *init_consfront(char *_nodename)
 
     if (!_nodename)
         snprintf(nodename, sizeof(nodename), "device/console/%d", consfrontends);
-    else
-        strncpy(nodename, _nodename, sizeof(nodename));
+    else {
+        strncpy(nodename, _nodename, sizeof(nodename) - 1);
+        nodename[sizeof(nodename) - 1] = 0;
+    }
 
     printk("******************* CONSFRONT for %s **********\n\n\n", nodename);
 
Signature · 1 line
1.7.10.4
#18 lore raw

PATCH 7/8 kdd: fix free of array-typed value

In reply to Matthew Daley

g->id is an array and is allocated as part of g itself; it's not a separate allocation.

Coverity-ID: 1054980

---
 tools/debugger/kdd/kdd-xen.c |    1 -
 1 file changed, 1 deletion(-)
tools/debugger/kdd/kdd-xen.c +0 -1
index 4fbea7d..f3f9529 100644
@@ -619,7 +619,6 @@ void kdd_guest_teardown(kdd_guest *g)
 {
     flush_maps(g);
     xc_interface_close(g->xc_handle);
-    free(g->id);
     free(g->hvm_buf);
     free(g);
 }
Signature · 1 line
1.7.10.4
Acked-by on v1 7/8
#19 lore raw

Re: [PATCH 7/8] kdd: fix free of array-typed value

Quoted 5 lines · Matthew Daley

g->id is an array and is allocated as part of g itself; it's not a separate allocation.

Coverity-ID: 1054980

Quoted 24 lines
---
 tools/debugger/kdd/kdd-xen.c |    1 -
 1 file changed, 1 deletion(-)
tools/debugger/kdd/kdd-xen.c +0 -1
index 4fbea7d..f3f9529 100644
@@ -619,7 +619,6 @@ void kdd_guest_teardown(kdd_guest *g)
 {
     flush_maps(g);
     xc_interface_close(g->xc_handle);
-    free(g->id);
     free(g->hvm_buf);
     free(g);
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v1 7/8
#20 lore raw

Re: [PATCH 7/8] kdd: fix free of array-typed value

In reply to Matthew Daley
Quoted 5 lines · Matthew Daley

g->id is an array and is allocated as part of g itself; it's not a separate allocation.

Coverity-ID: 1054980

Quoted 16 lines
---
 tools/debugger/kdd/kdd-xen.c |    1 -
 1 file changed, 1 deletion(-)
tools/debugger/kdd/kdd-xen.c +0 -1
index 4fbea7d..f3f9529 100644
@@ -619,7 +619,6 @@ void kdd_guest_teardown(kdd_guest *g)
 {
     flush_maps(g);
     xc_interface_close(g->xc_handle);
-    free(g->id);
     free(g->hvm_buf);
     free(g);
 }
#21 lore raw

PATCH 8/8 xenstored: fix possible, but unlikely, stack overflow

In reply to Matthew Daley

...when reading xenbus port from xenfs.

Coverity-ID: 1055741

---
 tools/xenstore/xenstored_linux.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xenstore/xenstored_linux.c +1 -1
index 5460ca5..cf40213 100644
@@ -32,7 +32,7 @@ evtchn_port_t xenbus_evtchn(void)
 	if (fd == -1)
 		return -1;
 
-	rc = read(fd, str, sizeof(str)); 
+	rc = read(fd, str, sizeof(str) - 1);
 	if (rc == -1)
 	{
 		int err = errno;
Signature · 1 line
1.7.10.4
Reviewed-by on v1 8/8
#22 lore raw

Re: [PATCH 8/8] xenstored: fix possible, but unlikely, stack overflow

Quoted 4 lines · Matthew Daley

...when reading xenbus port from xenfs.

Coverity-ID: 1055741

Quoted 17 lines
---
 tools/xenstore/xenstored_linux.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xenstore/xenstored_linux.c +1 -1
index 5460ca5..cf40213 100644
@@ -32,7 +32,7 @@ evtchn_port_t xenbus_evtchn(void)
 	if (fd == -1)
 		return -1;
 
-	rc = read(fd, str, sizeof(str)); 
+	rc = read(fd, str, sizeof(str) - 1);
 	if (rc == -1)
 	{
 		int err = errno;
#24 lore raw
In reply to Matthew Daley
Quoted 6 lines · Matthew Daley

libxl: fix use-after-free in discard_events iteration
libxl: correctly handle readlink() errors
mini-os: fix use-after-free in xs_daemon_close event iteration
mini-os: handle possibly overlong _nodename in init_consfront
kdd: fix free of array-typed value
xenstored: fix possible, but unlikely, stack overflow

I applied these tools/mini-os ones with the relevant acks/reviews given in the thread.

I assume someone else has/will take care of the Xen ones.

Ian.