implement more checks in coproc module
- check memory address range - check firmware size at an earlier stage
This commit is contained in:
parent
a4238d815d
commit
83b54d003d
@ -193,6 +193,7 @@ msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
|
||||
#: ports/cxd56/common-hal/pulseio/PulseIn.c
|
||||
#: ports/espressif/common-hal/coproc/Coproc.c
|
||||
#: ports/nrf/common-hal/pulseio/PulseIn.c
|
||||
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
|
||||
#: ports/stm/common-hal/pulseio/PulseIn.c py/argcheck.c
|
||||
@ -485,6 +486,7 @@ msgstr ""
|
||||
msgid "Already have all-matches listener"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/coproc/__init__.c
|
||||
#: shared-module/memorymonitor/AllocationAlarm.c
|
||||
#: shared-module/memorymonitor/AllocationSize.c
|
||||
msgid "Already running"
|
||||
@ -1015,7 +1017,7 @@ msgstr ""
|
||||
msgid "Firmware is invalid"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/coproc/__init__.c
|
||||
#: ports/espressif/common-hal/coproc/Coproc.c
|
||||
#: ports/espressif/common-hal/dualbank/__init__.c
|
||||
msgid "Firmware is too big"
|
||||
msgstr ""
|
||||
|
@ -27,12 +27,33 @@
|
||||
#include "shared-bindings/coproc/Coproc.h"
|
||||
#include "shared-bindings/coproc/CoprocMemory.h"
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
#include "esp32s2/ulp.h"
|
||||
#define ULP_COPROC_RESERVE_MEM (CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM)
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
#include "esp32s3/ulp.h"
|
||||
#define ULP_COPROC_RESERVE_MEM (CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM)
|
||||
#endif
|
||||
|
||||
#define RTC_SLOW_MEM_END ((uint32_t)RTC_SLOW_MEM + ULP_COPROC_RESERVE_MEM)
|
||||
|
||||
void common_hal_coproc_coproc_construct(coproc_coproc_obj_t *self,
|
||||
const uint8_t *buf, const size_t buf_len, coproc_memory_obj_t *coproc_memory) {
|
||||
// set CoprocMemory object
|
||||
if (coproc_memory != NULL) {
|
||||
if (coproc_memory->address < ((uint32_t)RTC_SLOW_MEM + buf_len) ||
|
||||
coproc_memory->address > (RTC_SLOW_MEM_END - coproc_memory->len)) {
|
||||
mp_raise_ValueError_varg(translate("%q out of range"), MP_QSTR_CoprocMemory);
|
||||
}
|
||||
}
|
||||
self->coproc_memory = coproc_memory;
|
||||
|
||||
// load buffer
|
||||
if (buf_len > ULP_COPROC_RESERVE_MEM) {
|
||||
mp_raise_RuntimeError(translate("Firmware is too big"));
|
||||
}
|
||||
self->buf_len = buf_len;
|
||||
self->buf = (uint8_t *)m_malloc(self->buf_len, false);
|
||||
memcpy(self->buf, buf, self->buf_len);
|
||||
|
@ -42,7 +42,7 @@ CONFIG_ESP32S2_DATA_CACHE_LINE_32B=y
|
||||
# CONFIG_ESP32S2_TRAX is not set
|
||||
CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM=0x0
|
||||
CONFIG_ESP32S2_ULP_COPROC_ENABLED=y
|
||||
CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM=4096
|
||||
CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM=8176
|
||||
CONFIG_ESP32S2_ULP_COPROC_RISCV=y
|
||||
CONFIG_ESP32S2_DEBUG_OCDAWARE=y
|
||||
# CONFIG_ESP32S2_DEBUG_STUBS_ENABLE is not set
|
||||
|
@ -68,7 +68,7 @@ CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE=32
|
||||
# CONFIG_ESP32S3_TRAX is not set
|
||||
CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM=0x0
|
||||
CONFIG_ESP32S3_ULP_COPROC_ENABLED=y
|
||||
CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=4096
|
||||
CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=8176
|
||||
CONFIG_ESP32S3_ULP_COPROC_RISCV=y
|
||||
CONFIG_ESP32S3_BROWNOUT_DET=y
|
||||
CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_7=y
|
||||
|
Loading…
Reference in New Issue
Block a user