Linux CAN drivers development
 help / color / mirror / Atom feed
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 2/5] can: j1939: fix possibility of UAF on j1939_session upon module unload
Date: Fri, 04 Dec 2026 16:29:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-250191@kernel.org> (raw)
In-Reply-To: <0f2790b7-4586-4a3c-80a3-d329a3fce1de@I-love.SAKURA.ne.jp>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] can: j1939: unconditional WQ_HIGHPRI offload in
  j1939_session_destroy()
--

commit ff8109ff98ecd01431b08fa480c06d1f155822f3
Author: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>

can: j1939: fix possibility of UAF on j1939_session upon module unload

This commit defers the final teardown of struct j1939_session (hrtimer
cancellation, netdev_put(), kfree(), and j1939_priv_put()) to j1939_wq so
that module unload waits for session destruction to complete and neither
hrtimer callback is still running before kfree().

> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> index fa30273df3263..4345921ede073 100644
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c

[ ... ]

> @@ -283,9 +301,8 @@ static void j1939_session_destroy(struct j1939_session *session)
>  		kfree_skb(skb);
>  	}
>  	__j1939_session_drop(session);
> -	netdev_put(session->priv->ndev, &session->priv_dev_tracker);
> -	j1939_priv_put(session->priv);
> -	kfree(session);
> +	INIT_WORK(&session->release_work, j1939_session_destroy_work);
> +	queue_work(j1939_wq, &session->release_work);
>  }

[Severity: Medium]
Does unconditionally queuing j1939_session_destroy_work() onto j1939_wq
introduce a per-frame scheduling regression on the transmit path?

Every j1939_sk_sendmsg() allocates a struct j1939_session via
j1939_sk_send_loop() -> j1939_tp_send(), including single-frame
J1939_SIMPLE messages.  On loopback completion, j1939_can_recv() ->
j1939_simple_recv() cancels the timers and calls j1939_session_put().

Because j1939_wq is allocated with WQ_HIGHPRI | WQ_PERCPU, every
transmitted frame now wakes a nice -20 kworker on the local CPU, which
can preempt normal tasks, adds a context switch, and defers kfree() out
of softirq.

In the common path, both timers are already inactive and callers like
j1939_can_recv() still hold a priv reference.  Could this check
!hrtimer_active() on both timers and refcount_dec_not_one() on
priv->kref.refcount to free inline, queueing work only otherwise?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/02d9f333-d774-4cec-9d12-cb181395fd8a@I-love.SAKURA.ne.jp?part=2

  reply	other threads:[~2026-12-04 16:29 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 [this message]
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

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-250191@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