Commit graph

4427 commits

Author SHA1 Message Date
Satya Tangirala
6ef4e37351 Use AServiceManager_waitForService() to connect to keystore2
Vold currently uses AServiceManager_getService() to connect to
keystore2, which has an internal timeout of 5s. Since a lot of vold
keystore2 connection failures are fatal, we instead use
AServiceManager_waitForService(), which will wait efficiently for
keystore2 to start, instead of timing out after 5s.

Bug: 185934601
Test: Cuttlefish boots.
Change-Id: Ib4e977a997e020082382e0686f448d1aa72834ec
2021-05-11 19:30:30 -07:00
Treehugger Robot
93dd933d85 Merge "Show names of processes killed by KillProcessesWithOpenFiles()" 2021-05-11 20:24:49 +00:00
Eric Biggers
297b23837e Merge "cryptfs: kill processes more quickly in wait_and_unmount()" 2021-05-11 20:00:14 +00:00
Eric Biggers
b4faeb8d44 cryptfs: kill processes more quickly in wait_and_unmount()
In wait_and_unmount(), kill the processes with open files after umount()
has been failing for 2 seconds rather than 17 seconds.  This avoids a
long boot delay on devices that use FDE.

Detailed explanation:

On FDE devices, vold needs to unmount the tmpfs /data in order to mount
the real, decrypted /data.  On first boot, it also needs to unmount the
unencrypted /data in order to encrypt it in-place.

/data can't be unmounted if files are open inside it.  In theory, init
is responsible for killing all processes with open files in /data, via
the property trigger "vold.decrypt=trigger_shutdown_framework".

However, years ago, commit 6e8440fd50 ("cryptfs: kill processes with
open files on tmpfs /data") added a fallback where vold kills the
processes itself.  Since then, in practice people have increasingly been
relying on this fallback, as services keep being added that use /data
but don't get stopped by trigger_shutdown_framework.

This is slowing down boot, as vold sleeps for 17 seconds before it
actually kills the processes.

The problematic services include services that are now started
explicitly in the post-fs-data trigger rather than implicitly as part of
a class (e.g., tombstoned), as well as services that now need to be
started as part of one of the early-boot classes like core or early_hal
but can still open files in /data later (e.g. keystore2 and credstore).

Another complication is that on default-encrypted devices (devices with
no PIN/pattern/password), trigger_shutdown_framework isn't run at all,
but rather it's expected that the relevant services simply weren't
started yet.  This means that we can't fix the problem just by fixing
trigger_shutdown_framework to kill all the needed processes.

Therefore, given that the vold fallback is being relied on in practice,
and FDE won't be supported much longer anyway (so simple fixes are very
much preferable here), let's just change wait_and_unmount() in vold to
use more appropriate timeouts.  Instead of waiting for 17 seconds before
killing processes, just wait for 2 seconds.  Keep the total timeout of
20 seconds, but spend most of it retrying killing the processes, and
only if the unmount is still failing.

This avoids the long boot delays in practice.

Bug: 187231646
Bug: 186165644
Test: Tested FDE on Cuttlefish, and checked logcat to verify that the
      boot delay is gone.
Change-Id: Id06a9615a87988c8336396c49ee914b35f8d585b
2021-05-10 20:44:07 -07:00
Eric Biggers
c78ae60087 Show names of processes killed by KillProcessesWithOpenFiles()
Otherwise only the pids are shown, and it's hard to tell which
processes actually got killed.

Bug: 187231646
Change-Id: Icccf60d0ad4439d702f36ace31abe092df1c69c2
2021-05-10 17:34:11 +00:00
Xin Li
ef439c5367 Merge "DO NOT MERGE - Mark RQ2A.210105.001 as merged." 2021-05-08 01:28:13 +00:00
Xin Li
140116266e DO NOT MERGE - Mark RQ2A.210105.001 as merged.
Bug: 180401296
Merged-In: Ic37985f98e6cbfe4fa38b981d3332c4dfc40c5b8
Change-Id: Ic82b58f8975ae7b5410d87536342f83e827a7893
2021-05-07 14:32:31 -07:00
rickywai
ae11ab712f Merge "Always unmount data and obb directory that mounted" 2021-05-06 08:09:05 +00:00
Ricky Wai
5f2a9fee66 Always unmount data and obb directory that mounted
Otherwise, when system removes user's volume, it will hang
as there are mounts (obb and data mounts) still remain mounted in system.

Bug: 187122943
Test: atest UserLifecycleTests#managedProfileUnlock_stopped, it's not blocked anymore

Change-Id: Ic37985f98e6cbfe4fa38b981d3332c4dfc40c5b8
2021-05-05 14:44:16 +00:00
Alan Stokes
b2678b6654 Merge "Only kill apps with storage app data isolation enabled" 2021-05-05 14:16:00 +00:00
Eric Biggers
7505efbd5d Merge "Log error message if setting project quota ID fails" 2021-05-04 16:06:14 +00:00
Eric Biggers
39aa9584b1 Log error message if setting project quota ID fails
Otherwise, the only sign of what went wrong may be system_server
logging a "ServiceSpecificException".

Bug: 187079978
Change-Id: I59b2ba2b0e679dfd1ec1fd8fff6790256fbfdf29
2021-05-03 12:39:36 -07:00
Ricky Wai
23356377ae Only kill apps with storage app data isolation enabled
Originally it kills all the apps with obb and data mounted.
Due to recent changes, all apps will have obb and data dirs mounted
in default root namespace. Hence all apps will be killed by
by KillProcessesWithMounts().

To fix this, we also check if the dir is mounted as tmpfs,
as the default namespace one is bind mounted to lowerfs,
which app data isolation is mounted as tmpfs, so we only
kill the process that have obb dir mounted as tmpfs.

Bug: 148049767
Test: Able to boot without warnings
Change-Id: I5f862ad6f64f5df739b68ea7c9815352bae3be5c
Merged-In: I45d9a63ed47cbc27aebb63357a43f51ad62275db
2021-04-30 13:58:07 +00:00
Treehugger Robot
d2bb367549 Merge "Fix cryptfs RSA signing with keystore2" 2021-04-26 18:51:13 +00:00
Hasini Gunasinghe
68bdb45cf8 Merge "Make vold use the updated keystore 2 API for storage keys." 2021-04-23 22:39:04 +00:00
Eric Biggers
940c0e5f6e Fix cryptfs RSA signing with keystore2
Fix KeymasterOperation::updateCompletely() to not treat an empty output
as an error, since for RSA signing (used by cryptfs / FDE) it is
expected that the output from update() be empty.  The output is instead
produced at the end by finish().

This is one of a set of changes that is needed to get FDE working again
so that devices that launched with FDE can be upgraded to Android 12.

Bug: 186165644
Change-Id: Icf120f8b9526d051d0ebe16bc8ad1edf712241e1
2021-04-23 10:44:41 -07:00
Jaegeuk Kim
177b9db866 Merge "mkfs_f2fs: give the log in kernel" 2021-04-20 22:08:26 +00:00
Janis Danisevskis
3915b08f80 Make vold use the updated keystore 2 API for storage keys.
This CL updates vold to use the updated storage key API that provides an
optional upgraded key blob. In this patch the upgraded key blob is not
yet stored by vold.

Bug: 185811713
Test: N/A
Change-Id: I39eeb20df0eb2b023479f3adebab264d29d00048
2021-04-20 12:53:12 -07:00
Jaegeuk Kim
2c1380f1ab mkfs_f2fs: give the log in kernel
It's very useful to see the mkfs log in console to debug any issues.

Bug: 172378121
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: Icdac3609860cf0bba3fa758cead885bd4960f2c0
2021-04-15 20:24:04 -07:00
Treehugger Robot
5e5819a761 Merge "vold: add getUnlockedUsers() method to Binder interface" 2021-04-15 02:33:22 +00:00
Eric Biggers
18ba15223c vold: add getUnlockedUsers() method to Binder interface
This is needed so that system_server can remind itself about which users
have their storage unlocked, if system_server is restarted due to a
userspace reboot (soft restart).

Bug: 146206679
Test: see I482ed8017f7bbc8f7d4fd5a2c0f58629317ce4ed
Change-Id: I02f0494d827094bd41bcfe5f63c24e204b728595
(cherry picked from commit 1799debfd6)
2021-04-13 10:53:00 -07:00
Satya Tangirala
08873d0d7d Merge changes from topic "vold-use-keystore2"
* changes:
  Remove Keymaster::isSecure() and simplify callers
  Make vold use keystore2 instead of keymaster
  Remove HardwareAuthToken support from vold::Keymaster
2021-04-08 00:48:19 +00:00
Satya Tangirala
23452c1e3a Remove Keymaster::isSecure() and simplify callers
Now that isSecure() always returns true, we can remove it and simplify
all the callers (i.e. cryptfs). Refer to the commit description for
Iaebfef082eca0da8a305043fafb6d85e5de14cf8 for why this function always
return true.

Bug: 181910578
Test: Cuttlefish and bramble boot
Change-Id: I185dd8180bd7842b05295263f0b1aa7205329a88
2021-04-08 00:47:54 +00:00
Satya Tangirala
e8de4ffd73 Make vold use keystore2 instead of keymaster
Make vold use keystore2 for all its operations instead of directly using
keymaster. This way, we won't have any clients that bypass keystore2,
and we'll no longer need to reserve a keymaster operation for vold.

Note that we now hardcode "SecurityLevel::TRUSTED_ENVIRONMENT" (TEE)
when talking to Keystore2 since Keystore2 only allows TEE and STRONGBOX.
Keystore2 presents any SOFTWARE implementation as a TEE to callers when
no "real" TEE is present. As far as storage encryption is concerned,
there's no advantage to using a STRONGBOX when a "real" TEE is present,
and a STRONGBOX can't be present if a "real" TEE isn't, so asking
Keystore2 for a TEE is the best we can do in any situation.

The difference in behaviour only really affects the full disk encryption
code in cryptfs.cpp, which used to explicitly check that the keymaster
device is a "real" TEE (as opposed to a SOFTWARE implementation) before
using it (it can no longer do so since Keystore2 doesn't provide a way
to do this).

A little code history digging (7c49ab0a0b in particular) shows that
cryptfs.cpp cared about two things when using a keymaster.
 - 1) that the keys generated by the keymaster were "standalone" keys -
      i.e. that the keymaster could operate on those keys without
      requiring /data or any other service to be available.
 - 2) that the keymaster was a non-SOFTWARE implementation so that things
      would still work in case a "real" TEE keymaster was ever somehow
      added to the device after first boot.

Today, all "real" TEE keymasters always generate "standalone" keys, and
a TEE has been required in Android devices since at least Android N. The
only two exceptions are Goldfish and ARC++, which have SOFTWARE
keymasters, but both those keymasters also generate "standalone" keys.

We're also no longer worried about possibly adding a "real" TEE KM to
either of those devices after first boot. So there's no longer a reason
cryptfs.cpp can't use the SOFTWARE keymaster on those devices.

There's also already an upgrade path in place (see
test_mount_encrypted_fs() in cryptfs.cpp) to upgrade the kdf that's
being used once a TEE keymaster is added to the device. So it's safe for
cryptfs.cpp to ask for a TEE keymaster from Keystore2 and use it
blindly, without checking whether or not it's a "real" TEE, which is why
Keymaster::isSecure() just returns true now. A future patch will remove
that function and simplify its callers.

Bug: 181910578
Test: cuttlefish and bramble boot. Adding, switching between, stopping
      and removing users work.
Change-Id: Iaebfef082eca0da8a305043fafb6d85e5de14cf8
2021-04-08 00:16:01 +00:00
Satya Tangirala
e13617100d Remove HardwareAuthToken support from vold::Keymaster
HardwareAuthTokens are no longer used by vold since Android P. So remove
the auth token parameter from vold. This patch doesn't remove the token
from IVold.aidl, and the methods in VoldNativeService.cpp return an
error if a non-empty auth token is passed to them.

Bug: 181910578
Test: cuttlefish and bramble boot with patch
Change-Id: I1a9f54e10f9efdda9973906afd0a5de5a699ada5
2021-04-07 02:05:35 -07:00
Alan Stokes
159a11f600 Merge "Vold will always bind mount obb and data dirs to lowerfs" 2021-03-23 17:25:18 +00:00
Ricky Wai
259a49ae15 Vold will always bind mount obb and data dirs to lowerfs
So shell / root will always access to them directly not via fuse.
And zygote will be unmount these directories to prevent them being
abused for leaking app visibility.

Also, /mnt/androidwritable is not very useful now as it's the same as
/mnt/installer, but we should make shell / root to access /mnt/androidwritable
later and /mnt/installer should only access obb but not data dir.

Bug: 182997439
Test: Able to boot without errors
Test: df on /sdcard/Android/data shows it's no on fuse.
Change-Id: I2ad10b1e80c135f637d37ddf502ee010f89f4946
2021-03-22 16:12:50 +00:00
Martijn Coenen
717c1926fc Merge "vold: do not acquire lock when abort fuse" 2021-03-19 08:21:00 +00:00
lijiazi
ffe7622d83 vold: do not acquire lock when abort fuse
reboot maybe cause a deadlock scenario:

