Commit Graph

262 Commits

Author SHA1 Message Date
Captain Throwback
4b9a9298ae gui: allow MTP even if media storage isn't present
Change-Id: I6766f804fa7f116ddc436d566d9647206b0d2e69
2021-10-17 15:08:29 -04:00
bigbiff
ab76bd7324 vab: correct default properties when vab is enabled
- do not show vab options in advanced
- do not perform merges when vab is disabled

Change-Id: I20997eca515600cb07fe896305b861ee9418c326
2021-10-16 16:29:46 +00:00
Captain Throwback
37c3aef4e8 crypto: only set crypto state and type if not already set
Move setting crypto state and type to functions and call those
functions rather than arbitrarily setting those props in every
case. This cleans up all the log spam from trying to set
read-only props, since they will now only get set if
they aren't already.

Change-Id: I392bee060d71c6ee50d0d92bf1b118d9049be41a
2021-10-06 22:27:49 +00:00
Captain Throwback
63573b550f mtp: don't create storage device after format data
Since we don't re-create data/media on FBE devices,
don't create an MTP storage device for it.

This fixes the bug when, after formatting data on
and FBE device, an empty Internal Storage appears
on the PC.

This also prevents an empty storage device from
being created if recovery is rebooted after formatting
data before booting to Android. A warning will appear
in the console that MTP is disabled in that case.

Currently the path is hardcoded to data/media; this
should probably be adjusted for cases where adoptable
storage is being used.

Change-Id: Iaafc5e3cde54c3ef6ffaf33f76d14c626b6e590d
2021-10-05 22:53:07 +00:00
bigbiff
d21252f1b5 merges: allow user to perform snapshot merges in advanced menu
Change-Id: I894a0ef5a0ec8e208053358f09a6b8a6d4ee408a
2021-10-05 22:32:19 +00:00
bigbiff
22851b9476 module load: attempt to load modules from /vendor
Use TW_LOAD_VENDOR_MODULES := "module1.ko module2.ko modulen.ko"
in BoardConfig to have TWRP attempt to load kernel modules during
startup. For fastboot ramdisks, TWRP will attempt to load from
the ramdisk from /vendor/lib/modules. You can have the build
system copy the modules to
$(TARGET_RECOVERY_ROOT_OUT)/vendor/lib/modules/1.1
Otherwise in recovery in boot mode, TWRP will attempt the following:
check /lib/modules (ramdisk vendor_boot)
check /lib/modules/N.N (ramdisk vendor_boot)
check /lib/modules/N.N-gki (ramdisk vendor_boot)
check /vendor/lib/modules (ramdisk)
check /vendor/lib/modules/1.1 (ramdisk prebuilt modules)
check /vendor/lib/modules/N.N (vendor mounted)
check /vendor/lib/modules/N.N-gki (vendor mounted)

Change-Id: I2dccf199e37d47cb7a7e79b0e11026d67b4e3186
2021-09-29 20:46:19 +00:00
bigbiff
437d86f6a0 wrappedkey: don't use twrp for processing anymore
Now in android-11 we can now process legacy and newer wrappedkey
support in our libfscrypt library. TWRP doesn't need to set a
property to check for wrapped key. libfscrypt will just process
wrappedkey fs_mgr flag for legacy wrapped key or wrappedkey_v0
for the newer wrapped key supported in android-11.

Change-Id: Ia94c7ebe34a05c9b25bbb7a5b2e899902c93d203
2021-09-28 00:53:32 +00:00
bigbiff
aed1bdfe59 get_args: process /data/cache/command
Change-Id: I744cdc5a72f53fd1224de242e30ff261e6104900
2021-09-25 20:52:58 +00:00
bigbiff
998f839e82 super processing: use logical flag to denote super status
To support all partitions that are on the super partition
we now parse for the logical flag in fstab to denote super
status.

- Remove guards for the first character being '/'.
- Skip commented lines in fstab
- Build Backup_Display_Name from partitions in super.
The first four lines that are in fstab will be
displayed.
Change-Id: I3f8980187bd4a136257dd6eeaeddd7ea71706cd3

Change-Id: I1ee7c02f91aafb646beaf401a43bcb22fa8c8c7a
2021-08-28 17:48:23 +00:00
Captain Throwback
878abc76c2 Run Update_System_Details during fstab processing
Fixes issue where devices where encryption failed wouldn't
have partition information until after an action was run

