[T-Mobile LG G3] Lou_Cipher:
Bug breaks phone encryption

Hey, think I've stumbled on a little bug that prevents encrypting the phone. When you try to use Settings -> Security -> Encrypt Phone to encrypt the device, it flashes the green droid, then goes to the cm boot animation and stays there until you pull the battery. It does correctly unmount /data, logcat shows it's looking for a file in the wrong place:

D/Cryptfs ( 269): unmounting /data succeeded
D/QSEECOMAPI: ( 269): QSEECom_get_handle sb_length = 0x2000
D/QSEECOMAPI: ( 269): App is not loaded in QSEE
E/QSEECOMAPI: ( 269): Error::Cannot open the file /vendor/firmware/keymaster/keymaster.mdt
E/QSEECOMAPI: ( 269): Error::Loading image failed with ret = -1
E/QCOMKeyMaster( 269): Loading keymaster app failed
E/Cryptfs ( 269): could not open keymaster device in keystore (Operation not permitted)
E/Cryptfs ( 269): Failed to init keymaster
F/libc ( 269): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x3c in tid 345 (vold)
F/libc ( 269): Unable to open connection to debuggerd: Connection refused
I/Vold ( 7354): Vold 2.1 (the revenge) firing up

127|root@d851:/ # find / | grep keymaster
/system/etc/firmware/keymaster.b00
/system/etc/firmware/keymaster.b01
/system/etc/firmware/keymaster.b02
/system/etc/firmware/keymaster.b03
/system/etc/firmware/keymaster.mdt
/system/lib/libsoftkeymaster.so

I symlinked /system/etc/firmware to /vendor/firmware/keymaster to see if it made a difference, and it does, but different error:

root@d851:/ # vdc cryptfs enablecrypto inplace password xxxxxxxx

Relevant logcat info:

I/Cryptfs ( 268): Using scrypt with keymaster for cryptfs KDF
E/Cryptfs ( 268): Invalid hex string
E/Cryptfs ( 268): Failed to convert passwd from hex
E/Cryptfs ( 268): scrypt failed
E/Cryptfs ( 268): Cannot create encrypted master key
E/Cryptfs ( 268): Error enabling encryption after framework is shutdown, no data changed, restarting system

Which, at a guess, means that wasn't the keymaster it was looking for.

