๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20728

Re: [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup

#20728
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 05:17
133 lines
13463 bytes
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
Technical Details
Message-ID: <179541106939.3135.3810191786366936844@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369046-linux-kernel-netdev=dewy.ru
References: <20261119042714.505405-1-davidlwesten@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369046-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179541106939.3135.3810191786366936844@kernel.org>
References: <20261119042714.505405-1-davidlwesten@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3798346"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:RBYA+Vl/3jRZ35RPb4cLWQ7UHto= sha256:K/AWZGC+AF+7hZkqfcBBgRESwi35V2vGigx5XPfVhy0=
	sha1:PpwqwD8Ojtwz4XvmNMzUU5iHgJk= sha256:KSBsf3tfaqjOtW9DjyJa2h9WFfMPnMC+5nznMg5ThmU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 7B00D125D8F; Mon, 23 Nov 2026 08:18:16 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id qMH9_OcygK6U;
	Mon, 23 Nov 2026 08:18:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369046-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 7EF60125D8E; Mon, 23 Nov 2026 08:18:03 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id D6D802CD7C; Mon, 23 Nov 2026 05:17:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795411076;
	b=CVlPB8Tr27h+SLbQC9SVNdyhbF0y3W290hW0IT9BUlA2LYvdY7NQGkzkyAEdCP9DuL35
	 ffzIXyCIrgtspu3zlthyP+iGWXV41k3inW+qHv+dk8LByWkJariOiWL/4FN3MqR9bdQsG
	 cFsEuLIh7reHTGPXfiSWNUb6a9qUUFZNkl2e1m72wLeVHCzQgHgUj9QlVRPti5IJ/Z0MN
	 DlGxTXEHAN8oOg1zWS577DSyvp9prwFtffSOYIheqz+unn+l97UcNbFoqEYs9J0FaTuyn
	 BEAd2saABGgfSrU5rlPjlyviq9tVtyvAKdx4UXyI2tVnYI5V0tZ0oK3KfW8cOMlgbew==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795411076;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=IMhTbm3P4pQBpn4x8bv/SjESH9+2ScPTvDd021i2bNg=;
	b=qHqZL9YfDZgO0Jtjbs+JlgrcSLSexrLIxEHDFj1LmgYIEvWAtWZSr0whBgXD+Ux40Li+
	 NGdOvUfZYFTwpfTRAl/8E79tBrSvYVYnf5kMtADkGhZ2ivGU5Cv6uoFh5sTF+IdD0qqny
	 qZ5QQJKhS4qrJ4z3s8bd0POHOMQ/NBkvejjxdZZkONNWQw+UWIOFBySD0/jwuelEn9TH8
	 kS8hqL58bUcrOLsBNBErVUCK6SMwidnyMFi5uZ8f6Iifo97mpqc/DlDz/lixVFjfz8GWA
	 Pe1hudeWtgUYKK42VTaPVVuEU130lBCOXDpXAhKy7yZBvUI3fR5FcotCsxyUK1veMLA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fMtyHkhT;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id ADCB9606A327;
	Mon, 23 Nov 2026 05:17:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fMtyHkhT
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795411070;
	b=Lv3vKPNOYJW4M+ZSfZGJ41Ixb6rDrl7bII0XwN568p6LF1GBVae3yqEUalkFrdamCaCH
	 4UkpZyAp7WZ3GAcaCzrNINhaRO0XnZFMfYVa/ei4MXGMmoTlVbHTPKJtS7ZexNzUYG64q
	 p58Xa0WRFRXnmoir5V/GdcFLD0iJ/DK8Oo2AhFs7b6/x0+CLroINEThKPczTcE2M6cq+N
	 Dl+LWLBJa6j5oCb1sRlBov6UytdIMElWzJkB3wY+E0Xk0ZqU7T6kjf9NaMZa8qa2UGq2S
	 oPYWhuKPAyywcrQnUm42r0a/VRjWJvdDgBAxHFiJnrDo0c4Kgc4t/lFKH7SFcwZbCqw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795411070;
	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=IMhTbm3P4pQBpn4x8bv/SjESH9+2ScPTvDd021i2bNg=;
	b=4Vh6NFQ4DNR6QIFm2rVPk/zBslrQHXeb9YyuQ7HlmdpL2YNNaIvHNpCY262Yt8NKTeZ9
	 dknHB/TnoCrdd6/hdKFgdoWvHLVkSh31tKegwGBLfH3eOS3LETR9B9sG2Pk9nv31ekYjI
	 Zv0gtKHRSmiQhjlcBAruVuvvssICAuinRDvz9TI28FwmHHB31d1EVnyKfEMm+g6Iw/TgD
	 aRxMaBAiE99lS2A11EKNVHzaT7C6wljtO0gaCYyJwFbr9OFKWmVDaPvA5n1ZlarMvGCmw
	 nQMTSJ7VRaJNAEs3xatYhL6wK+3SsUJ3IYvTxEc3dQe8fBlKu2+Fx6DtiRZbCwuqlmw==
X-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=fMtyHkhT;
	arc=none smtp.remote-ip=100.103.45.18
X-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 C8B52606A32A;
	Mon, 23 Nov 2026 05:17:50 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5B551F000C0;
	Mon, 23 Nov 2026 05:17:49 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795411070;
	bh=IMhTbm3P4pQBpn4x8bv/SjESH9+2ScPTvDd021i2bNg=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=fMtyHkhTeVLHcaEoeY8ndzMsYX09qfqHvS3b3kDhy1x7PWI8yEGyOqUNeqTfB+7S6
	 lu2oryNAcfmkKI6WVsFfq/9Yai6tpOB4rmqHAE4UrOomijvcT4ASPQawffYDhP73zz
	 ND1EpMpJBWHcLPlE0EAfWvw1x6VsVhN4+4Y7Bq3ji5ctpyf5Tq8BO77cUr035awrVf
	 7DHc0hL4hjLKBaYQuoFJoSASV6KT9p2G0UkM9gjLXanFsePRzn/gVUqQjQkptYbUl3
	 Z+zRR4SIT6SRsSur5uAxxc1Tzax3rIEg8pNaK6LVM32s81gh/3AGvFE8HDaKQDzb0S
	 MKyV/UBssrHEQ==
X-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
X-In-Reply-To: <20261119042714.505405-1-davidlwesten@gmail.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list