selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: Paul Moore <paul@paul-moore.com>, Dan Walsh <dwalsh@redhat.com>
Cc: miklos@szeredi.hu, vgoyal@redhat.com, omosnace@redhat.com,
	bfields@fieldses.org, salyzyn@android.com,
	linux-kernel@vger.kernel.org, linux-unionfs@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, selinux@vger.kernel.org
Subject: Re: overlayfs access checks on underlying layers
Date: Tue, 4 Dec 2018 09:43:15 -0500	[thread overview]
Message-ID: <5b52869e-b979-dcf6-becf-a97b8ed33909@tycho.nsa.gov> (raw)
In-Reply-To: <CAHC9VhRcQdLRZoYi9g-MZzG8xPaNyFFX1nPppo7D93BTFQ6BZg@mail.gmail.com>

On 12/3/18 6:27 PM, Paul Moore wrote:
> On Thu, Nov 29, 2018 at 5:22 PM Daniel Walsh <dwalsh@redhat.com> wrote:
>> On 11/29/18 2:47 PM, Miklos Szeredi wrote:
>>> On Thu, Nov 29, 2018 at 5:14 PM Stephen Smalley <sds@tycho.nsa.gov> wrote:
>>>
>>>> Possibly I misunderstood you, but I don't think we want to copy-up on
>>>> permission denial, as that would still allow the mounter to read/write
>>>> special files or execute regular files to which it would normally be
>>>> denied access, because the copy would inherit the context specified by
>>>> the mounter in the context mount case.  It still represents an
>>>> escalation of privilege for the mounter.  In contrast, the copy-up on
>>>> write behavior does not allow the mounter to do anything it could not do
>>>> already (i.e. read from the lower, write to the upper).
>>> Let's get this straight:  when file is copied up, it inherits label
>>> from context=, not from label of lower file?
>>
>> Yes, in the case of context mount, it will get the context mount directory.
>>
>> In the case of not context mount, it should maintain the label of  the
>> lower.
>>
>>> Next question: permission to change metadata is tied to permission to
>>> open?  Is it possible that open is denied, but metadata can be
>>> changed?
>>
>> Yes, SElinux handles open differently then setattr.  Although I am not
>> sure if any tools handle this.
>>
>>> DAC model allows this: metadata change is tied to ownership, not mode
>>> bits.   And different capability flag.
>>>
>>> If the same is true for MAC, then the pre-v4.20-rc1 is already
>>> susceptible to the privilege escalation you describe, right?
>>
>> After talking to Vivek, I am not sure their is a privilege escallation.
> 
> More on this below, but this thread doesn't have me convinced, and we
> are at -rc5 right now.  We need to come to some decision on this soon
> because we are running out of time before v4.20 is released with this
> code.
> 
>> For device nodes, the mounter has to have the ability to create the
>> devicenode with the context mount, if he can do this, then he can do it
>> with or without Overlay.  This might lead to users making mistakes on
>> security, but the model is sound. And I think this stands even in the
>> case of the lower is mounted NODEV and the upper is not.  If the mounter
>> can create a device on the upper with a particular label, then he does
>> not need the lower.
> 
> The problem I have when looking at the current code is that permission
> is given, regardless of what is requested, for any special_file() on
> an overlayfs mount.
> 
> It also looks like the mounter's creds are used when checking
> permissions regardless of the file has been copied up or not; I would
> expect that the mounter's permissions would only used when checking
> permissions against the lower inode, no?

No, that's never been the model as far as I know.  mounter's permissions 
are checked to the underlying inode, whether upper or lower.  client's 
permissions are only checked to the overlay inode.  upper and lower are 
logically backing store - upper for writes and lower for reads from 
unmodified files.  Now, in theory, upper should always be labeled the 
same as overlay, so client check against overlay should already imply 
client access to upper, unless someone has manually relabeled upper 
outside of the overlay.

   I think there is also some
