Commit graph

6050 commits

Author SHA1 Message Date
Jahdiel Alvarez
d7c42966b9 Verify if pid actually killed for processes with open files
Its possible for vold to read a pid from procfs, the pid is killed
externally and then vold tries to kill it. In this scenario, we sleep
for 5s without needing it. Verify the return value from the kill syscall
and validate that the pid was killed, if the pid didn't exist at the
moment of the kill call, then don't count the pid as being killed.

Test: Boots successfully
Bug: 307801020
Change-Id: Ie127108b85be7249cf8b2881f4917d653d032186
2023-10-30 09:50:48 -07:00
Eric Biggers
b5c02ec925 Merge "Rename "user key" methods in vold" into main 2023-10-25 16:24:44 +00:00
Eric Biggers
a53a66caed Rename "user key" methods in vold
Rename methods that refer to "user key" to be more precise about what
they mean.  For more details, see the corresponding frameworks/base
changes (I202ebbfd2b4f79fedb3ed120a8ad81500c126894 and
I5894beb97823dced5954e405d779fada49c79e8d).

No change in behavior except for some changed log messages.

Flag: exempt, mechanical refactoring only
Test: presubmit
Change-Id: I9edcb557172395f4f6cf8e837efcc06fcfefb37d
2023-10-19 19:58:46 +00:00
Eric Biggers
f15785a54d Merge changes If530edaf,I7f11a135,I28412f24,Ia27a61fa,If221e239 into main
* changes:
  Revert "fskeyring & userspace reboot: support CE keys"
  Evict adoptable storage CE and DE keys when possible
  Don't erase key from s_new_ce_keys on eviction
  Call fscrypt_destroy_volume_keys() under mCryptLock
  Fold read_and_install_user_ce_key() into fscrypt_unlock_user_key()
2023-10-06 19:52:39 +00:00
Eric Biggers
01604fb13f Revert "fskeyring & userspace reboot: support CE keys"
Userspace reboot turned out to be a dead end and is no longer supported.
Therefore, remove the code from vold that handled keeping CE storage
unlocked past the userdata filesystem being unmounted and mounted.

