[Devel] Re: BUG in tty_open when using containers and ptrace

Grzegorz Nosek root at localdomain.pl
Wed Jul 15 06:19:23 PDT 2009


On Tue, Jul 14, 2009 at 09:47:44PM -0700, Sukadev Bhattiprolu wrote:
> I am not too familiar with libvirt implementation, but do you think it
> is possible to repro this using ns_exec and fewer/minimal namespaces ?

Just run the program below. 2.6.29 oopses when the child tries to open
/dev/console. Possibly can be stripped down even further but I think
it's fairly minimal anyway.

BTW, I guess the patch should set ERR_PTR(-EIO) or something, instead
of NULL, am I right?

Best regards,
 Grzegorz Nosek

/*------------- cut ------------*/
#define _GNU_SOURCE
#include <fcntl.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/signal.h>
#include <unistd.h>

#include <linux/fs.h>

void dummy(int sig)
{
}

static int child(void *unused)
{
	signal(SIGINT, dummy);
	signal(SIGHUP, dummy);
	pause(); /* cheesy synchronisation to wait for /dev/pts/0 to appear */

	mount("/dev/pts/0", "/dev/console", NULL, MS_BIND, NULL);
	sleep(2);

	open("/dev/console", O_RDWR);
	dup(0);
	dup(0);
	write(1, "Hello world!\n", sizeof("Hello world!\n")-1);
	return 0;
}

int main(void)
{
	pid_t pid;
	char *stack;
	int fd;

	stack = malloc(16384);
	pid = clone(child, stack+16384, CLONE_NEWNS|SIGCHLD, NULL);

	fd = open("/dev/ptmx", O_RDWR|O_NOCTTY|O_NONBLOCK);
	unlockpt(fd);
	grantpt(fd);

	kill(pid, SIGHUP);
	sleep(1);
	return 0; /* exit before child opens /dev/console */
}

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list