Skip to content

Commit eda8951

Browse files
n7nixgregkh
authored andcommitted
AX.25: Close socket connection on session completion
[ Upstream commit 4a7d99ea1b27734558feb6833f180cd38a159940 ] A socket connection made in ax.25 is not closed when session is completed. The heartbeat timer is stopped prematurely and this is where the socket gets closed. Allow heatbeat timer to run to close socket. Symptom occurs in kernels >= 4.2.0 Originally sent 6/15/2016. Resend with distribution list matching scripts/maintainer.pl output. Signed-off-by: Basil Gunn <basil@pacabunga.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b30cc5b commit eda8951

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

net/ax25/af_ax25.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,8 @@ static int ax25_release(struct socket *sock)
976976
release_sock(sk);
977977
ax25_disconnect(ax25, 0);
978978
lock_sock(sk);
979-
ax25_destroy_socket(ax25);
979+
if (!sock_flag(ax25->sk, SOCK_DESTROY))
980+
ax25_destroy_socket(ax25);
980981
break;
981982

982983
case AX25_STATE_3:

net/ax25/ax25_ds_timer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void ax25_ds_heartbeat_expiry(ax25_cb *ax25)
102102
switch (ax25->state) {
103103

104104
case AX25_STATE_0:
105+
case AX25_STATE_2:
105106
/* Magic here: If we listen() and a new link dies before it
106107
is accepted() it isn't 'dead' so doesn't get removed. */
107108
if (!sk || sock_flag(sk, SOCK_DESTROY) ||
@@ -111,6 +112,7 @@ void ax25_ds_heartbeat_expiry(ax25_cb *ax25)
111112
sock_hold(sk);
112113
ax25_destroy_socket(ax25);
113114
bh_unlock_sock(sk);
115+
/* Ungrab socket and destroy it */
114116
sock_put(sk);
115117
} else
116118
ax25_destroy_socket(ax25);
@@ -213,7 +215,8 @@ void ax25_ds_t1_timeout(ax25_cb *ax25)
213215
case AX25_STATE_2:
214216
if (ax25->n2count == ax25->n2) {
215217
ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
216-
ax25_disconnect(ax25, ETIMEDOUT);
218+
if (!sock_flag(ax25->sk, SOCK_DESTROY))
219+
ax25_disconnect(ax25, ETIMEDOUT);
217220
return;
218221
} else {
219222
ax25->n2count++;

net/ax25/ax25_std_timer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void ax25_std_heartbeat_expiry(ax25_cb *ax25)
3838

3939
switch (ax25->state) {
4040
case AX25_STATE_0:
41+
case AX25_STATE_2:
4142
/* Magic here: If we listen() and a new link dies before it
4243
is accepted() it isn't 'dead' so doesn't get removed. */
4344
if (!sk || sock_flag(sk, SOCK_DESTROY) ||
@@ -47,6 +48,7 @@ void ax25_std_heartbeat_expiry(ax25_cb *ax25)
4748
sock_hold(sk);
4849
ax25_destroy_socket(ax25);
4950
bh_unlock_sock(sk);
51+
/* Ungrab socket and destroy it */
5052
sock_put(sk);
5153
} else
5254
ax25_destroy_socket(ax25);
@@ -144,7 +146,8 @@ void ax25_std_t1timer_expiry(ax25_cb *ax25)
144146
case AX25_STATE_2:
145147
if (ax25->n2count == ax25->n2) {
146148
ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
147-
ax25_disconnect(ax25, ETIMEDOUT);
149+
if (!sock_flag(ax25->sk, SOCK_DESTROY))
150+
ax25_disconnect(ax25, ETIMEDOUT);
148151
return;
149152
} else {
150153
ax25->n2count++;

net/ax25/ax25_subr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ void ax25_disconnect(ax25_cb *ax25, int reason)
264264
{
265265
ax25_clear_queues(ax25);
266266

267-
ax25_stop_heartbeat(ax25);
267+
if (!sock_flag(ax25->sk, SOCK_DESTROY))
268+
ax25_stop_heartbeat(ax25);
268269
ax25_stop_t1timer(ax25);
269270
ax25_stop_t2timer(ax25);
270271
ax25_stop_t3timer(ax25);

0 commit comments

Comments
 (0)