Skip to contentSkip to conversation

CLONE_NEWUSER|CLONE_FS root exploit

DISCUSSION Kees Cook 3 participants 5 messages Mar 13, 2013 – Mar 14, 2013

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

Hi,

It seem like we should block (at least) this combination. On 3.9, this exploit works once uidmapping is added.

http://www.openwall.com/lists/oss-security/2013/03/13/10

-Kees

----- Forwarded message from Sebastian Krahmer <[email protected]> -----

Date: Wed, 13 Mar 2013 16:39:56 +0100
From: Sebastian Krahmer <[email protected]>
To: [email protected]
Subject: [oss-security] CLONE_NEWUSER|CLONE_FS root exploit
Envelope-To: [email protected]

Hi,

Seems like CLONE_NEWUSER|CLONE_FS might be a forbidden combination.
During evaluating the new user namespace thingie, it turned out that its trivially exploitable to get a (real) uid 0, as demonstrated here:

http://stealth.openwall.net/xSports/clown-newuser.c

The trick is to setup a chroot in your CLONE_NEWUSER, but also affecting the parent, which is running in the init_user_ns, but with the chroot shared. Then its trivial to get a rootshell from that.

Tested on a openSUSE12.1 with a custom build 3.8.2 (x86_64).

I hope I didnt make anything wrong, mixing up the UIDs, or disabled important checks during kernel build on my test system. ;)

regards,
Sebastian

Signature · 9 lines
~ perl self.pl
~ $_='print"\$_=\47$_\47;eval"';eval
~ [email protected] - SuSE Security Team

----- End forwarded message -----

-- 
Kees Cook
Chrome OS Security
#1 lore raw
Quoted 6 lines · Kees Cook

Hi,

It seem like we should block (at least) this combination. On 3.9, this exploit works once uidmapping is added.

http://www.openwall.com/lists/oss-security/2013/03/13/10

Yes. That is a bad combination. It let's chroot confuse privileged processes.

Now to figure out if this is easier to squash by adding a user_namespace to fs_struct or by just forbidding this combination.

Eric

#2 lore raw
Quoted 7 lines · Eric W. Biederman
Quoted 5 lines · Kees Cook

Hi,

It seem like we should block (at least) this combination. On 3.9, this exploit works once uidmapping is added.

Quoted 7 lines
Quoted 1 line

http://www.openwall.com/lists/oss-security/2013/03/13/10

Yes. That is a bad combination. It let's chroot confuse privileged processes.

Now to figure out if this is easier to squash by adding a user_namespace to fs_struct or by just forbidding this combination.

It's worth making sure that setns(2) doesn't have similar issues.

Looking through other shared-but-not-a-namespace things, there are:

fs_struct: Buggy as noted.

files_struct: Probably harmless -- SCM_RIGHTS can emulate it

signal_struct: This interacts with the tty code. Is it okay?

sighand_struct: Looks safe. Famous last words.

FWIW, I've been alarmed in the past that struct path (e.g. the root directory) implies an mnt_namespace (hidden in struct mount), and it's entirely possible for the root directory's mnt_namespace not to match nsproxy->mnt_namespace. I'm not sure what the implications are, but this doesn't seem healthy.

--Andy

#3 lore raw
Quoted 10 lines · Andy Lutomirski
Quoted 9 lines · Eric W. Biederman
Quoted 6 lines · Kees Cook

Hi,

It seem like we should block (at least) this combination. On 3.9, this exploit works once uidmapping is added.

http://www.openwall.com/lists/oss-security/2013/03/13/10

Quoted 7 lines
Quoted 5 lines

Yes. That is a bad combination. It let's chroot confuse privileged processes.

Now to figure out if this is easier to squash by adding a user_namespace to fs_struct or by just forbidding this combination.

It's worth making sure that setns(2) doesn't have similar issues.

setns(2) and unshare(2) are done and merged. See commit.

commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71

Author: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected]>
Date:   Wed Mar 13 11:51:49 2013 -0700

userns: Don't allow CLONE_NEWUSER | CLONE_FS

Quoted 7 lines

Looking through other shared-but-not-a-namespace things, there are:

fs_struct: Buggy as noted.

files_struct: Probably harmless -- SCM_RIGHTS can emulate it

signal_struct: This interacts with the tty code. Is it okay?

It should be. The tty code is heavily pid based, and CLONE_NEWPID requires !CLONE_VM (which implies !CLONE_SIGHAND and !CLONE_VM).

Quoted 7 lines

sighand_struct: Looks safe. Famous last words.

FWIW, I've been alarmed in the past that struct path (e.g. the root directory) implies an mnt_namespace (hidden in struct mount), and it's entirely possible for the root directory's mnt_namespace not to match nsproxy->mnt_namespace. I'm not sure what the implications are, but this doesn't seem healthy.

The calls to check_mnt prevent abuse of the files found with fs_struct not matching the current mount namespace.

static inline int check_mnt(struct mount *mnt)

{
	return mnt->mnt_ns == current->nsproxy->mnt_ns;
}

Thanks for looking I know I did the same double take and wondered if I had missed anything else by accident when this bug showed up.

So far even just looking it all over again I can't see anything. But I have clearly been blind before.

Eric

#4 lore raw
Quoted 56 lines · Eric W. Biederman
Quoted 10 lines · Andy Lutomirski
Quoted 9 lines · Eric W. Biederman
Quoted 6 lines · Kees Cook

Hi,

It seem like we should block (at least) this combination. On 3.9, this exploit works once uidmapping is added.

http://www.openwall.com/lists/oss-security/2013/03/13/10

Quoted 7 lines
Quoted 5 lines

Yes. That is a bad combination. It let's chroot confuse privileged processes.

Now to figure out if this is easier to squash by adding a user_namespace to fs_struct or by just forbidding this combination.

It's worth making sure that setns(2) doesn't have similar issues.

setns(2) and unshare(2) are done and merged. See commit.

commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71

Author: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected]>
Date:   Wed Mar 13 11:51:49 2013 -0700

userns: Don't allow CLONE_NEWUSER | CLONE_FS

Quoted 7 lines

Looking through other shared-but-not-a-namespace things, there are:

fs_struct: Buggy as noted.

files_struct: Probably harmless -- SCM_RIGHTS can emulate it

signal_struct: This interacts with the tty code. Is it okay?

It should be. The tty code is heavily pid based, and CLONE_NEWPID requires !CLONE_VM (which implies !CLONE_SIGHAND and !CLONE_VM).

Quoted 7 lines

sighand_struct: Looks safe. Famous last words.

FWIW, I've been alarmed in the past that struct path (e.g. the root directory) implies an mnt_namespace (hidden in struct mount), and it's entirely possible for the root directory's mnt_namespace not to match nsproxy->mnt_namespace. I'm not sure what the implications are, but this doesn't seem healthy.

The calls to check_mnt prevent abuse of the files found with fs_struct not matching the current mount namespace.

static inline int check_mnt(struct mount *mnt)

{
        return mnt->mnt_ns == current->nsproxy->mnt_ns;
}
Quoted 5 lines

Thanks for looking I know I did the same double take and wondered if I had missed anything else by accident when this bug showed up.

So far even just looking it all over again I can't see anything. But I have clearly been blind before.

This is way too fun. Got another one :/

I'll follow up in a sec off-list.

--Andy