1:init->vdc->vold for abort_fuse blocked on futex hold by another
vold binder_x

2:binder_x blocked in binder_ioctl_write_read wait a dead service's
response

3:dead service is exiting and schedule a deferred work for put files
in binder_vma_close, after put files is completed, the binder_x will
eventually wake up

4:kworker execute binder_deferred_work is blocked on fuse request:
crash> bt 1707
PID: 1707   TASK: ffffffe366175e80  CPU: 2   COMMAND: "kworker/2:4"
 #0 [ffffff801b8b3ac0] __switch_to at ffffff962ce88a60
 #1 [ffffff801b8b3b10] __schedule at ffffff962e2d3d30
 #2 [ffffff801b8b3b70] schedule at ffffff962e2d3ff4
 #3 [ffffff801b8b3bc0] __fuse_request_send at ffffff962d20e008
 #4 [ffffff801b8b3c00] fuse_request_send at ffffff962d20deac
 #5 [ffffff801b8b3c30] fuse_flush at ffffff962d217fa4
 #6 [ffffff801b8b3c80] filp_close at ffffff962d0bd7b4
 #7 [ffffff801b8b3cb0] put_files_struct at ffffff962d0e7658
 #8 [ffffff801b8b3d30] binder_deferred_func at ffffff962dc9e60c
 #9 [ffffff801b8b3d90] process_one_work at ffffff962cee761c
 #10 [ffffff801b8b3e00] worker_thread at ffffff962cee7a68
 #11 [ffffff801b8b3e60] kthread at ffffff962ceecc14
waiting for init abort_fuse

suggested by maco, do not acquire lock when abort fuse.

Test: reboot stress test

Change-Id: If6dd7f5e9c413a16ba047204c33d82d6ff41c4ae
Signed-off-by: lijiazi <lijiazi@xiaomi.com>
2021-03-17 10:11:18 +00:00
Eric Biggers
759022d0f1 Merge "KeyStorage: improve logging for key generation" 2021-03-15 23:46:54 +00:00
Eric Biggers
b2024e0349 KeyStorage: improve logging for key generation
The error messages that are printed when probing for rollback resistance
support on a device that doesn't support rollback-resistant keys can
make it sound like something is going wrong.  Print a WARNING message
afterwards to try to make it clear what is going on.  Also adjust or add
DEBUG messages when starting to generate each key so that it's easier to
distinguish the log messages for different key generation operations.

Bug: 182815123
Test: boot on device that doesn't support rollback-resistant keys and
      check log.
Change-Id: I37a13eb5c1e839fb94581f3e7ec1cd8da0263d2b
2021-03-15 12:44:36 -07:00
Treehugger Robot
05bb5cc71e Merge "Avoid killing the FUSE daemon during unmount" 2021-03-05 18:08:14 +00:00
Zim
75273001a2 Avoid killing the FUSE daemon during unmount
The FUSE daemon is often holding fds on behalf of other apps and if a
volume is ejected the daemon would often get killed first while vold
is walking /proc/<pid>/fd to kill pids with open fds on the
volume. This is required for the volume unmount successfully.

To mitigate this, we avoid killing the FUSE daemon during the usual
/proc walk. This ensures that we first send SIGINT, SIGTERM and
SIGKILL to other apps first. There is an additional SIGKILL attempt
and on that last attempt, we kill the FUSE daemon as a last resort

Test: Manual
Bug: 171673908
Change-Id: I100d2ce4cb4c145cbb49e0696842e97dfba2c1c9
2021-03-05 11:05:16 +00:00
Abhijeet Kaur
2d0ea90538 Merge "Remove unused mount modes and re-number the modes for consistency" 2021-03-03 10:09:46 +00:00
Treehugger Robot
ca3fbd1e4b Merge "Set a default ACL on /data/media/userId." am: f6546171af
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1603534

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I13d1ee215c805b25d73e3d39508ea05cdc60b703
2021-03-02 19:03:54 +00:00
Treehugger Robot
f6546171af Merge "Set a default ACL on /data/media/userId." 2021-03-02 09:25:52 +00:00
Treehugger Robot
b06061cace Merge "[vold] expose binder headers to dependent modules" am: 51ff06df22
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1607482

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I32b3d8d656a07491b644c8fd05aa38b8031597a4
2021-02-26 04:33:56 +00:00
Treehugger Robot
51ff06df22 Merge "[vold] expose binder headers to dependent modules" 2021-02-26 03:35:10 +00:00
Songchun Fan
f77beb516b [vold] expose binder headers to dependent modules
This allows libincremental_aidl-cpp to be built via cc_library instead
of aidl_interface.

