-
Notifications
You must be signed in to change notification settings - Fork 220
fix(ng/host/spi): fix OOB reads when tx skb len < SPI_BUF_SIZE #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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. |

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: