Commit Graph

255 Commits

Author SHA1 Message Date
bigbiff
2d54867daa fbe formatting: add warning for fbe devices and remove unused string
Change-Id: Id7af18a4c39932d8685e3265bfa158494ffd10f0
2021-07-17 00:14:21 +00: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
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
d68e6413e5 partition: add support dm_use_original_path
* On some mediatek devices we must use symlinked path instead of the
      real block device.  Needed for decryption on some MTK HW FDE devices.

Change-Id: Ib48d745fd442c590aea2baf6d2dbe20aaaef9eec
2021-02-15 12:29:27 -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
Captain Throwback
acc7f0f873 wrappedkey: only run check on FBE devices
Change-Id: I3713fc4619279d8ee2de924df2bc4fbde944d834
2021-02-15 12:27:03 -05:00
Captain Throwback
b5af4f80d0 fbe: move key directory logging within key directory check
Change-Id: I9d1a50ab0fb8b9bbb2e0686c6ffe28b4b22634b4
2021-02-15 12:26:54 -05:00
Captain Throwback
dbc37b7a4c wrappedkey: set prop for metadata partition if flag is present
Change-Id: I0da59e81993a119d198dbfc350b7fca0e1cb3c5c
2021-02-15 12:26:46 -05:00
nebrassy
57f210d409 also set crypto state for non-metadata FBE
Change-Id: I586878cc6134d798b1d087415cb694d6738f279a
2021-02-15 12:25:47 -05:00
nebrassy
f74255ea1e set crypto state/type when detected
Change-Id: I4506d3ef11052dbebf974b5c387a3c7d5055f2ea
2020-11-11 01:59:11 +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
Captain Throwback
47bf7204f8 partition: support tntfs module
Change-Id: I0532b10f6748d00c80454a051ef63cc74a77780c
2020-10-22 22:26:02 +00:00
Mohd Faraz
815e24079b Fixes Decryption prompt asking when not needed
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
Change-Id: Ic366a50f02f283864cf44d7b36f40ff6432d4970
2020-09-24 16:08:07 -04: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
aac58612ea persist logs: remove persist from available log directories in
partitions.

Too many problems have been reported for TWRP attempting to store
logs in the persist partition. Selinux denials have caused issues
booting Android, and filling up persist has caused IMEI issues.

This patchset will remove persist from the list of available log
directories by default in order to avoid these and other possible
issues.

Change-Id: I29889d69f76270a8fbb764a79be3523821d8579c
2020-08-30 18:16:35 -04:00
DarthJabba9
43d70f4bc7 Exclude the dumpsys dumps from backups, to avoid error 255 when restoring data backups
Change-Id: I7a83b3789828c1400e31007e868263c54d8eb38c
(cherry picked from commit 13b07f8dbe27d85254e0a04f689a9ed6bde7673e)
2020-08-04 23:03:14 +00:00
bigbiff
5b911ca621 persist: contexts for lost+found not found when running e2fsdroid
When running e2fsdroid on persist, lost+found doesn't have any
entries in file_contexts. We are removing the lost+found directory
after a wipe now, and before the restore of the tar.
Change-Id: If5db0971884e296fae0211ff4806f3e16e394632

Change-Id: I9fa51dc9ef558cd82445df9a8fa377b1feda11aa
2020-07-19 09:32:13 -04:00
Mohd Faraz
e1d72623b7 Fix up cache wipe issue in A-Only device
* missed in 3754fabbea

Change-Id: I8fc3719e7f98c3d9b5fd96a9820b84773d4f5d7d
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
(cherry picked from commit 25371a7e1f7f7d690755e3b12140b39567456a98)
2020-07-06 20:56:57 -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
Captain Throwback
87d73d6620 FBE: set TW_IS_FBE based on whether key version path exists
- Should not be determined by whether support exists in TWRP
- Set to 0 by default if FBE is not detected

This also prevents the wrappedkey check from running
on FDE devices

Change-Id: I85d1952facdfafdaa1571fc1b11d4b4b7d9ba48e
(cherry picked from commit cf0dffce3413261f149a3565d8f27cb32490ae54)
2020-06-10 16:33:52 -04: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
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
Peter Cai
28ea7b000a partition: set fbe.data.wrappedkey automatically via flag
In change I79c2855d577156670b45c10c7c7b1fcd9fece8d9 we introduced a
property to enable wrappedkey mode. This change supports an extra
`wrappedkey` flag in fstab to automatically set the property to true.