Change-Id: I1c50ceaa56d67bfbc330bfa77300512a6e3034c0
2021-08-27 19:21:36 -04:00
Mohd Faraz
7fc7050b6d partitionmanager: Symlink dynamic partitions to /dev/block/boot/device/by-name/
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
Change-Id: Iebebe9234723bcda863098cdff6ed41e7b410e78
(cherry picked from commit a7c22b56ba9b6e2f3fb90edbde7ec206b7eca8d5)
2021-08-15 23:01:09 +00:00
bigbiff
cfa875c4d4 vab support: merges and unmapping super devices
- check for merges before formatting data
- add advanced option for unmapping super devices

Change-Id: I38d4d3bbdfa071969016c3e000c86a4d03c71e45
2021-08-09 23:04:33 +00:00
bigbiff
74a46278c3 repacker: override slot for flashing images instead of using bootctrl
Bootctrl is being unreliable during repacking. This overrides the slot
while repacking recovery in boot.

Change-Id: I0a04357af4e5f24591792bcfb27ccbd10b0a813b
2021-08-07 17:56:19 +00:00
bigbiff
bbbfe171f1 fscrypt: updates for wrapped key
- During OTA upgrades if security state or ROT changes then Keymaster
keys requires upgrade. So for such usescases, if the FBE ephemeral
key export fails, check whether KM key requires upgrade and try for
exporting ephemeral key again.

CRs-Fixed: 2632902
Change-Id: I3ee2fcd97a56b628dc4304867c8f2b8da875f883
Signed-off-by: Neeraj Soni <neersoni@codeaurora.org>

- Commit 77df7f2 / 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 c493903732d0c17b33091cf722cbcc3262292801)
Merged-In: I42d3f5fbe32cb2ec229f4b614cfb271412a3ed29
Change-Id: I42d3f5fbe32cb2ec229f4b614cfb271412a3ed29

Change-Id: I0449b812e91c13020a8b653f2149c33e46027b97
2021-06-25 18:42:20 -04:00
bigbiff
799243055f apex: only mount required apex files
Since recent kernels seem to limit the number of loopback
devices to 7, we now just mount the required apex files in TWRP.

To mount additional apex files specify TW_ADDITIONAL_APEX_FILES
in your BoardConfig, for example:
TW_ADDITIONAL_APEX_FILES := "apex1 apex2"

To disable Apex in your builds use:
TW_EXLUCDE_APEX := true
Change-Id: Ib55529a4dc17ce2b737b01b86100dca3dc75e6c9

Change-Id: I3b4dfbb164838ffb126016b0d862f67d3f170bf3
2021-05-18 20:35:52 -04:00
bigbiff
be4f46cbc3 sdcard: bind mount in post decrypt
also uncomment wiping code that should not be commented

Change-Id: I445f688628dcedb67544c22c7b0775ee62e0b267
2021-05-18 20:35:51 -04:00
bigbiff
a957f078be FsCrypt update: support fscrypt policies v1 and v2
This patchset introduces support decryption for Android 11.

In this update we deprecate ext4crypt. To specify the
policy version to use, use TW_USE_FSCRYPT_POLICY := 1 or
TW_USE_FSCRYPT_POLICY := 2. By default policy version will
be set to 2 if this variable is omitted.

Change-Id: I62a29c1bef36c259ec4b11259f71be613d20a112
2021-05-18 20:35:51 -04:00
Captain Throwback
8e70a11ef9 Use BOARD_SUPER_PARTITION_PARTITION_LIST for dynamic list
Simplifies code for retrieving this list rather than using
every possible specified super partition group

Change-Id: I1a3bd8e4b73ce18a176c74a52eb91d25709080f4
2021-04-24 21:25:58 +00:00
Captain Throwback
c693910723 Change missing logical partitions from LOGERR to LOGINFO
Between Android versions, there may be different partitions
that make up super. Just because a partition that in fstab
is not in super doesn't necessarily mean there's a problem.

Change this message to information only so the end user
doesn't think there's a problem when there isn't one

Change-Id: I9cb99aabe20e20059e66cf0cf13cff5ed056f529
(cherry picked from commit e432fb0214b49549e99396db512be98d53e1ed8b)
2021-04-06 22:44:05 +00:00
epicX
a721f955f7 Add support to change TWRP Folder
Change-Id: Id3b3b46d492bf83d1d9d3f535c880ea9d15b4107
2021-03-03 20:04:57 -05:00
Captain Throwback
89b56a1c97 Remove duplicate Update_System_Details() function calls
Only run Update_System_Details on boot after decryption is
complete, if device is unencrypted, or if decryption prompt
is cancelled.

