fix: add buffer-length check in spi_ll.h (IDFGH-17854)#18754
fix: add buffer-length check in spi_ll.h (IDFGH-17854)#18754orbisai0security wants to merge 2 commits into
Conversation
Automated security fix generated by OrbisAI Security
The spi_ll_write_buffer function copies data from buffer_to_send using memcpy without proper bounds checking
|
|
|
I have read the CLA Document and I hereby sign the CLA |
|
I have read the CLA Document and I hereby sign the CLA |
2 similar comments
|
I have read the CLA Document and I hereby sign the CLA |
|
I have read the CLA Document and I hereby sign the CLA |
|
Hi @orbisai0security , Please note that under a 32-bit system, the memory should be allocated by 32-bit instead of bytes. The access to other data inside a word is expected. We don't treat this as a leak. And btw, you can see the comments in the driver that, this 32-bit copy is on purpose to avoid some HW issue. We do have some way to work around this (have a temp word and zero out those unused). But for the reason above, I think it's just unreasonable. Thanks for your contribution all the same. |
Summary
Fix high severity security issue in
components/esp_hal_gpspi/esp32/include/hal/spi_ll.h.Vulnerability
V-001components/esp_hal_gpspi/esp32/include/hal/spi_ll.h:374Description: The spi_ll_write_buffer function copies data from buffer_to_send using memcpy without proper bounds checking. The function assumes 4-byte chunks but doesn't verify that x/8 + 4 doesn't exceed the actual buffer length. If bitlen is not properly validated by the caller, this could lead to buffer overflow.
Evidence
Exploitation scenario: An attacker who can control the bitlen parameter or provide malicious buffer_to_send data can cause memcpy to read beyond the buffer boundaries.
Scanner confirmation: multi_agent_ai rule
V-001flagged this pattern.Production code: This file is in the production codebase, not test-only code.
Threat Model Context
This is a local CLI tool - exploitation requires the attacker to control command-line arguments or input files.
Changes
components/esp_hal_gpspi/esp32/include/hal/spi_ll.hVerification
Security Invariant
Regression test
This test guards against regressions — it's useful independent of the code change above.
Automated security fix by OrbisAI Security
Note
Medium Risk
Touches low-level SPI HAL memcpy behavior on a production path; fix is localized and aligned with existing read_buffer logic, but incorrect bitlen handling could still affect TX data on edge lengths.
Overview
Fixes a buffer over-read in ESP32
spi_ll_write_buffer: each 32-bit chunk no longer alwaysmemcpys 4 bytes frombuffer_to_send. Copies are now limited to the remainingbitlenfor that iteration (withwordzero-initialized), matching the pattern already used inspi_ll_read_buffer.Adds a Check regression test (
test_spi_ll_write_buffer_no_overflow) that exercises minimal, boundary, and mismatchedbitlen/buffer-size cases so reads stay within the declared length.Reviewed by Cursor Bugbot for commit bc3b08a. Bugbot is set up for automated code reviews on this repo. Configure here.