From e93e8db21dfe3d62aa3f4684c3729de51b729feb Mon Sep 17 00:00:00 2001
Message-Id: <e93e8db21dfe3d62aa3f4684c3729de51b729feb.1383321464.git.jdenemar@redhat.com>
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Wed, 30 Oct 2013 17:01:43 +0000
Subject: [PATCH] Close all non-stdio FDs in virt-login-shell
CVE-2013-4400
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>
(cherry picked from commit b7fcc799ad5d8f3e55b89b94e599903e3c092467)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
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 1157cd0..c2c9947 100644
--- a/tools/virt-login-shell.c
+++ b/tools/virt-login-shell.c
@@ -308,6 +308,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.4.2