From: Oliver Hartkopp The rx timeout is only started at the end of isotp_send_fc() and for consecutive frames inside a block in isotp_rcv_cf(). So so->rx.state can stay in ISOTP_WAIT_DATA without a running rx timeout: - isotp_send_fc() returns early, when it can not allocate the skb or does not find the CAN device anymore - isotp_rcv_ff() does not send a flow control frame in listen mode - isotp_rcv_cf() has stopped the rx timeout and does not restart it at the end of a block, when the flow control frame is not sent On a bound socket the next first frame or single frame resets the state. But when the CAN device has been removed, no further CAN frame is received and so->rx.state remains in ISOTP_WAIT_DATA. isotp_bind() then rejects a new binding with -EAGAIN until the socket is closed. Start the rx timeout in isotp_rcv_ff() and isotp_rcv_cf() whenever the reception continues in ISOTP_WAIT_DATA state, before a flow control frame is sent. isotp_send_fc() restarts the rx timeout as before. All this runs under so->rx_lock, so the order of the rx timeout start and the transmission of the flow control frame does not matter. 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. So a listening socket reports a missing consecutive frame consistently, independent of its position in the PDU. Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol") Cc: stable@vger.kernel.org Signed-off-by: Oliver Hartkopp Link: https://patch.msgid.link/20261117-can-bcmlock-memcg-v6-6-6826a6227d36@hartkopp.net Cc: Vincent Mailhol Cc: Marc Kleine-Budde Cc: Oleksij Rempel Cc: Zhu Ling Cc: linux-can@vger.kernel.org Signed-off-by: Marc Kleine-Budde --- net/can/isotp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/net/can/isotp.c b/net/can/isotp.c index 8229b6a69ecd..0293d590186c 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; @@ -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); + /* 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; - } /* no creation of flow control frames */ if (so->opt.flags & CAN_ISOTP_LISTEN_MODE) -- 2.53.0