Commit graph

3464 commits

Author SHA1 Message Date
Zimuzo Ezeozue
a064500bf3 Merge "Convert paths to lower filesystem paths during setupAppDir" 2020-01-07 08:09:52 +00:00
Martijn Coenen
86f21a2211 Conditionally use sdcardfs.
In preparation of sdcardfs going away on devices launching with R,
conditionally use it.

Bug: 146419093
Test: cuttlefish with sdcardfs, cuttlefish without sdcardfs but with
FUSE
Change-Id: I2c1d4b428dcb43c3fd274dde84d5088984161993
2020-01-07 09:03:35 +01:00
Zim
c59d774149 Convert paths to lower filesystem paths during setupAppDir
Making FUSE request from vold is risky because the FUSE daemon may be
down and vold could get wedged.

Additionally, the FUSE daemon only responds to requests with matching
user id paths, i.e requests on /mnt/user/0/emulated/10 will fail.
So if vold (running as user 0) makes a request on
/storage/emulated/10, it really means /mnt/user/0/emulated/10
which will fail if it gets to the FUSE daemon.

TODO: Fix the lower filesystem paths to support devices without
sdcardfs

Bug: 141540368
Change-Id: I90d698f6aecd114d75b6d578ad08620988da7d7d
atest: atest android.appsecurity.cts.ExternalStorageHostTest#testMediaSandboxedFull
2020-01-06 21:55:13 +00:00
Zim
06b0cafb29 Fix /mnt/user/<userid> permission bits
Previously, when mounting a FUSE volume, the permission bits for
/mnt/user/<userid> were very strict, 700 which was good, however this
value was ignored because it was overriden in zygote to 755. In fact
if it wasn't ignored, apps wouldn't have had access to /sdcard becase
they would lack the directory 'execute' bit for /mnt/user/<userid>
needed while looking up /mnt/user/<userid>/emulated

Now we set it to a strict enough value, 710 that only allows apps
running under the same user id to lookup /mnt/user/<userid>.
This ensures that user 10 cannot access /mnt/user/0.

A special case is added for /mnt/user/0 for shell since it is not in
the 'everybody' group and would otherwise not be able to 'adb shell ls
/sdcard'

Bug: 135341433
Test: atest -c android.appsecurity.cts.ExternalStorageHostTest#testSecondaryUsersInaccessible

Change-Id: Ia427d1b69c7140254ae3459b98e51531d8322f1a
2020-01-06 12:51:18 +00:00
Martijn Coenen
e3102990ca Merge "Replace mkdirs() with setupAppDir()." 2020-01-06 09:04:13 +00:00
Martijn Coenen
cf5916f3fa Also delay creating found disks until user 0 is started.
Public and private volumes can be discovered before user 0 is up and
running; when using FUSE however, we can't mount these disks yet,
because we depend on the user to become unlocked before we can start the
FUSE daemon (which is the MediaProvider application process). So besides
waiting for any secure keyguard to be dismissed, also wait for user 0 to
be started.

Bug: 146419093
Test: Boot cuttlefish with a fake public volume; is available after
repeated boots.

Change-Id: I06fe4d336d1baec3a49886c3cf12d844a1d0eb26
2020-01-03 16:32:20 +01:00
Qilin Tan
5d0aaaf8e0 Fix the overflow issue in Checkpoint
When the partition is f2fs and the OS is 32bit, the data.f_bavail and
data.f_frsize are 32 bits in size. The product of them is also 32 bits
in size. If the available size of storage is greater than 4G, the
product may be greater than the unsigned long max value. If the product
is overflow and less than 100M. The UDC feature will be disabled.

There is also an overflow for std::strtoul when the variable content
is a very big number(more the unsigned long max value).

To avoid the overflow:
1. convert the variable data.f_bavvail to uint64_t and then compute the
multiplication.
2. use std::strtoull replace to std::strtoul.

Bug: 147118861
Change-Id: I60172ae4cb7c997e2ad4a36583be74736c25e565
2020-01-03 08:12:03 +00:00
Martijn Coenen
13ff668775 Replace mkdirs() with setupAppDir().
vold historically offerred functionality to create directories on behalf
of others. This functionality was purely used to create app-specific
data/obb/media dirs. Make this more explicit by renaming the method to
indicate this.

Additionally, in the past, we never needed to care about the UID set on
these directories, because sdcardfs would take care of that for us
automatically. But with sdcardfs going away, we need to make sure the
UID of the app-specific directories is set correctly. Allow the caller
to pass this in as an argument.

Bug: 146419093
Test: atest FuseDaemonHostTest
Change-Id: Ibeb5fdc91b40d53583bc0960ee11c4d640549c34
2019-12-31 15:58:41 +01:00
Automerger Merge Worker
6a9bd24233 Merge "Consistently use CLOCK_MONOTONIC for timing encryption" am: f9510e3262 am: 395c47e046 am: 61f5d1e399
Change-Id: Ie78c05e0857b980215c237520d4e8f04e376e74e
2019-12-27 02:37:50 +00:00
Automerger Merge Worker
61f5d1e399 Merge "Consistently use CLOCK_MONOTONIC for timing encryption" am: f9510e3262 am: 395c47e046
Change-Id: I5aa535a2dc31bce130c1e48c8a3cf9bdc1a8b238
2019-12-27 02:21:36 +00:00
Denis Hsu
395c47e046 Merge "Consistently use CLOCK_MONOTONIC for timing encryption"
am: f9510e3262

Change-Id: I6eb165b5e9214eb614434ecfa654cfcd22327af1
2019-12-26 18:03:33 -08:00
Treehugger Robot
f9510e3262 Merge "Consistently use CLOCK_MONOTONIC for timing encryption" 2019-12-27 01:51:56 +00:00
Denis Hsu
1740effeaa Consistently use CLOCK_MONOTONIC for timing encryption
time_started in encryptGroupsData is set from and compared to
clock_gettime(CLOCK_MONOTONIC, ...) nearly everywhere: "Clock that
cannot be set and represents monotonic time since some unspecified
starting point". However in cryptfs_enable_inplace_f2fs() it is set
from a different clock, time(NULL), with the result that the setprop
calls that indicate progress are wrong and can be called much too
often. The fix is to make this function consistent with
cryptfs_enable_inplace_ext4.

Bug: 146877356
Change-Id: I2707180e5c5bf723a5a880f6a3aac47f2bb34ccd
2019-12-26 18:53:53 +00:00
Automerger Merge Worker
da4d63eaff Merge "Clean up providing key via old API" am: 180b1a7f89 am: fe823efdae am: 270e041a14
Change-Id: I94cb7467ccd56711a4442fb6f1b795b8bf6bc284
2019-12-18 20:59:24 +00:00
Automerger Merge Worker
270e041a14 Merge "Clean up providing key via old API" am: 180b1a7f89 am: fe823efdae
Change-Id: Ic130119f9887dcb0d8459770aed2253bcbf909c1
2019-12-18 20:13:43 +00:00
Eric Biggers
fe823efdae Merge "Clean up providing key via old API"
am: 180b1a7f89

Change-Id: Icc84ee275ce240fc65eb872d44ffc856e8cc8dd0
2019-12-18 11:57:42 -08:00
Eric Biggers
180b1a7f89 Merge "Clean up providing key via old API" 2019-12-18 19:13:28 +00:00
Martijn Coenen
5e289ee859 Merge changes from topic "fuse_fix_shell"
* changes:
  Vold mkdirs should use lower filesystem.
  Use the default sdcardfs view for the Android/ bind-mount.
2019-12-18 07:58:53 +00:00
Eric Biggers
506342fb37 Clean up providing key via old API
- Use FSCRYPT_MAX_KEY_SIZE from <linux/fscrypt.h> instead of manually
  defining FS_AES_256_XTS_KEY_SIZE.  These have the same numeric value
  (64), but the former is supposed to be used, and AES-256-XTS isn't
  necessarily the encryption algorithm that is being used anyway.

