-
Notifications
You must be signed in to change notification settings - Fork 930
dmaengine: adi-dma: fix use-after-free in cyclic transfers #3112
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: adsp-6.12.0-y
Are you sure you want to change the base?
Conversation
Agreed! Claude overdid it IMO. I would go with your proposed fix as something temporary... Looking at the driver it seems like a big refactor is needed anyways. |
Yah, I dug a little deeper, especially since it removed the following comment: And after some prompting it concluded: Before I saw that comment I was confused why the cyclic and non-cyclic approaches were different. |
Probably over complicating again 😄 . That driver looks like a typical out of tree driver so we'll have to refactor it a bit. So, IMO, I would go with your fix. Yeah, we have a copy in there but it's a small struct and I would not expect overhead at all |
A race condition exists in the threaded interrupt handler when processing
cyclic DMA descriptors. The handler accesses channel->current_desc->result
after releasing the channel lock, creating a window where another CPU
executing adi_dma_terminate_all() can free the descriptor.
Race sequence:
CPU 0 (thread handler) CPU 1 (terminate_all)
---------------------- ---------------------
Lock channel->lock
Check current_desc->cyclic
Get callback pointer
Unlock channel->lock
Lock channel->lock
Free current_desc
Unlock channel->lock
Access current_desc->result <- Use-after-free
This results in accessing freed memory containing list poison values
(0xdead000000000100), leading to kernel crashes.
Fix this by copying the result structure to a local variable while
still holding the lock, then using the copy after unlocking. This
follows the same safe pattern used in the non-cyclic path, which
already uses a local descriptor pointer.
The fix is minimal and avoids the complications warned about in the
original code comment regarding cyclic descriptors and the pending
list during termination.
Signed-off-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Philip Molloy <philip.molloy@analog.com>
|
Before I force push, here is the more complicated patch for future reference: |
4bd5720 to
fd506fb
Compare
A customer reported a bug and proposed a fix for a kernel crash. The following stack trace is generated by simulating that crash.
I generated the patch in this PR based on the above. It will require more thorough review and testing. The comments are also fairly verbose and should likely get dropped before merging.
A more trivial fix would be as follows and more clearly identifies the problem: