From: sashiko-bot@kernel.org
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH net 07/11] can: isotp: reject socket options while a transfer is active
Date: Wed, 18 Nov 2026 22:10:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-222095@kernel.org> (raw)
In-Reply-To: <20261117220818.1142581-8-mkl@pengutronix.de>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] can: isotp: rxtimer left disarmed in isotp_rcv_cf() on
invalid cf->len
- [Medium] can: isotp: isotp_sendmsg() reads socket options outside
tx.state claim
--
commit 5df2197329153084f3880aee22e4689e00328a28
Author: Oliver Hartkopp <socketcan@hartkopp.net>
can: isotp: reject socket options while a transfer is active
This commit rejects setsockopt() calls with -EAGAIN in
isotp_setsockopt_locked() when so->tx.state or so->rx.state is not
ISOTP_IDLE, preventing socket options from changing while a transfer from a
previous binding is still draining.
Link: https://patch.msgid.link/20261117-can-bcmlock-memcg-v6-7-6826a6227d36@hartkopp.net
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 0293d590186c4..32c88749d75e7 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -1725,6 +1725,14 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
> if (so->bound)
> return -EISCONN;
>
> + /* A transmission or reception that outlived a previous binding
> + * (unbound by NETDEV_UNREGISTER) may still be draining and uses the
> + * socket options, see isotp_bind().
> + */
> + if (READ_ONCE(so->tx.state) != ISOTP_IDLE ||
> + READ_ONCE(so->rx.state) != ISOTP_IDLE)
> + return -EAGAIN;
[Severity: Medium]
Can an invalid consecutive frame leave so->rx.state permanently in
ISOTP_WAIT_DATA with so->rxtimer disarmed, causing isotp_setsockopt_locked()
(and isotp_bind()) to always return -EAGAIN after an unbind?
isotp_rcv_cf() cancels so->rxtimer before checking cf->len against
so->rx.ll_dl, and returns early on a length mismatch without restarting
so->rxtimer or resetting so->rx.state to ISOTP_IDLE:
net/can/isotp.c:isotp_rcv_cf() {
...
hrtimer_cancel(&so->rxtimer);
/* isotp_rx_timer_handler() may have raced us for so->rx.state
* while hrtimer_cancel() above waited for it to finish => recheck
*/
if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
return 1;
/* CFs are never longer than the FF */
if (cf->len > so->rx.ll_dl)
return 1;
/* CFs have usually the LL_DL length */
if (cf->len < so->rx.ll_dl) {
/* this is only allowed for the last CF */
if (so->rx.len - so->rx.idx > so->rx.ll_dl - ae - N_PCI_SZ)
return 1;
}
...
}
If a peer sends a First Frame followed by a Consecutive Frame with an
invalid length, so->rxtimer is disarmed while so->rx.state stays in
ISOTP_WAIT_DATA, so the reception never times out.
[Severity: Medium]
Does isotp_sendmsg() still read socket options outside the region where
so->tx.state is non-idle and so->bound is verified?
CPU0 CPU1
isotp_sendmsg()
ae = (so->opt.flags & ...)
wait_tx_done = (so->opt.flags & ...)
wait_event_interruptible(...)
isotp_notify(NETDEV_UNREGISTER)
so->bound = 0
/* previous tx finishes:
* so->tx.state = ISOTP_IDLE */
isotp_setsockopt_locked()
/* updates so->opt.flags */
isotp_bind()
so->bound = 1
WRITE_ONCE(so->tx.state, ISOTP_SENDING)
if (!READ_ONCE(so->bound)) ...
/* builds first frame with stale ae, while
* isotp_send_cframe() later reads new ae */
isotp_sendmsg() reads ae and wait_tx_done at function entry before claiming
so->tx.state = ISOTP_SENDING and rechecking so->bound. In addition, at the
end of isotp_sendmsg(), cf->flags = so->ll.tx_flags is read after publishing
WRITE_ONCE(so->tx.state, new_state), starting tx_hrt, and dropping
so->rx_lock, where an incoming FC abort or timeout can reset so->tx.state to
ISOTP_IDLE and allow a concurrent setsockopt(CAN_ISOTP_LL_OPTS) after unbind
to modify so->ll.tx_flags before cf->flags is assigned.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117220818.1142581-1-mkl@pengutronix.de?part=7
next prev parent reply other threads:[~2026-11-18 22:10 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 22:03 [PATCH net 0/11] pull-request: can 2026-11-17 Marc Kleine-Budde
2026-11-17 22:03 ` [PATCH net 01/11] can: bcm: copy the CAN frames outside of lock_sock() Marc Kleine-Budde
2026-11-17 22:12 ` netdev-bot+sinfo
2026-11-18 7:47 ` Oliver Hartkopp
2026-11-17 22:03 ` [PATCH net 02/11] can: bcm: do not remove the procfs entry in bcm_notify() Marc Kleine-Budde
2026-11-17 22:03 ` [PATCH net 03/11] can: raw: use a private mutex instead of lock_sock() Marc Kleine-Budde
2026-11-17 22:03 ` [PATCH net 04/11] can: isotp: " Marc Kleine-Budde
2026-11-17 22:03 ` [PATCH net 05/11] can: bcm: " Marc Kleine-Budde
2026-11-17 22:03 ` [PATCH net 06/11] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state Marc Kleine-Budde
2026-11-18 22:10 ` sashiko-bot
2026-11-18 22:19 ` netdev-bot+sashiko
2026-11-19 7:53 ` Oliver Hartkopp
2026-11-19 17:38 ` Oliver Hartkopp
2026-11-17 22:03 ` [PATCH net 07/11] can: isotp: reject socket options while a transfer is active Marc Kleine-Budde
2026-11-18 22:10 ` sashiko-bot [this message]
2026-11-18 22:19 ` netdev-bot+sashiko
2026-11-19 8:04 ` Oliver Hartkopp
2026-11-17 22:03 ` [PATCH net 08/11] can: netlink: fix static FD-NON-ISO mode validation Marc Kleine-Budde
2026-11-18 22:19 ` netdev-bot+sashiko
2026-11-19 8:13 ` Oliver Hartkopp
2026-11-17 22:03 ` [PATCH net 09/11] can: netlink: fix IFLA_CAN_BITRATE_MAX attribute sizing Marc Kleine-Budde
2026-11-17 22:03 ` [PATCH net 10/11] can: netlink: fix CAN XL PWM " Marc Kleine-Budde
2026-11-17 22:03 ` [PATCH net 11/11] can: gs_usb: gs_can_start_xmit(): don't leak uninitialized memory over USB Marc Kleine-Budde
2026-11-19 16:53 ` [PATCH net 0/11] pull-request: can 2026-11-17 Oliver Hartkopp
2026-11-19 17:32 ` Marc Kleine-Budde
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-222095@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.