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 v7 6/8] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state
Date: Sun, 22 Nov 2026 02:04:09 +0000	[thread overview]
Message-ID: <179531304900.3131.6873205153419606406@kernel.org> (raw)
In-Reply-To: <20261120-can-bcmlock-memcg-v7-6-f6b84f5257b1@hartkopp.net>

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

Critical: 0 · High: 0 · Medium: 1 · 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).

- [Medium] In net/can/isotp.c, isotp_rcv_ff() now arms so->rxtimer for
  ISOTP_FC_TIMEOUT (1 s) as soon as a First Frame is received, and it…

--

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, so the socket no longer
stays in that state indefinitely when no flow control frame is sent. It
also moves the consecutive frame length checks ahead of hrtimer_cancel(),
so an invalid CF is dropped without stopping the rx timeout.

Closes: https://lore.kernel.org/linux-can/179504035916.3136.12986898667697830880@kernel.org/

> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 8229b6a69ecd0..0b7db1ead7a90 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -634,6 +634,10 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
>  	so->rx.sn = 1;
>  	WRITE_ONCE(so->rx.state, ISOTP_WAIT_DATA);
>  
> +	/* start rx timeout, isotp_send_fc() restarts it */
> +	hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
> +		      HRTIMER_MODE_REL_SOFT);
> +
>  	/* no creation of flow control frames */
>  	if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
>  		return 0;

[Severity: Medium]
Could this abort valid transfers on a CAN_ISOTP_LISTEN_MODE socket?

In listen mode isotp_send_fc() is never called, so nothing restarts this
timer before the first CF. That means the listener's window for the
first CF is 1 s counted from the FF, not from the real receiver's FC.

The listener also never sees the real receiver's FC frames. isotp_bind()
sends only rx_id to isotp_rcv(). tx_id goes to isotp_rcv_echo(), which
drops anything that is not its own echo:

net/can/isotp.c:isotp_rcv_echo() {
    ...
	/* only handle my own local echo CF/SF skb's (no FF!) */
	if (skb->sk != sk)
		return;
    ...
}

The real peers can legitimately use a longer FF to first CF gap. The
Linux sender re-arms its timer for each FC.WT:

net/can/isotp.c:isotp_rcv_fc() {
    ...
	case ISOTP_FC_WT:
		/* start timer to wait for next FC frame */
		hrtimer_start(&so->txtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
			      HRTIMER_MODE_REL_SOFT);
    ...
}

The receiver's N_Cr window also starts when it sends its FC, not when
the FF arrived. So a transfer with one or more FC.WT frames, or with a
slow FC followed by a slow first CF, can have a gap of more than 1 s
and still be compliant.

In that case the sequence would be:

isotp_rcv_ff()
    WRITE_ONCE(so->rx.state, ISOTP_WAIT_DATA);
    hrtimer_start(&so->rxtimer, 1 s)
    return 0 (listen mode, no FC)

  real receiver sends FC.WT (not visible to the listener)

isotp_rx_timer_handler()
    sk->sk_err = ETIMEDOUT;
    WRITE_ONCE(so->rx.state, ISOTP_IDLE);

isotp_rcv_cf()
    if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
        return 0;

Each CF of that PDU is then dropped, so the listener reports ETIMEDOUT
and loses a PDU that both real peers completed. Before this patch, the
listen-mode socket stayed in WAIT_DATA without a timer between the FF
and the first CF, so such a PDU was still reassembled.

The commit message says:

  In listen mode a first frame that is not followed by consecutive
  frames now leads to ETIMEDOUT, like a missing consecutive frame inside
  a block already does.

A gap inside a block does not include the FC round trip, but the FF to
first CF gap always does. The message does not mention that slow but
compliant transfers are now aborted for listen-mode users, and the
patch is tagged for stable.

Would it make sense to use a longer timeout for the listen-mode FF case,
or at least to describe this trade-off in the commit message? The later
patch in the series ("can: isotp: reject socket options while a transfer
is active") does not change this behaviour.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-can-bcmlock-memcg-v7-0-f6b84f5257b1%40hartkopp.net

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