From: Ivan Grokhotkov Date: Wed, 22 Feb 2017 04:51:16 +0000 (+0800) Subject: spi_flash: protect spi_flash_unlock X-Git-Tag: v2.0-rc2~42^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbb71baca96d5f4c22be017dafef8d745834dac5;p=esp-idf spi_flash: protect spi_flash_unlock spi_flash_unlock was missing spi_flash_guard_start, which caused cache to be enabled during unlock operation, causing hard-to-trace crashes and cache data corruption. --- diff --git a/components/spi_flash/flash_ops.c b/components/spi_flash/flash_ops.c index 3581b34141..324c02a3d0 100644 --- a/components/spi_flash/flash_ops.c +++ b/components/spi_flash/flash_ops.c @@ -202,7 +202,9 @@ esp_err_t IRAM_ATTR spi_flash_write(size_t dst, const void *srcv, size_t size) size_t mid_size = (size - left_size) & ~3U; size_t right_off = left_size + mid_size; size_t right_size = size - mid_size - left_size; + spi_flash_guard_start(); rc = spi_flash_unlock(); + spi_flash_guard_end(); if (rc != SPI_FLASH_RESULT_OK) { goto out; } @@ -289,7 +291,9 @@ esp_err_t IRAM_ATTR spi_flash_write_encrypted(size_t dest_addr, const void *src, COUNTER_START(); spi_flash_disable_interrupts_caches_and_other_cpu(); SpiFlashOpResult rc; + spi_flash_guard_start(); rc = spi_flash_unlock(); + spi_flash_guard_end(); spi_flash_enable_interrupts_caches_and_other_cpu(); if (rc == SPI_FLASH_RESULT_OK) {