]> Git Repo - J-linux.git/commitdiff
can: j1939: socket: j1939_sk_bind(): make sure ml_priv is allocated
authorOleksij Rempel <[email protected]>
Fri, 7 Aug 2020 10:51:58 +0000 (12:51 +0200)
committerMarc Kleine-Budde <[email protected]>
Fri, 14 Aug 2020 10:38:47 +0000 (12:38 +0200)
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: 9d71dd0c7009 ("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]>
net/can/j1939/socket.c

index ad973370de12e434aabf9ac1d9090db3aec4a749..b93876c57fc48f5b9483c7021b4ba7ce4cd3e5a6 100644 (file)
@@ -467,6 +467,14 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
                        goto out_release_sock;
                }
 
+               if (!ndev->ml_priv) {
+                       netdev_warn_once(ndev,
+                                        "No CAN mid layer private allocated, please fix your driver and use alloc_candev()!\n");
+                       dev_put(ndev);
+                       ret = -ENODEV;
+                       goto out_release_sock;
+               }
+
                priv = j1939_netdev_start(ndev);
                dev_put(ndev);
                if (IS_ERR(priv)) {
This page took 0.052875 seconds and 4 git commands to generate.