Ignore DE retrieveKey failure for non-user-0

retrieveKey can fail in load_all_de_keys if a user
is partially removed, i.e. cases where
fscrypt_destroy_user_key() got interrupted. So just
ignore the failure, else could reboot into recovery.

Test: pm create-user foo
      pm remove-user 10
      adb reboot && check device not enter recovery

Signed-off-by: liulvping <liulvping@xiaomi.com>
Change-Id: Iba9d53a0833524d00e65d0427ab03002c5d8d509
This commit is contained in:
liulvping 2022-10-10 19:16:23 +08:00 committed by lvping liu
parent 03ad91c3c2
commit 69b048507f

View file

@ -417,7 +417,11 @@ static bool load_all_de_keys() {
userid_t user_id = std::stoi(entry->d_name); userid_t user_id = std::stoi(entry->d_name);
auto key_path = de_dir + "/" + entry->d_name; auto key_path = de_dir + "/" + entry->d_name;
KeyBuffer de_key; KeyBuffer de_key;
if (!retrieveKey(key_path, kEmptyAuthentication, &de_key)) return false; if (!retrieveKey(key_path, kEmptyAuthentication, &de_key)) {
// This is probably a partially removed user, so ignore
if (user_id != 0) continue;
return false;
}
EncryptionPolicy de_policy; EncryptionPolicy de_policy;
if (!install_storage_key(DATA_MNT_POINT, options, de_key, &de_policy)) return false; if (!install_storage_key(DATA_MNT_POINT, options, de_key, &de_policy)) return false;
auto ret = s_de_policies.insert({user_id, de_policy}); auto ret = s_de_policies.insert({user_id, de_policy});