History

ax25: Fix ax25 session cleanup problems

There are session cleanup problems in ax25_release() and ax25_disconnect(). If we setup a session and then disconnect, the disconnected session is still in "LISTENING" state that is shown below. Active AX.25 sockets Dest Source Device State Vr/Vs Send-Q Recv-Q DL9SAU-4 DL9SAU-3 ??? LISTENING 000/000 0 0 DL9SAU-3 DL9SAU-4 ??? LISTENING 000/000 0 0 The first reason is caused by del_timer_sync() in ax25_release(). The timers of ax25 are used for correct session cleanup. If we use ax25_release() to close ax25 sessions and ax25_dev is not null, the del_timer_sync() functions in ax25_release() will execute. As a result, the sessions could not be cleaned up correctly, because the timers have stopped. In order to solve this problem, this patch adds a device_up flag in ax25_dev in order to judge whether the device is up. If there are sessions to be cleaned up, the del_timer_sync() in ax25_release() will not execute. What's more, we add ax25_cb_del() in ax25_kill_by_device(), because the timers have been stopped and there are no functions that could delete ax25_cb if we do not call ax25_release(). Finally, we reorder the position of ax25_list_lock in ax25_cb_del() in order to synchronize among different functions that call ax25_cb_del(). The second reason is caused by improper check in ax25_disconnect(). The incoming ax25 sessions which ax25->sk is null will close heartbeat timer, because the check "if(!ax25->sk || ..)" is satisfied. As a result, the session could not be cleaned up properly. In order to solve this problem, this patch changes the improper check to "if(ax25->sk && ..)" in ax25_disconnect(). What`s more, the ax25_disconnect() may be called twice, which is not necessary. For example, ax25_kill_by_device() calls ax25_disconnect() and sets ax25->state to AX25_STATE_0, but ax25_release() calls ax25_disconnect() again. In order to solve this problem, this patch add a check in ax25_release(). If the flag of ax25->sk equals to SOCK_DEAD, the ax25_disconnect() in ax25_release() should not be executed.

Duoming Zhou committed 4 years ago

Commit 7d8a3a41 parent 9f4fc184 files · +20 −11Browse files

Unified · Split

4 files
  1. include/net/ax25.h +1 −0
  2. net/ax25/af_ax25.c +17 −10
  3. net/ax25/ax25_dev.c +1 −0
  4. net/ax25/ax25_subr.c +1 −1
include/net/ax25.h+1−0
@@ -228,6 +228,7 @@ typedef struct ax25_dev { · 227 unmodified lines
228228 ax25_dama_info dama;
229229 #endif
230230 refcount_t refcount;
231+ bool device_up;
231232 } ax25_dev;
232233
233234 typedef struct ax25_cb {
net/ax25/af_ax25.c+17−10
@@ -62,12 +62,12 @@ static void ax25_free_sock(struct sock *sk) · 61 unmodified lines
6262 */
6363 static void ax25_cb_del(ax25_cb *ax25)
6464 {
65+ spin_lock_bh(&ax25_list_lock);
6566 if (!hlist_unhashed(&ax25->ax25_node)) {
66− spin_lock_bh(&ax25_list_lock);
6767 hlist_del_init(&ax25->ax25_node);
68− spin_unlock_bh(&ax25_list_lock);
6968 ax25_cb_put(ax25);
7069 }
70+ spin_unlock_bh(&ax25_list_lock);
7171 }
7272
7373 /*
@@ -81,6 +81,7 @@ static void ax25_kill_by_device(struct net_device *dev) · 7 unmodified lines
8181
8282 if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
8383 return;
84+ ax25_dev->device_up = false;
8485
8586 spin_lock_bh(&ax25_list_lock);
8687 again:
@@ -91,6 +92,7 @@ again: · 4 unmodified lines
9192 spin_unlock_bh(&ax25_list_lock);
9293 ax25_disconnect(s, ENETUNREACH);
9394 s->ax25_dev = NULL;
95+ ax25_cb_del(s);
9496 spin_lock_bh(&ax25_list_lock);
9597 goto again;
9698 }
@@ -103,6 +105,7 @@ again: · 6 unmodified lines
103105 dev_put_track(ax25_dev->dev, &ax25_dev->dev_tracker);
104106 ax25_dev_put(ax25_dev);
105107 }
108+ ax25_cb_del(s);
106109 release_sock(sk);
107110 spin_lock_bh(&ax25_list_lock);
108111 sock_put(sk);
@@ -995,9 +998,11 @@ static int ax25_release(struct socket *sock) · 886 unmodified lines
995998 if (sk->sk_type == SOCK_SEQPACKET) {
996999 switch (ax25->state) {
9971000 case AX25_STATE_0:
998− release_sock(sk);
999− ax25_disconnect(ax25, 0);
1000− lock_sock(sk);
1001+ if (!sock_flag(ax25->sk, SOCK_DEAD)) {
1002+ release_sock(sk);
1003+ ax25_disconnect(ax25, 0);
1004+ lock_sock(sk);
1005+ }
10011006 ax25_destroy_socket(ax25);
10021007 break;
10031008
@@ -1053,11 +1058,13 @@ static int ax25_release(struct socket *sock) · 49 unmodified lines
10531058 ax25_destroy_socket(ax25);
10541059 }
10551060 if (ax25_dev) {
1056− del_timer_sync(&ax25->timer);
1057− del_timer_sync(&ax25->t1timer);
1058− del_timer_sync(&ax25->t2timer);
1059− del_timer_sync(&ax25->t3timer);
1060− del_timer_sync(&ax25->idletimer);
1061+ if (!ax25_dev->device_up) {
1062+ del_timer_sync(&ax25->timer);
1063+ del_timer_sync(&ax25->t1timer);
1064+ del_timer_sync(&ax25->t2timer);
1065+ del_timer_sync(&ax25->t3timer);
1066+ del_timer_sync(&ax25->idletimer);
1067+ }
10611068 dev_put_track(ax25_dev->dev, &ax25_dev->dev_tracker);
10621069 ax25_dev_put(ax25_dev);
10631070 }
net/ax25/ax25_dev.c+1−0
@@ -62,6 +62,7 @@ void ax25_dev_device_up(struct net_device *dev) · 61 unmodified lines
6262 ax25_dev->dev = dev;
6363 dev_hold_track(dev, &ax25_dev->dev_tracker, GFP_ATOMIC);
6464 ax25_dev->forward = NULL;
65+ ax25_dev->device_up = true;
6566
6667 ax25_dev->values[AX25_VALUES_IPDEFMODE] = AX25_DEF_IPDEFMODE;
6768 ax25_dev->values[AX25_VALUES_AXDEFMODE] = AX25_DEF_AXDEFMODE;
net/ax25/ax25_subr.c+1−1
@@ -268,7 +268,7 @@ void ax25_disconnect(ax25_cb *ax25, int reason) · 267 unmodified lines
268268 del_timer_sync(&ax25->t3timer);
269269 del_timer_sync(&ax25->idletimer);
270270 } else {
271− if (!ax25->sk || !sock_flag(ax25->sk, SOCK_DESTROY))
271+ if (ax25->sk && !sock_flag(ax25->sk, SOCK_DESTROY))
272272 ax25_stop_heartbeat(ax25);
273273 ax25_stop_t1timer(ax25);
274274 ax25_stop_t2timer(ax25);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t