Let's reinvent storage, yet again!

Now that we're treating storage as a runtime permission, we need to
grant read/write access without killing the app.  This is really
tricky, since we had been using GIDs for access control, and they're
set in stone once Zygote drops privileges.

The only thing left that can change dynamically is the filesystem
itself, so let's do that.  This means changing the FUSE daemon to
present itself as three different views:

/mnt/runtime_default/foo - view for apps with no access
/mnt/runtime_read/foo - view for apps with read access
/mnt/runtime_write/foo - view for apps with write access

There is still a single location for all the backing files, and
filesystem permissions are derived the same way for each view, but
the file modes are masked off differently for each mountpoint.

During Zygote fork, it wires up the appropriate storage access into
an isolated mount namespace based on the current app permissions.  When
the app is granted permissions dynamically at runtime, the system
asks vold to jump into the existing mount namespace and bind mount
the newly granted access model into place.

Bug: 21858077
Change-Id: I5a016f0958a92fd390c02b5ae159f8008bd4f4b7
This commit is contained in:
Jeff Sharkey 2015-06-23 14:30:37 -07:00
parent 9a53bb0f80
commit f38f29c87d
2 changed files with 238 additions and 375 deletions

View File

@ -67,15 +67,18 @@ on init
mkdir /mnt/user/0 0755 root root
mkdir /mnt/expand 0771 system system
# sdcard_r is GID 1028
mkdir /storage 0751 root sdcard_r
mount tmpfs tmpfs /storage mode=0751,uid=0,gid=1028
restorecon_recursive /storage
# Storage views to support runtime permissions
mkdir /storage 0755 root root
mkdir /mnt/runtime_default 0755 root root
mkdir /mnt/runtime_default/self 0755 root root
mkdir /mnt/runtime_read 0755 root root
mkdir /mnt/runtime_read/self 0755 root root
mkdir /mnt/runtime_write 0755 root root
mkdir /mnt/runtime_write/self 0755 root root
# Symlink to keep legacy apps working in multi-user world
mkdir /storage/self 0751 root sdcard_r
symlink /storage/self/primary /sdcard
symlink /mnt/user/0/primary /storage/self/primary
symlink /mnt/user/0/primary /mnt/runtime_default/self/primary
# memory control cgroup
mkdir /dev/memcg 0700 root system
@ -210,8 +213,10 @@ on post-fs
start logd
# once everything is setup, no need to modify /
mount rootfs rootfs / ro remount
# mount shared so changes propagate into child namespaces
# Mount shared so changes propagate into child namespaces
mount rootfs rootfs / shared rec
# Mount default storage into root namespace
mount none /mnt/runtime_default /storage slave bind rec
# We chown/chmod /cache again so because mount is run as root + defaults
chown system cache /cache

File diff suppressed because it is too large Load Diff