All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH v8 4/4] can: isotp: fix state machine corruption on signal interruption
Date: Sun, 12 Jul 2026 12:56:38 +0000	[thread overview]
Message-ID: <20260712125639.2C2521F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260712-isotp-fixes-v8-4-c39220a4e442@hartkopp.net>

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

Pre-existing issues:
- [High] The `so->tx_gen` mechanism fails to protect against delayed local echoes from aborted transfers if the CAN payload matches, leading to protocol pacing violations and timeouts.
- [High] Signal interruption during `wait_tx_done` causes racy state clobbering of concurrent transfers due to a stolen wakeup and lockless state update.
--

--- Patch [4]: [PATCH v8 4/4] can: isotp: fix state machine corruption on signal interruption ---
commit 7dee50f317c5e02a3ea6610e45f4dde065c0b96c
Author: Oliver Hartkopp <socketcan@hartkopp.net>

can: isotp: fix state machine corruption on signal interruption

This commit fixes a bug where a signal interrupting a thread waiting to start
a new transfer incorrectly aborts an ongoing transfer. By returning the error
directly, it avoids executing the cleanup path that forces the state back to
ISOTP_IDLE.

> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index c5b44d298618b..ceb590ae058eb 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -1047,7 +1047,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
>  		/* wait for complete transmission of current pdu */
>  		err = wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
>  		if (err)
> -			goto err_event_drop;
> +			return err;

[Severity: High]
This is a pre-existing issue, but does a similar race exist later in
isotp_sendmsg() when handling wait_tx_done?

If Thread A waits in wait_tx_done with a signal pending, and concurrently
the transfer finishes (setting state to ISOTP_IDLE and waking waiters),
Thread B could wake up and claim the socket locklessly:

Thread B:
    while (cmpxchg(&so->tx.state, ISOTP_IDLE, ISOTP_SENDING) != ISOTP_IDLE) {

Before Thread B increments so->tx_gen, if Thread A wakes up, evaluates its
wait condition, returns -ERESTARTSYS, and jumps to err_event_drop:

Thread A:
    if (wait_tx_done) {
        err = wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
        if (err)
            goto err_event_drop;
    }

Would Thread A then incorrectly reset the state back to ISOTP_IDLE while
Thread B is actively using the socket?

Thread A in err_event_drop:
    if (READ_ONCE(so->tx_gen) == gen) {
        so->cfecho = 0;
        so->tx.state = ISOTP_IDLE;
    }

>  	}
>  
>  	/* new transfer: bump the generation (gen is used below and by

[Severity: High]
This isn't a bug introduced by this patch, but does the so->tx_gen mechanism
fully protect against delayed local echoes from aborted transfers?

If a transfer is aborted while its CAN frame is already queued, and a new
transfer begins with matching first 4 bytes of payload, could the delayed
local echo from the aborted frame arrive and be falsely validated?

In isotp_rcv_echo():

    if (so->cfecho != *(u32 *)cf->data)
        goto out_unlock;
    
    gen = READ_ONCE(so->tx_gen);
    ...
    if (so->tx.state != ISOTP_SENDING || READ_ONCE(so->tx_gen) != gen)
        goto out_unlock;

Since gen is read directly from the current socket state (so->tx_gen) rather
than being persistently attached to the SKB, does this allow a stale echo to
prematurely advance the new transfer's state machine, leading to pacing
(STmin) violations and timeouts?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260712-isotp-fixes-v8-0-c39220a4e442@hartkopp.net?part=4

      reply	other threads:[~2026-07-12 12:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-12 12:41 [PATCH v8 0/4] net: can: isotp-fixes Oliver Hartkopp via B4 Relay
2026-07-12 12:41 ` Oliver Hartkopp
2026-07-12 12:41 ` [PATCH v8 1/4] can: isotp: use unconditional synchronize_rcu() in isotp_release() Oliver Hartkopp via B4 Relay
2026-07-12 12:41   ` Oliver Hartkopp
2026-07-12 12:54   ` sashiko-bot
2026-07-12 12:41 ` [PATCH v8 2/4] can: isotp: fix use-after-free race with concurrent NETDEV_UNREGISTER Oliver Hartkopp via B4 Relay
2026-07-12 12:41   ` Oliver Hartkopp
2026-07-12 12:59   ` sashiko-bot
2026-07-12 12:41 ` [PATCH v8 3/4] can: isotp: fix race between RX/TX timers and frame reception Oliver Hartkopp via B4 Relay
2026-07-12 12:41   ` Oliver Hartkopp
2026-07-12 12:53   ` sashiko-bot
2026-07-12 12:41 ` [PATCH v8 4/4] can: isotp: fix state machine corruption on signal interruption Oliver Hartkopp via B4 Relay
2026-07-12 12:41   ` Oliver Hartkopp
2026-07-12 12:56   ` sashiko-bot [this message]

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=20260712125639.2C2521F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=socketcan@hartkopp.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.