From: sashiko-bot@kernel.org
To: "Tetsuo Handa" <penguin-kernel@I-love.SAKURA.ne.jp>,
linux-can@vger.kernel.org
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH v16 5/5] can: j1939: fix possibility of list corruption in __j1939_ecu_release()
Date: Fri, 04 Dec 2026 16:23:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-250181@kernel.org> (raw)
In-Reply-To: <006957f0-5a7b-4e2a-85ec-f0a08a0ad471@I-love.SAKURA.ne.jp>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] can: j1939: O(N^2) zombie scan and lock fan-out from deferred
ECU list_del()
--
commit 75cc65689af4612193f82d163f25817aea7da880
Author: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
can: j1939: fix possibility of list corruption in __j1939_ecu_release()
This commit defers list_del(&ecu->list) from __j1939_ecu_release() to
__j1939_ecu_release_work() under write_lock_bh(&priv->lock), and updates
j1939_ecu lookup and reference-taking helpers to skip zero-refcount entries.
> diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
> index b8e517c6ad1ce..a9dc565e34c22 100644
> --- a/net/can/j1939/bus.c
> +++ b/net/can/j1939/bus.c
> @@ -28,6 +28,9 @@ static void __j1939_ecu_release_work(struct work_struct *work)
> struct j1939_ecu *ecu = container_of(work, struct j1939_ecu, release_work);
> struct j1939_priv *priv = ecu->priv;
>
> + write_lock_bh(&priv->lock);
> + list_del(&ecu->list);
> + write_unlock_bh(&priv->lock);
> /* There can't be any ref on this ECU because __j1939_ecu_release()
> * was already called. But we need to make sure that
> * j1939_ecu_timer_handler() is no longer running before kfree().
> @@ -42,7 +45,6 @@ static void __j1939_ecu_release(struct kref *kref)
> {
> struct j1939_ecu *ecu = container_of(kref, struct j1939_ecu, kref);
>
> - list_del(&ecu->list);
> INIT_WORK(&ecu->release_work, __j1939_ecu_release_work);
> queue_work(j1939_wq, &ecu->release_work);
> }
[Severity: Medium]
Can deferring list_del(&ecu->list) to j1939_wq cause O(n^2) scans over
priv->ecus under priv->lock?
j1939_ecu_create_locked() appends new entries with list_add_tail(), so
zero-refcount entries accumulate at the head of priv->ecus ahead of live
ones whenever create/release churn outpaces the workqueue.
During an address-claim burst in softirq, j1939_ac_process() alternating
unicast and idle 0xfe claims preempts j1939_wq. Lookup paths such as
j1939_ecu_get_by_name_locked() and j1939_ecu_find_by_name_locked() then
scan past all dead entries under priv->lock, starving the cleanup worker.
Separately, j1939_ecu_unmap_all() previously unlinked up to 254 mapped
entries inside one write_lock_bh(&priv->lock) critical section, but now
schedules up to 254 work items that each re-acquire write_lock_bh(),
increasing contention with j1939_can_recv() readers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/02d9f333-d774-4cec-9d12-cb181395fd8a@I-love.SAKURA.ne.jp?part=5
prev parent reply other threads:[~2026-12-04 16:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 16:03 [PATCH v16 0/5] can: j1939: make module more robust Tetsuo Handa
2026-12-04 16:03 ` [PATCH v16 1/5] can: j1939: fix possibility of UAF on j1939_priv upon module unload Tetsuo Handa
2026-12-04 16:34 ` sashiko-bot
2026-12-04 16:04 ` [PATCH v16 2/5] can: j1939: fix possibility of UAF on j1939_session " Tetsuo Handa
2026-12-04 16:29 ` sashiko-bot
2026-12-04 16:04 ` [PATCH v16 3/5] can: j1939: fix possibility of UAF on j1939_ecu " Tetsuo Handa
2026-12-04 16:04 ` [PATCH v16 4/5] can: j1939: fix "struct j1939_ecu" refcount leak Tetsuo Handa
2026-12-04 16:23 ` sashiko-bot
2026-12-04 16:05 ` [PATCH v16 5/5] can: j1939: fix possibility of list corruption in __j1939_ecu_release() Tetsuo Handa
2026-12-04 16:23 ` sashiko-bot [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=sashiko-outbox-250181@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=sashiko-reviews@lists.linux.dev \
--cc=socketcan@hartkopp.net \
/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