* [PATCH net v2] atm: fore200e: fix use-after-free in tasklets during device removal
@ 2026-02-06 9:48 Duoming Zhou
2026-02-06 10:48 ` Jijie Shao
0 siblings, 1 reply; 5+ messages in thread
From: Duoming Zhou @ 2026-02-06 9:48 UTC (permalink / raw)
To: netdev; +Cc: linux-atm-general, linux-kernel, 3chas3, shaojijie, Duoming Zhou
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().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
Changes in v2:
- Move tasklet_kill() after fore200e_reset().
drivers/atm/fore200e.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index f62e3857144..de04c407921 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -362,6 +362,10 @@ fore200e_shutdown(struct fore200e* fore200e)
if (fore200e->state > FORE200E_STATE_RESET) {
/* first, reset the board to prevent further interrupts or data transfers */
fore200e_reset(fore200e, 0);
+#ifdef FORE200E_USE_TASKLET
+ tasklet_kill(&fore200e->tx_tasklet);
+ tasklet_kill(&fore200e->rx_tasklet);
+#endif
}
/* then, release all allocated resources */
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] atm: fore200e: fix use-after-free in tasklets during device removal
2026-02-06 9:48 [PATCH net v2] atm: fore200e: fix use-after-free in tasklets during device removal Duoming Zhou
@ 2026-02-06 10:48 ` Jijie Shao
2026-02-06 14:56 ` duoming
0 siblings, 1 reply; 5+ messages in thread
From: Jijie Shao @ 2026-02-06 10:48 UTC (permalink / raw)
To: Duoming Zhou, netdev; +Cc: shaojijie, linux-atm-general, linux-kernel, 3chas3
on 2026/2/6 17:48, Duoming Zhou wrote:
> 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().
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
> Changes in v2:
> - Move tasklet_kill() after fore200e_reset().
>
> drivers/atm/fore200e.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
> index f62e3857144..de04c407921 100644
> --- a/drivers/atm/fore200e.c
> +++ b/drivers/atm/fore200e.c
> @@ -362,6 +362,10 @@ fore200e_shutdown(struct fore200e* fore200e)
> if (fore200e->state > FORE200E_STATE_RESET) {
> /* first, reset the board to prevent further interrupts or data transfers */
> fore200e_reset(fore200e, 0);
> +#ifdef FORE200E_USE_TASKLET
> + tasklet_kill(&fore200e->tx_tasklet);
> + tasklet_kill(&fore200e->rx_tasklet);
> +#endif
> }
I'm sorry if I gave you a confusing comment.
If (fore200e->state <= FORE200E_STATE_RESET), is there no need to do tasklet_kill()?
Tips: If you need to send v3, please don’t repost your patche within one 24h period:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html
Jijie Shao
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] atm: fore200e: fix use-after-free in tasklets during device removal
2026-02-06 10:48 ` Jijie Shao
@ 2026-02-06 14:56 ` duoming
2026-02-09 6:41 ` Jijie Shao
0 siblings, 1 reply; 5+ messages in thread
From: duoming @ 2026-02-06 14:56 UTC (permalink / raw)
To: Jijie Shao; +Cc: netdev, linux-atm-general, linux-kernel, 3chas3
On Fri, 6 Feb 2026 18:48:38 +0800 Jijie Shao wrote:
> > 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().
> >
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> > ---
> > Changes in v2:
> > - Move tasklet_kill() after fore200e_reset().
> >
> > drivers/atm/fore200e.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
> > index f62e3857144..de04c407921 100644
> > --- a/drivers/atm/fore200e.c
> > +++ b/drivers/atm/fore200e.c
> > @@ -362,6 +362,10 @@ fore200e_shutdown(struct fore200e* fore200e)
> > if (fore200e->state > FORE200E_STATE_RESET) {
> > /* first, reset the board to prevent further interrupts or data transfers */
> > fore200e_reset(fore200e, 0);
> > +#ifdef FORE200E_USE_TASKLET
> > + tasklet_kill(&fore200e->tx_tasklet);
> > + tasklet_kill(&fore200e->rx_tasklet);
> > +#endif
> > }
>
> I'm sorry if I gave you a confusing comment.
>
> If (fore200e->state <= FORE200E_STATE_RESET), is there no need to do tasklet_kill()?
The following four states that are preceding FORE200E_STATE_RESET are only set
during device initialization: FORE200E_STATE_BLANK, FORE200E_STATE_REGISTER,
FORE200E_STATE_CONFIGURE, and FORE200E_STATE_MAP.
If the device is in any of these states, it means the initialization is
not complete and interrupts have not been registered. Therefore, tasklet
could not be scheduled through fore200e_interrupt().
If the device is in FORE200E_STATE_RESET state, the fore200e_reset() has
already reset the device, which could prevent further interrupts and
tasklet scheduling.
So there is no need to do tasklet_kill() if the state of fore200e is
less than or equal to FORE200E_STATE_RESET.
Best regards,
Duoming Zhou
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] atm: fore200e: fix use-after-free in tasklets during device removal
2026-02-06 14:56 ` duoming
@ 2026-02-09 6:41 ` Jijie Shao
2026-02-09 8:30 ` duoming
0 siblings, 1 reply; 5+ messages in thread
From: Jijie Shao @ 2026-02-09 6:41 UTC (permalink / raw)
To: duoming; +Cc: shaojijie, netdev, linux-atm-general, linux-kernel, 3chas3
on 2026/2/6 22:56, duoming@zju.edu.cn wrote:
> On Fri, 6 Feb 2026 18:48:38 +0800 Jijie Shao wrote:
>>> 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().
>>>
>>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>>> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
>>> ---
>>> Changes in v2:
>>> - Move tasklet_kill() after fore200e_reset().
>>>
>>> drivers/atm/fore200e.c | 4 ++++
>>> 1 file changed, 4 insertions(+)
>>>
>>> diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
>>> index f62e3857144..de04c407921 100644
>>> --- a/drivers/atm/fore200e.c
>>> +++ b/drivers/atm/fore200e.c
>>> @@ -362,6 +362,10 @@ fore200e_shutdown(struct fore200e* fore200e)
>>> if (fore200e->state > FORE200E_STATE_RESET) {
>>> /* first, reset the board to prevent further interrupts or data transfers */
>>> fore200e_reset(fore200e, 0);
>>> +#ifdef FORE200E_USE_TASKLET
>>> + tasklet_kill(&fore200e->tx_tasklet);
>>> + tasklet_kill(&fore200e->rx_tasklet);
>>> +#endif
>>> }
>> I'm sorry if I gave you a confusing comment.
>>
>> If (fore200e->state <= FORE200E_STATE_RESET), is there no need to do tasklet_kill()?
> The following four states that are preceding FORE200E_STATE_RESET are only set
> during device initialization: FORE200E_STATE_BLANK, FORE200E_STATE_REGISTER,
> FORE200E_STATE_CONFIGURE, and FORE200E_STATE_MAP.
>
> If the device is in any of these states, it means the initialization is
> not complete and interrupts have not been registered. Therefore, tasklet
> could not be scheduled through fore200e_interrupt().
>
> If the device is in FORE200E_STATE_RESET state, the fore200e_reset() has
> already reset the device, which could prevent further interrupts and
> tasklet scheduling.
>
> So there is no need to do tasklet_kill() if the state of fore200e is
> less than or equal to FORE200E_STATE_RESET.
Yeah, I agree.
But I reviewed the fore200e_init() again, and it only needs to do tasklet_kill()
when "fore200e->state >= fFORE200E_STATE_IRQ"(in fore200e_irq_request());
otherwise, "fore200e->tx_tasklet" has not been initialized.
Jijie Shao
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] atm: fore200e: fix use-after-free in tasklets during device removal
2026-02-09 6:41 ` Jijie Shao
@ 2026-02-09 8:30 ` duoming
0 siblings, 0 replies; 5+ messages in thread
From: duoming @ 2026-02-09 8:30 UTC (permalink / raw)
To: Jijie Shao; +Cc: netdev, linux-atm-general, linux-kernel, 3chas3
On Mon, 9 Feb 2026 14:41:52 +0800 Jijie Shao wrote:
> >>> 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().
> >>>
> >>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> >>> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> >>> ---
> >>> Changes in v2:
> >>> - Move tasklet_kill() after fore200e_reset().
> >>>
> >>> drivers/atm/fore200e.c | 4 ++++
> >>> 1 file changed, 4 insertions(+)
> >>>
> >>> diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
> >>> index f62e3857144..de04c407921 100644
> >>> --- a/drivers/atm/fore200e.c
> >>> +++ b/drivers/atm/fore200e.c
> >>> @@ -362,6 +362,10 @@ fore200e_shutdown(struct fore200e* fore200e)
> >>> if (fore200e->state > FORE200E_STATE_RESET) {
> >>> /* first, reset the board to prevent further interrupts or data transfers */
> >>> fore200e_reset(fore200e, 0);
> >>> +#ifdef FORE200E_USE_TASKLET
> >>> + tasklet_kill(&fore200e->tx_tasklet);
> >>> + tasklet_kill(&fore200e->rx_tasklet);
> >>> +#endif
> >>> }
> >> I'm sorry if I gave you a confusing comment.
> >>
> >> If (fore200e->state <= FORE200E_STATE_RESET), is there no need to do tasklet_kill()?
> > The following four states that are preceding FORE200E_STATE_RESET are only set
> > during device initialization: FORE200E_STATE_BLANK, FORE200E_STATE_REGISTER,
> > FORE200E_STATE_CONFIGURE, and FORE200E_STATE_MAP.
> >
> > If the device is in any of these states, it means the initialization is
> > not complete and interrupts have not been registered. Therefore, tasklet
> > could not be scheduled through fore200e_interrupt().
> >
> > If the device is in FORE200E_STATE_RESET state, the fore200e_reset() has
> > already reset the device, which could prevent further interrupts and
> > tasklet scheduling.
> >
> > So there is no need to do tasklet_kill() if the state of fore200e is
> > less than or equal to FORE200E_STATE_RESET.
>
> Yeah, I agree.
> But I reviewed the fore200e_init() again, and it only needs to do tasklet_kill()
> when "fore200e->state >= fFORE200E_STATE_IRQ"(in fore200e_irq_request());
> otherwise, "fore200e->tx_tasklet" has not been initialized.
Thank you for your time and suggestions! You are right, I will adopt your
suggestions in the v3 patch.
Best regards,
Duoming Zhou
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-09 8:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-06 9:48 [PATCH net v2] atm: fore200e: fix use-after-free in tasklets during device removal Duoming Zhou
2026-02-06 10:48 ` Jijie Shao
2026-02-06 14:56 ` duoming
2026-02-09 6:41 ` Jijie Shao
2026-02-09 8:30 ` duoming
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox