Skip to content

Commit af804b7

Browse files
oleremmarckleinebudde
authored andcommitted
can: j1939: socket: j1939_sk_bind(): make sure ml_priv is allocated
This patch adds check to ensure that the struct net_device::ml_priv is allocated, as it is used later by the j1939 stack. The allocation is done by all mainline CAN network drivers, but when using bond or team devices this is not the case. Bail out if no ml_priv is allocated. Reported-by: [email protected] Fixes: 9d71dd0 ("can: add support of SAE J1939 protocol") Cc: linux-stable <[email protected]> # >= v5.4 Signed-off-by: Oleksij Rempel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent cd3b363 commit af804b7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

net/can/j1939/socket.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
467467
goto out_release_sock;
468468
}
469469

470+
if (!ndev->ml_priv) {
471+
netdev_warn_once(ndev,
472+
"No CAN mid layer private allocated, please fix your driver and use alloc_candev()!\n");
473+
dev_put(ndev);
474+
ret = -ENODEV;
475+
goto out_release_sock;
476+
}
477+
470478
priv = j1939_netdev_start(ndev);
471479
dev_put(ndev);
472480
if (IS_ERR(priv)) {

0 commit comments

Comments
 (0)