Commit 8d2e0cb
spi: fix use-after-free on managed registration failure
The SPI API is asymmetric and the controller is freed as part of
deregistration (unless it has been allocated using
devm_spi_alloc_host/target()).
A recent change converting the managed registration function to use
devm_add_action_or_reset() inadvertently introduced a (mostly
theoretical) regression where a non-devres managed controller could be
freed as part of failed registration. This in turn would lead to
use-after-free in controller driver error paths.
Fix this by taking another reference before calling
devm_add_action_or_reset() and not releasing it on errors for
non-devres allocated controllers.
An alternative would be a partial revert of the offending commit, but
it is better to handle this explicitly until the API has been fixed
(e.g. see 5e844cc ("spi: Introduce device-managed SPI controller
allocation")).
Fixes: b6376db ("spi: Simplify devm_spi_*_controller()")
Reported-by: Felix Gu <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Cc: Andy Shevchenko <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Acked-by: Andy Shevchenko <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>1 parent cc34d77 commit 8d2e0cb
1 file changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3534 | 3534 | | |
3535 | 3535 | | |
3536 | 3536 | | |
3537 | | - | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
3538 | 3545 | | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
3539 | 3550 | | |
3540 | 3551 | | |
3541 | 3552 | | |
| |||
0 commit comments