From cefb0de23f0a303b3fb061b14139f8edab21a230 Mon Sep 17 00:00:00 2001 From: bigbiff Date: Sun, 15 Aug 2021 18:52:04 -0400 Subject: [PATCH] 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 --- libtar/append.c | 1 - libtar/extract.c | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libtar/append.c b/libtar/append.c index 6f0b2527..dff0f88d 100755 --- a/libtar/append.c +++ b/libtar/append.c @@ -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 { diff --git a/libtar/extract.c b/libtar/extract.c index 65ea1d16..08e2914c 100755 --- a/libtar/extract.c +++ b/libtar/extract.c @@ -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");