]> xenbits.xensource.com Git - libvirt.git/commitdiff
Close all non-stdio FDs in virt-login-shell (CVE-2013-4400)
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 9 Oct 2013 14:14:34 +0000 (15:14 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 21 Oct 2013 13:03:52 +0000 (14:03 +0100)
We don't want to inherit any FDs in the new namespace
except for the stdio FDs. Explicitly close them all,
just in case some do not have the close-on-exec flag
set.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
tools/virt-login-shell.c

index c754ae4bf99ee563eeb0b868cb87d4a2dd959531..01969506c26e75c29d2083f495c8f9a9802498c4 100644 (file)
@@ -313,6 +313,18 @@ main(int argc, char **argv)
     if (cpid == 0) {
         pid_t ccpid;
 
+        int openmax = sysconf(_SC_OPEN_MAX);
+        int fd;
+        if (openmax < 0) {
+            virReportSystemError(errno,  "%s",
+                                 _("sysconf(_SC_OPEN_MAX) failed"));
+            return EXIT_FAILURE;
+        }
+        for (fd = 3; fd < openmax; fd++) {
+            int tmpfd = fd;
+            VIR_MASS_CLOSE(tmpfd);
+        }
+
         /* Fork once because we don't want to affect
          * virt-login-shell's namespace itself
          */