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] net: wwan: iosm: clear the MUX pointer after freeing the MUX
Date: Sat, 05 Dec 2026 15:48:19 +0000 [thread overview]
Message-ID: <179648569911.3146.4857985823300228341@kernel.org> (raw)
In-Reply-To: <20261201145553.14624-1-davidlwesten@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (2) · 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 fix relies on ipc_imem_sys_wwan_close() seeing ipc_imem->mux
== NULL.
Pre-existing issues:
- [High] ipc_imem_cleanup() in drivers/net/wwan/iosm/iosm_ipc_imem.c
never cancels ipc_imem->adb_timer.
- [High] Teardown frees the MUX and then sets ipc_imem->mux to NULL in
ipc_imem_cleanup() without first stopping or synchronizing the other…
--
net: wwan: iosm: clear the MUX pointer after freeing the MUX
This commit sets ipc_imem->mux to NULL after ipc_mux_deinit() frees it.
It does this in ipc_imem_cleanup() and in the error path of
ipc_imem_run_state_worker(). ipc_imem_sys_wwan_close() then skips the
session close when the netdevs are unregistered.
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c
> index 4405c85318880..998493b730b0a 100644
> --- a/drivers/net/wwan/iosm/iosm_ipc_imem.c
> +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c
[ ... ]
> @@ -1245,6 +1246,7 @@ void ipc_imem_cleanup(struct iosm_imem *ipc_imem)
>
> if (test_and_clear_bit(FULLY_FUNCTIONAL, &ipc_imem->flag)) {
> ipc_mux_deinit(ipc_imem->mux);
> + ipc_imem->mux = NULL;
> ipc_debugfs_deinit(ipc_imem);
> ipc_wwan_deinit(ipc_imem->wwan);
> ipc_port_deinit(ipc_imem->ipc_port);
[Severity: High]
The fix relies on the NULL check in ipc_imem_sys_wwan_close():
drivers/net/wwan/iosm/iosm_ipc_imem_ops.c:ipc_imem_sys_wwan_close() {
if (ipc_imem->mux && if_id >= IP_MUX_SESSION_START &&
if_id <= IP_MUX_SESSION_END)
ipc_mux_close_session(ipc_imem->mux, if_id);
}
Is that check enough when a netdev close races with removal?
ipc_imem_cleanup() frees the MUX and clears the pointer without holding
RTNL. RTNL is only taken later, in ipc_wwan_deinit()->wwan_unregister_ops().
A userspace ndo_stop can run at the same time, for example
"ip link set wwan0 down", possibly in response to the
UEVENT_MDM_NOT_READY that cleanup sends first:
CPU1 (holding RTNL)
ipc_wwan_link_stop()
ipc_imem_sys_wwan_close()
sees ipc_imem->mux != NULL
ipc_mux_close_session()
ipc_mux_schedule()
ipc_mux_session_close()
ipc_mux_dl_acb_send_cmds(..., true, false)
blocks up to 1s waiting for the CP reply
CPU0
ipc_pcie_remove()
ipc_imem_cleanup()
ipc_mux_deinit(ipc_imem->mux); /* kfree(ipc_mux) */
ipc_imem->mux = NULL;
The CP reply never arrives once phase is IPC_P_OFF_REQ, because
ipc_imem_handle_irq() ignores the IRQ. When CPU1 wakes up,
ipc_mux_session_close() runs:
ipc_mux->session[if_id].flow_ctl_en_cnt = 0;
ipc_mux->session[if_id].flow_ctl_dis_cnt = 0;
ipc_mux->session[if_id].flow_ctl_mask = 0;
ipc_mux_session_reset(ipc_mux, if_id);
Then ipc_mux_close_session() clears session[session_nr].flags. Wouldn't
those writes still land on the freed MUX?
The queued ipc_mux_tq_cmd_send() also reloads ipc_imem->mux in the
tasklet. It then dereferences ipc_mux->channel without a NULL check.
The check in ipc_imem_sys_wwan_close() also loads ipc_imem->mux twice
without READ_ONCE(). Could the second load see NULL after the first one
saw a valid pointer?
The commit message says this fixes "closing a netdev that is still up
uses the freed MUX". This race looks like the same class of bug, and the
NULL sentinel doesn't seem to close it.
Two alternatives come to mind:
- Unregister the netdevs with ipc_wwan_deinit() before ipc_mux_deinit().
ipc_mux_stop_netif_for_all_sessions() would then need to avoid the
freed wwan.
- Serialize the MUX free against ndo_stop with RTNL.
Would either of these be more robust than the NULL sentinel?
[Severity: High]
This isn't a bug introduced by this patch, but ipc_imem_cleanup()
cancels only four of the five hrtimers in struct iosm_imem. adb_timer is
not one of them:
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);
Whenever MUX_AGGREGATION UL data is encoded, ipc_mux_tq_ul_trigger_encode()
and ipc_imem_handle_irq() arm adb_timer with a 500us period. So it is
often pending while UL traffic is flowing.
If it fires during teardown:
ipc_imem_adb_timer_cb()
ipc_task_queue_send_task(ipc_imem, ipc_imem_tq_adb_timer_cb, ...)
ipc_imem_tq_adb_timer_cb()
ipc_mux_ul_adb_finish(ipc_imem->mux)
ul_adb = &ipc_mux->ul_adb;
if (!ul_adb->dest_skb)
Before this patch that was a use-after-free of the MUX. With this patch
it becomes a NULL pointer dereference in tasklet context.
The window is wide. ipc_wwan_deinit() runs synchronize_net() through
netdev unregistration after the NULL store and before ipc_task_deinit().
If the timer fires after ipc_task_deinit() and kfree(ipc_imem->ipc_task),
can ipc_task_queue_send_task() also touch the freed ipc_task?
Should adb_timer be cancelled along with the other hrtimers in
ipc_imem_cleanup()?
[Severity: High]
This is a pre-existing issue, but none of the other users of
ipc_imem->mux check for NULL. None of them are synchronized against the
free in ipc_imem_cleanup() either. The only thing separating them is a
plain store of ipc_imem->phase = IPC_P_OFF_REQ.
On the TX side, ipc_imem_sys_wwan_transmit() checks phase without a lock
and then calls:
ret = ipc_mux_ul_trigger_encode(ipc_imem->mux, if_id, skb);
ipc_mux_ul_trigger_encode() dereferences ipc_mux->session[if_id] and
ipc_mux->channel right away. A transmit that passed the phase check
before cleanup stored IPC_P_OFF_REQ can run at the same time as
kfree(ipc_mux).
ipc_mux_ul_trigger_encode() also queues ipc_mux_tq_ul_trigger_encode()
to the tasklet:
struct iosm_mux *ipc_mux = ipc_imem->mux;
...
ul_data_pend = ipc_mux_ul_data_encode(ipc_mux);
if (ul_data_pend) {
if (ipc_mux->protocol == MUX_AGGREGATION)
...
ipc_mux->ev_mux_net_transmit_pending = false;
ipc_mux_ul_data_encode() handles a NULL MUX, but the write to
ev_mux_net_transmit_pending does not. ipc_mux_tq_cmd_send() has the same
pattern.
Nothing flushes the tasklet before ipc_mux_deinit(). tasklet_kill() runs
only in ipc_task_deinit(), well after the MUX is gone. Once phase !=
IPC_P_RUN, ipc_imem_channel_close() also skips the synchronous pipe
close.
An ipc_imem_handle_irq() already running on another CPU may have passed
the IPC_P_OFF_REQ check. It can then call ipc_mux_dl_decode(),
ipc_mux_ul_encoded_process() and ipc_mux_check_n_restart_tx() on
ipc_imem->mux while cleanup frees it.
This patch turns some of these paths from a use-after-free into a NULL
dereference, but can the race itself still happen?
Would these users need to be quiesced first, for example with
netif_device_detach() and tasklet_disable() before the free, or by
reordering the teardown?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201145553.14624-1-davidlwesten%40gmail.com
prev parent reply other threads:[~2026-12-05 15:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 14:55 [PATCH net] net: wwan: iosm: clear the MUX pointer after freeing the MUX David Westen
2026-12-04 2:40 ` patchwork-bot+netdevbpf
2026-12-05 15:48 ` 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=179648569911.3146.4857985823300228341@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.