summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleksij Rempel <o.rempel@pengutronix.de>2020-08-07 12:51:58 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-08-26 10:40:50 +0200
commit143df6b3584a0f6314c71f5dd0e5de9bba5e453d (patch)
treeed73399d5220994e7cc345598491788fffa92f47
parent60be1488a3ae1350c0f629ef7956d9192cf6cba9 (diff)
downloadlinux-stable-143df6b3584a0f6314c71f5dd0e5de9bba5e453d.tar.gz
linux-stable-143df6b3584a0f6314c71f5dd0e5de9bba5e453d.tar.bz2
linux-stable-143df6b3584a0f6314c71f5dd0e5de9bba5e453d.zip
can: j1939: socket: j1939_sk_bind(): make sure ml_priv is allocated
commit af804b7826350d5af728dca4715e473338fbd7e5 upstream. 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: syzbot+f03d384f3455d28833eb@syzkaller.appspotmail.com Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Cc: linux-stable <stable@vger.kernel.org> # >= v5.4 Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.kernel.org/r/20200807105200.26441-4-o.rempel@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--net/can/j1939/socket.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index f7587428febd..11d566c70a94 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -466,6 +466,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)) {