From: sashiko-bot@kernel.org
To: "Nagamani PV" <nagamani@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
linux-s390@vger.kernel.org,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH net v2 2/2] s390/ctcm: Fix use-after-free in channel_remove()
Date: Thu, 17 Sep 2026 13:22:24 +0000 [thread overview]
Message-ID: <20260917132225.646FF1F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260916132149.4185912-3-nagamani@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] timer: use-after-free in channel_remove() due to re-arming after timer_delete_sync()
--
commit f0230a69308edd523997bd09005283eab61bb03e
Author: Nagamani PV <nagamani@linux.ibm.com>
s390/ctcm: Fix use-after-free in channel_remove()
This commit attempts to fix a use-after-free in channel_remove() by replacing
fsm_deltimer() calls with direct calls to timer_delete_sync() before freeing
the channel structure. The commit message states timer_shutdown_sync() was
avoided to prevent self-deadlocks if FSM action functions call fsm_deltimer()
from within the timer callback chain.
Link: https://sashiko.dev/#/patchset/20260803182736.2356374-1-nagamani@linux.ibm.com?part=1
> diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
> --- a/drivers/s390/net/ctcm_main.c
> +++ b/drivers/s390/net/ctcm_main.c
> @@ -211,9 +211,9 @@ static void channel_remove(struct channel *ch)
> while (*c) {
> if (*c == ch) {
> *c = ch->next;
> - fsm_deltimer(&ch->timer);
> + timer_delete_sync(&ch->timer.tl);
> if (IS_MPC(ch))
> - fsm_deltimer(&ch->sweep_timer);
> + timer_delete_sync(&ch->sweep_timer.tl);
[Severity: High]
Can this sequence lead to a use-after-free if the main timer is re-armed
during teardown?
Looking at channel_remove(), the patch deliberately uses timer_delete_sync()
instead of timer_shutdown_sync(). While timer_delete_sync() waits for a
running callback to finish, it does not mark the timer as shut down or
prevent it from being re-armed.
If a concurrent sweep_timer callback executes during channel_remove(), it
can re-arm the main timer via ctcmpc_chx_send_sweep():
drivers/s390/net/ctcm_fsms.c:ctcmpc_chx_send_sweep() {
...
fsm_addtimer(&wch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, wch);
fsm_newstate(wch->fsm, CTC_STATE_TX);
...
}
If channel_remove() calls timer_delete_sync() on ch->timer.tl first, and
then spin-waits for ch->sweep_timer.tl, the sweep_timer callback could
re-arm ch->timer right before the teardown thread proceeds to free the
channel structure via kfree(ch).
Since the kernel Timer API requires timer_shutdown_sync() to safely
prevent this exact re-arming scenario before freeing, does leaving the
timer capable of being re-armed leave it active on the timer wheel after
the channel memory is gone?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260916132149.4185912-1-nagamani@linux.ibm.com?part=2
next prev parent reply other threads:[~2026-09-17 13:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 14:45 [PATCH net 0/2] s390/ctcm: Fix timer bugs in fsm.c Nagamani PV
2026-09-07 14:45 ` [PATCH net 1/2] s390/ctcm: Fix timer corruption in fsm_addtimer() Nagamani PV
2026-09-08 14:45 ` sashiko-bot
2026-09-10 2:46 ` netdev-bot+sashiko
2026-09-11 10:12 ` Nagamani PV
2026-09-07 14:45 ` [PATCH net 2/2] s390/ctcm: Fix use-after-free in channel_remove() Nagamani PV
2026-09-08 14:45 ` sashiko-bot
2026-09-10 2:46 ` netdev-bot+sashiko
2026-09-11 10:26 ` Nagamani PV
2026-09-16 13:21 ` [PATCH net v2 0/2] s390/ctcm: Fix timer bugs in fsm.c Nagamani PV
2026-09-16 13:21 ` [PATCH net v2 1/2] s390/ctcm: Fix timer corruption in fsm_addtimer() Nagamani PV
2026-09-17 13:22 ` sashiko-bot
2026-09-16 13:21 ` [PATCH net v2 2/2] s390/ctcm: Fix use-after-free in channel_remove() Nagamani PV
2026-09-17 13:22 ` sashiko-bot [this message]
2026-09-21 23:15 ` [PATCH net v2 0/2] s390/ctcm: Fix timer bugs in fsm.c Jakub Kicinski
2026-09-22 10:54 ` Nagamani PV
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=20260917132225.646FF1F00898@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=nagamani@linux.ibm.com \
--cc=sashiko-reviews@lists.linux.dev \
/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