1
0
Fork 0
alistair23-linux/net/can/j1939
Zhang Changzhong b9c4a9a07c can: j1939: j1939_sk_bind(): return failure if netdev is down
[ Upstream commit 08c487d8d8 ]

When a netdev down event occurs after a successful call to
j1939_sk_bind(), j1939_netdev_notify() can handle it correctly.

But if the netdev already in down state before calling j1939_sk_bind(),
j1939_sk_release() will stay in wait_event_interruptible() blocked
forever. Because in this case, j1939_netdev_notify() won't be called and
j1939_tp_txtimer() won't call j1939_session_cancel() or other function
to clear session for ENETDOWN error, this lead to mismatch of
j1939_session_get/put() and jsk->skb_pending will never decrease to
zero.

To reproduce it use following commands:
1. ip link add dev vcan0 type vcan
2. j1939acd -r 100,80-120 1122334455667788 vcan0
3. presses ctrl-c and thread will be blocked forever

This patch adds check for ndev->flags in j1939_sk_bind() to avoid this
kind of situation and return with -ENETDOWN.

Fixes: 9d71dd0c70 ("can: add support of SAE J1939 protocol")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
Link: https://lore.kernel.org/r/1599460308-18770-1-git-send-email-zhangchangzhong@huawei.com
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-11-18 19:20:19 +01:00
..
Kconfig can: add support of SAE J1939 protocol 2019-09-04 14:22:33 +02:00
Makefile can: add support of SAE J1939 protocol 2019-09-04 14:22:33 +02:00
address-claim.c can: add support of SAE J1939 protocol 2019-09-04 14:22:33 +02:00
bus.c can: add support of SAE J1939 protocol 2019-09-04 14:22:33 +02:00
j1939-priv.h can: add support of SAE J1939 protocol 2019-09-04 14:22:33 +02:00
main.c can: j1939: warn if resources are still linked on destroy 2019-11-13 10:42:34 +01:00
socket.c can: j1939: j1939_sk_bind(): return failure if netdev is down 2020-11-18 19:20:19 +01:00
transport.c net: j1939: j1939_session_fresh_new(): fix missing initialization of skbcnt 2020-10-29 09:57:24 +01:00