Commit graph

4488 commits

Author SHA1 Message Date
Eric Biggers
27f3ab89d0 Merge changes I8d2bd67d,I704522b2
* changes:
  FsCrypt: silently skip "." and ".." when loading keys
  Utils: add IsDotOrDotDot() and use it in the appropriate places
2020-11-03 17:02:46 +00:00
Eric Biggers
9a67e05fc3 Merge "KeyUtil: don't use keepOld=true for system DE and volume keys" am: 4a969dba60 am: 1d692f3b7b am: 83ff4db88a
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1480696

Change-Id: I23bd8f557ddd143a9e1efa1d9e79a8181f9a5901
2020-11-03 00:43:46 +00:00
Eric Biggers
83ff4db88a Merge "KeyUtil: don't use keepOld=true for system DE and volume keys" am: 4a969dba60 am: 1d692f3b7b
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1480696

Change-Id: Idec4eb2c0afca69c0b322935397bea009f5683f1
2020-11-03 00:23:55 +00:00
Eric Biggers
2c9d6d6675 KeyUtil: don't use keepOld=true for system DE and volume keys
Commit 77df7f207d / http://aosp/1217657 ("Refactor to use
EncryptionPolicy everywhere we used to use raw_ref") unintentionally
made fscrypt_initialize_systemwide_keys() start specifying keepOld=true
(via default parameter value) when retrieving the system DE key, and
likewise for read_or_create_volkey() and volume keys.

As a result, if the associated Keymaster key needs to be upgraded, the
upgraded key blob gets written to "keymaster_key_blob_upgraded", but it
doesn't replace the original "keymaster_key_blob", nor is the original
key deleted from Keymaster.  This happens at every boot, eventually
resulting in the RPMB partition in Keymaster becoming full.

Only the metadata encryption key ever needs keepOld=true, since it's the
only key that isn't stored in /data, and the purpose of keepOld=true is
to allow a key that isn't stored in /data to be committed or rolled back
when a userdata checkpoint is committed or rolled back.

So, fix this bug by removing the default value of keepOld, and
specifying false everywhere except the metadata encryption key.

Note that when an affected device gets this fix, it will finally upgrade
its system DE key correctly.  However, this fix doesn't free up space in
Keymaster that was consumed by this bug.

