[PATCH 03/14] Close all non-stdio FDs in virt-login-shell (CVE-2013-4400)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

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@xxxxxxxxxx>
---
 tools/virt-login-shell.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c
index c754ae4..0196950 100644
--- a/tools/virt-login-shell.c
+++ b/tools/virt-login-shell.c
@@ -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
          */
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]