- Use the new name FSCRYPT_KEY_DESCRIPTOR_SIZE instead of the old name
  FS_KEY_DESCRIPTOR_SIZE.  These have the same numeric value (8).

- Don't try to handle sizeof(fscrypt_key::raw) > FSCRYPT_MAX_KEY_SIZE,
  as this simply isn't the case.

- Set fscrypt_key::mode to 0 rather than FS_ENCRYPTION_MODE_AES_256_XTS.
  This field has always been ignored by the kernel, and AES-256-XTS
  isn't necessarily the encryption algorithm that is being used anyway.

- Initialize the fields of fscrypt_key in order.

This is a cleanup only.

Test: booted hikey with fileencryption=aes-256-xts and a kernel that
      doesn't support the new fscrypt ioctls.
Bug: none
Change-Id: Ie2a7e9240aa479dfab2765c11db8a7124d20c643
2019-12-17 13:48:25 -08:00
Automerger Merge Worker
82c87c5209 Merge "Use <linux/fscrypt.h> from Bionic" am: 1d3cd24c4e am: c1e5cbe182 am: feef5dc6d0
Change-Id: If95d848f36bc9dd1180812ba06ec6b486d9daafc
2019-12-17 18:07:00 +00:00
Automerger Merge Worker
feef5dc6d0 Merge "Use <linux/fscrypt.h> from Bionic" am: 1d3cd24c4e am: c1e5cbe182
Change-Id: Ie0142719a4b3836912aa4b41ce72f782e8c68f43
2019-12-17 17:50:04 +00:00
Eric Biggers
c1e5cbe182 Merge "Use <linux/fscrypt.h> from Bionic"
am: 1d3cd24c4e

Change-Id: Icf5a715146d6edd6740fcff0b45df9e817fac1ef
2019-12-17 09:39:37 -08:00
Eric Biggers
1d3cd24c4e Merge "Use <linux/fscrypt.h> from Bionic" 2019-12-17 17:35:03 +00:00
Martijn Coenen
1986bfda8d Vold mkdirs should use lower filesystem.
If vold's view of /storage is FUSE, it means that creation of
directories in Android/ will go through FUSE as well. The implementation
of fs_mkdirs() tries to opendir() individual parts of the entire path;
so for a path "/storage/emulated/0/Android", it will try to opendir()
"/storage", "/storage/emulated", etc.

By default, "/storage/emulated" is created with 711 permissions; while
vold itself is root, access to /storage/emulated is routed through
MediaProvider (because of FUSE), and MediaProvider doesn't run as root,
nor does it have the capabilities to bypass the ACL. This means that
fs_mkdirs() as it is will fail, because opendir("/storage/emulated")
will fail from MediaProvider.

To prevent this, route these accesses directly to the lower filesystem
(currently, sdcardfs), by renaming the paths.

Bug: 146189163
Test: atest AdoptableHostTest
Change-Id: Idbb41b9ffad9713f3b255c51bd4de16f4d090223
2019-12-17 14:43:26 +01:00
Eric Biggers
3e9c996ab0 Use <linux/fscrypt.h> from Bionic
aosp/1184798 has updated the kernel headers to 5.4, so we no longer need
the file fscrypt_uapi.h.  In KeyUtil.cpp we also now don't need
<linux/fs.h>, but rather just the more specific <linux/fscrypt.h>.

Test: build
Bug: None
Change-Id: I56d17826eb7c3b95c74ce0435a4feae7f3cc325e
2019-12-16 16:19:44 -08:00
Martijn Coenen
adecd0ae75 Use the default sdcardfs view for the Android/ bind-mount.
Now that StorageManager asks vold to create package directories again,
apps only need write access in their own app-private directory. Both
app-private and OBB dirs will be created by privileged daemons as
needed.

This means we can use the "default" sdcardfs view for the Android/
bind-mount again. This has the added benefit that it fixes shell, which
wasn't in the "everybody" group, and therefore suddenly couldn't enter
/sdcard/Android anymore.

