Skip to content

Commit 730a125

Browse files
Tetsuo Handagregkh
authored andcommitted
can: j1939: make j1939_sk_bind() fail if device is no longer registered
[ Upstream commit 46cea21 ] There is a theoretical race window in j1939_sk_netdev_event_unregister() where two j1939_sk_bind() calls jump in between read_unlock_bh() and lock_sock(). The assumption jsk->priv == priv can fail if the first j1939_sk_bind() call once made jsk->priv == NULL due to failed j1939_local_ecu_get() call and the second j1939_sk_bind() call again made jsk->priv != NULL due to successful j1939_local_ecu_get() call. Since the socket lock is held by both j1939_sk_netdev_event_unregister() and j1939_sk_bind(), checking ndev->reg_state with the socket lock held can reliably make the second j1939_sk_bind() call fail (and close this race window). Fixes: 7fcbe5b ("can: j1939: implement NETDEV_UNREGISTER notification handler") Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Acked-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://patch.msgid.link/5732921e-247e-4957-a364-da74bd7031d7@I-love.SAKURA.ne.jp Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b166b8e commit 730a125

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

net/can/j1939/socket.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
482482
goto out_release_sock;
483483
}
484484

485+
if (ndev->reg_state != NETREG_REGISTERED) {
486+
dev_put(ndev);
487+
ret = -ENODEV;
488+
goto out_release_sock;
489+
}
490+
485491
can_ml = can_get_ml_priv(ndev);
486492
if (!can_ml) {
487493
dev_put(ndev);

0 commit comments

Comments
 (0)