From aa30414cd603acc790f01c3ab18bf420af098180 Mon Sep 17 00:00:00 2001 From: jb881122 Date: Fri, 26 Apr 2024 12:14:50 -0500 Subject: [PATCH] oor: Don't accept modified boot images by default Change-Id: Ic222908d63e640dcb896bb44777a914c9d412be5 --- oor/src/bl_check.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/oor/src/bl_check.c b/oor/src/bl_check.c index ec8953e..5d3fb67 100644 --- a/oor/src/bl_check.c +++ b/oor/src/bl_check.c @@ -8,6 +8,8 @@ #include #include +#ifdef CRC_PERMISSIVE + char *find_bytes(char *mem, size_t mem_len, char *to_find, size_t to_find_len) { char *ret = NULL; @@ -59,21 +61,6 @@ out: return ret; } -bootloader_config *get_config_from_crc(char *bl_code, size_t bl_code_len) { - bootloader_config *config = NULL; - uint32_t bl_crc = 0; - - bl_crc = crc32(bl_code, bl_code_len); - for(size_t i = 0; i < num_configs; i++) { - if(configs[i].code_crc == bl_crc) { - config = &configs[i]; - break; - } - } - - return config; -} - char bl_equals_str[] = "androidboot.bootloader=%s"; bootloader_config *get_config_from_string(char *bl_code, size_t bl_code_len) { @@ -98,16 +85,35 @@ out: return config; } -bootloader_config *get_config(char *bl_code, size_t bl_code_len) { - bootloader_config *ret = NULL; +#endif /* CRC_PERMISSIVE */ - if(bl_code_len < 0x40000) { - goto out; +bootloader_config *get_config_from_crc(char *bl_code, size_t bl_code_len) { + bootloader_config *config = NULL; + uint32_t bl_crc = 0; + + bl_crc = crc32(bl_code, bl_code_len); + for(size_t i = 0; i < num_configs; i++) { + if(configs[i].code_crc == bl_crc) { + config = &configs[i]; + break; + } } + return config; +} + +bootloader_config *get_config(char *bl_code, size_t bl_code_len) { + bootloader_config *ret = NULL; + ret = get_config_from_crc(bl_code, bl_code_len); +#ifdef CRC_PERMISSIVE if(!ret) { + /* Make sure too-small bootloaders fail gracefully */ + if(bl_code_len < 0x40000) { + goto out; + } + ret = get_config_from_string(bl_code, bl_code_len); if(ret) { printf("WARNING: CRC Mismatch\n"); @@ -115,6 +121,7 @@ bootloader_config *get_config(char *bl_code, size_t bl_code_len) { } out: +#endif if(ret) { printf("Bootloader found: %s\n", ret->name); } else { -- 2.20.1