Mailinglist Archive: vhostmd (6 mails)

< Previous Next >
[vhostmd] [PATCH] Bug fix: chdir ("/") when daemonizing self.
  • From: "Richard W.M. Jones" <rjones@xxxxxxxxxx>
  • Date: Wed, 9 Dec 2009 14:32:30 +0000
  • Message-id: <20091209143230.GA18646@xxxxxxxxxxxxxxxxxxxx>

This is quite a serious bug in the daemonization code. If we don't
chdir, then an arbitrary directory can be held open. For example:

# cd /tmp/foo
# /etc/init.d/vhostmd start
# pgrep vhostmd
19538
# ls -l /proc/19538/cwd
lrwxrwxrwx 1 root root 0 Dec 9 07:20 /proc/19538/cwd -> /tmp/foo

[This bug was identified by Dan Berrange]

Rich.

--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
From 6aba263066ede4721aab1fa9bf9415c51a3195a1 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones@xxxxxxxxxx>
Date: Wed, 9 Dec 2009 14:29:49 +0000
Subject: [PATCH] chdir ("/") when daemonizing self.

---
vhostmd/vhostmd.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
index 034dc26..77d196e 100644
--- a/vhostmd/vhostmd.c
+++ b/vhostmd/vhostmd.c
@@ -183,6 +183,9 @@ static int daemonize(void)
if (close(stdoutfd) < 0)
goto cleanup;
stdoutfd = -1;
+
+ if (chdir ("/") == -1)
+ goto cleanup;

if (setsid() < 0)
goto cleanup;
--
1.6.5.2

< Previous Next >
List Navigation
Follow Ups