Merge branch 'coredump_sanity_check_v5.2' into 'release/v5.2'

fix(coredump): increase sanity check before get summary (v5.2)

See merge request espressif/esp-idf!30528
This commit is contained in:
Alexey Gerenkov 2024-06-04 21:21:50 +08:00
commit 824d5823ba
2 changed files with 15 additions and 23 deletions

View File

@ -758,25 +758,22 @@ typedef struct {
void *n_ptr;
} elf_note_content_t;
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
/* Below are the helper function to parse the core dump ELF stored in flash */
static esp_err_t elf_core_dump_image_mmap(esp_partition_mmap_handle_t* core_data_handle, const void **map_addr)
{
size_t out_size;
assert (core_data_handle);
const esp_partition_t *core_part = NULL;
uint32_t out_size;
assert(core_data_handle);
assert(map_addr);
/* Find the partition that could potentially contain a (previous) core dump. */
const esp_partition_t *core_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_DATA_COREDUMP,
NULL);
if (!core_part) {
ESP_COREDUMP_LOGE("Core dump partition not found!");
return ESP_ERR_NOT_FOUND;
}
if (core_part->size < sizeof(uint32_t)) {
ESP_COREDUMP_LOGE("Core dump partition too small!");
return ESP_ERR_INVALID_SIZE;
/* Retrieve the partition and size. */
esp_err_t err = esp_core_dump_partition_and_size_get(&core_part, &out_size);
if (err != ESP_OK) {
return err;
}
/* Data read from the mmapped core dump partition will be garbage if flash
* encryption is enabled in hardware and core dump partition is not encrypted
*/
@ -784,13 +781,8 @@ static esp_err_t elf_core_dump_image_mmap(esp_partition_mmap_handle_t* core_data
ESP_COREDUMP_LOGE("Flash encryption enabled in hardware and core dump partition is not encrypted!");
return ESP_ERR_NOT_SUPPORTED;
}
/* Read the size of the core dump file from the partition */
esp_err_t ret = esp_partition_read(core_part, 0, &out_size, sizeof(uint32_t));
if (ret != ESP_OK) {
ESP_COREDUMP_LOGE("Failed to read core dump data size");
return ret;
}
/* map the full core dump parition, including the checksum. */
/* map the full core dump partition, including the checksum. */
return esp_partition_mmap(core_part, 0, out_size, ESP_PARTITION_MMAP_DATA,
map_addr, core_data_handle);
}

View File

@ -52,7 +52,7 @@ esp_err_t esp_core_dump_write_data(core_dump_write_data_t *wr_data, void *data,
#define ESP_COREDUMP_FLASH_ERASE(_off_, _len_) esp_flash_erase_region(esp_flash_default_chip, _off_, _len_)
esp_err_t esp_core_dump_image_check(void);
static esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
static void esp_core_dump_flash_print_write_start(void)
{
@ -242,7 +242,7 @@ static esp_err_t esp_core_dump_flash_write_prepare(core_dump_write_data_t *wr_da
padding = COREDUMP_CACHE_SIZE - modulo;
}
/* Now we can check whether we have enough space in our core dump parition
/* Now we can check whether we have enough space in our core dump partition
* or not. */
if ((*data_len + padding + cs_len) > s_core_flash_config.partition.size) {
ESP_COREDUMP_LOGE("Not enough space to save core dump!");
@ -465,7 +465,7 @@ esp_err_t esp_core_dump_image_erase(void)
return err;
}
static esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size)
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size)
{
uint32_t core_size = 0;
const esp_partition_t *core_part = NULL;