Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796485700; b=32vg0eNTItmharB4ZBbUXbFCqz4r4SNQl5BhcaWhb2RTmjnBCRZ7jAQpK0zBnV1zBTcc MtZ7FggT9y+nQ8InO400683RzdBpv7/tsb/iIeGZg0713QEGsbPILNFcwu7H9MrkJVfza QYzdhZM74sD+y1BCoQ925TygIlPnUj+kS1jAozUhdkF17ZXl8TEcoaRd44LTSuS8W9dXB vJ5Gkg6qyxvsbtFCFf40aCMV29QkHURcC33lF0V6UemKxBwKzKrtrctC3/O+ZLbZurD64 iNF18yTZvExHEpjIM9gp5XP8IYfk1aUZg6JsymfX2lLGZ1UXCnMVdkXURN4oJzzQSDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796485700; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=be4cQ3FJwPW8cUehmyjDCniDKKsjRqH99yGollV9LV0=; b=SzHTsBLP1oc6ZgaOPPe0f0dL0RttpT8nW8JKl93W6dX7lWHTKtHXTnhegi6SLGY5huCQ xNkqBpjxyfNfEi7Yl8IgkzuOFEUHVxjiC7V3fCR6zftJmuggB16J08uzRnTJmA68Vm676 XiQ3UzljJ9QnNUwuIO5ADpVCb2FE35/24R2PkUcIxgpB1wzoC7Gsi4jU0HHAzbb+HBWnm JOyYAuhSlfgPZckhCma6yd2wUuNyztwJkyk/X3hr8Gd2mOTmvhapjw1BTN5km4Ep9pdBy sSLspZ4wYB+46pwjfjmTJrwNdPshXBd8j6aRtsDtp9KK5+JStNThPjQBRyroGjvdfiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TTPS9+6t; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B395E606A322 for ; Sat, 5 Dec 2026 15:48:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TTPS9+6t Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9503D1F00936; Sat, 5 Dec 2026 15:48:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796485700; bh=be4cQ3FJwPW8cUehmyjDCniDKKsjRqH99yGollV9LV0=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=TTPS9+6tr0SV/nyhDV1NXSNfcPfT6Scv1S8HF1uoEL5VXqLPqSCK8xJTnLlYa0Byx 4w8iNQvqDDBQZtdf8jZmQ8IJ11/6S1pESgyJ/lz8I/GNJpnzMSguJusMSo8wJ1THzs G9xjz1HkrUkGHQv+eCZuVYGvbWVC6p/NfL6yZ5bmekmydbi4y3X52qR+ZdmEBj2swb wPaRfh1D8c71TyhXDjZ8PQnZhUCwGy65E17gXZhInYtYi4euunTauQe8jyqrgis69X aajqZ8excuyDa2zgwxoAacRje7MnfHa0xW8AGVtPGyLh+YziozFyNI2wIzwl8aa7kS Xczsw0shtDw3w== Subject: Re: [PATCH net] net: wwan: iosm: clear the MUX pointer after freeing the MUX 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 Date: Sat, 05 Dec 2026 15:48:19 +0000 Message-ID: <179648569911.3146.4857985823300228341@kernel.org> In-Reply-To: <20261201145553.14624-1-davidlwesten@gmail.com> References: <20261201145553.14624-1-davidlwesten@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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