Test: On bramble:
  - Flashed rvc-d1-dev build, with wiping userdata
  - Flashed a newer build, without wiping userdata
  - Log expectedly shows key upgrades:
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key: /metadata/vold/metadata_encryption/key
        D vold    : Upgrading key: /data/unencrypted/key
        D vold    : Upgrading key: /data/misc/vold/user_keys/de/0
        D vold    : Upgrading key: /data/misc/vold/user_keys/ce/0/current
  - Rebooted
  - Log unexpectedly shows the system DE key being upgraded again:
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key: /data/unencrypted/key
  - "keymaster_key_blob_upgraded" unexpectedly still exists:
        $ adb shell find /data /metadata -name keymaster_key_blob_upgraded
        /data/unencrypted/key/keymaster_key_blob_upgraded
  - Applied this fix and flashed, without wiping userdata
  - Log shows system DE key being upgraded (expected because due to the
    bug, the upgraded key didn't replace the original one before)
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key: /data/unencrypted/key
  - "keymaster_key_blob_upgraded" expectedly no longer exists
        $ adb shell find /data /metadata -name keymaster_key_blob_upgraded
  - Rebooted
  - Log expectedly doesn't show any more key upgrades
        $ adb logcat | grep 'Upgrading key'
Bug: 171944521
Bug: 172019387
(cherry picked from commit c493903732)
Merged-In: I42d3f5fbe32cb2ec229f4b614cfb271412a3ed29
Change-Id: I42d3f5fbe32cb2ec229f4b614cfb271412a3ed29
2020-11-02 16:10:09 -08:00
Eric Biggers
1d692f3b7b Merge "KeyUtil: don't use keepOld=true for system DE and volume keys" am: 4a969dba60
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1480696

Change-Id: I45f11f64c84b540a27cdc39af493a2ee4e552bce
2020-11-03 00:08:56 +00:00
Eric Biggers
6b84039847 FsCrypt: silently skip "." and ".." when loading keys
Avoid logging useless messages like:

    D vold    : Skipping non-key .
    D vold    : Skipping non-key ..
    D vold    : Skipping non-de-key .
    D vold    : Skipping non-de-key ..

Change-Id: I8d2bd67d554605a5ab9faadd3730870dfe0881f6
2020-11-02 15:47:42 -08:00
Eric Biggers
7bcf427369 Utils: add IsDotOrDotDot() and use it in the appropriate places
Change-Id: I704522b26acfb3e7c423d9a14d69ede513b50482
2020-11-02 15:47:24 -08:00
Eric Biggers
4a969dba60 Merge "KeyUtil: don't use keepOld=true for system DE and volume keys" 2020-11-02 23:31:23 +00:00
Eric Biggers
c493903732 KeyUtil: don't use keepOld=true for system DE and volume keys
Commit 77df7f207d / http://aosp/1217657 ("Refactor to use
EncryptionPolicy everywhere we used to use raw_ref") unintentionally
made fscrypt_initialize_systemwide_keys() start specifying keepOld=true
(via default parameter value) when retrieving the system DE key, and
likewise for read_or_create_volkey() and volume keys.

As a result, if the associated Keymaster key needs to be upgraded, the
upgraded key blob gets written to "keymaster_key_blob_upgraded", but it
doesn't replace the original "keymaster_key_blob", nor is the original
key deleted from Keymaster.  This happens at every boot, eventually
resulting in the RPMB partition in Keymaster becoming full.

Only the metadata encryption key ever needs keepOld=true, since it's the
only key that isn't stored in /data, and the purpose of keepOld=true is
to allow a key that isn't stored in /data to be committed or rolled back
when a userdata checkpoint is committed or rolled back.

So, fix this bug by removing the default value of keepOld, and
specifying false everywhere except the metadata encryption key.

Note that when an affected device gets this fix, it will finally upgrade
its system DE key correctly.  However, this fix doesn't free up space in
Keymaster that was consumed by this bug.

Test: On bramble:
  - Flashed rvc-d1-dev build, with wiping userdata
  - Flashed a newer build, without wiping userdata
  - Log expectedly shows key upgrades:
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key: /metadata/vold/metadata_encryption/key
        D vold    : Upgrading key: /data/unencrypted/key
        D vold    : Upgrading key: /data/misc/vold/user_keys/de/0
        D vold    : Upgrading key: /data/misc/vold/user_keys/ce/0/current
  - Rebooted
  - Log unexpectedly shows the system DE key being upgraded again:
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key: /data/unencrypted/key
  - "keymaster_key_blob_upgraded" unexpectedly still exists:
        $ adb shell find /data /metadata -name keymaster_key_blob_upgraded
        /data/unencrypted/key/keymaster_key_blob_upgraded
  - Applied this fix and flashed, without wiping userdata
  - Log shows system DE key being upgraded (expected because due to the
    bug, the upgraded key didn't replace the original one before)
        $ adb logcat | grep 'Upgrading key'
        D vold    : Upgrading key: /data/unencrypted/key
  - "keymaster_key_blob_upgraded" expectedly no longer exists
        $ adb shell find /data /metadata -name keymaster_key_blob_upgraded
  - Rebooted
  - Log expectedly doesn't show any more key upgrades
        $ adb logcat | grep 'Upgrading key'
Bug: 171944521
Bug: 172019387
Change-Id: I42d3f5fbe32cb2ec229f4b614cfb271412a3ed29
2020-10-30 14:53:43 -07:00
Eric Biggers
d6f1a98f4b Merge "Fix argument type for FS_IOC_GETFLAGS and FS_IOC_SETFLAGS" am: 569fb8365e am: 524e094991 am: 2fe31ededf
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1472321

Change-Id: Ica87f8b5d1a4eea3e403f5694f2557fa6891d002
2020-10-28 17:18:50 +00:00
Eric Biggers
2fe31ededf Merge "Fix argument type for FS_IOC_GETFLAGS and FS_IOC_SETFLAGS" am: 569fb8365e am: 524e094991
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1472321

Change-Id: I7d9b20e25b93c0f9707714027ab6c15fa9d224f7
2020-10-28 16:50:42 +00:00
Eric Biggers
524e094991 Merge "Fix argument type for FS_IOC_GETFLAGS and FS_IOC_SETFLAGS" am: 569fb8365e
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1472321

Change-Id: I5cb2651ee48ab2a9afb9ec5ded8259cd006ecbfe
2020-10-28 16:26:09 +00:00
Eric Biggers
569fb8365e Merge "Fix argument type for FS_IOC_GETFLAGS and FS_IOC_SETFLAGS" 2020-10-28 16:16:26 +00:00
Eric Biggers
f9d9ac29d0 Fix argument type for FS_IOC_GETFLAGS and FS_IOC_SETFLAGS
These ioctls take a pointer to an 'int' (or an 'unsigned int', it
doesn't matter), not an 'unsigned long'.  See 'man ioctl_iflags'.
Presumably it happened to work anyway because Android only runs on
little endian platforms.

Bug: 146419093
Bug: 163453310
Change-Id: I73099dafd4ee8d497c0a754149271871a37454f6
Signed-off-by: Eric Biggers <ebiggers@google.com>
2020-10-28 04:48:09 +00:00
Yo Chiang
a182ca0ef1 Merge "Add IVold::destroyDsuMetadataKey()" am: cb581cc8de am: 3ae0c6737c am: 9502610f8e
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1452395

Change-Id: I79d72f95e00888afa69f55b48e76f28d47972457
2020-10-26 06:37:07 +00:00
Yo Chiang
9502610f8e Merge "Add IVold::destroyDsuMetadataKey()" am: cb581cc8de am: 3ae0c6737c
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1452395

Change-Id: I7cb2b806de2f70e6ce569001d79f07a4ce6c8556
2020-10-26 06:20:25 +00:00
Yo Chiang
3ae0c6737c Merge "Add IVold::destroyDsuMetadataKey()" am: cb581cc8de
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1452395

Change-Id: I6241d71e331eebe0222696a052e40d2222a9c537
2020-10-26 05:49:35 +00:00
Yo Chiang
cb581cc8de Merge "Add IVold::destroyDsuMetadataKey()" 2020-10-26 05:27:36 +00:00
Treehugger Robot
4bcbd7a4d7 [automerger skipped] Merge "Set media folder +F for adopted storage as well" am: 739ca2c298 am: 19adff5f27 am: e2fefec3bb -s ours
am skip reason: Change-Id I08f13b57a4de3538e88b38eb95b0ac115a5a5ce8 with SHA-1 083221f5cf is in history

Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1397560

Change-Id: Iee4294f9e16c934cfc99daed87fd9ad7b678fe56
2020-10-22 05:50:25 +00:00
Treehugger Robot
e2fefec3bb Merge "Set media folder +F for adopted storage as well" am: 739ca2c298 am: 19adff5f27
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1397560

Change-Id: I855399600230f5a27d8058ec7fee0df9b2d22f22
2020-10-22 00:32:21 +00:00
Treehugger Robot
19adff5f27 Merge "Set media folder +F for adopted storage as well" am: 739ca2c298
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1397560

Change-Id: I90d0e56e260094661217dd20135f9fde6da96e98
2020-10-21 23:12:51 +00:00
Treehugger Robot
739ca2c298 Merge "Set media folder +F for adopted storage as well" 2020-10-21 22:04:11 +00:00
Daniel Rosenberg
cc874804dd Set media folder +F for adopted storage as well
We previously only set +F for /data/media, but adopted storage needs
this as well. Instead we add support for adding attrs to PrepareDir.

Bug: 163453310
Test: sm set-virtual-disk true
      follow UI setup and confirm +F on /mnt/expand/*/media
Change-Id: I08f13b57a4de3538e88b38eb95b0ac115a5a5ce8
Merged-In: I08f13b57a4de3538e88b38eb95b0ac115a5a5ce8
2020-10-20 18:55:54 -07:00
Eric Biggers
4855216c24 Merge "vold: Generate storage key without rollback resistance" am: 4f5e9c196f am: b6d1a31949 am: 6417fb00bd
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1426109

Change-Id: I02bf9412685cd1cd0b3bef6783035b9017fce337
2020-10-21 00:51:20 +00:00
Eric Biggers
6417fb00bd Merge "vold: Generate storage key without rollback resistance" am: 4f5e9c196f am: b6d1a31949
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1426109

Change-Id: Iaab2239444df05a089224bd145fe6d9c4baee436
2020-10-21 00:02:21 +00:00
Eric Biggers
b6d1a31949 Merge "vold: Generate storage key without rollback resistance" am: 4f5e9c196f
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1426109

Change-Id: Ibf06476010946d799c4b1fa5143ed4eac96f301a
2020-10-20 23:45:41 +00:00
Eric Biggers
4f5e9c196f Merge "vold: Generate storage key without rollback resistance" 2020-10-20 23:17:22 +00:00
Gaurav Kashyap
75736a8811 vold: Generate storage key without rollback resistance
Generate a storage key without rollback_resistance when device doesnt
support the corresponding tag.

Bug: 168527558

Change-Id: Iaf27c64dba627a31c9cbd9178458bf6785d00251
2020-10-20 16:19:33 +00:00
Eric Biggers
5d2092bf82 Merge changes Idc575106,Id6457a2b am: 3e0e53dbe5 am: 8671044a64 am: 377a71922d
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462712

Change-Id: I13758415cf228dae8b4d708ea67b58acb98781ed
2020-10-19 17:49:13 +00:00
Eric Biggers
e488044d97 Merge "MetadataCrypt: remove unnecessary retry loop" am: 80fdc5a4e3 am: 5a1e03f705 am: c65ba5bd4c
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462708

Change-Id: I897b84d329e2bb58ade03a66bcf7056174180a97
2020-10-19 17:49:03 +00:00
Eric Biggers
36a0a80bdf Merge "Silence useless LOOP_GET_STATUS64 warnings" am: 6f70c92aee am: 4d0d21e69d am: c823f0b95f
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462709

Change-Id: I0333415fa84d00038d86e7264941cc3249aac41d
2020-10-19 17:48:45 +00:00
Eric Biggers
377a71922d Merge changes Idc575106,Id6457a2b am: 3e0e53dbe5 am: 8671044a64
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462712

Change-Id: I9c673f9b4bf31b88c8ffa74e6f32f8eb4d2f9045
2020-10-19 17:30:11 +00:00
Eric Biggers
c65ba5bd4c Merge "MetadataCrypt: remove unnecessary retry loop" am: 80fdc5a4e3 am: 5a1e03f705
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462708

Change-Id: I5211d2aba15fcd8e201862428f79eb282ecff889
2020-10-19 17:30:00 +00:00
Eric Biggers
c823f0b95f Merge "Silence useless LOOP_GET_STATUS64 warnings" am: 6f70c92aee am: 4d0d21e69d
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462709

Change-Id: Iacf84a01d4937c62befac52cd1f0eb6ab6104663
2020-10-19 17:28:34 +00:00
Eric Biggers
8671044a64 Merge changes Idc575106,Id6457a2b am: 3e0e53dbe5
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462712

Change-Id: If01239e184cd19de660fa158d599c9826ea0cf71
2020-10-19 16:26:21 +00:00
Eric Biggers
5a1e03f705 Merge "MetadataCrypt: remove unnecessary retry loop" am: 80fdc5a4e3
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462708

Change-Id: Id26dbda854480c74d07fcec87f1d045325bf625a
2020-10-19 16:26:15 +00:00
Eric Biggers
4d0d21e69d Merge "Silence useless LOOP_GET_STATUS64 warnings" am: 6f70c92aee
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1462709

Change-Id: I75d169008b857848c314598cac4d87f27d6919b1
2020-10-19 16:26:06 +00:00
Eric Biggers
3e0e53dbe5 Merge changes Idc575106,Id6457a2b
* changes:
  IdleMaint: skip swap space, bind mounts, and virtual filesystems
  IdleMaint: use fstab_default from VoldUtil
2020-10-19 16:08:02 +00:00
Eric Biggers
80fdc5a4e3 Merge "MetadataCrypt: remove unnecessary retry loop" 2020-10-19 16:05:53 +00:00
Eric Biggers
6f70c92aee Merge "Silence useless LOOP_GET_STATUS64 warnings" 2020-10-19 16:05:17 +00:00
Eric Biggers
9a3dc8c709 IdleMaint: skip swap space, bind mounts, and virtual filesystems
When the idle maintenance task runs on Cuttlefish, there are several
warnings printed to logcat after the expected messages:

    D vold    : Starting trim of /data
    I vold    : Trimmed 0 bytes on /data in 36ms
    D vold    : Starting trim of /cache
    I vold    : Trimmed 58662912 bytes on /cache in 0ms
    D vold    : Starting trim of /metadata
    I vold    : Trimmed 7725056 bytes on /metadata in 12ms
    D vold    : Starting trim of none
    W vold    : Failed to open none: No such file or directory
    D vold    : Starting trim of /sdcard
    W vold    : Failed to open /sdcard: Not a directory
    D vold    : Starting trim of /mnt/vendor/shared
    W vold    : Trim failed on /mnt/vendor/shared: Inappropriate ioctl for device

This is because vold gathers the filesystems to trim from the fstab, but
it fails to exclude some entries that aren't appropriate to trim:

    /dev/block/zram0 none swap defaults zramsize=75%
    /tmp /sdcard none defaults,bind recoveryonly
    shared /mnt/vendor/shared virtiofs nosuid,nodev,noatime nofail

These should be excluded because they are swap space, a bind mount, and
a virtual filesystem respectively.

Fix addFromFstab() to exclude the above cases.

Afterwards, the messages on Cuttlefish are:

    D vold    : Starting trim of /data
    I vold    : Trimmed 0 bytes on /data in 39ms
    D vold    : Starting trim of /cache
    I vold    : Trimmed 58662912 bytes on /cache in 0ms
    D vold    : Starting trim of /metadata
    I vold    : Trimmed 9822208 bytes on /metadata in 12ms

Change-Id: Idc575106fe6f81c737f684429d58dba4bd5478ad
2020-10-15 16:56:16 -07:00
Eric Biggers
019d5163cc IdleMaint: use fstab_default from VoldUtil
vold already reads the default fstab into memory when starting up, and
the default fstab isn't allowed to change later.  So in IdleMaint.cpp,
just use 'fstab_default' instead of reading it again.

This also has the advantage that fstab entries for "logical partitions"
now get a properly updated blk_device, which is needed in order to start
using blk_device to exclude virtual filesystems in addFromFstab().

Change-Id: Id6457a2b7972d01dde4bca0c5f2da86374d930af
2020-10-15 16:54:38 -07:00
Eric Biggers
10724d93a1 Silence useless LOOP_GET_STATUS64 warnings
When vold starts up, there are lots of warnings like:

    W vold    : Failed to LOOP_GET_STATUS64 /dev/block/loop30: No such device or address
    W vold    : Failed to LOOP_GET_STATUS64 /dev/block/loop29: No such device or address
    W vold    : Failed to LOOP_GET_STATUS64 /dev/block/loop28: No such device or address

vold is iterating through all loop devices and unbinding the file from
any vold-managed ones.

It's expected that not all loop devices have a file bound to them,
however.  On these, LOOP_GET_STATUS64 fails with ENXIO.

Don't print a warning in such cases.

Change-Id: I91755259dc2c09b1869627259d1e59d5edd6f145
2020-10-15 15:26:27 -07:00
Eric Biggers
836b51bf26 MetadataCrypt: remove unnecessary retry loop
As per the discussion at http://aosp/1456266, the retry loop in
create_crypto_blk_dev() doesn't appear to be needed.  Remove it.

For now don't bother removing the same retry loop in cryptfs.cpp, since
the FDE code isn't really being updated anymore and eventually will be
removed entirely.

Change-Id: Iba0b046f9cdd9723ea1a2ae70f4d4aed4355b97b
2020-10-15 14:46:35 -07:00
Yo Chiang
0af25a3a98 Add IVold::destroyDsuMetadataKey()
destroyDsuMetadataKey() / destroy_dsu_metadata_key() calls
android::gsi::GetDsuMetadataKeyDir() to query the DSU metadata
encryption key dir and destroy the key.
This releases the resource and allows consecutive DSU installations to
use the same key *directory*, but not the same key *blob*.

Bug: 168571434
Test: 1. Install a DSU system.
  2. Boot the DSU system and reboot back to the host system.
  3. Wipe the DSU installation.
  4. DSU metadata key dir /metadata/vold/metadata_encryption/dsu/dsu is
     destroyed.
Change-Id: Ib851177315a5a266807f46ccfd446de1848232cf
2020-10-13 16:00:43 +08:00
Martijn Coenen
08dcc7ee30 Merge "Use dm.CreateDevice() with a timeout." am: e9023dc7bb am: 7da18c97ef am: 3d5a8fd0d9
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1456266

Change-Id: Ib1fc9055a823fd3aa7fb4e0e5ae4eb3d5077fb05
2020-10-12 19:22:11 +00:00
Martijn Coenen
3d5a8fd0d9 Merge "Use dm.CreateDevice() with a timeout." am: e9023dc7bb am: 7da18c97ef
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1456266

Change-Id: If3c48689e76062c7819bba9a8ac43c2e14e4d189
2020-10-12 19:04:22 +00:00
Martijn Coenen
7da18c97ef Merge "Use dm.CreateDevice() with a timeout." am: e9023dc7bb
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1456266

Change-Id: Id232a623d6aa3beaa3fdb5b31c722e96da6d75c9
2020-10-12 18:46:02 +00:00
Martijn Coenen
e9023dc7bb Merge "Use dm.CreateDevice() with a timeout." 2020-10-12 18:07:39 +00:00
Martijn Coenen
e0c38eba26 Use dm.CreateDevice() with a timeout.
Using the regular CreateDevice() variant with getDmDeviceByName() has a
race-condition that is documented in libdm/dm.h; instead, use the
variant with a timeout, which guarantees that the block device exists
when it returns.

Test: atest AdoptableHostTest
Bug: 150935323
Change-Id: Ic06cad9af7c44e23359d95b262f68dba27ddfb3a
2020-10-12 16:59:50 +02:00