This significantly decreases the delay in reaching the
decryption prompt on devices with large used storage
capacity

Use refreshsizes action to update system details when
Cancel button is pressed at decryption prompt

Change-Id: I9e436b1c57664a5269f42dc1cda4f6097f7e3062
2021-03-03 20:04:48 -05:00
bigbiff
4a60bee82e android root: restore context for android system root
In this patchset we will store and reset the android system
root context after a wipe and restore to prevent issues
with no context labels in the file_contexts being applied.
This will prevent no boot issues in android with selinux
denials on the system root partition.

Change-Id: I87fd3a6060fbaa3e7bdfd7a4b1d09feeb4fa3f27
(cherry picked from commit 35d2bfda3c89ebd212a9bd2328bffd7464f95d47)
2021-02-15 12:29:48 -05:00
Peter Cai
439d60cb9d partitionmanager: support delayed adopted storage mount
* On some devices, the external mmc driver will only load the card after
  a certain delay. The original code will break and fail to mount any
  adopted storage in this case.

* Add a special fstab flag to allow the partitionmanager to retry after
  a delay.

Change-Id: I219978850ff3ba7ad9dc7ca96fc30634c9574164
2021-02-15 12:29:19 -05:00
bigbiff
af253cd0ef debug: remove unneeded debug message
Change-Id: I271e7fca0e3786fe90d324d2d1ccba9fa6394b9f
2021-02-15 12:25:08 -05:00
bigbiff
1f9e4847ce twrpinstall: create library for twrpinstall
This library will need to mirror AOSP for any changes to installing
packages. The library has been separated out in order to make importing
updates from AOSP into the TWRP project.

twinstall.cpp has been removed from the recovery binary and added to
this library. It has been refactored for libziparchive.

Sideload has been reworked to use the newer methods from AOSP on
flashing packages through adb sideload.

We are also removing old libraries for adb and verifier.

Lastly before flashing a zip or image, we want to unlock block devices
for writing so that when an OTA is flashed to the inactive slot,
the flash will succeed.

Change-Id: I6d8702fc9031ffaf9f666b4ba375dc7d9362e473
2020-12-02 13:43:42 -05:00
Mohd Faraz
d9e6671e96 Added apex resync script
BUG: Some devices having issues with mounted apex while flashing some packages.
 TEST: Added a device specific script in the device tree, which deloaded the apex, which are not needed and its fine.

 Example script: https://gist.github.com/AndroiableDroid/cf5a04f80b6326c759a59be5d828434e

Change-Id: I5c89dcd92871fec63c6a875c1a47eb8145ba71fa
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
2020-11-11 19:06:54 +00:00
nebrassy
f74255ea1e set crypto state/type when detected
Change-Id: I4506d3ef11052dbebf974b5c387a3c7d5055f2ea
2020-11-11 01:59:11 +00:00
Captain Throwback
18aea279ca fde: move crypto state & type setting to function
In order to make sure the crypto state and type is set
properly if the device is encrypted, move this check to
a function and call it in cases where the default password
is being used and in cases where it isn't. This will ensure that
an unencrypted device isn't set as encrypted by mistake.

Change-Id: I736f9cbee0e95d7390a09c8235b9914feddaceaf
2020-11-11 00:58:52 +00:00
Captain Throwback
228223bbb1 fde: set ro.crypto.type to block
Since we set ro.crypto.type to "file" for FBE, we should also set
this prop for FDE.

Change-Id: Id3a581da5d4b58c41c2c361593ad7266898a6f54
2020-10-28 12:22:56 +00:00
Mohd Faraz
9a4ef26299 Unmount vendor after apex
BUG: prebuilt vendor blobs are being overriden by vendor partition, which causes failed to decrypt the device
TEST: after this patch vendor is no more overriding and decryption working as expected.

 * Devices using the stock or the rom based libs then it needed to add the TW_USES_VENDOR_LIBS := true in the BoardConfig

Change-Id: I3cbc7fe6df2289081e9198941cfb65a1a7e0e6a3
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
2020-10-23 22:17:01 +00:00
Noah Jacobson
81d638d235 Add support for multi-user decryption
* Add CLI support using the command "twrp decrypt <PASSWORD> [USER ID]"
* Add GUI support using the menu Advanced --> Decrypt User

multiuser: Parse users only when Decrypt_DE runs successfully

