Skip to content

Commit bec9640

Browse files
author
Vlad Yasevich
committed
sctp: Disallow new connection on a closing socket
If a socket has a lot of association that are in the process of of being closed/aborted, it is possible for a remote to establish new associations during the time period that the old ones are shutting down. If this was a result of a close() call, there will be no socket and will cause a memory leak. We'll prevent this by setting the socket state to CLOSING and disallow new associations when in this state. Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
1 parent af87b82 commit bec9640

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎include/net/sctp/constants.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ typedef enum {
231231
SCTP_SS_LISTENING = TCP_LISTEN,
232232
SCTP_SS_ESTABLISHING = TCP_SYN_SENT,
233233
SCTP_SS_ESTABLISHED = TCP_ESTABLISHED,
234-
SCTP_SS_DISCONNECTING = TCP_CLOSING,
234+
SCTP_SS_CLOSING = TCP_CLOSING,
235235
} sctp_sock_state_t;
236236

237237
/* These functions map various type to printable names. */

‎net/sctp/sm_statefuns.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
334334
if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
335335
return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
336336

337+
/* If the INIT is coming toward a closing socket, we'll send back
338+
* and ABORT. Essentially, this catches the race of INIT being
339+
* backloged to the socket at the same time as the user isses close().
340+
* Since the socket and all its associations are going away, we
341+
* can treat this OOTB
342+
*/
343+
if (sctp_sstate(ep->base.sk, CLOSING))
344+
return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
345+
337346
/* Verify the INIT chunk before processing it. */
338347
err_chunk = NULL;
339348
if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,

‎net/sctp/socket.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,7 @@ SCTP_STATIC void sctp_close(struct sock *sk, long timeout)
13611361

13621362
sctp_lock_sock(sk);
13631363
sk->sk_shutdown = SHUTDOWN_MASK;
1364+
sk->sk_state = SCTP_SS_CLOSING;
13641365

13651366
ep = sctp_sk(sk)->ep;
13661367

0 commit comments

Comments
 (0)