Change-Id: I4f060d4ed6b2a5680649b8746dfa7fd903fe2d35
(cherry picked from commit 40ed06e850de2dc7cc06c2e647688212563f1ec2)
2020-05-13 00:39:19 +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
dianlujitao
b76a73a1a9 Fix backup and restore after autodetection for SAR
This reverts commit 8a411c8d25.

 * Always use "/system" to interact with the frontend and replace it
   with the detected path before taking actions.
 * Don't replace the pretty display name and backup name set during
   processing fstab after wipe. This improves UX and ensures that the
   system backup is always named system.ext4.win despite the actual
   mount point is /system_root so TWRP is able to recover either SAR or
   non-SAR backups.

Change-Id: Ie2594d2678d0c75ce25c0d1087d47b035b3f10e9
2020-05-10 21:35:01 +00:00
Chaosmaster
f6e42ce390 Implement autodetection for SAR, based on the installed system
This will detect whether SAR is present in the currently installed
OS and set the property ro.twrp.sar accordingly.
After setting the property it will call the bootscript
/sbin/sarsetup.sh (if present) to give device maintainers the
option to do setup operations depending on SAR-status, such
as modifiyng the fstab.

If no system is detected and AB_OTA_UPDATER is defined or built with
Android 10 and upwards, it will fallback to using SAR, otherwise it
will use ro.build.system_root_image as basis for deciding whether SAR
is required or not.

The property ro.twrp.sar will also be used by
TWPartitionManager::Get_Android_Root_Path()

This allows maintaining a single TWRP-build for devices switching
to SAR for Android 10.

The default behavior (when no system is installed)
is determined by the build-flags AB_OTA_UPDATER and
BOARD_BUILD_SYSTEM_ROOT_IMAGE

Change-Id: I2a48c6c81a6ea6fad6e452c06bfbe4d9da0f1e5c
2020-05-10 15:43:56 -04:00
Chaosmaster
da97480567 Create/Remove system_root/system bind mount, when mounting System
This will automatically create and remove a bind mount
/system -> /system_root/system
everytime "System" is mounted via the GUI or ORS.
This should get rid of issues with ZIPs trying to mount
the system-partition to /system on SAR-devices, while keeping
the filesystem-layout in sync with AOSP from a user-perspective.

Change-Id: I7f531d113b07c31b39d8f87edac76a7fc79075e7
2020-05-10 15:43:55 -04:00
Chaosmaster
3b6827372e Set system-partition mount point to proper location
This sets the system mount point to either /system_root or /system
depending on whether SAR is detected or not irregardless of what
is specified in fstab.

This removes the need to edit fstab for SAR-builds and simplifies
building unified (SAR/non-SAR) builds.

Change-Id: I154fd76f842702be9e5d09005463c8e5f1d289a4
2020-05-10 15:43:54 -04:00
bigbiff
d58ba18272 AOSP10 TWRP Merge: fix conflicts and update libraries needed
This allows flame to boot TWRP. Still will need to work on
super partition for vendor and system access.

The plan will be to cherry-pick any updates to android-9.0
through gerrit.twrp.me to this branch as a WIP.
2020-03-23 11:18:29 -04:00
Mauronofrio Matarrese
6d5d08a1c0 Move decryption error from logerror to loginfo
Change-Id: Iffa01968dfb92d2cc91b0b6a33c87d7f270430db
2020-02-17 17:13:04 -05:00
Darth9
0864aa54ce Prevent errors caused by /data/per_boot/
Change-Id: I543723f3da4f57fb4d580661216acc1abaac883e
2020-02-01 21:27:53 +00:00
mauronofrio
9bf73351e5 Encryption: try wrapped key also for device without metadata support
Change-Id: I8b58e45ec0d42470226083e8003dcd8152a91af1
2019-11-23 22:29:15 +01:00
big biff
69ab4a6000 Merge "fix build error in 9.0 with TW_NO_EXFAT_FUSE:=true" into android-9.0 2019-08-04 00:49:41 +02:00
Ian Macdonald
a3b25a3ebe Backup_Tar(): Properly localise string instead of using English.
Change-Id: Id13885a30e3a412e5b7b42de0e63cd7fc885dfc1
2019-06-24 00:28:38 +02:00
dianlujitao
3cf05a569e Resolve e2fsdroid failure in certain cases
* Set proper SELinux context for system-as-root system, AOSP uses "/"
   in fstab while TWRP uses "/system_root" so an exception is necessary.
 * Skip initializing context if the target partition doesn't exist in
   /file_contexts e.g. /usb-otg.

