From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>, linux-can@vger.kernel.org
Cc: "Marc Kleine-Budde" <mkl@pengutronix.de>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH can-next v5 08/24] can: isotp: add N_As timeout monitoring for SF/FF/CF
Date: Thu, 03 Dec 2026 14:11:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-247920@kernel.org> (raw)
In-Reply-To: <20261203-getsockopt-memcg-isotp-v5-8-bbe89b3d3b71@hartkopp.net>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] can: isotp: isotp_sendmsg() only cancels echotimer on
can_send() error
--
commit b37dcf6e7f04378576a9f03bcc246c557c97e4b0
Author: Oliver Hartkopp <socketcan@hartkopp.net>
can: isotp: add N_As timeout monitoring for SF/FF/CF
This commit monitors SF, FF, and CF transmissions with the 1 s N_As
timeout using the local echo timer, starting the N_Bs flow control
timeout when the FF echo arrives or cancelling both timers if an FC
arrives first.
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 2ef4cbc9962ea..368e50bd82fd7 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
[ ... ]
> @@ -1330,7 +1339,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
> }
> /* WAIT_FIRST_FC for standard FF, else stays ISOTP_SENDING */
> WRITE_ONCE(so->tx.state, new_state);
> - hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, 0),
> + hrtimer_start(&so->echotimer, ktime_set(ISOTP_TIMEOUT, 0),
> HRTIMER_MODE_REL_SOFT);
> spin_unlock_bh(&so->rx_lock);
>
> @@ -1357,7 +1366,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
> }
>
> /* no transmission -> no timeout monitoring */
> - hrtimer_cancel(tx_hrt);
> + hrtimer_cancel(&so->echotimer);
> goto err_out_drop_locked;
> }
[Severity: Medium]
Can this error path leave so->txtimer or so->txfrtimer armed or running
when can_send() fails?
Because isotp_sendmsg() publishes ISOTP_WAIT_FIRST_FC and drops
so->rx_lock before calling can_send(), an incoming FC frame on so->rxid
can race with a failing can_send():
CPU0 (isotp_sendmsg) CPU1 (softirq)
WRITE_ONCE(so->tx.state,
ISOTP_WAIT_FIRST_FC)
hrtimer_start(&so->echotimer, ...)
spin_unlock_bh(&so->rx_lock)
can_send(skb, 1) /* fails */
isotp_rcv() -> isotp_rcv_fc()
/* ISOTP_FC_WT arrives */
hrtimer_cancel(&so->echotimer)
WRITE_ONCE(so->tx.state, ISOTP_WAIT_FC)
hrtimer_start(&so->txtimer, ...)
spin_lock_bh(&so->rx_lock)
hrtimer_cancel(&so->echotimer) <-- so->txtimer left armed
WRITE_ONCE(so->tx.state, ISOTP_IDLE)
spin_unlock_bh(&so->rx_lock)
Previously tx_hrt pointed to &so->txtimer in standard FF mode, so
hrtimer_cancel(tx_hrt) drained it. Now an undrained so->txtimer that is
already running can asynchronously set sk->sk_err = ECOMM and invoke
sk_error_report() after isotp_sendmsg() has already returned the
can_send() error.
Similarly, if an ISOTP_FC_CTS frame arrives and triggers a CF echo that
arms so->txfrtimer, the lock-free isotp_txfr_timer_handler() can re-arm
so->echotimer or send a stray CF frame with a non-zero so->cfecho after
isotp_sendmsg() returns failure.
Jumping to err_event_drop instead would perform the same so->tx_gen
check under so->rx_lock and drain so->txfrtimer, so->txtimer, and
so->echotimer in order.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-getsockopt-memcg-isotp-v5-0-bbe89b3d3b71@hartkopp.net?part=8
next prev parent reply other threads:[~2026-12-03 14:11 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 11:55 [PATCH can-next v5 00/24] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 01/24] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 02/24] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
2026-12-03 12:22 ` sashiko-bot
2026-12-03 11:55 ` [PATCH can-next v5 03/24] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
2026-12-03 12:41 ` sashiko-bot
2026-12-03 11:55 ` [PATCH can-next v5 04/24] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 05/24] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 06/24] can: isotp: add the frame transmission time to the CF broadcast gap Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 07/24] can: isotp: limit the frame transmission time to the N_As/N_Ar timeout Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 08/24] can: isotp: add N_As timeout monitoring for SF/FF/CF Oliver Hartkopp
2026-12-03 14:11 ` sashiko-bot [this message]
2026-12-03 11:55 ` [PATCH can-next v5 09/24] can: isotp: add N_Ar timeout monitoring for FC Oliver Hartkopp
2026-12-03 14:30 ` sashiko-bot
2026-12-03 11:56 ` [PATCH can-next v5 10/24] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
2026-12-03 14:50 ` sashiko-bot
2026-12-03 11:56 ` [PATCH can-next v5 11/24] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 12/24] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 13/24] can: isotp: drop frames without N_PCI Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 14/24] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 15/24] can: isotp: check the minimum FF_DL Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 16/24] can: isotp: check the data length of the last CF Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 17/24] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 18/24] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 19/24] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 20/24] can: isotp: rename variable for the required content length Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 21/24] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 22/24] can: isotp: change return type of functions to void Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 23/24] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 24/24] can: isotp: introduce CAN_ISOTP_MIN_TX_DL 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=sashiko-outbox-247920@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox