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,
	sashiko-bot@kernel.org, zihanx@nebusec.ai,
	o.rempel@pengutronix.de, yewentian395@gmail.com, kuba@kernel.org
Subject: Re: [PATCH can-next 14/22] can: isotp: ignore invalid SF and FF frames during a reception
Date: Sat, 28 Nov 2026 10:20:23 +0000	[thread overview]
Message-ID: <179586122316.3131.4927340987108567833@kernel.org> (raw)
In-Reply-To: <20261126-getsockopt-memcg-isotp-v1-14-681ef8d8c2c9@hartkopp.net>

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

Critical: 0 · High: 0 · Medium: 1 · 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] In isotp_rcv_sf() (net/can/isotp.c), the patch moves the
  termination of an ongoing reception (hrtimer_cancel(&so->rxtimer);…
- [Low] The commit 'can: isotp: ignore invalid SF and FF frames during a
  reception' fixes a real, user-visible bug, but it has no Fixes: tag…

--

can: isotp: ignore invalid SF and FF frames during a reception

This commit moves the rx timer cancel and the ISOTP_IDLE state reset in
isotp_rcv_sf() and isotp_rcv_ff() so they run after the frame validity
checks. An invalid SF or FF should then no longer end an ongoing
reception. isotp_rcv_ff() now parses LL_DL and FF_DL into local variables
and stores them in so->rx only after the FF has been validated.

> Check the SF/FF first and terminate an ongoing reception only for a
> valid SF/FF. isotp_rcv_ff() reads the LL_DL and FF_DL into local
> variables to keep the data of an ongoing reception for invalid FFs.
>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>

[Severity: Low]
Should this patch have a Fixes: tag and Cc: stable?

The hrtimer_cancel() calls that run before the validity checks in
isotp_rcv_sf() and isotp_rcv_ff() come from commit e057dd3fc20f ("can: add
ISO 15765-2:2016 transport protocol"). The WRITE_ONCE() state resets in the
same place were last changed by commit 050f010f920d ("can: isotp: fix timer
drain order, wakeup handling and tx_gen ordering").

In those kernels, any node on the bus can end an ongoing reception without
any notice. It only has to send an invalid SF (SF_DL 0) or an invalid FF
(CAN_DL != padlen(CAN_DL), FF_DL below FF_DLmin, or an unneeded 32 bit
escape). isotp_rcv_cf() then drops the remaining CFs:

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

Because the timer has been cancelled, no ETIMEDOUT is reported for the lost
PDU either. Earlier isotp fixes such as 050f010f920d had both Fixes: and
Cc: stable.

> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index f6801c18172cf..39bae46701cc3 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -549,12 +549,14 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
>  	struct isotp_sock *so = isotp_sk(sk);
>  	struct sk_buff *nskb;
>  
> -	hrtimer_cancel(&so->rxtimer);
> -	WRITE_ONCE(so->rx.state, ISOTP_IDLE);
> -
> +	/* ignore invalid SFs (ongoing reception is not affected) */
>  	if (!len || len > cf->len - pcilen)
>  		return 1;
>  
> +	/* terminate a potentially ongoing reception */
> +	hrtimer_cancel(&so->rxtimer);
> +	WRITE_ONCE(so->rx.state, ISOTP_IDLE);
> +
>  	if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
>  	    check_pad(so, cf, pcilen + len, so->opt.rxpad_content)) {
>  		/* malformed PDU - report 'not a data message' */

[Severity: Medium]
Has the SF been fully validated at this point?

When CAN_ISOTP_CHK_PAD_LEN or CAN_ISOTP_CHK_PAD_DATA is set, an SF with a
valid SF_DL but wrong padding is still rejected as malformed by the
check_pad() test. That test now runs after the ongoing reception has
already been aborted.

Take a socket that has received a valid FF, so rx.state is ISOTP_WAIT_DATA
and the rx timer is running. An SF with a valid SF_DL and bad padding then
arrives:

isotp_rcv()
  isotp_rcv_sf()
    SF_DL length check passes
    hrtimer_cancel(&so->rxtimer)
    WRITE_ONCE(so->rx.state, ISOTP_IDLE)
    check_pad() fails -> sk->sk_err = EBADMSG, return

isotp_rcv_cf() then drops the remaining CFs of the interrupted PDU, because
rx.state is no longer ISOTP_WAIT_DATA. Since the timer was cancelled, no
ETIMEDOUT is reported for that PDU. The application only sees EBADMSG for
the SF, which was never delivered.

This seems to contradict the new comment "ignore invalid SFs (ongoing
reception is not affected)". It also contradicts the commit message, which
says "terminate an ongoing reception only for a valid SF/FF".

Should the termination also move after the padding check?

The ordering stays the same later in the series, after these functions
are changed to return void and check_pad() is renamed to chk_pad_fail().

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net

  reply	other threads:[~2026-11-28 10:20 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 01/22] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 02/22] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 03/22] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
2026-11-27 10:08   ` Oliver Hartkopp
2026-11-27 11:50     ` Oleksij Rempel
2026-11-27 11:58       ` Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 04/22] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 05/22] can: isotp: add the frame transmission time to the protocol timeouts Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 06/22] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 07/22] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 08/22] can: isotp: reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 09/22] can: isotp: drop frames without N_PCI Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 10/22] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 11/22] can: isotp: check the minimum FF_DL Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 12/22] can: isotp: check the data length of the last CF Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 13/22] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 14/22] can: isotp: ignore invalid SF and FF frames during a reception Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko [this message]
2026-11-26 21:05 ` [PATCH can-next 15/22] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 16/22] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 17/22] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
2026-11-26 21:06 ` [PATCH can-next 18/22] can: isotp: rename variable for the required content length Oliver Hartkopp
2026-11-26 21:06 ` [PATCH can-next 19/22] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
2026-11-26 21:06 ` [PATCH can-next 20/22] can: isotp: change return type of functions to void Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-26 21:06 ` [PATCH can-next 21/22] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
2026-11-26 21:06 ` [PATCH can-next 22/22] can: isotp: introduce CAN_ISOTP_MIN_TX_DL Oliver Hartkopp
2026-11-28 10:20   ` netdev-bot+sashiko
2026-11-28 17:54 ` [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups 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=179586122316.3131.4927340987108567833@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-bot@kernel.org \
    --cc=socketcan@hartkopp.net \
    --cc=yewentian395@gmail.com \
    --cc=zihanx@nebusec.ai \
    /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