This is a revert of commit 1c6731c649 (https://r.android.com/1254615)
with various conflicts resolved.

Bug: 292469129
Change-Id: If530edaf7c1566dd3bd8b1322f935f38a2e66beb
Merged-In: If530edaf7c1566dd3bd8b1322f935f38a2e66beb
(cherry picked from commit 2b97a88ba4)
2023-10-06 15:30:18 +00:00
Eric Biggers
1eddb7cb6d Evict adoptable storage CE and DE keys when possible
Adoptable storage CE and DE keys were not being explicitly evicted,
resulting in the benefits of key eviction not being fully realized on
devices that use adoptable storage.  Fix this by evicting the adoptable
storage keys when the corresponding internal storage keys are evicted:

- In lockUserKey, evict the CE keys for adoptable storage volumes, not
  just the CE key for internal storage as was done before.

- In destroyUserKey, evict the user's CE and DE keys for adoptable
  storage, not just the internal storage keys as was done before.

To make this possible, starting keeping track of the EncryptionPolicy of
each currently installed adoptable storage key.

(This CL is reworked from https://r.android.com/2660878,
 original author Arnab Sen <arnabse@amazon.com>)

Test: On Cuttlefish with config_multiuserMaxRunningUsers changed to 1:
    sm set-virtual-disk true
    sm partition disk:7,416 private
    pm create-user 10
    am start-user 10
    am stop-user 10
    # Verified that this fails with "Required key not available".
    touch /mnt/expand/f1ad173b-d6d9-4948-8eb7-ccdd7b053b22/misc_ce/10/foo.txt
    am start-user 10
    pm remove-user 10
    # Checked for all the expected "Evicted fscrypt key" messages.
    # 2 from when user was stopped, and 4 from when user was removed.
    adb logcat | grep Evicted

Change-Id: I7f11a135d8550618cd96013f834cebd54be5ef84
Merged-In: I7f11a135d8550618cd96013f834cebd54be5ef84
(cherry picked from commit 68fd3689a1)
2023-10-06 15:30:16 +00:00
Eric Biggers
0798ed5470 Don't erase key from s_new_ce_keys on eviction
Erasing a key from s_new_ce_keys is equivalent to destroying it, so it
shouldn't be done when the key is merely being evicted.

This didn't matter in practice since eviction requests don't come in
before the key gets persisted, but fix this to avoid confusion.

Test: see I7f11a135d8550618cd96013f834cebd54be5ef84
Change-Id: I28412f243925b5a7242449b617fe9de9c90912b6
Merged-In: I28412f243925b5a7242449b617fe9de9c90912b6
(cherry picked from commit 3529302ede)
2023-10-06 15:30:15 +00:00
Eric Biggers
7862729266 Call fscrypt_destroy_volume_keys() under mCryptLock
Everything in FsCrypt.cpp seems to run under VolumeManager::mCryptLock,
except for fscrypt_destroy_volume_keys() which uses mLock instead.

This was sort of okay because fscrypt_destroy_volume_keys() didn't
operate on any in-memory data structures.  However, that is going to be
changed.  Therefore, rework VoldNativeService::forgetPartition() to call
fscrypt_destroy_volume_keys() under mCryptLock.

Test: see I7f11a135d8550618cd96013f834cebd54be5ef84
Change-Id: Ia27a61faf2fdd546cdbddb2a3985c7c6696f6aa6
Merged-In: Ia27a61faf2fdd546cdbddb2a3985c7c6696f6aa6
(cherry picked from commit ce86e24d23)
2023-10-06 15:30:13 +00:00
Eric Biggers
fc1df0eae0 Fold read_and_install_user_ce_key() into fscrypt_unlock_user_key()
No change in behavior, except for removing a redundant check of
's_ce_policies.count(user_id)' and removing an extra ERROR message.

Test: see I7f11a135d8550618cd96013f834cebd54be5ef84
Change-Id: If221e23991e8e04138ae7dbdafe8160b00893655
Merged-In: If221e23991e8e04138ae7dbdafe8160b00893655
(cherry picked from commit 92428b247f)
2023-10-06 15:30:09 +00:00
Xin Li
ab9fe7e68a Merge "Merge Android 14" into main 2023-10-06 05:34:19 +00:00
Xin Li
a4f866af63 Merge Android 14
Bug: 298295554
Merged-In: Ic9bc7a7971790fa19a04181b6f89a33a0088bdd8
Change-Id: I4ac11a6613a6a01fe24ac273d7e2e25497309c25
2023-10-05 15:45:30 -07:00
Treehugger Robot
963b84c497 Merge "Handle errors corrected exit status returned by fsck" into main am: 81ed259a35
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2651499

Change-Id: I31ecc8519bd6b450c70353ad6ba18e7ef378d7bc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-12 02:13:14 +00:00
Treehugger Robot
81ed259a35 Merge "Handle errors corrected exit status returned by fsck" into main 2023-09-12 01:03:08 +00:00
Pawan Wagh
063b03d410 Merge "Adding corpus for vold fuzzer" into main am: b6f66fd7b4
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2741033

Change-Id: Ic9d4b295db45c8b53dfc40454ef4a32b2cf2a9dd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-08 07:42:26 +00:00
Pawan Wagh
b6f66fd7b4 Merge "Adding corpus for vold fuzzer" into main 2023-09-08 06:53:26 +00:00
Himanshu Gupta
8422dde06e Merge "Adding public volume mounts for clone user." into main am: 4a8594b223
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2679182

Change-Id: I1f1d9e598806a5fa143d8a745f95ebdf2dadab52
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-07 10:49:20 +00:00
Himanshu Gupta
4a8594b223 Merge "Adding public volume mounts for clone user." into main 2023-09-07 10:13:05 +00:00
Pawan Wagh
efe3c891bd Adding corpus for vold fuzzer
Generated corpus using binder2corpus tool from recordings
of vold transactions and using it with vold service fuzzer.

Test: m vold_native_service_fuzzer && adb sync data && adb shell /data/fuzz/arm64/vold_native_service_fuzzer/vold_native_service_fuzzer /data/fuzz/arm64/vold_native_service_fuzzer/vold_native_service_fuzzer_corpus -runs=1000
Bug: b/299138341
Change-Id: Ic9bc7a7971790fa19a04181b6f89a33a0088bdd8
2023-09-06 21:20:16 +00:00
Daeho Jeong
4922ef2616 Merge "Correct reserved blocks to segments" into main am: ab2b49bb74
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2736813

Change-Id: If2eed3d67a9b1250b99a02b1d1043e0f24e223cc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-31 23:53:45 +00:00
Daeho Jeong
ab2b49bb74 Merge "Correct reserved blocks to segments" into main 2023-08-31 22:46:23 +00:00
Daeho Jeong
b868a88c1a Correct reserved blocks to segments
Align units to a segment unit when adjusting free segment number.

Test: run the smart idle maint service.
Change-Id: I4fd74ac92adc4ae1a0ded4a7df75a690d829eb20
Signed-off-by: Daeho Jeong <daehojeong@google.com>
2023-08-31 12:54:01 -07:00
Jooyung Han
d592cd545b Merge "Do not read ro.apex.updatable." into main am: 170f15bb4c
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2727653

Change-Id: I1bfea3565d290b6723c1d8727fbfd748d91a43c9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-31 02:35:21 +00:00
Jooyung Han
170f15bb4c Merge "Do not read ro.apex.updatable." into main 2023-08-31 01:11:11 +00:00
himanshuz
0ad0862159 Adding public volume mounts for clone user.
Public SdCard Volumes are mounted only for user 0
(foreground user). This gives ENONT if the cloned
user tries to access the files in SdCard with
paths like "/storage/AB02-G212/DCIM/"

This change adds SdCard Volume mnt under
/mnt/usr/<cloned-user>/ which allows cloned apps
access to SdCard via direct file paths.

Bug: 203395175
Test: Manual by building and flashing device.
Change-Id: I091c40d3cb19915145cd5af40d1e79d5a9ecfa02
2023-08-29 10:38:43 +00:00
Jooyung Han
a9f2171c42 Do not read ro.apex.updatable.
We no longer support ro.apex.updatable=false case. Hence no need to read
it.

Bug: 297460439
Test: device boots
Change-Id: I9b71ea96052741073f092ca6abcfbe92a927128a
2023-08-25 15:38:12 +09:00
Xin Li
e737fd0a43 Merge Android U (ab/10368041)
Bug: 291102124
Merged-In: Idda5d816c2a012afa35658f1b2d86ae2787c1faf
Change-Id: I9be9d1ad2b5b186bb8276263b3b42297ebfa332f
2023-08-17 16:51:54 -07:00
Paul Lawrence
0923cc69d7 Merge "Add vdc volume getStorageSize" into main am: f05039392c
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2706217

Change-Id: I82ad84f8b63fb5f9204a35e1940cb9a77d45bc23
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-15 15:36:27 +00:00
Paul Lawrence
f05039392c Merge "Add vdc volume getStorageSize" into main 2023-08-15 14:51:08 +00:00
Eric Biggers
59e7388536 Merge "Revert "Introduce ro.crypto.uses_fs_ioc_add_encryption_key property"" into main am: 50e681b4ba
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2705760

Change-Id: I2ed5f6e758fc48bc842c05652c8c002edaae991a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-15 00:44:25 +00:00
Paul Lawrence
d73dfd4ab0 Add vdc volume getStorageSize
StorageStatsManager.getTotalBytes currently takes the size of /data and
rounds up to known probable sizes to guess the size of internal storage.
This is not always correct.

Instead, find the device /data is on and get the size of that device.
This should give a more accurate answer.

Bug: 295358118
Test: vdc volume getStorageSize returns storage size
Change-Id: I907892041b1ce2cd72092a9877ac34c12bf3f254
2023-08-14 23:51:39 +00:00
Eric Biggers
50e681b4ba Merge "Revert "Introduce ro.crypto.uses_fs_ioc_add_encryption_key property"" into main 2023-08-14 20:54:30 +00:00
Jooyung Han
6d57d3a9fa Merge changes from topic "revert-2685449-apexdata-dirs-NPLMAAVHNV" into main am: 866faf55e3
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2705735

Change-Id: I074c6b9bc82169bc4ce611bd4bf2aacd63816f56
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-11 23:34:11 +00:00
Tomasz Wasilczyk
affd3c30cc Merge "Use String8/16 c_str" into main am: 920fe9b065
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2705933

Change-Id: I44bd263aab55b4a1c9b73215a1719e02dbc6cdfe
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-11 23:33:01 +00:00
Jooyung Han
866faf55e3 Merge changes from topic "revert-2685449-apexdata-dirs-NPLMAAVHNV" into main
* changes:
  Use /data/misc/apexdata for the list of APEXes
  Revert "Use apexservice to get the list of apexes"
2023-08-11 23:23:18 +00:00
Tomasz Wasilczyk
920fe9b065 Merge "Use String8/16 c_str" into main 2023-08-11 22:56:12 +00:00
Eric Biggers
2114e26501 Revert "Introduce ro.crypto.uses_fs_ioc_add_encryption_key property"
This reverts commit 78f806198f.

There is no code that reads this system property, logcat already shows
whether the FS keyring is being used, and all devices launching with
Android 11 and later are guaranteed to use the FS keyring anyway.

Bug: 154327249
Change-Id: Id906efedd89d5bcac5370fb141cdbf7848932d95
2023-08-11 20:27:44 +00:00
Tomasz Wasilczyk
fa1b3971fd Use String8/16 c_str
Bug: 295394788
Test: make checkbuild
Change-Id: I6029b226006c4e82849411adfe539d5c43763e18
2023-08-11 16:12:17 +00:00
Jooyung Han
64d727c503 Use /data/misc/apexdata for the list of APEXes
vold_prepare_subdirs should create apexdata directories for each APEX.
Previously, it gets the list by scanning /apex directory. However,
vold/vold_prepare_subdirs run in the bootstrap mount namespace, they can
see only bootstrap apexes in /apex. The reason why it worked was that
unintended side effects of how we managed /apex directory for both mount
namespace.

Instead, since apexdata directories are already populated by init in
/data/misc/apexdata, we can use that directory for the same purpose.

Bug: 295345486
Test: CtsPackageSettingHostTestCases
Change-Id: I453cd59f54ccbb140f73b5e8576b36fa49f9bc59
2023-08-12 01:05:53 +09:00
Jooyung Han
6d07925510 Revert "Use apexservice to get the list of apexes"
Revert submission 2685449-apexdata-dirs

Reason for revert: b/295345486 performance regression.

Reverted changes: /q/submissionid:2685449-apexdata-dirs

Bug: b/295345486
Test: n/a
Change-Id: I710a416398148b544635e32e6b8066fb0560171f
2023-08-12 00:45:30 +09:00
Jooyung Han
f10ff3ad79 Merge "Use apexservice to get the list of apexes" into main am: d54caf0598
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2685449

Change-Id: I53d9757abead3b69e832bc906b7bf747399f8180
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-09 07:15:45 +00:00
Jooyung Han
d54caf0598 Merge "Use apexservice to get the list of apexes" into main 2023-08-09 06:37:02 +00:00
David Anderson
ba9097a253 Merge "vold: fix idlemaint abort may hold the wakelock" into main am: 1d0290c4fb
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2672655

Change-Id: I94c330852d10c8c9eda83023d50f8ad0252ade28
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-03 23:07:34 +00:00
David Anderson
1d0290c4fb Merge "vold: fix idlemaint abort may hold the wakelock" into main 2023-08-03 22:28:28 +00:00
Jooyung Han
443a73b100 Use apexservice to get the list of apexes
In this change, the logic to get the list of apexes is replaced with
the query to apexservice, which is the source of truth. This dedups
the manual scanning of /apex for the apex list, which should be
internal to apexd. (Note how vold_prepare_subdirs filtered out
directories with "@" character).

This also makes vold_prepare_subdirs immune to the upcoming changes:
/apex directory containing only bootstrap APEXes in the bootstrap NS.

Until now, getting the list of apexes by scanning /apex was okay
because of the accidental fact that /apex directory has directories
for all the apexes, not only bootstrap apexes.

Bug: 293949266
Bug: 293546778
Test: CtsPackageSettingHostTestCases
Change-Id: I3fe373ca6f4c2281439bb2449845a1a14357131e
2023-08-01 10:51:49 +00:00
Ryan Prichard
727ef62350 Merge "Add a ZeroingAllocator::rebind<Other> for Other==char" into main am: c2b3fefa01
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2673490

Change-Id: Ib95f19d558139205647dfa086b92c966bcdbc7ba
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-26 00:10:17 +00:00
Ryan Prichard
c2b3fefa01 Merge "Add a ZeroingAllocator::rebind<Other> for Other==char" into main 2023-07-25 23:32:50 +00:00
Ryan Prichard
4c513f2c7e Add a ZeroingAllocator::rebind<Other> for Other==char
Newer versions of libc++ check that an allocator can be rebound to the
same element type. We need to add a rebind member to ZeroingAllocator
to fix this compiler error:

prebuilts/clang/host/linux-x86/clang-r498229/include/c++/v1/vector:376:19: error: static assertion failed due to requirement 'is_same<android::vold::ZeroingAllocator, std::allocator<char>>::value': [allocator.requirements] states that rebinding an allocator to the same type should result in the original allocator
    static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It likely doesn't matter in practice because this allocator is only
used with std::vector, which probably doesn't use allocator rebinding,
because it won't allocate an internal node type (e.g. unlike std::map,
std::list, etc).