BUG: 181266844
Test: builds
Change-Id: I4f0bc82629c0df758467aa074274b30f9dc6718d
2021-02-25 15:32:16 -08:00
Kalesh Singh
c08bc3b0b8 Merge "vold: Use Wakelock::tryGet()" am: 8439ab27d6
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1600813

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I4b028c047da40cbbd20c0a99d4c957d87bfcf0c2
2021-02-24 22:14:06 +00:00
Kalesh Singh
8439ab27d6 Merge "vold: Use Wakelock::tryGet()" 2021-02-24 18:49:58 +00:00
Abhijeet Kaur
e715ec1364 Remove unused mount modes and re-number the modes for consistency
Also, add REMOUNT_MODE_ANDROID_WRITABLE to return "/mnt/runtime/write".

Bug: 148454884
Test: builds
Change-Id: I5a38c88f46034c494604bb001cf4d4c400c8f73e
2021-02-24 14:52:37 +00:00
Martijn Coenen
5adf92a988 Set a default ACL on /data/media/userId.
This directory is used as a root for external storage on adopted storage
devices. It needs to be writable by processes holding the AID_MEDIA_RW
GID permission; in particular, it should be writable by the FUSE daemon.

On devices with sdcardfs, this was ensured automatically, because
sdcardfs presented a view of this directory that was writable, that we
could use for the FUSE daemon. But on devices without sdcardfs, the FUSE
daemon sees the raw filesystem and its permissions. This also means that
files created by the FUSE daemon will have their uid/gid set to the uid
of the FUSE daemon; to ensure these files stay writable to other system
applications that have AID_MEDIA_RW, use a default ACL to make sure the
gid stays AID_MEDIA_RW.

In particular, this fixes an issue with app cloning, where we want the
FUSE daemon of user 0 to be able to access the files of the app clone
user, and vice versa.

Bug: 154057120
Test: inspect uid/gid of /data/media/0 and contents
Change-Id: Ic5d63457ec917ea407b900dbb7773d89311780c6
2021-02-24 12:45:09 +01:00
Kalesh Singh
98062dcd89 vold: Use Wakelock::tryGet()
Acquiring a wakelock can fail if the suspend service is unavailable.
Explicitly check that wakelock was acquired before performing
operations that require the device to stay on.

Bug: b/179229598
Test: Boot test on Pixel 4 device
Change-Id: If30087223e44098801a31d1bfd239ac22e891abe
2021-02-22 17:24:51 -05:00
Xin Li
0ee13dfc4f Mark ab/7061308 as merged in stage.
Bug: 180401296
Merged-In: I7124285f41c6a854ad5c86677bc94d78ddca5a97
Change-Id: Icf8db3d8557a3835e0834eec134bb4b111ec3af0
2021-02-20 00:24:42 -08:00
Treehugger Robot
2a3e67a9e0 Merge changes from topic "fsync-fixes" am: 6c36c6f421
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1590896

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ifacc42ef9b4abe897a598e3cd8dcef4650b8f5ff
2021-02-19 19:54:09 +00:00
Treehugger Robot
6c36c6f421 Merge changes from topic "fsync-fixes"
* changes:
  Add syncs when creating parent directories
  Sync parent directory in storeKeyAtomically()
  Move pathExists() to Utils.cpp
2021-02-19 19:23:47 +00:00
Dhiraj Jadhav
375884bd0a Merge "Revert "Revert "Revert "Set a default ACL on /data/media/userId."""" am: a98846d8d5
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1592902

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I7c3c8bd230bcc14471d127ddc2276634cd2b2a43
2021-02-18 18:45:58 +00:00
Dhiraj Jadhav
a98846d8d5 Merge "Revert "Revert "Revert "Set a default ACL on /data/media/userId."""" 2021-02-18 17:38:20 +00:00
Dhiraj Jadhav
72005fd1e6 Revert "Revert "Revert "Set a default ACL on /data/media/userId."""
This reverts commit ea9681e4cd.

Reason for revert: storage Permission causing b/179362637 adb push to fail

Change-Id: Ibc1d8b5b685c22545b7e2d15de58059960b87e14
2021-02-18 04:57:03 +00:00