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 v7 7/8] can: isotp: reject socket options while a transfer is active
Date: Sun, 22 Nov 2026 02:04:10 +0000 [thread overview]
Message-ID: <179531305000.3131.3851387722489339935@kernel.org> (raw)
In-Reply-To: <20261120-can-bcmlock-memcg-v7-7-f6b84f5257b1@hartkopp.net>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch gates isotp_setsockopt_locked() (net/can/isotp.c, lines
1733-1739) on tx.state/rx.state == ISOTP_IDLE.
- [Low] The commit message says that reading
CAN_ISOTP_EXTEND_ADDR/CAN_ISOTP_WAIT_TX_DONE after the claim means…
--
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, the same way
isotp_bind() already does. It also moves the reads of the
CAN_ISOTP_EXTEND_ADDR and CAN_ISOTP_WAIT_TX_DONE flags in
isotp_sendmsg() to after the transfer claim and the so->bound recheck.
Closes: https://sashiko.dev/#/bug/linux-d1d3ef49-c24e-4f3a-91ce-20f8fb222684
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 0b7db1ead7a90..642fec500af9d 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
[ ... ]
> @@ -1188,6 +1188,10 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
> goto err_out_drop;
> }
>
> + /* read the options after the claim of the transfer */
> + ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
> + wait_tx_done = (so->opt.flags & CAN_ISOTP_WAIT_TX_DONE) ? 1 : 0;
> +
[Severity: Low]
The commit message says that reading these flags after the claim means
"all socket options used by isotp_sendmsg() are covered by this check".
Does that also hold for so->ll.tx_flags?
Later in isotp_sendmsg(), so->ll.tx_flags is read only after the state
has been published, the timer armed and rx_lock dropped:
WRITE_ONCE(so->tx.state, new_state);
hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, 0),
HRTIMER_MODE_REL_SOFT);
spin_unlock_bh(&so->rx_lock);
/* send the first or only CAN frame */
cf->flags = so->ll.tx_flags;
isotp_tx_timeout() takes no lock and can cmpxchg() tx.state back to
ISOTP_IDLE. That happens if the sending task is delayed past the 1s/2s
timeout after spin_unlock_bh(), for example by CFS bandwidth
throttling, RT starvation or a vCPU stall. A malformed or OVFLW FC
handled in isotp_rcv_fc() can reset the state in the same way.
Suppose the bound device is also unregistered in that window, so
isotp_notify() clears so->bound. isotp_setsockopt_locked() then passes
both the -EISCONN check and the new IDLE check. Its CAN_ISOTP_LL_OPTS
case does memcpy(&so->ll, ll, sizeof(*ll)) at the same time as the
plain read of so->ll.tx_flags above.
The impact looks limited to a data race on a single u8 that KCSAN can
flag. The device is already down by then, so can_send() rejects the
skb with -ENETDOWN.
Could cf->flags = so->ll.tx_flags be moved before the final
spin_lock_bh()/hrtimer_start() block, so that the commit message claim
holds?
[ ... ]
> @@ -1726,6 +1730,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: Low]
This comment points to isotp_bind(), which says "the FC/echo and RX
watchdog timers bound how long this takes". The commit message makes
the same point:
As the transmission and the reception always end by their timeouts at
the latest, this state is only temporary.
Is that accurate for the window in isotp_sendmsg() between the claim
and the final hrtimer_start()? Under rx_lock, isotp_sendmsg() cancels
all three TX timers and moves tx.state out of IDLE:
hrtimer_cancel(&so->txfrtimer);
hrtimer_cancel(&so->txtimer);
hrtimer_cancel(&so->echotimer);
...
WRITE_ONCE(so->tx.state, ISOTP_SENDING);
It then calls memcpy_from_msg(), dev_get_by_index() and
sock_alloc_send_skb(). No timer is armed until
hrtimer_start(tx_hrt, ...) near the end of the function.
memcpy_from_msg() can block on a user page fault, for example with
userfaultfd or a FUSE-backed mapping. A blocking sock_alloc_send_skb()
can wait up to sk_sndtimeo, which defaults to MAX_SCHEDULE_TIMEOUT.
If NETDEV_UNREGISTER clears so->bound during that window, setsockopt()
and bind() would keep returning -EAGAIN until sendmsg() makes progress,
not just for a period bounded by a timer.
There is no memory-safety issue here. Could the comment and commit
message be updated to describe this case?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-can-bcmlock-memcg-v7-0-f6b84f5257b1%40hartkopp.net
next prev parent reply other threads:[~2026-11-22 2:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 11:28 [PATCH v7 0/8] can: avoid RTNL stalls and fix CAN_ISOTP and netlink issues Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 1/8] can: bcm: copy the CAN frames outside of lock_sock() Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 2/8] can: bcm: do not remove the procfs entry in bcm_notify() Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 3/8] can: raw: use a private mutex instead of lock_sock() Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 4/8] can: isotp: " Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 5/8] can: bcm: " Oliver Hartkopp
2026-11-22 2:04 ` netdev-bot+sashiko
2026-11-22 17:55 ` Oliver Hartkopp
2026-11-20 11:29 ` [PATCH v7 6/8] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state Oliver Hartkopp
2026-11-22 2:04 ` netdev-bot+sashiko
2026-11-22 15:57 ` Oliver Hartkopp
2026-11-20 11:29 ` [PATCH v7 7/8] can: isotp: reject socket options while a transfer is active Oliver Hartkopp
2026-11-22 2:04 ` netdev-bot+sashiko [this message]
2026-11-22 18:26 ` Oliver Hartkopp
2026-11-20 11:29 ` [PATCH v7 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=179531305000.3131.3851387722489339935@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