From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
linux-can@vger.kernel.org,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Vincent Mailhol" <mailhol@kernel.org>
Subject: Re: [PATCH v3 2/2] can: isotp: fix use-after-free race with concurrent NETDEV_UNREGISTER
Date: Fri, 10 Jul 2026 13:07:16 +0000 [thread overview]
Message-ID: <20260710130716.89E921F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260710-isotp-fixes-v3-2-08db68e27d0b@hartkopp.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Lockless check of `so->bound` in `isotp_bind()` creates a TOCTOU race that bypasses the newly added wait for `ISOTP_IDLE`, allowing cross-device packet injection.
--
--- Patch [2]: [PATCH v3 2/2] can: isotp: fix use-after-free race with concurrent NETDEV_UNREGISTER ---
commit e4c5bbbd972ba76bfee06412e3abf69c164cec65
Author: Oliver Hartkopp <socketcan@hartkopp.net>
can: isotp: fix use-after-free race with concurrent NETDEV_UNREGISTER
This commit fixes a use-after-free race in isotp_release() and isotp_notify()
by taking a tracked reference to the net_device and serializing bind/release
with rtnl_lock(). It also adds a wait in isotp_bind() to ensure any active
transmissions settle if the socket was unbound by a concurrent device
unregistration.
Link: https://lore.kernel.org/linux-can/20260707101420.47F261F000E9@smtp.kernel.org/
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index d30937345bcdc..d98863bad0d9f 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
[ ... ]
> @@ -1310,6 +1319,18 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l
> if (!addr->can_ifindex)
> return -ENODEV;
>
> + if (!so->bound) {
> + /* A transmission that outlived a previous binding (unbound
> + * by NETDEV_UNREGISTER) must settle before so->tx can be
> + * reused; the FC/echo watchdog timers bound this wait.
> + */
> + err = wait_event_interruptible(so->wait,
> + so->tx.state == ISOTP_IDLE);
> + if (err)
> + return err;
> + }
> +
> + rtnl_lock();
> lock_sock(sk);
>
> if (so->bound) {
[Severity: High]
Can this lockless check of so->bound bypass the wait if the socket is
unbound just before acquiring the locks?
If a user initiates a bind to a new device while the socket is currently
bound and transmitting, the initial if (!so->bound) check will be false,
skipping the wait for ISOTP_IDLE.
If a concurrent NETDEV_UNREGISTER runs and clears so->bound before this
thread acquires rtnl_lock(), the inner if (so->bound) check will then
evaluate to false.
Does this allow the bind to succeed while the state machine is still
transmitting, potentially injecting the remaining payload onto the newly
bound CAN device?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260710-isotp-fixes-v3-0-08db68e27d0b@hartkopp.net?part=2
prev parent reply other threads:[~2026-07-10 13:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 12:56 [PATCH v3 0/2] net: can: isotp-fixes Oliver Hartkopp via B4 Relay
2026-07-10 12:56 ` [PATCH v3 1/2] can: isotp: use unconditional synchronize_rcu() in isotp_release() Oliver Hartkopp via B4 Relay
2026-07-10 13:18 ` sashiko-bot
2026-07-10 12:56 ` [PATCH v3 2/2] can: isotp: fix use-after-free race with concurrent NETDEV_UNREGISTER Oliver Hartkopp via B4 Relay
2026-07-10 13:07 ` 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=20260710130716.89E921F000E9@smtp.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=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