linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Vagin <avagin@parallels.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Andrey Vagin <avagin@openvz.org>, <linux-fsdevel@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Serge Hallyn <serge.hallyn@canonical.com>
Subject: Re: [PATCH] mnt: don't allow to detach the namespace root
Date: Tue, 7 Oct 2014 17:40:12 +0400	[thread overview]
Message-ID: <20141007134011.GA569@paralelels.com> (raw)
In-Reply-To: <20141007132431.GF7996@ZenIV.linux.org.uk>

On Tue, Oct 07, 2014 at 02:24:36PM +0100, Al Viro wrote:
> On Tue, Oct 07, 2014 at 04:00:12PM +0400, Andrey Vagin wrote:
> > This patch fixes a bug, which is triggered by following code:
> > while (1) {
> >         if (umount2("/", MNT_DETACH) ||
> > 	    setns(fd, CLONE_NEWNS))
> >                 return break;
> > }
> 
> Excuse me, but that makes no sense whatsoever (not to mention that
> reproducer won't compile - return break; alone is enough to make
> sure of that).
> 
> Could you post the real reproducer?

#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sched.h>
#include <unistd.h>
#include <sys/mount.h>

int main(int argc, char **argv)
{
	int fd;

	fd = open("/proc/self/ns/mnt", O_RDONLY);
	if (fd < 0)
		return 1;
	while (1) {
		if (umount2("/", MNT_DETACH) ||
		    setns(fd, CLONE_NEWNS))
			break;
	}

	return 0;
}

root@ubuntu:/home/avagin# gcc -Wall nsenter.c -o nsenter
root@ubuntu:/home/avagin# strace ./nsenter
execve("./nsenter", ["./nsenter"], [/* 22 vars */]) = 0
...
open("/proc/self/ns/mnt", O_RDONLY)     = 3
umount("/", MNT_DETACH)                 = 0
setns(3, 131072)                        = 0
umount("/", MNT_DETACH


  reply	other threads:[~2014-10-07 13:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 12:00 [PATCH] mnt: don't allow to detach the namespace root Andrey Vagin
2014-10-07 13:24 ` Al Viro
2014-10-07 13:40   ` Andrew Vagin [this message]
2014-10-07 19:27     ` [PATCH] umount: Do not allow unmounting rootfs Eric W. Biederman
2014-10-07 19:53       ` Andrew Vagin
2014-10-07 20:58         ` Eric W. Biederman
2014-10-07 22:00           ` Andrew Vagin
2014-10-07 23:35             ` Eric W. Biederman
2014-10-07 23:40               ` [PATCH] mnt: Move the clear of MNT_LOCKED from copy_tree to it's Eric W. Biederman
2014-10-08 10:46                 ` Andrew Vagin
2014-10-08 10:47       ` [PATCH] umount: Do not allow unmounting rootfs Andrew Vagin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141007134011.GA569@paralelels.com \
    --to=avagin@parallels.com \
    --cc=avagin@openvz.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=serge.hallyn@canonical.com \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).