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@intel.com,
mail@maciej.szmigiero.name
Subject: Re: [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it
Date: Fri, 27 Nov 2026 19:50:10 +0000 [thread overview]
Message-ID: <179580901077.3135.14183564471297822250@kernel.org> (raw)
In-Reply-To: <20261126194143.32283-2-davidlwesten@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 (1) · Medium: 4 (1) · 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).
- [Medium] During ipc_imem_cleanup(), each netdev that is up now runs a
blocking MUX CLOSE_SESSION command.
- [Medium] The commit message says closing the netdev tells the modem to
close the session "so that it stops writing into the MUX buffers…
- [Medium] The CLOSE_SESSION command issued by the netdev close runs
asynchronously in tasklet context, and nothing in ipc_imem_cleanup()…
- [Medium] The new IPC_P_OFF_REQ branch in
ipc_imem_td_update_timer_start() assumes…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
ipc_mux_deinit() frees the MUX and nothing clears ipc_imem->mux.
- [Medium] Concern: ipc_imem_cleanup() cancels td_alloc_timer,
tdupdate_timer, fast_update_timer and startup_timer but never…
--
net: wwan: iosm: free the MUX after the netdevs that use it
This patch reorders ipc_imem_cleanup() so the MUX is freed after debugfs,
the ports and the wwan netdevs. It fixes a KASAN use-after-free that hits
when a netdev that is up gets closed during unbind. It also makes
ipc_imem_td_update_timer_start() ring the doorbell directly during the
IPC_P_OFF_REQ phase.
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c
> index 4405c85318880..3ab409166c506 100644
> --- a/drivers/net/wwan/iosm/iosm_ipc_imem.c
> +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c
> @@ -178,7 +178,8 @@ void ipc_imem_msg_send_feature_set(struct iosm_imem *ipc_imem,
> void ipc_imem_td_update_timer_start(struct iosm_imem *ipc_imem)
> {
> /* Use the TD update timer only in the runtime phase */
> - if (!ipc_imem->enter_runtime || ipc_imem->td_update_timer_suspended) {
> + if (!ipc_imem->enter_runtime || ipc_imem->td_update_timer_suspended ||
> + ipc_imem->phase == IPC_P_OFF_REQ) {
> /* trigger the doorbell irq on CP directly. */
> ipc_protocol_doorbell_trigger(ipc_imem->ipc_protocol,
> IPC_HP_TD_UPD_TMR_START);
[Severity: Medium]
Does this doorbell reach the modem when the CP is in device sleep?
ipc_protocol_doorbell_trigger() goes through ipc_pm_signal_hpda_doorbell()
with host_slp_check=true. If the link is asleep, ipc_pm_trigger() calls
ipc_pm_link_activate(). That function only sends the wakeup sleep-control
IRQ and returns false:
drivers/net/wwan/iosm/iosm_ipc_pm.c:ipc_pm_link_activate() {
...
ipc_cp_irq_sleep_control(ipc_pm->pcie, IPC_MEM_DEV_PM_WAKEUP);
ipc_pm->ap_state = IPC_MEM_DEV_PM_ACTIVE_WAIT;
goto not_active;
...
}
ipc_pm_signal_hpda_doorbell() then only latches the update:
if (!ipc_pm_trigger(ipc_pm, IPC_PM_UNIT_IRQ, true)) {
ipc_pm->pending_hpda_update = true;
...
return;
}
Only ipc_pm_on_link_wake() flushes pending_hpda_update. It is reached via
ipc_imem_slp_control_exec() from ipc_imem_handle_irq(), which returns early
for the whole cleanup:
if (old_phase == IPC_P_OFF_REQ) {
Take an idle wwan0 with the modem in device sleep, which is enabled by
default via ipc_imem_msg_send_device_sleep(). In that state, would
CLOSE_SESSION be written to the UL TD ring without the HP doorbell ever
firing, and the PM handshake be left in IPC_MEM_DEV_PM_ACTIVE_WAIT?
Whether the CP still processes the TD ring after the wakeup IRQ, without an
HP doorbell, depends on the firmware.
> @@ -1244,10 +1245,10 @@ void ipc_imem_cleanup(struct iosm_imem *ipc_imem)
> cancel_work_sync(&ipc_imem->run_state_worker);
>
> if (test_and_clear_bit(FULLY_FUNCTIONAL, &ipc_imem->flag)) {
> - ipc_mux_deinit(ipc_imem->mux);
> ipc_debugfs_deinit(ipc_imem);
> - ipc_wwan_deinit(ipc_imem->wwan);
> ipc_port_deinit(ipc_imem->ipc_port);
> + ipc_wwan_deinit(ipc_imem->wwan);
[Severity: Medium]
Can this stall unbind for a full second per active session while RTNL is
held?
ipc_imem_cleanup() sets ipc_imem->phase = IPC_P_OFF_REQ before it gets
here, and the MUX is now still MUX_S_ACTIVE when the netdevs are closed:
wwan_unregister_ops() <- rtnl_lock()
unregister_netdevice_many()
ipc_wwan_link_stop()
ipc_imem_sys_wwan_close()
ipc_mux_close_session()
ipc_mux_schedule(MUX_E_MUX_SESSION_CLOSE)
ipc_mux_session_close()
ipc_mux_dl_acb_send_cmds(..., blocking=true)
ipc_mux_acb_send()
ipc_mux_acb_send() waits on channel->ul_sem for up to
IPC_MUX_CMD_RUN_DEFAULT_TIMEOUT (1000 ms). For a MUX command, only
ipc_mux_dl_cmdresps_decode_process() completes ul_sem. It is reached only
via ipc_imem_dl_pipe_process() from ipc_imem_handle_irq(), which drops
every MSI in IPC_P_OFF_REQ:
if (old_phase == IPC_P_OFF_REQ) {
dev_dbg(... "Ignoring MSI. Deinit sequence in progress!" ...);
return;
So the wait always runs out. After the timeout, ipc_mux_acb_send() logs
"ch[%d] timeout" and sends UEVENT_MDM_TIMEOUT right after MDM_NOT_READY.
ipc_mux_session_close() then logs "CLOSE_SESSION send failed".
This repeats for each session that is up, up to
IPC_MEM_MUX_IP_SESSION_ENTRIES, all under RTNL. Nothing gates it on the link
being active, so surprise removal hits it too.
The port closes behave much the same, since ipc_protocol_msg_send() waits
500 ms per pipe. So "The reply is ignored, as for the port closes" is
accurate, but those waits do not happen under RTNL.
The later patch in the series ("re-bind the driver when the modem rebooted
during S3") short-circuits ipc_mux_dl_acb_send_cmds() only when
IOSM_MODEM_GONE is set, so a normal unbind still stalls.
Should the session close be skipped or made non-blocking during cleanup?
If not, should the commit message at least mention the stall?
> + ipc_mux_deinit(ipc_imem->mux);
[Severity: Medium]
The commit message says closing the netdev "tells the modem to close the
session, so that it stops writing into the MUX buffers before they are
freed". Is that ordering actually enforced?
In IPC_P_OFF_REQ the CLOSE_SESSION reply is never decoded, so the host
never learns whether the modem acted on it.
The wait in ipc_mux_acb_send() is interruptible, and only a 0 return counts
as failure. A pending signal makes it return -ERESTARTSYS at once:
if (wait_for_completion_interruptible_timeout
(completion, msecs_to_jiffies(wait_time_milliseconds)) ==
0) {
When the last session closes, ipc_mux_channel_close() calls
ipc_imem_channel_close(). That skips the PIPE_CLOSE messages but still
frees the TD buffers:
if (ipc_imem->phase == IPC_P_RUN) {
ipc_imem_pipe_close(ipc_imem, &channel->ul_pipe);
ipc_imem_pipe_close(ipc_imem, &channel->dl_pipe);
}
ipc_imem_pipe_cleanup(ipc_imem, &channel->ul_pipe);
ipc_imem_pipe_cleanup(ipc_imem, &channel->dl_pipe);
ipc_imem_pipe_cleanup() -> ipc_protocol_pipe_cleanup() unmaps and frees
the UL and DL skbs. That includes the CLOSE_SESSION ACB that was just
doorbelled and the DL buffers the reply would be written into. The modem
is told IPC_UNINIT only later, in ipc_imem_device_ipc_uninit().
Freeing the MUX pipe buffers without a device handshake predates this
patch, but the patch adds a new TD that the device is told to process.
If the modem reads the ACB or writes the response after these buffers are
freed, can that cause an IOMMU fault? Without an IOMMU, can it cause a DMA
write into freed memory?
[Severity: Medium]
Can the queued CLOSE_SESSION command still touch the MUX after
ipc_mux_deinit() frees it?
ipc_mux_acb_send() queues the command asynchronously:
int ret = ipc_task_queue_send_task(ipc_mux->imem, ipc_mux_tq_cmd_send,
0, &ipc_mux->acb,
sizeof(ipc_mux->acb), false);
ipc_mux_tq_cmd_send() later does:
struct iosm_mux *ipc_mux = ipc_imem->mux;
...
skb_queue_tail(&ipc_mux->channel->ul_list, acb->skb);
Only the interruptible wait above orders this before the free. If a signal
is pending, that wait returns at once and the netdev teardown continues.
ipc_mux_deinit() then calls kfree(ipc_mux) without clearing
ipc_imem->mux.
The tasklet is killed only later, in ipc_task_deinit(), which runs after
the sleeping ipc_imem_device_ipc_uninit().
If the ipc_task tasklet has not run by the time of the kfree,
ipc_mux_tq_cmd_send() would dereference the freed MUX. That is the same
class of bug this patch is fixing.
Does the MUX free need to happen after the task queue is drained, rather
than just later in the sequence?
[Severity: Medium]
This isn't a bug introduced by this patch, but ipc_imem_cleanup() cancels
four of the hrtimers and never cancels adb_timer:
hrtimer_cancel(&ipc_imem->td_alloc_timer);
hrtimer_cancel(&ipc_imem->tdupdate_timer);
hrtimer_cancel(&ipc_imem->fast_update_timer);
hrtimer_cancel(&ipc_imem->startup_timer);
ipc_imem_adb_timer_start() has no IPC_P_OFF_REQ guard like the one added to
ipc_imem_td_update_timer_start(). ipc_imem_tq_adb_timer_cb() calls
ipc_mux_ul_adb_finish(ipc_imem->mux) on a pointer that is never cleared.
ipc_mux_tq_ul_trigger_encode() can still arm adb_timer if it was queued
before the phase store, and the phase check is a plain, unordered load.
This patch makes the window much smaller, because ipc_mux_deinit() now runs
after the port and netdev teardown. A use-after-free would now need the
tasklet to be starved for that whole period. Only the MUX_AGGREGATION
(7560) path uses adb_timer.
The later patch in the series only adds an IOSM_MODEM_GONE check to
ipc_imem_adb_timer_start().
Should adb_timer be cancelled along with the other timers?
[Severity: High]
This is a pre-existing issue, but ipc_mux_deinit() frees the MUX without
clearing ipc_imem->mux. Does that leave a reachable use-after-free on the
error path of ipc_imem_run_state_worker()?
err_ipc_mux_deinit:
ipc_mux_deinit(ipc_imem->mux);
err_out:
ipc_uevent_send(ipc_imem->dev, UEVENT_CD_READY_LINK_DOWN);
ipc_imem_wwan_channel_init() can fail in three ways: the CP version reads
back as -1, ipc_wwan_init() fails to allocate, or wwan_register_ops()
fails. In each case the MUX is freed, FULLY_FUNCTIONAL is not set, and
ipc_imem->mux is left dangling.
The modem stays in the run phase, so later MSIs reach ipc_imem_handle_irq()
in IPC_P_RUN:
if (ipc_mux_ul_data_encode(ipc_imem->mux)) {
ipc_imem_td_update_timer_start(ipc_imem);
if (ipc_imem->mux->protocol == MUX_AGGREGATION)
ipc_mux_ul_data_encode() handles a NULL pointer but not a dangling one. The
ipc_imem->mux check in ipc_imem_sys_wwan_close() also assumes the pointer is
cleared after the free.
Would setting ipc_imem->mux to NULL after ipc_mux_deinit() fix this? It
would also harden the cleanup path that this patch reorders.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126194143.32283-1-davidlwesten%40gmail.com
next prev parent reply other threads:[~2026-11-27 19:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 19:41 [PATCH net v3 0/2] net: wwan: iosm: fix S3 resume by re-binding the driver after it David Westen
2026-11-26 19:41 ` [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it David Westen
2026-11-27 19:50 ` netdev-bot+sashiko [this message]
2026-11-26 19:41 ` [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 David Westen
2026-11-27 13:49 ` Maciej S. Szmigiero
2026-11-27 16:46 ` David Westen
2026-11-27 19:50 ` netdev-bot+sashiko
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=179580901077.3135.14183564471297822250@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=loic.poulain@oss.qualcomm.com \
--cc=m.chetan.kumar@intel.com \
--cc=mail@maciej.szmigiero.name \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ryazanov.s.a@gmail.com \
/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