Skip to contentSkip to conversation

Unreliable permission checking with OverlayFS

DISCUSSION Ignacy Gawędzki 1 participant 2 messages Jan 23, 2016 – Jan 25, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

It seems some results of permission checking are cached in situations where it looks like they shouldn't be.

See the following test-case:

  # umask 022
  # mkdir ro rw work mnt
  # chmod 700 ro
  # echo bar > ro/foo
  # mount overlay -t overlay -olowerdir=$PWD/ro,upperdir=$PWD/rw,workdir=$PWD/work mnt
  # echo 3 > /proc/sys/vm/drop_caches
  # sudo -u nobody cat mnt/foo
  cat: mnt/foo: Permission denied
  # cat mnt/foo
  bar
  # sudo -u nobody cat mnt/foo
  bar

So it seems that when the caches are empty, checking access to mnt/foo eventually checks access to ro/foo, which for user nobody is denied. But as soon as some user that has access to underlying ro/foo triggers a successful access to mnt/foo, user nobody succeeds in accessing it as well.

I admit this setup is a bit twisted, but I suppose this behavior qualifies as a bug.

Cheers,

Ignacy

PS: I've filed a bug in the kernel bugtracker about this issue as
well: https://bugzilla.kernel.org/show_bug.cgi?id=111131 .

Signature · 3 lines
Ignacy Gawędzki
R&D Engineer
Green Communications
#1 lore raw

Hi again,

I played around a bit with permissions and OverlayFS and found the following general odd behavior. When caches are empty and access permissions are checked, the upper layer is checked first and if that passes, the lower layer is checked next. Apart from the fact that some positive check results are cached regardless of the accessing UID, it seems that the checking procedure itself is wrong.

Take the following example: in the lower directory there's a directory foo with permissions 0700, containing some world-readable file. In the upper layer, the same directory foo exists but with permissions 0755.

drwxr-xr-x lower/
drwx------ lower/foo/
-rw-r--r-- lower/foo/bar

drwxr-xr-x upper/
drwxr-xr-x upper/foo/

This situation would happen after the permissions of foo are changed from 0700 to 0755 in the overlay directory. Then when permissions are checked for access to that file in foo, the permissions of foo in the lower directory should be ignored in favor of the permissions of foo in the upper directory.

In other words, as the documentation of OverlayFS itself puts it:

"Only the lists of names from directories are merged. Other content such as metadata and extended attributes are reported for the upper directory only. These attributes of the lower directory are hidden."

As I understand it, as soon as upper/foo exists its permissions should completely override those of lower/foo. This is obviously actually not the case as anyone not allowed to read lower/foo/bar who tries to read foo/bar from the overlay when the caches are empty is actually denied access.

Cheers,

Ignacy

Signature · 3 lines
Ignacy Gawędzki
R&D Engineer
Green Communications