Skip to content

Commit

Permalink
kernel: reject v3 and v3.1 signature scheme for manager verification
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Oct 11, 2023
1 parent a3b92d6 commit 8828939
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions kernel/apk_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,10 @@ check_v2_signature(char *path, unsigned expected_size, const char *expected_sha2
u64 size8, size_of_block;

loff_t pos;
bool block_valid;

const int NOT_EXIST = 0;
const int INVALID = 1;
const int VALID = 2;
int v2_signing_status = NOT_EXIST;
int v3_signing_status = NOT_EXIST;
bool v2_signing_valid = false;
bool v3_signing_exist = false;
bool v3_1_signing_exist = false;

int i;
struct file *fp = ksu_filp_open_compat(path, O_RDONLY, 0);
Expand Down Expand Up @@ -188,23 +185,27 @@ check_v2_signature(char *path, unsigned expected_size, const char *expected_sha2
offset = 4;
pr_info("id: 0x%08x\n", id);
if (id == 0x7109871au) {
block_valid = check_block(fp, &size4, &pos, &offset,
v2_signing_valid = check_block(fp, &size4, &pos, &offset,
expected_size, expected_sha256);
v2_signing_status = block_valid ? VALID : INVALID;
} else if (id == 0xf05368c0u) {
block_valid = check_block(fp, &size4, &pos, &offset,
expected_size, expected_sha256);
v3_signing_status = block_valid ? VALID : INVALID;
// http://aospxref.com/android-14.0.0_r2/xref/frameworks/base/core/java/android/util/apk/ApkSignatureSchemeV3Verifier.java#73
v3_signing_exist = true;
} else if (id == 0x1b93ad61u) {
// http://aospxref.com/android-14.0.0_r2/xref/frameworks/base/core/java/android/util/apk/ApkSignatureSchemeV3Verifier.java#74
v3_1_signing_exist = true;
}
pos += (size8 - offset);
}

clean:
filp_close(fp, 0);

return (v2_signing_status == NOT_EXIST && v3_signing_status == VALID) ||
(v2_signing_status == VALID && v3_signing_status == NOT_EXIST) ||
(v2_signing_status == VALID && v3_signing_status == VALID);
if (v3_signing_exist || v3_1_signing_exist) {
pr_err("Unexpected v3 signature scheme found!\n");
return false;
}

return v2_signing_valid;
}

#ifdef CONFIG_KSU_DEBUG
Expand Down

0 comments on commit 8828939

Please sign in to comment.