Skip to content

Commit 1809c82

Browse files
Tetsuo Handamarckleinebudde
authored andcommitted
net: can: j1939: j1939_xtp_rx_rts_session_active(): deactivate session upon receiving the second rts
Since j1939_session_deactivate_activate_next() in j1939_tp_rxtimer() is called only when the timer is enabled, we need to call j1939_session_deactivate_activate_next() if we cancelled the timer. Otherwise, refcount for j1939_session leaks, which will later appear as | unregister_netdevice: waiting for vcan0 to become free. Usage count = 2. problem. Reported-by: syzbot <syzbot+881d65229ca4f9ae8c84@syzkaller.appspotmail.com> Closes: https://syzkaller.appspot.com/bug?extid=881d65229ca4f9ae8c84 Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Acked-by: Oleksij Rempel <o.rempel@pengutronix.de> Fixes: 9d71dd0 ("can: add support of SAE J1939 protocol") Link: https://patch.msgid.link/b1212653-8fa1-44e1-be9d-12f950fb3a07@I-love.SAKURA.ne.jp Cc: stable@vger.kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 6c1f514 commit 1809c82

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

net/can/j1939/transport.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,8 +1695,16 @@ static int j1939_xtp_rx_rts_session_active(struct j1939_session *session,
16951695

16961696
j1939_session_timers_cancel(session);
16971697
j1939_session_cancel(session, J1939_XTP_ABORT_BUSY);
1698-
if (session->transmission)
1698+
if (session->transmission) {
16991699
j1939_session_deactivate_activate_next(session);
1700+
} else if (session->state == J1939_SESSION_WAITING_ABORT) {
1701+
/* Force deactivation for the receiver.
1702+
* If we rely on the timer starting in j1939_session_cancel,
1703+
* a second RTS call here will cancel that timer and fail
1704+
* to restart it because the state is already WAITING_ABORT.
1705+
*/
1706+
j1939_session_deactivate_activate_next(session);
1707+
}
17001708

17011709
return -EBUSY;
17021710
}

0 commit comments

Comments
 (0)