Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: mkl@pengutronix.de
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
	linux-can@vger.kernel.org, kernel@pengutronix.de,
	zhuling0805@qq.com, stable@vger.kernel.org,
	socketcan@hartkopp.net, mailhol@kernel.org,
	o.rempel@pengutronix.de
Subject: Re: [PATCH net 06/11] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state
Date: Wed, 18 Nov 2026 22:19:19 +0000	[thread overview]
Message-ID: <179504035916.3136.12986898667697830880@kernel.org> (raw)
In-Reply-To: <20261117220818.1142581-7-mkl@pengutronix.de>

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] The fix is incomplete.

--

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. Previously the
timeout could be missing when isotp_send_fc() failed, in listen mode, or
at the end of a block. Without it, a socket whose CAN device was removed
could stay in ISOTP_WAIT_DATA, and isotp_bind() would keep returning
-EAGAIN.

Link: https://patch.msgid.link/20261117-can-bcmlock-memcg-v6-6-6826a6227d36@hartkopp.net

> 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]
Does isotp_rcv_cf() still have paths that leave so->rx.state in
ISOTP_WAIT_DATA with no rx timer armed?

Earlier in isotp_rcv_cf(), the timer is cancelled unconditionally. Two
length checks after that cancel return before this new hrtimer_start()
is reached:

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;
	}
    ...
}

Neither path restarts the timer or sets rx.state to ISOTP_IDLE.

Both paths look reachable from the bus, because isotp_rcv() only checks
skb->len against so->ll.mtu and never checks cf->len:

- On a CAN CC socket, padlen() gives rx.ll_dl = 8 for the first frame.
  A following CF with len < 8, sent while more than 7 bytes are still
  outstanding, takes the second return.

- On a CAN FD socket, a first frame with len 8 (ll_dl = 8) followed by
  a CF with len 12..64 takes the first return.

The frames could come from any remote node, or from a local CAN_RAW
socket on vcan.

Suppose such a malformed CF is the last frame before NETDEV_UNREGISTER.
isotp_notify() does not reset rx.state, and isotp_rx_timer_handler() is
not armed. So isotp_bind() would still return -EAGAIN until the socket
is closed:

net/can/isotp.c:isotp_bind() {
    ...
	if (READ_ONCE(so->tx.state) != ISOTP_IDLE ||
	    READ_ONCE(so->rx.state) != ISOTP_IDLE) {
		err = -EAGAIN;
		goto out;
	}
    ...
}

This is the failure the commit message says it removes.

The later patch in this series, "can: isotp: reject socket options while
a transfer is active", adds the same rx.state != ISOTP_IDLE -> -EAGAIN
check to isotp_setsockopt_locked(). So setsockopt() would be blocked in
the same stuck state.

There is also a case before the device is removed. In
CAN_ISOTP_HALF_DUPLEX mode, isotp_rcv() drops every incoming FC frame
while rx.state is not ISOTP_IDLE. That lasts until the next FF or SF
arrives.

Could these two returns also re-arm the rx timer (or set ISOTP_IDLE)? An
alternative would be to restructure the function so that every return
after hrtimer_cancel() that keeps ISOTP_WAIT_DATA re-arms the timer.

>  	/* 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/20261117220818.1142581-2-mkl%40pengutronix.de

  reply	other threads:[~2026-11-18 22:19 UTC|newest]

Thread overview: 17+ 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:19   ` netdev-bot+sashiko [this message]
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:19   ` netdev-bot+sashiko
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-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

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=179504035916.3136.12986898667697830880@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=socketcan@hartkopp.net \
    --cc=stable@vger.kernel.org \
    --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