fscrypt policy: don't bail restore if we cannot lookup policy

When TWRP is unable to lookup a fscrypt policy, we should not bail
the entire restore. Let's note that we had an issue with the lookup
in the log and continue restoring.

Change-Id: Ida80458356c12f81ff47f583beb05dd392486a0d
This commit is contained in:
bigbiff
2021-08-15 18:52:04 -04:00
parent d04f8e0078
commit cefb0de23f
2 changed files with 12 additions and 8 deletions
-1
View File
@@ -185,7 +185,6 @@ tar_append_file(TAR *t, const char *realname, const char *savename)
printf("failed to lookup fscrypt tar policy for '%s' - '%s'\n", realname, policy_hex);
free(t->th_buf.fep);
t->th_buf.fep = NULL;
return -1;
}
}
else {
+12 -7
View File
@@ -570,6 +570,7 @@ tar_extract_dir(TAR *t, const char *realname)
#endif
printf("tar_extract_dir(): restoring fscrypt policy %s to dir %s\n", (char *)policy_hex, realname);
#endif
bool policy_lookup_error = false;
#ifdef USE_FSCRYPT_POLICY_V1
uint8_t binary_policy[FS_KEY_DESCRIPTOR_SIZE];
memset(&binary_policy, 0, FS_KEY_DESCRIPTOR_SIZE);
@@ -581,24 +582,28 @@ tar_extract_dir(TAR *t, const char *realname)
#ifdef USE_FSCRYPT_POLICY_V1
if (!lookup_ref_tar(t->th_buf.fep->master_key_descriptor, &binary_policy[0])) {
printf("error looking up fscrypt policy for '%s' - %s\n", realname, t->th_buf.fep->master_key_descriptor);
return -1;
policy_lookup_error = true;
}
memcpy(&t->th_buf.fep->master_key_descriptor, binary_policy, FS_KEY_DESCRIPTOR_SIZE);
bytes_to_hex(t->th_buf.fep->master_key_descriptor, FS_KEY_DESCRIPTOR_SIZE, policy_hex);
#else
if (!lookup_ref_tar(t->th_buf.fep->master_key_identifier, &binary_policy[0])) {
printf("error looking up fscrypt policy for '%s' - %s\n", realname, t->th_buf.fep->master_key_identifier);
return -1;
policy_lookup_error = true;
}
memcpy(&t->th_buf.fep->master_key_identifier, binary_policy, FSCRYPT_KEY_IDENTIFIER_SIZE);
bytes_to_hex(t->th_buf.fep->master_key_identifier, FSCRYPT_KEY_IDENTIFIER_SIZE, policy_hex);
#endif
printf("attempting to restore policy: %s\n", policy_hex);
if (!fscrypt_policy_set_struct(realname, t->th_buf.fep))
if (!policy_lookup_error)
{
printf("tar_extract_file(): failed to restore fscrypt policy to dir '%s' '%s'!!!\n", realname, policy_hex);
//return -1; // This may not be an error in some cases, so log and ignore
}
printf("attempting to restore policy: %s\n", policy_hex);
if (!fscrypt_policy_set_struct(realname, t->th_buf.fep))
{
printf("tar_extract_file(): failed to restore fscrypt policy to dir '%s' '%s'!!!\n", realname, policy_hex);
//return -1; // This may not be an error in some cases, so log and ignore
}
} else
printf("No policy was found. Continuing restore.");
}
else
printf("NULL FSCRYPT\n");