multiuser: Warn when not all users are decrypted

Change-Id: Ia5e943b13c2d5ec5c34ae97661133c19ff471e6d
2020-10-23 00:52:04 +00:00
Ian Macdonald
160e8d3955 Improve 'super' partition description in back-up menu.
For the back-up menu, we can detail what the super partition includes by
aggregating one of BOARD_GOOGLE_DYNAMIC_PARTITIONS_PARTITION_LIST or
BOARD_QTI_DYNAMIC_PARTITIONS_PARTITION_LIST.

We comma-separate the list and capitalise the first letter of each
dynamic partition.

Change-Id: I663eaf4f28b4591293aae21c2dd11f615f625746
2020-10-22 22:45:36 +00:00
Mohd Faraz
2a1e375076 Write correct mount Opts in fstab
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
Change-Id: I4049be4a693bde3f1bc3a088ce864eca5515ae5f
2020-10-22 22:32:57 +00:00
bigbiff
df8436b51a fastboot: implement fastbootd in twrp
fastbootd is a userspace daemon that runs in the recovery
ramdisk. It allows writing single partitions to the super
partition via fastboot CLI. When TWRP sees the fastboot option
in the misc partition during startup, it will start with
the fastbootd page and fastbootd running. Otherwise it will
run recovery normally.

Change-Id: Id7b12d29ef21dbd5950dc884dd1cd788f25357f0
2020-10-21 17:47:27 -04:00
Mauronofrio Matarrese
c1bb76ea74 Removing fake error: E: recv error on uevent
This shouldn't be an error, so i hide the line about the error.

Change-Id: I3ef667435dfa843440cc594409c8d20add676576
2020-09-24 19:24:58 +00:00
bigbiff
c2cb385d5d wiping: this will fix wipe with devices that don't use the
/dev/block/mapper/userdata symlink to the setup device mapper.

Change-Id: I1d5a1ed59f7c445ce86ccd52dae1e2e729e06815
2020-09-13 18:05:41 +00:00
bigbiff
8da46fa939 Revert "Implement autodetection for SAR, based on the installed system"
Change-Id: I9e6c549013c1d5564d0a2e369510535e3869dff6
2020-09-09 20:13:12 -04:00
Mohd Faraz
e3948ece83 Fix up issue during decryption
* Since some devices are unable to decrypt after processing of the fstab,
   because of the partition details updation, and after intro of dynamic partitioning
   here decryption process was going on after complete processing of the dynamic volumes.

 * This patch fix these issue, it process the logical volumes at their time not after all processing fstabs.
   This fixes the decryption issue.
   Translate more partitions i.e., ODM, Product.
   Added more partitions in unmount partitions.

Change-Id: I977c0cf0c40e5311f54a78c98f1fd89f71c6ac57
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
2020-09-09 22:49:37 +00:00
bigbiff
ad58e1bfae repack: move sbin to /system ramdisk and update repacking
for android-10

This will support updating the ramdisk to a different
compression format and co-exist with magisk.

We are also cleaning up and removing non android-10
api makefile actions.

We are also moving twrp repacking to its own class. We
check the new ramdisk format and if it's different
we have magisk compress using the new ramdisk format.

Change-Id: I770030aae7797e75817178b2f0fccd9f39dc23af
2020-09-08 10:08:33 -04:00
bigbiff
25d25b9e67 log storage: change AB device log storage to /data/recovery
This patchset is now exlcuding /data/cache from backup, and removing it
from the wipe exclusion list to prevent errors on restore and wiping
/data.

This patchset changes the directory from /data/cache to /data/recovery for TWRP
to store logs and other file information. This will help with AB
devices that don't want recovery to mess with /data/cache.

This patchset will make ORS use /data/cache for AB devices.

Remove policy code because we don't need to set a policy for the
recovery directory.

Change-Id: I1d140276314fd34804a72297d6e25a52e58210a0
2020-07-07 00:55:42 +00:00
bigbiff
7ba7500953 decrypt: AOSP 10 requires the use of fscrypt
fscrypt aosp doc: https://source.android.com/security/encryption/file-based
kernel fscrypt doc: https://www.kernel.org/doc/html/v4.18/filesystems/fscrypt.html

This commit implements the ability for TWRP to use fscrypt to decrypt
files on the fscrypt implementation. It has been implemented mostly
in a new successor library to e4crypt called libtwrpfscrypt. Most of the
code was ported from AOSP vold.

