From: ebiederm@xmission.com (Eric W. Biederman)
To: Andy Lutomirski <luto@amacapital.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>, Jim Lieb <jlieb@panasas.com>,
tytso@mit.edu, viro@zeniv.linux.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
bfields@redhat.com, jlayton@redhat.com
Subject: Re: [PATCH 1/3] switch_creds: Syscall to switch creds for file server ops
Date: Wed, 23 Oct 2013 22:59:54 -0700 [thread overview]
Message-ID: <8761snb44l.fsf@xmission.com> (raw)
In-Reply-To: <52687468.3060206@mit.edu> (Andy Lutomirski's message of "Wed, 23 Oct 2013 18:14:16 -0700")
Andy Lutomirski <luto@amacapital.net> writes:
> On 10/16/2013 08:52 PM, Eric W. Biederman wrote:
>> Al Viro <viro@ZenIV.linux.org.uk> writes:
>>
>>> On Wed, Oct 16, 2013 at 06:18:16PM -0700, Eric W. Biederman wrote:
>>>
>>>> That doesn't look bad but it does need capable(CAP_SETUID) &&
>>>> capable(CAP_SETGID) or possibly something a little more refined.
>>>
>>> D'oh
>>>
>>>> I don't think we want file descriptor passing to all of a sudden become
>>>> a grant of privilege, beyond what the passed fd can do.
>>>
>>> Definitely. And an extra ) to make it compile wouldn't hurt either...
>>
>> There also appears to need to be a check that we don't gain any
>> capabilities.
>>
>> We also need a check so that you don't gain any capabilities, and
>> possibly a few other things.
>
> Why? I like the user_ns part, but I'm not immediately seeing the issue
> with capabilities.
My reasoning was instead of making this syscall as generic as possible
start it out by only allowing the cases Jim cares about and working with
a model where you can't gain any permissions you couldn't gain
otherwise.
Although the fd -1 trick to revert to your other existing cred seems
reasonable.
>> So I suspect we want a check something like:
>>
>> if ((new_cred->securebits != current_cred->securebits) ||
>> (new_cred->cap_inheritable != current_cred->cap_inheritable) ||
>> (new_cred->cap_permitted != current_cred->cap_permitted) ||
>> (new_cred->cap_effective != current_cred->cap_effective) ||
>> (new_cred->cap_bset != current_cred->cap_bset) ||
>> (new_cred->jit_keyring != current_cred->jit_keyring) ||
>> (new_cred->session_keyring != current_cred->session_keyring) ||
>> (new_cred->process_keyring != current_cred->process_keyring) ||
>> (new_cred->thread_keyring != current_cred->thread_keyring) ||
>> (new_cred->request_keyring != current_cred->request_keyring) ||
>> (new_cred->security != current_cred->security) ||
>> (new_cred->user_ns != current_cred->user_ns)) {
>> return -EPERM;
>> }
>>
>
> I *really* don't like the idea of being able to use any old file
> descriptor. I barely care what rights the caller needs to have to
> invoke this -- if you're going to pass an fd that grants a capability
> (in the non-Linux sense of the work), please make sure that the sender
> actually wants that behavior.
>
> IOW, have a syscall to generate a special fd for this purpose. It's
> only a couple lines of code, and I think we'll really regret it if we
> fsck this up.
>
> (I will take it as a personal challenge to find at least one exploitable
> privilege escalation in this if an arbitrary fd works.)
If you can't switch to a uid or a gid you couldn't switch to otherwise
then the worst that can happen is an information leak. And information
leaks are rarely directly exploitable.
> Also... real_cred looks confusing. AFAICS it is used *only* for knfsd
> and faccessat. That is, current userspace can't see it. But now you'll
> expose various oddities. For example, AFAICS a capability-less process
> that's a userns owner can always use setuid. This will *overwrite*
> real_cred. Then you're screwed, especially if this happens by
> accident.
And doing in userland what faccessat, and knfsd do in the kernel is
exactly what is desired here. But maybe there are issues with that.
> That being said, Windows has had functions like this for a long time.
> Processes have a primary token and possibly an impersonation token. Any
> process can call ImpersonateLoggedOnUser (no privilege required) to
> impersonate the credentials of a token (which is special kind of fd).
> Similarly, any process can call RevertToSelf to undo it.
>
> Is there any actual problem with allowing completely unprivileged tasks
> to switch to one of these magic cred fds? That would avoid needing a
> "revert" operation.
If the permission model is this switching of credentials doesn't get you
anything you couldn't get some other way. That would seem to totally
rules out unprivileged processes switching these things.
> Another note: I think that there may be issues if the creator of a token
> has no_new_privs set and the user doesn't. Imagine a daemon that
> accepts one of these fds, impersonates it, and calls exec. This could
> be used to escape from no_new_privs land.
Which is why I was suggesting that we don't allow changing any field in
the cred except for uids and gids.
Eric
next prev parent reply other threads:[~2013-10-24 5:59 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-16 22:01 [RFC PATCH 0/3] System call to switch user credentials Jim Lieb
2013-10-16 22:01 ` [PATCH 1/3] switch_creds: Syscall to switch creds for file server ops Jim Lieb
2013-10-16 22:42 ` Al Viro
2013-10-17 1:18 ` Eric W. Biederman
2013-10-17 1:20 ` Al Viro
2013-10-17 3:35 ` Jim Lieb
2013-10-17 3:35 ` Jim Lieb
2013-10-17 3:52 ` Eric W. Biederman
2013-10-24 1:14 ` Andy Lutomirski
2013-10-24 5:59 ` Eric W. Biederman [this message]
2013-10-24 19:04 ` Jim Lieb
2013-10-24 19:04 ` Jim Lieb
2013-10-24 19:28 ` Andy Lutomirski
2013-10-24 20:24 ` Jim Lieb
2013-10-24 20:24 ` Jim Lieb
2013-10-31 19:09 ` Andy Lutomirski
2013-10-31 19:09 ` Andy Lutomirski
2013-10-31 19:43 ` Jim Lieb
2013-10-31 19:48 ` Andy Lutomirski
2013-10-31 20:39 ` Jim Lieb
2013-11-01 13:24 ` Tetsuo Handa
2013-11-01 15:49 ` Jim Lieb
2013-11-01 16:07 ` Tetsuo Handa
2013-11-01 17:16 ` Jim Lieb
2013-10-16 22:01 ` [PATCH 2/3] switch_creds: Add x86 syscall number Jim Lieb
2013-10-16 22:01 ` [PATCH 3/3] switch_creds: Assign x86_64 syscall number for switch_creds Jim Lieb
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=8761snb44l.fsf@xmission.com \
--to=ebiederm@xmission.com \
--cc=bfields@redhat.com \
--cc=jlayton@redhat.com \
--cc=jlieb@panasas.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=tytso@mit.edu \
--cc=viro@ZenIV.linux.org.uk \
--cc=viro@zeniv.linux.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.