Skip to content

Commit

Permalink
can: isotp: isotp_release(): omit unintended hrtimer restart on socke…
Browse files Browse the repository at this point in the history
…t release

commit 14a4696 upstream.

When closing the isotp socket, the potentially running hrtimers are
canceled before removing the subscription for CAN identifiers via
can_rx_unregister().

This may lead to an unintended (re)start of a hrtimer in
isotp_rcv_cf() and isotp_rcv_fc() in the case that a CAN frame is
received by isotp_rcv() while the subscription removal is processed.

However, isotp_rcv() is called under RCU protection, so after calling
can_rx_unregister, we may call synchronize_rcu in order to wait for
any RCU read-side critical sections to finish. This prevents the
reception of CAN frames after hrtimer_cancel() and therefore the
unintended (re)start of the hrtimers.

Link: https://lore.kernel.org/r/20210618173713.2296-1-socketcan@hartkopp.net
Fixes: e057dd3 ("can: add ISO 15765-2:2016 transport protocol")
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
hartkopp authored and gregkh committed Jul 14, 2021
1 parent af94ef8 commit 22bfa94
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions net/can/isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,6 @@ static int isotp_release(struct socket *sock)

lock_sock(sk);

hrtimer_cancel(&so->txtimer);
hrtimer_cancel(&so->rxtimer);

/* remove current filters & unregister */
if (so->bound) {
if (so->ifindex) {
Expand All @@ -1037,10 +1034,14 @@ static int isotp_release(struct socket *sock)
SINGLE_MASK(so->rxid),
isotp_rcv, sk);
dev_put(dev);
synchronize_rcu();
}
}
}

hrtimer_cancel(&so->txtimer);
hrtimer_cancel(&so->rxtimer);

so->ifindex = 0;
so->bound = 0;

Expand Down

0 comments on commit 22bfa94

Please sign in to comment.