Linux CAN drivers development
 help / color / mirror / Atom feed
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 6/8] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state
Date: Thu, 19 Nov 2026 06:59:22 +0000	[thread overview]
Message-ID: <179507156226.3132.18273836206289416422@kernel.org> (raw)
In-Reply-To: <20261117-can-bcmlock-memcg-v6-6-6826a6227d36@hartkopp.net>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

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).

- [High] This fix is incomplete: isotp_rcv_cf() (net/can/isotp.c) can
  still leave so->rx.state at ISOTP_WAIT_DATA with no rx timer running.

--

can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state

This patch starts the rx timeout in isotp_rcv_ff() and isotp_rcv_cf()
whenever reception continues in ISOTP_WAIT_DATA state, before a flow
control frame is sent. Without it, so->rx.state can stay in
ISOTP_WAIT_DATA with no rx timer running, and isotp_bind() then returns
-EAGAIN after the CAN device has been removed.

> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 8229b6a69ecd0..0293d590186c4 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c

[ ... ]

> @@ -726,13 +730,13 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
>  		return 0;
>  	}
>  
> +	/* start rx timeout, isotp_send_fc() restarts it */
> +	hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
> +		      HRTIMER_MODE_REL_SOFT);
> +

[Severity: High]
Can isotp_rcv_cf() still leave so->rx.state at ISOTP_WAIT_DATA with no rx
timer running?

Earlier in isotp_rcv_cf() the timer is cancelled unconditionally, and two
length checks after that return without resetting rx.state or restarting
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 first check is hit on a CANFD_MTU socket when an 8-byte FF is followed
by a CF longer than 8 bytes. The second check is hit on classic CAN by a CF
with DLC < 8 in the middle of a PDU. A remote CAN node can send either
frame.

The new hrtimer_start() comes after both checks, so neither path reaches
it. That means isotp_rx_timer_handler() cannot fire, and it is the only
asynchronous path from ISOTP_WAIT_DATA back to ISOTP_IDLE.

If the CAN device is then unregistered, the NETDEV_UNREGISTER branch of
isotp_notify() clears so->bound, so->dev and so->ifindex but leaves
so->rx.state alone. No further FF or SF arrives to reset the state, so
isotp_bind() keeps returning -EAGAIN until the socket is closed:

	if (READ_ONCE(so->tx.state) != ISOTP_IDLE ||
	    READ_ONCE(so->rx.state) != ISOTP_IDLE) {
		err = -EAGAIN;
		goto out;
	}

This is the symptom the commit message says is fixed. The subject also
says the timeout is "always" started.

The next patch in the series, "can: isotp: reject socket options while a
transfer is active", adds the same rx.state != ISOTP_IDLE check to
isotp_setsockopt_locked(). With that patch, setsockopt() would also return
-EAGAIN permanently in this case. That patch's statement that receptions
always end by their timeouts at the latest also would not hold for these
paths. No later patch in the series appears to address this.

Would it make sense to reset so->rx.state to ISOTP_IDLE on these two early
returns, or to restart the timer there? Another option is to reset
so->rx.state in the NETDEV_UNREGISTER handler of isotp_notify(), which
would cover every such path at once.

>  	/* perform blocksize handling, if enabled */
> -	if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs) {
> -		/* start rx timeout watchdog */
> -		hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
> -			      HRTIMER_MODE_REL_SOFT);
> +	if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs)
>  		return 0;
> -	}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-can-bcmlock-memcg-v6-0-6826a6227d36%40hartkopp.net

  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 [this message]
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
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=179507156226.3132.18273836206289416422@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