fix(ng/host/spi): fix OOB reads when tx skb len < SPI_BUF_SIZE#706
fix(ng/host/spi): fix OOB reads when tx skb len < SPI_BUF_SIZE#706derMihai wants to merge 1 commit intoespressif:masterfrom
Conversation
|
Hello @derMihai ,Thank you for the thorough explanation. We appreciate your time in detailing the change. While I ponder how to simplify the solution somewhat, to make the change more transport-agnostic. Thanks a lot for your efforts. |
|
One solution could be to delegate the skb allocation to the transport layer. We can remove the generic |
|
Hello @derMihai, Please find the attached modified patch, which sits on top of current master, 711a1b7. Would you be able to test it on your setup and let me know whether it fixes the issue? Please note that I have not tested this patch myself. Summary of changes
Thanks in advance for your testing and feedback. |
|
Oops! Missed to attach the file. PTA: 0001-fix-ng-host-spi-fix-OOB-reads-when-tx-skb-len-SPI_BU.patch |
|
Thank you, this works just fine. Are you taking over to a new pull request? |
|
If you are fine with it, I will just merge the patch I had attached with you being author. (Let me know !) Although, Merging this might need to verify testing on stdio, just to make sure, nothing is broken. (internal) @Shreyas0-7 , Can you please cross check this on SDIO? |
|
Sure. You don't necessarily have to add me as author, I merely reported the bug. |
|
@derMihai , I think I made mistake in last patch shared. |
|
@derMihai I have pushed the changes in esp_hosted_fg, which had same issues you have reported for esp_hosted_ng. @Shreyas0-7 can you please propagate the changes to NG from above commit? |

Description
The SPI framing protocol assumes
SPI_BUF_SIZEtransfer sizes, but the tx skb size is not extended to cover that. This results in out-of-bounds reads, sending random kernel memory down the bus.I fixed this by re-allocating the tx skb whenever its size is smaller than
SPI_BUF_SIZE. This is done before the SPI transfer. A more efficient approach would be to do this inprocess_tx_packet(), where the skb is usually re-allocated anyway to meet alignment requirements. But since that happens in the transport-independent part of the driver it would require some more refactoring.The
esp_spi_work()function, where I added the new logic, was already nesting a lot so I took the liberty to refactor it a bit, including throwing away the mutex and instead enforcing serial execution withalloc_ordered_workqueue(). If hope that's ok.Testing
I tested this by running a BLE speed test for about 10 mins (
l2cat, part of bluer) on the following setup:6.12.47+rpt-rpi-v8Checklist
Before submitting a Pull Request, please ensure the following: