Re: [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup
From: netdev-bot+sashiko
Date: Mon Nov 23 2026 - 00:17:56 EST
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch adds hrtimer_cancel(&ipc_imem->adb_timer) to
ipc_imem_cleanup() (drivers/net/wwan/iosm/iosm_ipc_imem.c:1242).
--
net: wwan: iosm: cancel the ADB timer on cleanup
This patch adds an hrtimer_cancel() for adb_timer to ipc_imem_cleanup(),
next to the cancels for the other imem hrtimers. The aim is to stop a
pending ADB timer from queueing a task that finishes the ADB on the freed
MUX, and to keep the hrtimer from being freed with the imem while it is
still enqueued.
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c
> index 4405c85318880..20f8da53a3ea7 100644
> --- a/drivers/net/wwan/iosm/iosm_ipc_imem.c
> +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c
> @@ -1239,6 +1239,7 @@ void ipc_imem_cleanup(struct iosm_imem *ipc_imem)
> hrtimer_cancel(&ipc_imem->tdupdate_timer);
> hrtimer_cancel(&ipc_imem->fast_update_timer);
> hrtimer_cancel(&ipc_imem->startup_timer);
> + hrtimer_cancel(&ipc_imem->adb_timer);
[Severity: High]
Does this cancel fully close the use-after-free that the commit message
describes? When it runs, the netdev TX path, the IRQ handler and the
ipc_task tasklet are all still live. Any of them can re-arm adb_timer
before ipc_mux_deinit() frees the MUX.
ipc_imem_adb_timer_start() only checks whether the timer is already
active:
void ipc_imem_adb_timer_start(struct iosm_imem *ipc_imem)
{
if (!hrtimer_active(&ipc_imem->adb_timer)) {
...
hrtimer_start(&ipc_imem->adb_timer,
ipc_imem->hrtimer_period,
HRTIMER_MODE_REL);
}
}
The netdevs stay registered until ipc_wwan_deinit(), and the TX queues
are only stopped inside ipc_mux_deinit(). So TX traffic during cleanup can
still go through this path:
ipc_mux_ul_trigger_encode()
ipc_task_queue_send_task(ipc_mux_tq_ul_trigger_encode)
ipc_mux_tq_ul_trigger_encode()
ipc_mux_ul_data_encode() /* only checks MUX_S_ACTIVE */
ipc_imem_adb_timer_start()
The mux state stays MUX_S_ACTIVE until ipc_mux_deinit(). That means the
timer can be re-armed for 500 us at any point between this new cancel and
ipc_mux_deinit(), including during
cancel_work_sync(&ipc_imem->run_state_worker).
ipc_imem_handle_irq() also calls ipc_imem_adb_timer_start(). Its only
guard is an unsynchronized check of ipc_imem->phase at the top. The MSI
IRQs stay requested until ipc_pcie_resources_release(), which runs after
ipc_imem_cleanup() returns.
Next, ipc_mux_deinit() calls kfree(ipc_mux) and leaves ipc_imem->mux
pointing at freed memory. After that, ipc_imem_device_ipc_uninit() polls
for up to 30 ms before ipc_task_deinit() is reached:
while ((ipc_state <= IPC_MEM_DEVICE_IPC_DONT_CARE) &&
(ipc_state != IPC_MEM_DEVICE_IPC_UNINIT) &&
(timeout > 0)) {
usleep_range(1000, 1250);
...
}
Could a re-armed 500 us timer fire inside this window and run this?
ipc_imem_adb_timer_cb()
ipc_task_queue_send_task(ipc_imem_tq_adb_timer_cb)
ipc_imem_tq_adb_timer_cb()
ipc_mux_ul_adb_finish(ipc_imem->mux) /* freed MUX */
ipc_mux_ul_adb_finish() writes through the MUX with no checks. It updates
adbh->sequence_nr and adb_tx_sequence_nr, and it calls skb_put() on
ul_adb->dest_skb, among other writes.
If the timer is still pending later, its callback would use the ipc_task
that ipc_imem_cleanup() has already freed. If it is still pending when
ipc_pcie_deinit() calls kfree(ipc_pcie->imem), the hrtimer embedded in the
imem is freed while it is still enqueued.
There is also a second case. Suppose adb_timer fired just before this
cancel. hrtimer_cancel() returns once the callback has finished, but the
ipc_imem_tq_adb_timer_cb entry that the callback queued (wait=false) is
still sitting in the ipc_task queue.
Nothing flushes that queue before the MUX is freed:
- cancel_work_sync() only covers the workqueue.
- In IPC_P_OFF_REQ, ipc_imem_channel_close() skips the synchronous pipe
close messages, so ipc_mux_deinit() doesn't flush the tasklet either.
- tasklet_kill() in ipc_task_deinit() waits for an already-scheduled
tasklet to run instead of dropping it, and it is only reached after
kfree(ipc_mux).
If the tasklet is delayed (BH disabled, ksoftirqd, PREEMPT_RT), can that
stale entry run ipc_mux_ul_adb_finish() on the freed MUX?
The next patch in the series, "net: wwan: iosm: fix S3 resume by
re-binding the driver around it", doesn't change ipc_imem_cleanup(). It
does run this teardown from the PM_SUSPEND_PREPARE notifier on every
non-s2idle suspend, and that happens before tasks are frozen. With that
patch, live TX traffic during teardown becomes the normal case.
Would it make sense to stop the producers (netif TX, the IRQ and the
tasklet) before ipc_mux_deinit(), and cancel adb_timer after that point or
add a second cancel there? Two other options would be to skip
ipc_imem_adb_timer_start() once teardown has begun, and to keep
ipc_imem_tq_adb_timer_cb() from using a stale ipc_imem->mux.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119042714.505405-1-davidlwesten%40gmail.com