Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Feb 2008 13:09:14 GMT
From:      Piotr Koper <piotr.koper@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/120753: Zombie jails (jailed child process exits while non-jailed parent is alive)
Message-ID:  <200802171309.m1HD9EXK008651@www.freebsd.org>
Resent-Message-ID: <200802171320.m1HDK2EN023463@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         120753
>Category:       kern
>Synopsis:       Zombie jails (jailed child process exits while non-jailed parent is alive)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Feb 17 13:20:02 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Piotr Koper
>Release:        6.2-RELEASE, 6.3-RELEASE
>Organization:
>Environment:
FreeBSD node01 6.3-RELEASE FreeBSD 6.3-RELEASE #7: Sun Feb  3 03:56:47 CET 2008     root@node01:/usr/obj/usr/src/sys/NODE  i386

>Description:
1. fork ()
2. child: jail (...)
3. child: execv (...)
4. parent: sleep (...)

So, when parent sleeps, child has already died, but:

$ ps auxw | grep J
root          21566  0.0  0.0     0     0  p2  ZJ    1:53PM   0:00.00 <defunct>
$ jls
   JID  IP Address      Hostname                      Path
     7  127.0.0.1       jail-fork                     /
$

When the parent exits, the jail disappears.

$ jls
$

But when you double fork the jail disappears as soon as the child process dies:
1. fork ()
2. child: fork ()
3. child: parent: exit ()
4. child: child: jail (...)
5. child: child: execv (...)
6. parent: sleep (10)

$ jls
$

See "How to repeat".
>How-To-Repeat:
Compile the code bellow and try two scenario:

1. $ ./jail-fork & sleep 1 ; jls ; ps auxw | grep J
2. $ ./jail-fork double-fork & sleep 1 ; jls ; ps auxw | grep J

For 1: you sees:
root          24113  0.0  0.0     0     0  p2  ZJ    2:06PM   0:00.00 <defunct>

For 2: everything is ok - no zombie process

<!-- file:jail-fork.c --!>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/jail.h>
#include <unistd.h>

int
main (int argc, char *argv[])
{
        struct in_addr in;
        struct jail j;
        char *j_argv[] = { "/bin/ls", "/COPYRIGHT" };

        j.version = 0;
        j.path = "/";
        j.hostname = "jail-fork";

        if (inet_aton ("127.0.0.1", &in) == 0)
                perror ("inet_addr");

        j.ip_number = ntohl (in.s_addr);

        /* Just fork, we'd like to create a background jailed process. */
        if (fork () == 0)
        {
                /* Fork again if additional arguments supplied */
                if (argc > 1 && fork () > 0)
                                exit (0);

                if (jail (&j) < 0)
                        perror ("jail");

                execv (j_argv[0], j_argv);
                perror ("execv");
        }

        sleep (3);

        return 0;
}

>Fix:


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802171309.m1HD9EXK008651>