forked from Minki/linux
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>
This commit is contained in:
parent
af87b823ca
commit
bec9640bb0
@ -231,7 +231,7 @@ typedef enum {
|
|||||||
SCTP_SS_LISTENING = TCP_LISTEN,
|
SCTP_SS_LISTENING = TCP_LISTEN,
|
||||||
SCTP_SS_ESTABLISHING = TCP_SYN_SENT,
|
SCTP_SS_ESTABLISHING = TCP_SYN_SENT,
|
||||||
SCTP_SS_ESTABLISHED = TCP_ESTABLISHED,
|
SCTP_SS_ESTABLISHED = TCP_ESTABLISHED,
|
||||||
SCTP_SS_DISCONNECTING = TCP_CLOSING,
|
SCTP_SS_CLOSING = TCP_CLOSING,
|
||||||
} sctp_sock_state_t;
|
} sctp_sock_state_t;
|
||||||
|
|
||||||
/* These functions map various type to printable names. */
|
/* These functions map various type to printable names. */
|
||||||
|
@ -334,6 +334,15 @@ sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
|
|||||||
if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
|
if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
|
||||||
return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
|
return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
|
||||||
|
|
||||||
|
/* If the INIT is coming toward a closing socket, we'll send back
|
||||||
|
* and ABORT. Essentially, this catches the race of INIT being
|
||||||
|
* backloged to the socket at the same time as the user isses close().
|
||||||
|
* Since the socket and all its associations are going away, we
|
||||||
|
* can treat this OOTB
|
||||||
|
*/
|
||||||
|
if (sctp_sstate(ep->base.sk, CLOSING))
|
||||||
|
return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
|
||||||
|
|
||||||
/* Verify the INIT chunk before processing it. */
|
/* Verify the INIT chunk before processing it. */
|
||||||
err_chunk = NULL;
|
err_chunk = NULL;
|
||||||
if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
|
if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
|
||||||
|
@ -1361,6 +1361,7 @@ SCTP_STATIC void sctp_close(struct sock *sk, long timeout)
|
|||||||
|
|
||||||
sctp_lock_sock(sk);
|
sctp_lock_sock(sk);
|
||||||
sk->sk_shutdown = SHUTDOWN_MASK;
|
sk->sk_shutdown = SHUTDOWN_MASK;
|
||||||
|
sk->sk_state = SCTP_SS_CLOSING;
|
||||||
|
|
||||||
ep = sctp_sk(sk)->ep;
|
ep = sctp_sk(sk)->ep;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user