Skip to content

Commit d3e8e4c

Browse files
JereLeppanendavem330
authored andcommitted
sctp: Start shutdown on association restart if in SHUTDOWN-SENT state and socket is closed
Commit bdf6fa5 ("sctp: handle association restarts when the socket is closed.") starts shutdown when an association is restarted, if in SHUTDOWN-PENDING state and the socket is closed. However, the rationale stated in that commit applies also when in SHUTDOWN-SENT state - we don't want to move an association to ESTABLISHED state when the socket has been closed, because that results in an association that is unreachable from user space. The problem scenario: 1. Client crashes and/or restarts. 2. Server (using one-to-one socket) calls close(). SHUTDOWN is lost. 3. Client reconnects using the same addresses and ports. 4. Server's association is restarted. The association and the socket move to ESTABLISHED state, even though the server process has closed its descriptor. Also, after step 4 when the server process exits, some resources are leaked in an attempt to release the underlying inet sock structure in ESTABLISHED state: IPv4: Attempt to release TCP socket in state 1 00000000377288c7 Fix by acting the same way as in SHUTDOWN-PENDING state. That is, if an association is restarted in SHUTDOWN-SENT state and the socket is closed, then start shutdown and don't move the association or the socket to ESTABLISHED state. Fixes: bdf6fa5 ("sctp: handle association restarts when the socket is closed.") Signed-off-by: Jere Leppänen <[email protected]> Acked-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1378817 commit d3e8e4c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

net/sctp/sm_statefuns.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,12 +1856,13 @@ static enum sctp_disposition sctp_sf_do_dupcook_a(
18561856
/* Update the content of current association. */
18571857
sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
18581858
sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1859-
if (sctp_state(asoc, SHUTDOWN_PENDING) &&
1859+
if ((sctp_state(asoc, SHUTDOWN_PENDING) ||
1860+
sctp_state(asoc, SHUTDOWN_SENT)) &&
18601861
(sctp_sstate(asoc->base.sk, CLOSING) ||
18611862
sock_flag(asoc->base.sk, SOCK_DEAD))) {
1862-
/* if were currently in SHUTDOWN_PENDING, but the socket
1863-
* has been closed by user, don't transition to ESTABLISHED.
1864-
* Instead trigger SHUTDOWN bundled with COOKIE_ACK.
1863+
/* If the socket has been closed by user, don't
1864+
* transition to ESTABLISHED. Instead trigger SHUTDOWN
1865+
* bundled with COOKIE_ACK.
18651866
*/
18661867
sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
18671868
return sctp_sf_do_9_2_start_shutdown(net, ep, asoc,

0 commit comments

Comments
 (0)