Skip to content
/ linux Public

Commit e075ec9

Browse files
stonezdmSasha Levin
authored andcommitted
atm: fore200e: fix use-after-free in tasklets during device removal
[ Upstream commit 8930878 ] When the PCA-200E or SBA-200E adapter is being detached, the fore200e is deallocated. However, the tx_tasklet or rx_tasklet may still be running or pending, leading to use-after-free bug when the already freed fore200e is accessed again in fore200e_tx_tasklet() or fore200e_rx_tasklet(). One of the race conditions can occur as follows: CPU 0 (cleanup) | CPU 1 (tasklet) fore200e_pca_remove_one() | fore200e_interrupt() fore200e_shutdown() | tasklet_schedule() kfree(fore200e) | fore200e_tx_tasklet() | fore200e-> // UAF Fix this by ensuring tx_tasklet or rx_tasklet is properly canceled before the fore200e is released. Add tasklet_kill() in fore200e_shutdown() to synchronize with any pending or running tasklets. Moreover, since fore200e_reset() could prevent further interrupts or data transfers, the tasklet_kill() should be placed after fore200e_reset() to prevent the tasklet from being rescheduled in fore200e_interrupt(). Finally, it only needs to do tasklet_kill() when the fore200e state is greater than or equal to FORE200E_STATE_IRQ, since tasklets are uninitialized in earlier states. In a word, the tasklet_kill() should be placed in the FORE200E_STATE_IRQ branch within the switch...case structure. This bug was identified through static analysis. Fixes: 1da177e ("Linux-2.6.12-rc2") Cc: stable@kernel.org Suggested-by: Jijie Shao <shaojijie@huawei.com> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn> Reviewed-by: Jijie Shao <shaojijie@huawei.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20260210094537.9767-1-duoming@zju.edu.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9f8ad19 commit e075ec9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/atm/fore200e.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ fore200e_shutdown(struct fore200e* fore200e)
376376
fallthrough;
377377
case FORE200E_STATE_IRQ:
378378
free_irq(fore200e->irq, fore200e->atm_dev);
379+
#ifdef FORE200E_USE_TASKLET
380+
tasklet_kill(&fore200e->tx_tasklet);
381+
tasklet_kill(&fore200e->rx_tasklet);
382+
#endif
379383

380384
fallthrough;
381385
case FORE200E_STATE_ALLOC_BUF:

0 commit comments

Comments
 (0)