mbox series

[v2,00/10] allow unprivileged overlay mounts

Message ID 20201207163255.564116-1-mszeredi@redhat.com (mailing list archive)
Headers show
Series allow unprivileged overlay mounts | expand

Message

Miklos Szeredi Dec. 7, 2020, 4:32 p.m. UTC
I've done some more work to verify that unprivileged mount of overlayfs is
safe.

One thing I did is to basically audit all function calls made by overlayfs
to see if it's normally called with any checks and whether overlayfs calls
it with the same (permission and other) checks.

Some of this work has already made it into 5.8 and this series contains
more fixes.

A general observation is that overlayfs does not call security_path_*()
hooks on the underlying fs.  I don't see this as a problem, because a
simple bind mount done inside a private mount namespace also defeats the
path based security checks.  Maybe I'm missing something here, so I'm
interested in comments from AppArmor and Tomoyo developers.

Eric, do you have thought about what to look for with respect to
unprivileged mount safety and whether you think this is ready for upstream?

Git tree:
  git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git#ovl-unpriv-v2

Thanks,
Miklos


Miklos Szeredi (10):
  vfs: move cap_convert_nscap() call into vfs_setxattr()
  vfs: verify source area in vfs_dedupe_file_range_one()
  ovl: check privs before decoding file handle
  ovl: make ioctl() safe
  ovl: simplify file splice
  ovl: user xattr
  ovl: do not fail when setting origin xattr
  ovl: do not fail because of O_NOATIME
  ovl: do not get metacopy for userxattr
  ovl: unprivieged mounts

 fs/overlayfs/copy_up.c     |   3 +-
 fs/overlayfs/file.c        | 126 +++----------------------------------
 fs/overlayfs/inode.c       |  10 ++-
 fs/overlayfs/namei.c       |   3 +
 fs/overlayfs/overlayfs.h   |   8 ++-
 fs/overlayfs/ovl_entry.h   |   1 +
 fs/overlayfs/super.c       |  56 +++++++++++++++--
 fs/overlayfs/util.c        |  12 +++-
 fs/remap_range.c           |  10 ++-
 fs/xattr.c                 |  17 +++--
 include/linux/capability.h |   2 +-
 security/commoncap.c       |   3 +-
 12 files changed, 110 insertions(+), 141 deletions(-)

Comments

Tetsuo Handa Dec. 8, 2020, 10:27 a.m. UTC | #1
On 2020/12/08 1:32, Miklos Szeredi wrote:
> A general observation is that overlayfs does not call security_path_*()
> hooks on the underlying fs.  I don't see this as a problem, because a
> simple bind mount done inside a private mount namespace also defeats the
> path based security checks.  Maybe I'm missing something here, so I'm
> interested in comments from AppArmor and Tomoyo developers.

Regarding TOMOYO, I don't want overlayfs to call security_path_*() hooks on the
underlying fs, but the reason is different. It is not because a simple bind mount
done inside a private mount namespace defeats the path based security checks.
TOMOYO does want to check what device/filesystem is mounted on which location. But
currently TOMOYO is failing to check it due to fsopen()/fsmount()/move_mount() API.
John Johansen Dec. 10, 2020, 8:56 a.m. UTC | #2
On 12/8/20 2:27 AM, Tetsuo Handa wrote:
> On 2020/12/08 1:32, Miklos Szeredi wrote:
>> A general observation is that overlayfs does not call security_path_*()
>> hooks on the underlying fs.  I don't see this as a problem, because a
>> simple bind mount done inside a private mount namespace also defeats the
>> path based security checks.  Maybe I'm missing something here, so I'm
>> interested in comments from AppArmor and Tomoyo developers.
> 
> Regarding TOMOYO, I don't want overlayfs to call security_path_*() hooks on the
> underlying fs, but the reason is different. It is not because a simple bind mount
> done inside a private mount namespace defeats the path based security checks.
> TOMOYO does want to check what device/filesystem is mounted on which location. But
> currently TOMOYO is failing to check it due to fsopen()/fsmount()/move_mount() API.
> 

Regardless of TOMOYO's approach I would say that overlays should call the
security_path_*() hooks, making it possible for an LSM to do something based off of
them when needed.

The current state of private mounts with regard to path based mediation is broken.
I just haven't had time to try and come up with an acceptable fix for it. overlayfs
is actually broken under apparmor mediation, and accesses to the lower layer end up
getting denied but there is no way to properly allow them. So policy that hits this
needs a flag set that allows for it in a very hacky way (its on the list of things
to fix).

Path based mediation has to carefully control mounts otherwise policy can be
circumvented as Miklos rightly points out. Ideally path based LSM wouldn't allow
you to do the simple bind mount inside a private mount namespace (at least not
unless policy allowed for it). AppArmor does mediate the mount hooks and bind
mounts in a private mount namespace (if they go through the LSM mount hooks) will
be denied. Again the problem is how to allow them, and this is broken.
Miklos Szeredi Dec. 10, 2020, 9:39 a.m. UTC | #3
On Thu, Dec 10, 2020 at 10:00 AM John Johansen
<john.johansen@canonical.com> wrote:
>
> On 12/8/20 2:27 AM, Tetsuo Handa wrote:
> > On 2020/12/08 1:32, Miklos Szeredi wrote:
> >> A general observation is that overlayfs does not call security_path_*()
> >> hooks on the underlying fs.  I don't see this as a problem, because a
> >> simple bind mount done inside a private mount namespace also defeats the
> >> path based security checks.  Maybe I'm missing something here, so I'm
> >> interested in comments from AppArmor and Tomoyo developers.
> >
> > Regarding TOMOYO, I don't want overlayfs to call security_path_*() hooks on the
> > underlying fs, but the reason is different. It is not because a simple bind mount
> > done inside a private mount namespace defeats the path based security checks.
> > TOMOYO does want to check what device/filesystem is mounted on which location. But
> > currently TOMOYO is failing to check it due to fsopen()/fsmount()/move_mount() API.
> >
>
> Regardless of TOMOYO's approach I would say that overlays should call the
> security_path_*() hooks, making it possible for an LSM to do something based off of
> them when needed.
>
> The current state of private mounts with regard to path based mediation is broken.
> I just haven't had time to try and come up with an acceptable fix for it. overlayfs
> is actually broken under apparmor mediation, and accesses to the lower layer end up
> getting denied but there is no way to properly allow them. So policy that hits this
> needs a flag set that allows for it in a very hacky way (its on the list of things
> to fix).
>
> Path based mediation has to carefully control mounts otherwise policy can be
> circumvented as Miklos rightly points out. Ideally path based LSM wouldn't allow
> you to do the simple bind mount inside a private mount namespace (at least not
> unless policy allowed for it). AppArmor does mediate the mount hooks and bind
> mounts in a private mount namespace (if they go through the LSM mount hooks) will
> be denied. Again the problem is how to allow them, and this is broken.

Okay, so what does that mean for overlayfs?

AA can deny the overlay mount just as well as the bind mount, and it
can allow it just as well as the bind mount.  Policy could be the
same.

Also all the security_path_ hooks will still get called for each
access on overlayfs itself.  They won't be called for the accesses
which overlayfs does on underlying layers, but is that needed?

Overlay could call those hooks itself (since the vfs_ helpers don't)
but the big question is whether that makes any sense.  AFAICS it might
make sense, but only if AA would correctly handle bind mounts, and
especially detached bind mounts (which is what overlayfs technically
uses).

Thanks,
Miklos

Tja
John Johansen Dec. 15, 2020, 11:03 a.m. UTC | #4
On 12/10/20 1:39 AM, Miklos Szeredi wrote:
> On Thu, Dec 10, 2020 at 10:00 AM John Johansen
> <john.johansen@canonical.com> wrote:
>>
>> On 12/8/20 2:27 AM, Tetsuo Handa wrote:
>>> On 2020/12/08 1:32, Miklos Szeredi wrote:
>>>> A general observation is that overlayfs does not call security_path_*()
>>>> hooks on the underlying fs.  I don't see this as a problem, because a
>>>> simple bind mount done inside a private mount namespace also defeats the
>>>> path based security checks.  Maybe I'm missing something here, so I'm
>>>> interested in comments from AppArmor and Tomoyo developers.
>>>
>>> Regarding TOMOYO, I don't want overlayfs to call security_path_*() hooks on the
>>> underlying fs, but the reason is different. It is not because a simple bind mount
>>> done inside a private mount namespace defeats the path based security checks.
>>> TOMOYO does want to check what device/filesystem is mounted on which location. But
>>> currently TOMOYO is failing to check it due to fsopen()/fsmount()/move_mount() API.
>>>
>>
>> Regardless of TOMOYO's approach I would say that overlays should call the
>> security_path_*() hooks, making it possible for an LSM to do something based off of
>> them when needed.
>>
>> The current state of private mounts with regard to path based mediation is broken.
>> I just haven't had time to try and come up with an acceptable fix for it. overlayfs
>> is actually broken under apparmor mediation, and accesses to the lower layer end up
>> getting denied but there is no way to properly allow them. So policy that hits this
>> needs a flag set that allows for it in a very hacky way (its on the list of things
>> to fix).
>>
>> Path based mediation has to carefully control mounts otherwise policy can be
>> circumvented as Miklos rightly points out. Ideally path based LSM wouldn't allow
>> you to do the simple bind mount inside a private mount namespace (at least not
>> unless policy allowed for it). AppArmor does mediate the mount hooks and bind
>> mounts in a private mount namespace (if they go through the LSM mount hooks) will
>> be denied. Again the problem is how to allow them, and this is broken.
> 
> Okay, so what does that mean for overlayfs?
> 
> AA can deny the overlay mount just as well as the bind mount, and it
> can allow it just as well as the bind mount.  Policy could be the
> same.
> 
not entirely the private mount is always detached from the namespace and we have
no way to correlate the private mount to the overlay so the only safe thing is
to deny operations on the private mount.

Ideally we would have a way to provide some kind of correlation so we could
make an informed decision.

> Also all the security_path_ hooks will still get called for each
> access on overlayfs itself.  They won't be called for the accesses
> which overlayfs does on underlying layers, but is that needed?
> 
maybe but maybe not. The thing is apparmor doesn't just used security_path_
hooks which means we get some operation on leaking through that are using
the private mount. Its this inconsistent partial view that is problematic.

> Overlay could call those hooks itself (since the vfs_ helpers don't)
> but the big question is whether that makes any sense.  AFAICS it might
> make sense, but only if AA would correctly handle bind mounts, and
> especially detached bind mounts (which is what overlayfs technically
> uses).
> 

I haven't investigated enough to say for sure whether AA needs the path
hooks called, but I think it probably doesn't. What AA does need is a
way to determine what to do with private mounts when it encounters them
in the none path hooks.

That could be a simple as a hook when the private mount is setup so it
can setup some state.

> Thanks,
> Miklos
> 
> Tja
>