> weird behavior if the underlying inode only allows the mounter to
> write (no read) and a write is requested at the overlayfs layer.  I'm
> sure I'm missing some subtle thing with overlayfs, but why aren't we
> doing something like the following:
> 
>    int ovl_permission(...) {
> 
>      if (!realinode) {
>        ...
>      }
> 
>      err = generic_permission(inode, mask);
>      if (err)
>        return err;
> 
>      if (upperinode) {
>        err = inode_permission(upperinode, mask);
>      } else {
>        // on the lower inode, always use the mounter's creds
>        old_cred = ovl_override_creds(...);
> 
>        // check to see if we have the right perms first, if
>        // that fails switch to a read/copy-up check if we
>        // are doing a write (note: we are not bypassing the
>        // exec check, the task can change the metadata like
>        // every other fs)
>        err = inode_permission(lowerinode, mask);
>        if (err && (mask & (MAY_EXEC | MAY_APPEND))) {
>          // PM: my guess is that we also need to add a
>          // "&& !special_file(lowerinode)" to the conditional
>          // above because you can't copy-up a dev node in the
>          // normal sense, but we'll leave that as a discussion
>          // point for now...
>          // turn the write into a read (copy-up)
>          mask &= ~(MAY_WRITE | MAY_APPEND);
>          mask |= MAY_READ;
>          err = inode_permission(lowerinode, mask);
>        }
> 
>        // reset the creds
>        revert_creds(old_cred);
>      }
> 
>      return err;
>    }
> 
>> For sockets, I see the case where a process is listening on the lower
>> level socket, the mounter mounts the overlay over the directory with the
>> socket.  Then the mounter changes the attributes of the socket,
>> performing a copy up.  If the mounter can not talk to the socket and the
>> other end is still listening, then this could be an issue.  If the
>> socket is no longer connected to the listener on the lower, then this is
>> not an issue.
>>
>> Similar for a FIFO.
> 
> See my comment "// PM: my guess ..." in the pseudo code above.  I
> think the write->read permission mask conversion really should only
> apply to normal files where you can do a copy-up.
> 
>> With SELinux we are also always checking not only the file access to the
>> socker, but also checking whether the label of the client is able to
>> talk to the label of the server daemon.  So we are protected by a
>> secondary check.
> 
> That's making some assumptions on the LSM and the LSM's loaded policy
> and is not something I would want to rely on.

If you copy a socket or fifo and try to connect or open the copy, you 
aren't going to get the same result as if you accessed the original. 
Copy-up really makes no sense for those AFAICT.

  reply	other threads:[~2018-12-04 14:40 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27 19:55 overlayfs access checks on underlying layers Miklos Szeredi
2018-11-27 19:58 ` Miklos Szeredi
2018-11-27 21:05   ` Vivek Goyal
2018-11-28 10:00     ` Miklos Szeredi
2018-11-28 17:03       ` Vivek Goyal
2018-11-28 19:34         ` Stephen Smalley
2018-11-28 20:24           ` Miklos Szeredi
2018-11-28 21:46             ` Stephen Smalley
2018-11-29 11:04               ` Miklos Szeredi
2018-11-29 13:49                 ` Vivek Goyal
2019-03-04 17:01                   ` Mark Salyzyn
2019-03-04 17:56                     ` Casey Schaufler
2019-03-04 18:44                     ` Stephen Smalley
2019-03-04 19:21                       ` Amir Goldstein
2018-11-29 16:16                 ` Stephen Smalley
2018-11-29 16:22                   ` Stephen Smalley
2018-11-29 19:47                   ` Miklos Szeredi
2018-11-29 21:03                     ` Stephen Smalley
2018-11-29 21:19                       ` Stephen Smalley
2018-12-04 13:32                         ` Miklos Szeredi
2018-12-04 14:30                           ` Stephen Smalley
2018-12-04 14:45                             ` Miklos Szeredi
2018-12-04 15:35                               ` Stephen Smalley
2018-12-04 15:39                                 ` Miklos Szeredi
2018-12-11 15:50                                   ` Paul Moore
2018-12-04 15:15                             ` Vivek Goyal
2018-12-04 15:22                               ` Vivek Goyal
2018-12-04 15:31                                 ` Miklos Szeredi
2018-12-04 15:42                                   ` Vivek Goyal
2018-12-04 16:05                                     ` Stephen Smalley
2018-12-04 16:17                                       ` Vivek Goyal
2018-12-04 16:49                                         ` Stephen Smalley
2018-12-05 13:43                                           ` Vivek Goyal
2018-12-06 20:26                                             ` Stephen Smalley
2018-12-11 21:48                                               ` Vivek Goyal
2018-12-12 14:51                                                 ` Stephen Smalley
2018-12-13 14:58                                                   ` Vivek Goyal
2018-12-13 16:12                                                     ` Stephen Smalley
2018-12-13 18:54                                                       ` Vivek Goyal
2018-12-13 20:09                                                         ` Stephen Smalley
2018-12-13 20:26                                                           ` Vivek Goyal
2018-12-04 15:42                               ` Stephen Smalley
2018-12-04 16:15                                 ` Vivek Goyal
2018-11-29 22:22                     ` Daniel Walsh
2018-12-03 23:27                       ` Paul Moore
2018-12-04 14:43                         ` Stephen Smalley [this message]
2018-12-04 23:01                           ` Paul Moore

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=5b52869e-b979-dcf6-becf-a97b8ed33909@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=bfields@fieldses.org \
    --cc=dwalsh@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=salyzyn@android.com \
    --cc=selinux@vger.kernel.org \
    --cc=vgoyal@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).