Alternatively, ZeroingAllocator could be changed to a
ZeroingAllocator<T> that can zero arbitrary types, but it doesn't seem
necessary currently, and types other than char wouldn't be used.

Bug: b/175635923
Test: treehugger
Change-Id: I42e9d8f02a18637fc67e94cc1358d2ed733a7268
2023-07-24 21:36:32 -07:00
Li Chong
5b224dc337 vold: fix idlemaint abort may hold the wakelock
when the idlemaint run is working, if two or more idlemaint abort concurrency are working.
all idlemaint abort will hold the wakelock, until idlemaint run finished,
but it just nofity one idlemaint abort thread to stop and release the wakelock.
Remaining idlemaint abort threads will hold the wakelock until next idlemaint run to notify them.

Bug: 292383791
Test: see the issue Description

Change-Id: I5312be2e0e92c41483cab26e627a4ae562e5aed8
2023-07-24 15:23:30 +08:00
Martijn Coenen
7f304c1cf3 Merge "SM: Change volume mountUserId for new user" into main am: c7bed872c0
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2657116

Change-Id: Ice2d9032bb1c9186b1b39d0a0a5f9ed1115537f3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-17 08:34:45 +00:00
Martijn Coenen
c7bed872c0 Merge "SM: Change volume mountUserId for new user" into main 2023-07-17 08:05:33 +00:00