mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: davidlwesten@gmail.com
Cc: netdev@vger.kernel.org, loic.poulain@oss.qualcomm.com,
	ryazanov.s.a@gmail.com, johannes@sipsolutions.net,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com,
	m.chetan.kumar@linux.intel.com, linux-kernel@vger.kernel.org,
	mail@maciej.szmigiero.name, nihaal@cse.iitm.ac.in,
	stable@vger.kernel.org
Subject: Re: [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup
Date: Mon, 23 Nov 2026 05:17:49 +0000	[thread overview]
Message-ID: <179541106939.3135.3810191786366936844@kernel.org> (raw)
In-Reply-To: <20261119042714.505405-1-davidlwesten@gmail.com>

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

      parent reply	other threads:[~2026-11-23  5:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  4:27 David Westen
2026-11-19  4:27 ` [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it David Westen
2026-11-22 20:01   ` Maciej S. Szmigiero
2026-11-23  3:17     ` David Westen
2026-11-23  5:17   ` netdev-bot+sashiko
2026-11-23  5:17 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179541106939.3135.3810191786366936844@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=davidlwesten@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=m.chetan.kumar@linux.intel.com \
    --cc=mail@maciej.szmigiero.name \
    --cc=netdev@vger.kernel.org \
    --cc=nihaal@cse.iitm.ac.in \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®