Bug: 146189163
Test: atest AdoptableHostTest
Change-Id: I37ca3b19ea4d11ed866efa808f51be945a4dc080
2019-12-13 16:05:03 +01:00
Abhijeet Kaur
a70feb449e Merge "Replace "sys.fuse_snapshot" with "persist.sys.fuse"" 2019-12-13 14:03:29 +00:00
Abhijeet Kaur
01fa0e0d8d Replace "sys.fuse_snapshot" with "persist.sys.fuse"
With the newly added flag for Settings developer options, which is now
used to change the state of FUSE, PROP_FUSE now acts as the snapshot
feature flag for the current boot.

Bug: 145391093
Test: atest AdoptableHostTest
Change-Id: I22363b088e88c764294cbd61c6d94160c907fae3
2019-12-13 10:26:32 +00:00
Greg Kaiser
5298ccc2a7 Initialize mFuseMounted
We missed one of the constructors before.

Bug: 137890172
Test: TreeHugger
Change-Id: If2f8a15d5abdff6e3a457a76e9d54b2c58d80422
2019-12-12 05:41:46 -08:00
Automerger Merge Worker
0aeb0c388e Merge "Allow fscrypt_mount_metadata_encrypted to be called more than once" am: 69199c70ec am: c39c12d0c3 am: 4f2f5d03b1
Change-Id: Ic40fd05dd91509c1a53488d9758c9fa39a7e0b84
2019-12-11 19:30:34 +00:00
Automerger Merge Worker
4f2f5d03b1 Merge "Allow fscrypt_mount_metadata_encrypted to be called more than once" am: 69199c70ec am: c39c12d0c3
Change-Id: I075c96eff7910c7a68c295ecf5f887b9deb929c0
2019-12-11 19:09:42 +00:00
Nikita Ioffe
c39c12d0c3 Merge "Allow fscrypt_mount_metadata_encrypted to be called more than once"
am: 69199c70ec

Change-Id: I743a9bbcca76af3fc1701d315e7e053b7ebea57e
2019-12-11 10:47:20 -08:00
Nikita Ioffe
69199c70ec Merge "Allow fscrypt_mount_metadata_encrypted to be called more than once" 2019-12-11 18:40:21 +00:00
TreeHugger Robot
b4569d73ee Merge "Correctly initialize mFuseMounted." 2019-12-11 14:49:38 +00:00
Martijn Coenen
fd7362d2a8 Correctly initialize mFuseMounted.
Wasn't done before.

Bug: 137890172
Test: builds
Change-Id: I413505fae23031a2da71086cbfd85e0b1aec459c
2019-12-11 14:26:27 +00:00
Martijn Coenen
9b712e6188 Merge changes from topic "fuse_bindmount"
* changes:
  Use a regular set for started users.
  When unmounting, only kill user-specific paths.
  Bind mount Android/ directory in FUSE.
  Use sdcardfs for pass-through mounts.
2019-12-11 07:51:37 +00:00
Automerger Merge Worker
ed36dcd1a7 Merge "Clear the warm_reset flag after boot is successful" am: 3fc3d75eb0 am: 9e9e9143b0 am: 9586a3dd1b
Change-Id: I906a715f21297d87b8ecc55313690998f344b726
2019-12-10 18:58:41 +00:00
Tianjie Xu
9586a3dd1b Merge "Clear the warm_reset flag after boot is successful" am: 3fc3d75eb0
am: 9e9e9143b0

Change-Id: Ib1fe4e420b7d673cfbdb4b425ba8b9f97cbea2fc
2019-12-10 10:39:46 -08:00
Tianjie Xu
9e9e9143b0 Merge "Clear the warm_reset flag after boot is successful"
am: 3fc3d75eb0

Change-Id: I7da336fa51761f133c633a9ba9997c99772b1e9c
2019-12-10 10:37:48 -08:00
Tianjie Xu
3fc3d75eb0 Merge "Clear the warm_reset flag after boot is successful" 2019-12-10 18:28:26 +00:00
Martijn Coenen
745e0a9acb Use a regular set for started users.
We want started users to be an ordered set; eg user 0 should always go
first. This is because volumes for users other than 0 depend on user 0
coming up first, because the volume for user 0 is the one mounting
sdcardfs.

Bug: 13789012
Test: atest AdoptableHostTest
Change-Id: Ic9119f0a24bd261e5362019836ac240b90c681c0
2019-12-10 16:49:16 +01:00
Martijn Coenen
8f1e7f289f When unmounting, only kill user-specific paths.
The path for emulated volumes is set to /storage/emulated,
not /storage/emulated/<userid> . When unmounting, we only
want to kill process with a reference to /<userid>; this prevents
killing processed needlessly.

Bug: 137890172
Test: atest AdoptableHostTest
Change-Id: I70e36e87077e87db9b3c7e07dc0e481ba06c2c14
2019-12-10 16:49:16 +01:00
Martijn Coenen
5700261e5a Bind mount Android/ directory in FUSE.
For apps seeing the FUSE filesystem, we want to bind-mount the Android/
directory to the lower filesystem. The main reason for this is game
performance - Android/ contains both OBBs and app-private external data,
and both are heavily accessed during game startup. This is a pretty
straightforward bind-mount on top of /mnt/user.

Bug: 137890172
Test: Running the following:
df /storge/emulated/0 ==> /dev/fuse (FUSE)
df /storage/emulated/0/Android ==> /data/media (sdcardfs)
Test: atest AdoptableHostTest

Change-Id: Ic17a5751b5a94846ee565ff935644a078044ab06
2019-12-10 16:49:16 +01:00
Martijn Coenen
6f5802e160 Use sdcardfs for pass-through mounts.
The pass-through mount is used by MediaProvider to access external
storage. Previously, it was the raw filesystem (eg ext4/f2fs); the
problem with that is that the permissions on that filesystem don't allow
MediaProvider to access all the files it needs to - in particular
directories under Android/

To solve this problem, we can have the pass-through mount sit on top of
sdcardfs instead of the raw filesystem. This means we need to mount
sdcardfs even in case we're using FUSE, but we already needed to do this
anyway for other performance reasons.

Bug: 135341433
Test: atest AdoptableHostTest
Change-Id: I893d5e5076c5096d2d55212f643c9a857242e964
2019-12-10 16:49:16 +01:00
Oli Lan
9072cef152 Merge changes from topics "createapexdirs", "createapexrollbackdirs" am: 3e1c0478b9 am: 0ad91e40ea
am: f243a3b105

Change-Id: I29b4de125231880894571a003791f02c58ce1049
2019-12-10 05:09:30 -08:00
Oli Lan
0c871647ff Create DE_n and CE_n APEX data directories. am: 94457217cb am: e7216f643d
am: 3f26f52ede

Change-Id: I0ce19d096e41b7a3879a1c63a211fc62ee7b93e0
2019-12-10 05:09:26 -08:00
Oli Lan
f243a3b105 Merge changes from topics "createapexdirs", "createapexrollbackdirs" am: 3e1c0478b9
am: 0ad91e40ea

Change-Id: I63e3a68a9d197c89aa195409c9847d6334f1dd14
2019-12-10 05:07:29 -08:00
Oli Lan
3f26f52ede Create DE_n and CE_n APEX data directories. am: 94457217cb
am: e7216f643d

Change-Id: I2afb35d4744224f19e3dafb327ba26f3348e09a5
2019-12-10 05:07:26 -08:00
Oli Lan
0ad91e40ea Merge changes from topics "createapexdirs", "createapexrollbackdirs"
am: 3e1c0478b9

Change-Id: I8ec5a0d3d1519eec788604dbaa5e41b869b8d428
2019-12-10 05:04:20 -08:00
Oli Lan
e7216f643d Create DE_n and CE_n APEX data directories.
am: 94457217cb

Change-Id: I5e2a86ae85152b2ea36547783a86ccae654eb6ea
2019-12-10 05:04:17 -08:00