Notable updates include:
 - updated policy storage by libtar
 - lookup of fbe policies by libtwrpfscrypt
 - threaded keystore operations

Big thanks to Dees_Troy for the initial trailblazing
of encryption in TWRP.

Change-Id: I69cd2eba3693a9914e00213d4943229635d0cdae
2020-06-22 12:17:22 +02:00
Simon Shi
f4c1553789 super: emmc shouldn't be mount-only.
Bugs:
E:Cannot restore super -- mounted read only.

Change-Id: I07891b3f45a8601c1cafa45f9dd2a7a94482ac06
2020-06-18 02:38:24 +08:00
Simon Shi
407437ed39 super: Don't mount while prepare
Some of the partitions will not be unmount automatically. They shouldn't
be mounted by default.

Bugs:
DM_DEV_REMOVE failed for [product]: Device or resource busy
Cannot unmap product before removing group qti_dynamic_partitions.
script aborted: assert failed: update_dynamic_partitions(package_extract_file("dynamic_partitions_op_list"))
assert failed: update_dynamic_partitions(package_extract_file("dynamic_partitions_op_list"))error: 25
Updater process ended with ERROR: 7

Change-Id: I7cbd5c29456ca2731b94a69bbf9ad77058cef09c
2020-06-16 00:06:48 +08:00
bigbiff
32cbabe413 apex: mount up apex files into /sbin for library access
This patch uses the loop device to mount files under
/sbin/ from /system/apex in order for the device to
use libraries or other files store inside these files.

Each apex file is mounted over a loop device into a
directory correpsonding to the apex filename under
/sbin/.

Once apex mounting is completed, TWRP will set a
property twrp.apex.loaded to true so that init
can use them as a LD_LIBARY_PATH source.
Change-Id: I69f14a969123ac9cf1afc85b6cf76836cb092fb2

Change-Id: Ica6a7d8e479bcaec8bec4483b5e8d2b45ee105fb
2020-06-08 20:38:04 +00:00
bigbiff
ee7b7ffba4 super partition: mount super partitions using fs_mgr
We are now requiring fstab v2 for android-10+ trees. You can
specify twrp flags using /etc/twrp.flags to label and
annotate partitions.

This patchset uses fs_mgr to load the super partition and build
device mapper blocks off vendor and system depending on the slot
in use. These are mapped to partitions in TWRP and allowed to
be mounted read-only. The super partition is also mapped into a
TWRP partition in order to backup the entire partition. You cannot
backup individual device mapper blocks due to the device can only
be read-only. Therefore you cannot write back to the device mapper.

Change-Id: Icc1d895dcf96ad5ba03989c9bf759419d83673a3
2020-06-08 20:37:29 +00:00
Mohd Faraz
b98b4f7b96 partitionmanager: magisk update sytnax as per new binaries
Change-Id: I51994b991472cf103de067b9856ff3df1bf35a90
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
(cherry picked from commit 5738e760646d67791e938954a8873da41209d58c)
2020-05-30 20:05:43 +00:00
bigbiff
adc599e005 Revert "Add support for multi-user decryption"
This reverts commit 0b25b1d79b.

Reason for revert: Changes need to be made to libtwrpfscrypt to include this patchset. Will cherry-pick this patch later and make necessary modifications.

Change-Id: I7601d7b820129709b05d9b4368573b6f1048de02
2020-05-28 19:36:30 +00:00
Noah Jacobson
0b25b1d79b Add support for multi-user decryption
* Add CLI support using the command "twrp decrypt <PASSWORD> [USER ID]"
* Add GUI support using the menu Advanced --> Decrypt User

Change-Id: Id2681bc2b1012a0571417f7a6e0b980b1b25c61c
(cherry picked from commit 5a79f67a1b1bd1bcadeca0a4896a871646652534)
2020-05-20 19:11:15 -04:00
mauronofrio
fc79aa6375 Encryption: don't try wrapped key if not needed
This commit is used to directly use the wrapped key
decryption when the "wrappedkey" flag is set in the
fstab.

Change-Id: I74310c3bbec378ee684a8f6d0395a9776dd22abf
(cherry picked from commit 1db943295de9728e364bf0e75bfe9f1a98d413a1)
2020-05-13 00:40:25 +00:00
bigbiff
437b93a087 Merge remote-tracking branch 'origin/android-9.0' into android-10.0
Change-Id: Ie850f431f0d2c39c86b9c10701676a24770ab447
2020-05-10 20:06:41 -04:00