]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
fa49991a216b91405984c3df7f0752748bc27635
[thirdparty/kernel/stable-queue.git] /
1 From c0f3f01e29cf2a07bf7fd78c441100782c31a8be Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 7 Sep 2020 14:31:48 +0800
4 Subject: can: j1939: j1939_sk_bind(): return failure if netdev is down
5
6 From: Zhang Changzhong <zhangchangzhong@huawei.com>
7
8 [ Upstream commit 08c487d8d807535f509ed80c6a10ad90e6872139 ]
9
10 When a netdev down event occurs after a successful call to
11 j1939_sk_bind(), j1939_netdev_notify() can handle it correctly.
12
13 But if the netdev already in down state before calling j1939_sk_bind(),
14 j1939_sk_release() will stay in wait_event_interruptible() blocked
15 forever. Because in this case, j1939_netdev_notify() won't be called and
16 j1939_tp_txtimer() won't call j1939_session_cancel() or other function
17 to clear session for ENETDOWN error, this lead to mismatch of
18 j1939_session_get/put() and jsk->skb_pending will never decrease to
19 zero.
20
21 To reproduce it use following commands:
22 1. ip link add dev vcan0 type vcan
23 2. j1939acd -r 100,80-120 1122334455667788 vcan0
24 3. presses ctrl-c and thread will be blocked forever
25
26 This patch adds check for ndev->flags in j1939_sk_bind() to avoid this
27 kind of situation and return with -ENETDOWN.
28
29 Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
30 Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
31 Link: https://lore.kernel.org/r/1599460308-18770-1-git-send-email-zhangchangzhong@huawei.com
32 Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
33 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
34 Signed-off-by: Sasha Levin <sashal@kernel.org>
35 ---
36 net/can/j1939/socket.c | 6 ++++++
37 1 file changed, 6 insertions(+)
38
39 diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
40 index bf9fd6ee88fe0..0470909605392 100644
41 --- a/net/can/j1939/socket.c
42 +++ b/net/can/j1939/socket.c
43 @@ -475,6 +475,12 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
44 goto out_release_sock;
45 }
46
47 + if (!(ndev->flags & IFF_UP)) {
48 + dev_put(ndev);
49 + ret = -ENETDOWN;
50 + goto out_release_sock;
51 + }
52 +
53 priv = j1939_netdev_start(ndev);
54 dev_put(ndev);
55 if (IS_ERR(priv)) {
56 --
57 2.27.0
58