Tried running with the wipe argument (WARNING!!! DO NOT run this command unless you don't care about the contents of your internal storage, this will wipe it!), and so far it hasn't returned, and I have a blank screen

vdc cryptfs enablecrypto wipe password xxxxxx

So far logcat shows:

D/Cryptfs ( 269): unmounting /data succeeded
D/QSEECOMAPI: ( 269): QSEECom_get_handle sb_length = 0x2000
D/QSEECOMAPI: ( 269): App is not loaded in QSEE
D/QSEECOMAPI: ( 269): Loaded image: APP id = 2
I/Cryptfs ( 269): keymaster version is 3
D/QSEECOMAPI: ( 269): QSEECom_dealloc_memory
D/QSEECOMAPI: ( 269): QSEECom_shutdown_app, app_id = 2
D/QSEECOMAPI: ( 269): QSEECom_get_handle sb_length = 0x2000
D/QSEECOMAPI: ( 269): App is not loaded in QSEE
D/QSEECOMAPI: ( 269): Loaded image: APP id = 2
D/QSEECOMAPI: ( 269): QSEECom_dealloc_memory
D/QSEECOMAPI: ( 269): QSEECom_shutdown_app, app_id = 2
I/Cryptfs ( 269): Using scrypt with keymaster for cryptfs KDF
D/QSEECOMAPI: ( 269): QSEECom_get_handle sb_length = 0x2000
D/QSEECOMAPI: ( 269): App is not loaded in QSEE
D/QSEECOMAPI: ( 269): Loaded image: APP id = 2
I/Cryptfs ( 269): Signing safely-padded object
D/QSEECOMAPI: ( 269): QSEECom_dealloc_memory
D/QSEECOMAPI: ( 269): QSEECom_shutdown_app, app_id = 2
I/Cryptfs ( 269): Using scrypt with keymaster for cryptfs KDF
D/QSEECOMAPI: ( 269): QSEECom_get_handle sb_length = 0x2000
D/QSEECOMAPI: ( 269): App is not loaded in QSEE
D/QSEECOMAPI: ( 269): Loaded image: APP id = 2
I/Cryptfs ( 269): Signing safely-padded object
D/QSEECOMAPI: ( 269): QSEECom_dealloc_memory
D/QSEECOMAPI: ( 269): QSEECom_shutdown_app, app_id = 2
I/Cryptfs ( 269): Enabling support for allow_discards in dmcrypt.
I/Cryptfs ( 269): load_crypto_mapping_table: target_type = crypt
I/Cryptfs ( 269): load_crypto_mapping_table: real_blk_name = /dev/block/platform/msm_sdcc.1/by-name/userdata, extra_params = 1 allow_discards
I/Cryptfs ( 269): Making empty filesystem with command /system/bin/make_ext4fs -a /data -l 27325360640 /dev/block/dm-0
I/make_ext4fs( 269): SELinux: Loaded file_contexts from /file_contexts
I/make_ext4fs( 269): Creating filesystem with parameters:
I/make_ext4fs( 269): Size: 27325358080
I/make_ext4fs( 269): Block size: 4096
I/make_ext4fs( 269): Blocks per group: 32768
I/make_ext4fs( 269): Inodes per group: 8176
I/make_ext4fs( 269): Inode size: 256
I/make_ext4fs( 269): Journal blocks: 32768
I/make_ext4fs( 269): Label:
I/make_ext4fs( 269): Blocks: 6671230
I/make_ext4fs( 269): Block groups: 204
I/make_ext4fs( 269): Reserved block group size: 1024
I/make_ext4fs( 269): Created filesystem with 11/1667904 inodes and 148720/6671230 blocks
I/rmt_storage( 285): rmt_storage_connect_cb: clnt_h=0x6 conn_h=0xb6b01090
I/rmt_storage( 285): rmt_storage_rw_iovec_cb: /boot/modem_fs1: clnt_h=0x1: req_h=0xa msg_id=3: R/W request received
I/rmt_storage( 285): wakelock acquired: 1, error no: 42
I/rmt_storage( 285): rmt_storage_client_thread: /boot/modem_fs1: clnt_h=0x1 Unblock worker thread (th_id: -1229455232)
I/rmt_storage( 285): rmt_storage_client_thread: /boot/modem_fs1: clnt_h=0x1: req_h=0xa msg_id=3: Bytes written = 1572864
I/rmt_storage( 285): rmt_storage_client_thread: /boot/modem_fs1: clnt_h=0x1: req_h=0xa msg_id=3: Send response: res=0 err=0
I/rmt_storage( 285): rmt_storage_client_thread: /boot/modem_fs1: clnt_h=0x1 About to block rmt_storage client thread (th_id: -1229455232) wakelock released: 1, error no: 22
I/rmt_storage( 285):
I/rmt_storage( 285): rmt_storage_disconnect_cb: clnt_h=0x0x6 conn_h=0x0xb6b01090

That was several minutes ago. Currently top shows makefs_ext4 still running, but no cpu utilization, and memory use remains constant. iostat shows heavy write activity on dm-0, but strangely, while blk_wrtn/s fluctuates and stays in the 120 range, the blk_wrtn total never changes. Not sure what's up with that, but I'm going to leave this bad boy running for a while and see if it will finish encrypting. I just have a blank screen at the moment, as I initiated encryption from the command line, it probably didn't launch the usual pretties for the screen, so I just have to wait this out. I'll check back in to let you know if it works. If it does, we've got two problems: one, encryption looking for keymaster.mdt in the wrong place (easy fix), and two, for some reason failed to do in-place encryption, failing on key generation (no idea how difficult to fix, haven't looked at the code yet).

Also not sure if this is an upstream cm 12 issue, or specific to this rom, but my guess would be upstream.

[EDIT]Update, after hours of waiting, nothing. Device was not encrypted. Also, has anyone else noticed issues with recognizing when a charger is connected? Haven't tracked it down, but mine will intermittently think it's unplugged until a reboot. This occurs even when I can connect it to my computer via mpt no problem.

[EDIT]OK, now we're getting weird. After all that, I rebooted, and went the settings app, and for spits and giggles I hit Encrypt Phone again. This time it appears to be working, I get the green android, an actual progress percentage. Will check back with success/fail, but seriously no idea why it's working now.