STM32: Parse the IRQ vectors get_irq_handler was written to read - #763
Conversation
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Validation record for head
Caveats: the 9 skips are the pre-existing |
|
Corpus decompilation diffs can be found at angr/dec-snapshots@master...angr/cle_763 |
|
Is there a better way this could be implemented? |
VectorTable.from_bytes built the structure with from_buffer_copy over the first 64 bytes and discarded the rest, so get_irq_handler raised AttributeError on the self._data it expected. The peripheral vectors it wants live past those 64 bytes anyway, which is exactly the part the ctypes fields cannot describe: the fields cover the 16 system exception vectors, and how many IRQ vectors follow them is a property of the device that a raw flash image does not record. from_bytes now unpacks the words after the system vectors into irq_handlers, and get_irq_handler indexes that. A Cortex-M NVIC drives at most 480 external interrupt lines, so the parse stops there instead of reporting whatever code follows the table as a handler, and a negative IRQ number is rejected rather than silently reading a system exception vector. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
4f523b9 to
d6b2e5c
Compare
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Agreed, and done in What drove the raw read, for the record. The ctypes fields describe the 16 system exception vectors, which the architecture fixes, and every peripheral IRQ vector lies past the end of the structure — the format is just u32 words, but the structure cannot have a field for them because how many there are is a property of the device, and a raw flash image does not record it. The Nucleo-L152RE fixture runs 16328 words past its system vectors and only its device's IRQ count of them are vectors, so the old patch read bytes on demand rather than materialising all of that. That is not a reason not to parse, though: a Cortex-M NVIC drives at most 480 external interrupt lines (ARMv8-M; 240 on ARMv7-M), so the table cannot be longer than that whatever the image holds. Parsing bounded by the NVIC costs 480 words and fixes a bug the byte read had —
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS
VectorTable.get_irq_handlerreadself._data, an attribute the structure never set, so every call raisedAttributeError.from_bytesbuilt the structure withfrom_buffer_copyover the first 64 bytes and discarded the rest, which is where the peripheral IRQ vectors it wants live.Those 64 bytes are the 16 system exception vectors the ctypes fields describe; how many IRQ vectors follow them is a property of the device that a raw flash image does not record.
from_bytesnow unpacks the words after them intoirq_handlersandget_irq_handlerindexes that. A Cortex-M NVIC drives at most 480 external interrupt lines, so the parse stops there rather than reporting whatever code follows the table as a handler, and a negative IRQ number is rejected.The regression reads the IRQ vectors of the Nucleo-L152RE image already in
binariesand checks them againstDefault_Handlerin the ELF build of the same firmware;python -m pytest tests/test_stm32.pycovers it.Follow-up to #716, as requested in #716 (comment). Validation: #763 (comment)