Skip to content

Commit 4e072b3

Browse files
committed
Merge branch 'fix/coverity_reports_security' into 'master'
fix(security): Fixed coverity warnings from `nvs_sec_provider` and `esp_tee` components Closes IDF-12190, IDF-12194, and IDF-12197 See merge request espressif/esp-idf!36721
2 parents 700e41f + 1f6d450 commit 4e072b3

File tree

3 files changed

+19
-39
lines changed

3 files changed

+19
-39
lines changed

components/esp_tee/subproject/main/common/panic/panic_helper_riscv.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -113,34 +113,26 @@ void panic_print_isrcause(const void *f, int core)
113113
{
114114
RvExcFrame *regs = (RvExcFrame *) f;
115115

116-
/* Please keep in sync with PANIC_RSN_* defines */
117-
static const char *pseudo_reason[] = {
118-
"Unknown reason",
119-
"Interrupt wdt timeout on CPU0",
120-
"Interrupt wdt timeout on CPU1",
121-
"Cache error",
122-
};
123-
124116
const void *addr = (void *) regs->mepc;
125-
const char *rsn = pseudo_reason[0];
117+
const char *rsn = "Unknown reason";
126118

127119
/* The mcause has been set by the CPU when the panic occurred.
128120
* All SoC-level panic will call this function, thus, this register
129121
* lets us know which error was triggered. */
130-
if (regs->mcause == ETS_CACHEERR_INUM) {
131-
/* Panic due to a cache error, multiple cache error are possible,
132-
* assign function print_cache_err_details to our structure's
133-
* details field. As its name states, it will give more details
134-
* about why the error happened. */
135-
rsn = pseudo_reason[PANIC_RSN_CACHEERR];
136-
} else if (regs->mcause == ETS_INT_WDT_INUM) {
137-
/* Watchdog interrupt occurred, get the core on which it happened
138-
* and update the reason/message accordingly. */
139-
#if SOC_CPU_NUM > 1
140-
_Static_assert(PANIC_RSN_INTWDT_CPU0 + 1 == PANIC_RSN_INTWDT_CPU1,
141-
"PANIC_RSN_INTWDT_CPU1 must be equal to PANIC_RSN_INTWDT_CPU0 + 1");
122+
switch (regs->mcause) {
123+
case ETS_CACHEERR_INUM:
124+
rsn = "Cache error";
125+
break;
126+
case PANIC_RSN_INTWDT_CPU0:
127+
rsn = "Interrupt wdt timeout on CPU0";
128+
break;
129+
#if SOC_CPU_CORES_NUM > 1
130+
case PANIC_RSN_INTWDT_CPU1:
131+
rsn = "Interrupt wdt timeout on CPU1";
132+
break;
142133
#endif
143-
rsn = pseudo_reason[PANIC_RSN_INTWDT_CPU0 + core];
134+
default:
135+
break;
144136
}
145137

146138
const char *desc = "Exception was unhandled.";

examples/security/nvs_encryption_hmac/main/main.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* NVS Encryption with HMAC-based encryption key protection scheme example
33
*
4-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
4+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
55
*
66
* SPDX-License-Identifier: Unlicense OR CC0-1.0
77
*/
@@ -39,14 +39,7 @@ static esp_err_t example_custom_nvs_part_init(const char *label)
3939
esp_err_t ret = ESP_FAIL;
4040
#if defined(CONFIG_NVS_ENCRYPTION) && defined(CONFIG_NVS_SEC_KEY_PROTECT_USING_HMAC)
4141
nvs_sec_cfg_t cfg = {};
42-
nvs_sec_scheme_t *sec_scheme_handle = NULL;
43-
44-
nvs_sec_config_hmac_t sec_scheme_cfg = NVS_SEC_PROVIDER_CFG_HMAC_DEFAULT();
45-
46-
ret = nvs_sec_provider_register_hmac(&sec_scheme_cfg, &sec_scheme_handle);
47-
if (ret != ESP_OK) {
48-
return ret;
49-
}
42+
nvs_sec_scheme_t *sec_scheme_handle = nvs_flash_get_default_security_scheme();
5043

5144
ret = nvs_flash_read_security_cfg_v2(sec_scheme_handle, &cfg);
5245
if (ret != ESP_OK) {

examples/security/security_features_app/main/security_features_app_main.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -72,12 +72,7 @@ static esp_err_t example_custom_nvs_part_init(const char *name)
7272
#if CONFIG_NVS_ENCRYPTION
7373
esp_err_t ret = ESP_FAIL;
7474
nvs_sec_cfg_t cfg = {};
75-
nvs_sec_scheme_t *sec_scheme_handle = NULL;
76-
nvs_sec_config_hmac_t sec_scheme_cfg = NVS_SEC_PROVIDER_CFG_HMAC_DEFAULT();
77-
ret = nvs_sec_provider_register_hmac(&sec_scheme_cfg, &sec_scheme_handle);
78-
if (ret != ESP_OK) {
79-
return ret;
80-
}
75+
nvs_sec_scheme_t *sec_scheme_handle = nvs_flash_get_default_security_scheme();
8176

8277
ret = nvs_flash_read_security_cfg_v2(sec_scheme_handle, &cfg);
8378
if (ret != ESP_OK) {

0 commit comments

Comments
 (0)