linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jann Horn <jann@thejh.net>, Michal Hocko <mhocko@kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Linux Containers <containers@lists.linux-foundation.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Andy Lutomirski <luto@amacapital.net>,
	linux-mm@kvack.org, linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [REVIEW][PATCH] exec: Don't exec files the userns root can not read.
Date: Wed, 19 Oct 2016 08:33:58 -0500	[thread overview]
Message-ID: <87mvi0mpix.fsf@xmission.com> (raw)
In-Reply-To: <CAOQ4uxjyZF346vq-Oi=HwB=jj6ePycHBnEfvVPet9KqPxL9mgg@mail.gmail.com> (Amir Goldstein's message of "Wed, 19 Oct 2016 09:13:01 +0300")

Amir Goldstein <amir73il@gmail.com> writes:

>> diff --git a/fs/exec.c b/fs/exec.c
>> index 6fcfb3f7b137..f724ed94ba7a 100644
>> --- a/fs/exec.c
>> +++ b/fs/exec.c
>> @@ -1270,12 +1270,21 @@ EXPORT_SYMBOL(flush_old_exec);
>>
>>  void would_dump(struct linux_binprm *bprm, struct file *file)
>>  {
>> -       if (inode_permission(file_inode(file), MAY_READ) < 0)
>> +       struct inode *inode = file_inode(file);
>> +       if (inode_permission(inode, MAY_READ) < 0) {
>> +               struct user_namespace *user_ns = current->mm->user_ns;
>>                 bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
>> +
>> +               /* May the user_ns root read the executable? */
>> +               if (!kuid_has_mapping(user_ns, inode->i_uid) ||
>> +                   !kgid_has_mapping(user_ns, inode->i_gid)) {
>> +                       bprm->interp_flags |= BINPRM_FLAGS_EXEC_INACCESSIBLE;
>> +               }
>
> This feels like it should belong inside
> inode_permission(file_inode(file), MAY_EXEC)
> which hopefully should be checked long before getting here??

It is the active ingredient in capable_wrt_inode_uidgid and is indeed
inside of inode_permission.

What I am testing for here is if I have a process with a full
set of capabilities in current->mm->user_ns will the inode be readable.

I can see an argument for calling prepare_creds stuffing the new cred
full of capabilities.  Calling override_cred.  Calling inode_permission,
restoring the credentials.  But it seems very much like overkill and
more error prone because of the more code involved.

So I have done the simple thing that doesn't hide what is really going on.

Eric

  reply	other threads:[~2016-10-19 15:05 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87twcbq696.fsf@x220.int.ebiederm.org>
2016-10-17 17:25 ` [REVIEW][PATCH] mm: Add a user_ns owner to mm_struct and fix ptrace_may_access Jann Horn
2016-10-17 17:33   ` Eric W. Biederman
2016-10-18 13:50 ` Michal Hocko
2016-10-18 13:57   ` Jann Horn
2016-10-18 14:56   ` Eric W. Biederman
2016-10-18 15:05     ` Jann Horn
2016-10-18 15:35       ` Eric W. Biederman
2016-10-18 19:12         ` Jann Horn
2016-10-18 21:07           ` Eric W. Biederman
2016-10-18 21:15             ` [REVIEW][PATCH] exec: Don't exec files the userns root can not read Eric W. Biederman
2016-10-19  6:13               ` Amir Goldstein
2016-10-19 13:33                 ` Eric W. Biederman [this message]
2016-10-19 17:04                   ` Eric W. Biederman
2016-10-19 15:30               ` Andy Lutomirski
2016-10-19 16:52                 ` Eric W. Biederman
2016-10-19 17:29                   ` Jann Horn
2016-10-19 17:32                     ` Andy Lutomirski
2016-10-19 17:55                       ` Eric W. Biederman
2016-10-19 18:38                         ` Andy Lutomirski
2016-10-19 21:26                           ` Eric W. Biederman
2016-10-19 23:17                             ` Andy Lutomirski
2016-11-17 17:02                               ` [REVIEW][PATCH 0/3] Fixing ptrace vs exec vs userns interactions Eric W. Biederman
2016-11-17 17:05                                 ` [REVIEW][PATCH 1/3] ptrace: Capture the ptracer's creds not PT_PTRACE_CAP Eric W. Biederman
2016-11-17 23:14                                   ` Kees Cook
2016-11-18 18:56                                     ` Eric W. Biederman
2016-11-17 23:27                                   ` Andy Lutomirski
2016-11-17 23:44                                     ` Eric W. Biederman
2016-11-17 17:08                                 ` [REVIEW][PATCH 2/3] exec: Don't allow ptracing an exec of an unreadable file Eric W. Biederman
2016-11-17 20:47                                   ` Willy Tarreau
2016-11-17 21:07                                     ` Kees Cook
2016-11-17 21:32                                       ` Willy Tarreau
2016-11-17 21:51                                         ` Eric W. Biederman
2016-11-17 22:50                                           ` [REVIEW][PATCH 2/3] ptrace: Don't allow accessing an undumpable mm Eric W. Biederman
2016-11-17 23:17                                             ` Kees Cook
2016-11-17 23:28                                       ` [REVIEW][PATCH 2/3] exec: Don't allow ptracing an exec of an unreadable file Andy Lutomirski
2016-11-17 23:29                                   ` Andy Lutomirski
2016-11-17 23:55                                     ` Eric W. Biederman
2016-11-18  0:10                                       ` Andy Lutomirski
2016-11-18  0:35                                         ` Eric W. Biederman
2016-11-17 17:10                                 ` [REVIEW][PATCH 3/3] exec: Ensure mm->user_ns contains the execed files Eric W. Biederman
2016-11-19  7:17                                 ` [REVIEW][PATCH 0/3] Fixing ptrace vs exec vs userns interactions Willy Tarreau
2016-11-19  9:28                                   ` Willy Tarreau
2016-11-19  9:33                                     ` Willy Tarreau
2016-11-19 18:44                                     ` Eric W. Biederman
2016-11-19 18:35                                   ` Eric W. Biederman
2016-11-19 18:37                                     ` Eric W. Biederman
2016-10-18 18:06     ` [REVIEW][PATCH] mm: Add a user_ns owner to mm_struct and fix ptrace_may_access Michal Hocko

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=87mvi0mpix.fsf@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=amir73il@gmail.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=jann@thejh.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@amacapital.net \
    --cc=mhocko@kernel.org \
    --cc=oleg@redhat.com \
    /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).