From: netdev-bot+sashiko@kernel.org
To: socketcan@hartkopp.net
Cc: linux-can@vger.kernel.org, mkl@pengutronix.de,
o.rempel@pengutronix.de, mailhol@kernel.org, zhuling0805@qq.com,
kuba@kernel.org
Subject: Re: [PATCH v6 7/8] can: isotp: reject socket options while a transfer is active
Date: Thu, 19 Nov 2026 06:59:23 +0000 [thread overview]
Message-ID: <179507156318.3132.6797739670423336759@kernel.org> (raw)
In-Reply-To: <20261117-can-bcmlock-memcg-v6-7-6826a6227d36@hartkopp.net>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The patch says the new -EAGAIN in isotp_setsockopt_locked()
(net/can/isotp.c:1732-1734) is "only temporary" because "the…
- [Medium] isotp_sendmsg() computes `ae` (CAN_ISOTP_EXTEND_ADDR) and
`wait_tx_done` (CAN_ISOTP_WAIT_TX_DONE) from so->opt.flags in its…
- [Low] The patch carries a plain `Cc: stable@vger.kernel.org` with
`Fixes: e057dd3fc20f` (2020) and no `# depends on` note.
--
can: isotp: reject socket options while a transfer is active
This patch makes isotp_setsockopt_locked() return -EAGAIN while
so->tx.state or so->rx.state is not ISOTP_IDLE, matching the check that
already exists in isotp_bind(). The goal is to stop setsockopt() from
changing so->opt, so->ll and so->tx.ll_dl under an isotp_sendmsg() that
keeps running after NETDEV_UNREGISTER has cleared so->bound.
Closes: https://sashiko.dev/#/bug/linux-d1d3ef49-c24e-4f3a-91ce-20f8fb222684
> 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]
The commit message says:
As the transmission and the reception always end by their timeouts at
the latest, this state is only temporary.
Does that hold on the rx side? isotp_rcv_cf() cancels the rx watchdog
before it checks the frame length. Two of the early returns that follow
leave so->rx.state in ISOTP_WAIT_DATA and never re-arm the timer:
net/can/isotp.c:isotp_rcv_cf() {
...
hrtimer_cancel(&so->rxtimer);
...
/* 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;
}
...
}
The earlier patch in this series, "can: isotp: always start the rx
timeout in ISOTP_WAIT_DATA state", adds hrtimer_start() in isotp_rcv_ff()
and after the CF data copy. It does not cover these returns.
While the socket is bound, a later SF or FF resets the state. But
isotp_notify() for NETDEV_UNREGISTER unregisters isotp_rcv() and
isotp_rcv_echo() and clears so->bound. It does not reset rx.state or the
timers:
net/can/isotp.c:isotp_notify() {
...
so->ifindex = 0;
WRITE_ONCE(so->bound, 0);
WRITE_ONCE(so->dev, NULL);
...
}
After that, only isotp_release() writes rx.state.
Here is one sequence. A remote peer sends an FF and then a short CF that
is not the last one. On CAN FD, a CF longer than the FF's LL_DL has the
same effect. Then the device goes away, for example a USB adapter is
unplugged or a vcan is deleted.
Can rx.state then stay in ISOTP_WAIT_DATA for good? If so, every later
setsockopt() on the unbound socket returns -EAGAIN until the socket is
closed. isotp_bind() has the same state check, so the socket could not
be rebound either. Before this patch, setsockopt() on an unbound socket
always succeeded.
[Severity: Medium]
Does this fully close the option-change race the commit message
describes? isotp_sendmsg() reads two values from so->opt.flags in its
declarations. This happens before the so->bound check and before
so->tx.state is claimed:
net/can/isotp.c:isotp_sendmsg() {
...
int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
int wait_tx_done = (so->opt.flags & CAN_ISOTP_WAIT_TX_DONE) ? 1 : 0;
...
/* so->bound is only checked once above - a wakeup may have
* unbound/rebound the socket meanwhile => recheck
*/
if (!READ_ONCE(so->bound)) {
err = -EADDRNOTAVAIL;
goto err_out_drop;
}
...
}
The new check only covers the window after tx.state has been claimed.
The recheck after the claim only tests so->bound. Consider:
Thread A (bound socket)
isotp_sendmsg()
reads ae and wait_tx_done
is preempted, or waits in the claim loop behind another transfer
NETDEV_UNREGISTER
isotp_notify()
WRITE_ONCE(so->bound, 0);
Thread B (same socket, tx and rx idle)
setsockopt(CAN_ISOTP_OPTS)
toggles CAN_ISOTP_EXTEND_ADDR, passes the new check
bind() to another device
passes the idle check, so->bound = 1
Thread A
claims tx.state = ISOTP_SENDING
the recheck sees so->bound == 1
builds the SF/FF with the old ae
isotp_send_cframe() and isotp_rcv() recompute ae from the new
so->opt.flags:
net/can/isotp.c:isotp_send_cframe() {
...
int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
...
}
So the SF/FF and the CFs/FCs of the same PDU would disagree on the
extended address byte. Also, wait_tx_done would no longer match the
configured flags.
This does not corrupt memory: the frame indices are bounded by
so->tx.ll_dl and so->tx.len, which are read after the claim. Could ae
and wait_tx_done be computed after the claim and the bound recheck
instead?
[Severity: Low]
This patch has a plain "Cc: stable@vger.kernel.org" with
"Fixes: e057dd3fc20f". But the argument that the -EAGAIN is only
temporary depends on the earlier series patch "can: isotp: always start
the rx timeout in ISOTP_WAIT_DATA state".
Without that patch, isotp_rcv_ff() in CAN_ISOTP_LISTEN_MODE returns
before any rxtimer is started. isotp_rcv_cf() also does not restart the
timer at a block boundary when no FC is sent. That patch's own commit
message says this leaves rx.state in ISOTP_WAIT_DATA "until the socket
is closed" once the device is gone.
If this patch is backported alone, would this -EAGAIN become permanent
for those sockets?
The commit message also says:
isotp_bind() already rejects a new binding while so->tx.state or
so->rx.state are not ISOTP_IDLE for the same reason.
That check in isotp_bind() was added by commit 20bab8b88baac1 in July
2026, so older stable trees probably don't have it.
Other patches in this series use "Cc: stable@vger.kernel.org # depends
on ...". For example, "can: bcm: use a private mutex instead of
lock_sock()" depends on "can: bcm: copy the CAN frames outside of
lock_sock()". Should this patch have a similar dependency note?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-can-bcmlock-memcg-v6-0-6826a6227d36%40hartkopp.net
next prev parent reply other threads:[~2026-11-19 6:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:35 [PATCH v6 0/8] can: avoid RTNL stalls and fix CAN_ISOTP and netlink issues Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 1/8] can: bcm: copy the CAN frames outside of lock_sock() Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 2/8] can: bcm: do not remove the procfs entry in bcm_notify() Oliver Hartkopp
2026-11-19 6:59 ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 3/8] can: raw: use a private mutex instead of lock_sock() Oliver Hartkopp
2026-11-19 6:59 ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 4/8] can: isotp: " Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 5/8] can: bcm: " Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 6/8] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state Oliver Hartkopp
2026-11-19 6:59 ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 7/8] can: isotp: reject socket options while a transfer is active Oliver Hartkopp
2026-11-17 17:17 ` sashiko-bot
2026-11-17 18:58 ` Oliver Hartkopp
2026-11-19 6:59 ` netdev-bot+sashiko [this message]
2026-11-17 16:35 ` [PATCH v6 8/8] can: netlink: fix static FD-NON-ISO mode validation Oliver Hartkopp
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=179507156318.3132.6797739670423336759@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=socketcan@hartkopp.net \
--cc=zhuling0805@qq.com \
/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