LWN.net Logo

Re: CLONE_NEWUSER|CLONE_FS root exploit

From:  Andy Lutomirski <luto-kltTT9wpgjJwATOyAt5JVQ-AT-public.gmane.org>
To:  "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w-AT-public.gmane.org>
Subject:  Re: CLONE_NEWUSER|CLONE_FS root exploit
Date:  Thu, 14 Mar 2013 14:32:10 -0700
Message-ID:  <CALCETrUiQ+V9kHozA7ySjf3_UswXFkmzFq2eWzKrOW8Yhqh-ZA@mail.gmail.com>
Cc:  containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA-AT-public.gmane.org, Sebastian Krahmer <krahmer-l3A5Bk7waGM-AT-public.gmane.org>, Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw-AT-public.gmane.org>, Oleg Nesterov <oleg-H+wXaHxf7aLQT0dZR+AlfA-AT-public.gmane.org>, Linux Kernel Mailing List <linux-kernel-u79uwXL29TY76Z2rM5mHXA-AT-public.gmane.org>
Archive-link:  Article, Thread

On Thu, Mar 14, 2013 at 1:29 PM, Eric W. Biederman
<ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org> wrote:
> Andy Lutomirski <luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.org> writes:
>
>> On 03/13/2013 11:35 AM, Eric W. Biederman wrote:
>>> Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org> writes:
>>>
>>>> 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.
>>
>> 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/w@public.gmane.org>
> Date:   Wed Mar 13 11:51:49 2013 -0700
>
>     userns: Don't allow CLONE_NEWUSER | CLONE_FS
>
>
>> 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).
>
>> 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.

This is way too fun.  Got another one :/

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

--Andy


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds