From 60ab9631d7f645d17ed543d1dbdb69e799fac230 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Thu, 2 May 2024 13:23:35 +0530 Subject: [PATCH 1/2] fix(tests): remove unused partition NVS bin file --- .../test_apps/main/partition_plaintext.bin | Bin 8192 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 components/nvs_flash/test_apps/main/partition_plaintext.bin diff --git a/components/nvs_flash/test_apps/main/partition_plaintext.bin b/components/nvs_flash/test_apps/main/partition_plaintext.bin deleted file mode 100644 index 76fe7122269f0d1f8c8e8a379f7801d4fb062690..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmezO|Nnmm1_p-zSim8%yLVRM2fr8?8ULTOTf&}FnwwkcmzbMcT#%TY%D}(~HII>z z@xQG^-(j$PsD*cGCCD}ghI*L1AmjhX^Q=6;@}3C!2ADh(hKd~iuoW?nkj z2qA|5|5sa!D;PLh88}%PI9nOGSQ)rl8MvW^6r&RpgPeZDBCvjs)Cwb~%sh|*Yz+VZ z?>CV;&d9{P`s{m{YcOd>561tqHGNiK>SthJWcdFdWd5lql6_!#r^Mn^GZT>U3?TFS z_zxd8G%`+1O2#x7CIT{l>)F?vG4&(N&q!WtpOISOmYI_ZHX9T}91Q>eTYQw-#Hj3= z-igNtAoI(uo_xa8k1+qJc9C!r*y#u>co_cwpTV7z#mL0W!pg?Z!HL5Tkoo?SdABh2 zL(NxY`Y&Psg{>GIbqMpN8UFuYuu8fqF)2AEH7z|OGb=kMH!r`Su&B7Cw5+_MvI-KB zj7}L0Nvks_CS~R!G&3+TJmC5N|JK#3M#UwGMI{DU0Yu8s$k@cx%-q5fViShSQTfsE z8BHIf`D3(v0GGt0L&DAVZY!x^|Q?8UmvsFd71*Aut*O MqaiRF0@Mfr0AP*B!T Date: Thu, 2 May 2024 13:24:45 +0530 Subject: [PATCH 2/2] fix(tests): correct the flash write length for NVS encrypted test Write only till the embedded file size in the NVS partition. Earlier the length was kept as the whole partition size and it could result in accessing embedded rodata beyond the MMU mapped range. --- components/nvs_flash/test_apps/main/test_nvs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/components/nvs_flash/test_apps/main/test_nvs.c b/components/nvs_flash/test_apps/main/test_nvs.c index 4c4f4ef7ed..b0687b608f 100644 --- a/components/nvs_flash/test_apps/main/test_nvs.c +++ b/components/nvs_flash/test_apps/main/test_nvs.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ #include #include #include +#include #include #include @@ -587,6 +588,7 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena extern const char nvs_key_start[] asm("_binary_encryption_keys_bin_start"); extern const char nvs_key_end[] asm("_binary_encryption_keys_bin_end"); extern const char nvs_data_sch0_start[] asm("_binary_partition_encrypted_bin_start"); + extern const char nvs_data_sch0_end[] asm("_binary_partition_encrypted_bin_end"); const esp_partition_t* key_part = esp_partition_find_first( ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS, NULL); @@ -600,15 +602,24 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena ESP_ERROR_CHECK( esp_partition_write(key_part, i, nvs_key_start + i, SPI_FLASH_SEC_SIZE) ); } - for (int i = 0; i < nvs_part->size; i+= SPI_FLASH_SEC_SIZE) { + const int content_size = nvs_data_sch0_end - nvs_data_sch0_start - 1; + TEST_ASSERT_TRUE((content_size % SPI_FLASH_SEC_SIZE) == 0); + + const int size_to_write = MIN(content_size, nvs_part->size); + for (int i = 0; i < size_to_write; i+= SPI_FLASH_SEC_SIZE) { ESP_ERROR_CHECK( esp_partition_write(nvs_part, i, nvs_data_sch0_start + i, SPI_FLASH_SEC_SIZE) ); } err = nvs_flash_read_security_cfg(key_part, &xts_cfg); #elif CONFIG_NVS_SEC_KEY_PROTECT_USING_HMAC extern const char nvs_data_sch1_start[] asm("_binary_partition_encrypted_hmac_bin_start"); + extern const char nvs_data_sch1_end[] asm("_binary_partition_encrypted_hmac_bin_end"); - for (int i = 0; i < nvs_part->size; i+= SPI_FLASH_SEC_SIZE) { + const int content_size = nvs_data_sch1_end - nvs_data_sch1_start - 1; + TEST_ASSERT_TRUE((content_size % SPI_FLASH_SEC_SIZE) == 0); + + const int size_to_write = MIN(content_size, nvs_part->size); + for (int i = 0; i < size_to_write; i+= SPI_FLASH_SEC_SIZE) { ESP_ERROR_CHECK( esp_partition_write(nvs_part, i, nvs_data_sch1_start + i, SPI_FLASH_SEC_SIZE) ); }