]> xenbits.xensource.com Git - qemu-xen-traditional.git/commitdiff
main loop: Big hammer to fix logfile disk DoS in Xen setups xen-4.6.3
authorIan Jackson <ian.jackson@eu.citrix.com>
Thu, 19 May 2016 18:38:35 +0000 (19:38 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 10 Jun 2016 10:50:50 +0000 (11:50 +0100)
Each time round the main loop, we now fstat stderr.  If it is too big,
we dup2 /dev/null onto it.  This is not a very pretty patch but it is
very simple, easy to see that it's correct, and has a low risk of
collateral damage.

There is no limit by default but can be adjusted by setting a new
environment variable.

This is part of CVE-2014-3672.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Tested-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Set the default to 0 so that it won't affect non-xen installation. The
limit will be set by Xen toolstack.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
(ad-hoc cherry-pick from 44a072f0de0d57c95c2212bbce02888832b7b74f)
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
(cherry picked from commit 6e20809727261599e8527c456eb078c0e89139a1)
(cherry picked from commit 698d6d6f8d095edadb0c23612b552a89dd3eee4c)

vl.c

diff --git a/vl.c b/vl.c
index c864e7de755498c7b0326a6c9d0b6b9220df1796..f9c4d7ec24ecb5a569f1cd39139f182558cc53c7 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -3752,6 +3752,50 @@ static void host_main_loop_wait(int *timeout)
 }
 #endif
 
+static void check_cve_2014_3672_xen(void)
+{
+    static unsigned long limit = ~0UL;
+    const int fd = 2;
+    struct stat stab;
+
+    if (limit == ~0UL) {
+        const char *s = getenv("XEN_QEMU_CONSOLE_LIMIT");
+        /* XEN_QEMU_CONSOLE_LIMIT=0 means no limit */
+        limit = s ? strtoul(s,0,0) : 0;
+    }
+    if (limit == 0)
+        return;
+
+    int r = fstat(fd, &stab);
+    if (r) {
+        perror("fstat stderr (for CVE-2014-3672 check)");
+        exit(-1);
+    }
+    if (!S_ISREG(stab.st_mode))
+        return;
+    if (stab.st_size <= limit)
+        return;
+
+    /* oh dear */
+    fprintf(stderr,"\r\n"
+            "Closing stderr due to CVE-2014-3672 limit. "
+            " Set XEN_QEMU_CONSOLE_LIMIT to number of bytes to override,"
+            " or 0 for no limit.\n");
+    fflush(stderr);
+
+    int nfd = open("/dev/null", O_WRONLY);
+    if (nfd < 0) {
+        perror("open /dev/null (for CVE-2014-3672 check)");
+        exit(-1);
+    }
+    r = dup2(nfd, fd);
+    if (r != fd) {
+        perror("dup2 /dev/null (for CVE-2014-3672 check)");
+        exit(-1);
+    }
+    close(nfd);
+}
+
 void main_loop_wait(int timeout)
 {
     IOHandlerRecord *ioh;
@@ -3763,6 +3807,8 @@ void main_loop_wait(int timeout)
 
     host_main_loop_wait(&timeout);
 
+    check_cve_2014_3672_xen();
+
     /* poll any events */
     /* XXX: separate device handlers from system ones */
     nfds = -1;