Change-Id: I8f802c34e18fb9f65bf936d11967c83a451b0493
2019-05-15 16:27:17 +08:00
dianlujitao
19e8461ff7 Pass file_contexts path to e2fsdroid
* Otherwise no context will be initialized but existing context will be
   erased and lead to unexpected behavior, e.g., device no longer boots
   after restoring a system backup due to missing valid seclabel of the
   system partition.

Change-Id: I60c62fdc699714bb906a40ce5e1f40299681f72a
2019-04-22 17:55:13 +08:00
Martin Dünkelmann
6d8437812b fix build error in 9.0 with TW_NO_EXFAT_FUSE:=true
'bootable/recovery/partition.cpp:1476:158:

error:

format specifies type unsigned int

but the argument has type unsigned long

[-Werror,-Wformat]'

if using TW_NO_EXFAT_FUSE := true;

Change-Id: Icff5893a0de746ecfa3b247dc83c74a42e04bb08
2019-04-04 22:14:04 +02:00
Dees Troy
9a4d7403d9 Fix build in 5.1 tree
Change-Id: I15f888d58c01de00920dc5c56148d363f4dd79b8
2019-04-03 05:23:34 +02:00
Ethan Yonker
7e94158684 Support both old and new mkfs.f2fs
Easiest way I could find to determine if we have the old or the
new mkfs.f2fs version is to pipe the usage output to grep and
grep the output for "reserved" and redirect the output to a file.
If the file has any data in it, then we must have the old
mkfs.f2fs that uses -r.

Change-Id: I7f1ed88b577a3f9827a98f0868d8f82e4e4886ac
2019-03-22 08:18:24 -05:00
dianlujitao
4879b37b5d Fix the long broken format function
* For EXT2/3:
   * Align mke2fs options with Android 9.0 fs_mgr_format.cpp.
 * For EXT4:
   * Note that make_ext4fs is still in use on Android 8.1 to workaround
     a FDE encryption bug even though mke2fs has become the default
     choice. The bug is fixed in Android 9.0+.
 * For F2FS:
   * Drop the broken "-r" option, it's never ported to O, explicitly
     pass number of sectors instead.
   * Keep all options aligned with Pie fs_mgr.
   * Check existence before start wiping, as Wipe_EXT4 does.
 * For all:
   * Calculate block size at runtime, and reserve the space specified
     via negative "length" option from fstab. Note that positive length
     will be ignored.
   * If the partition has crypto footer, and "length" is not specified
     in fstab, automatically reverse CRYPT_FOOTER_OFFSET (16384).
   * Remove the default crypto key location: footer, this is a bad
     assumption since most partitions don't use encryption! We need to
     know the real situation to decide whether to reserve crypto footer
     on format.
   * If the current action is "wipe" or "change filesystem", wipe crypto
     footer or block device after mkfs if the partition is
     unencrypted or undecrypted (e.g., wrong password).
   * If the current action is "format data", unconditionally wipe crypto
     footer or block device.

Change-Id: I7304a8ee703131ea4a08ab7c60334af28cac28b3
2019-03-21 16:15:52 -05:00
Ethan Yonker
98661c1a29 Update FDE decrypt to pie from CAF
cryptfs.cpp based on CAF tag LA.UM.7.3.r1-05900-sdm845.0
Used CAF because AOSP no longer contains code for qcom's hardware
crypto.

Change-Id: I921cbe9bed70989f91449e23b5ac3ec1037b7b97
2019-03-20 15:33:48 -05:00
Erfan Abdi
b859e91cd4 partition: add squashfs support
Change-Id: I56217b8fa4f247773157e04b03bd87128c612a00
Signed-off-by: Erfan Abdi <erfangplus@gmail.com>
2019-02-05 18:19:42 +02:00
Ethan Yonker
54970bb1a9 Fix Check_Lifetime_Writes on AB devices
Change-Id: Ie1904d9c48639e8ac9f95d9d2dfb1d965c571928
2019-01-17 16:19:55 -06:00