Skip to content

Commit 04f1991

Browse files
lxingregkh
authored andcommitted
sctp: move the format error check out of __sctp_sf_do_9_1_abort
[ Upstream commit 245709e ] When T2 timer is to be stopped, the asoc should also be deleted, otherwise, there will be no chance to call sctp_association_free and the asoc could last in memory forever. However, in sctp_sf_shutdown_sent_abort(), after adding the cmd SCTP_CMD_TIMER_STOP for T2 timer, it may return error due to the format error from __sctp_sf_do_9_1_abort() and miss adding SCTP_CMD_ASSOC_FAILED where the asoc will be deleted. This patch is to fix it by moving the format error check out of __sctp_sf_do_9_1_abort(), and do it before adding the cmd SCTP_CMD_TIMER_STOP for T2 timer. Thanks Hangbin for reporting this issue by the fuzz testing. v1->v2: - improve the comment in the code as Marcelo's suggestion. Fixes: 96ca468 ("sctp: check invalid value of length parameter in error cause") Reported-by: Hangbin Liu <liuhangbin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c6ed56c commit 04f1991

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

net/sctp/sm_statefuns.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ static inline bool sctp_chunk_length_valid(struct sctp_chunk *chunk,
170170
return true;
171171
}
172172

173+
/* Check for format error in an ABORT chunk */
174+
static inline bool sctp_err_chunk_valid(struct sctp_chunk *chunk)
175+
{
176+
struct sctp_errhdr *err;
177+
178+
sctp_walk_errors(err, chunk->chunk_hdr);
179+
180+
return (void *)err == (void *)chunk->chunk_end;
181+
}
182+
173183
/**********************************************************
174184
* These are the state functions for handling chunk events.
175185
**********************************************************/
@@ -2255,6 +2265,9 @@ enum sctp_disposition sctp_sf_shutdown_pending_abort(
22552265
sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
22562266
return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
22572267

2268+
if (!sctp_err_chunk_valid(chunk))
2269+
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2270+
22582271
return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
22592272
}
22602273

@@ -2298,6 +2311,9 @@ enum sctp_disposition sctp_sf_shutdown_sent_abort(
22982311
sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
22992312
return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
23002313

2314+
if (!sctp_err_chunk_valid(chunk))
2315+
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2316+
23012317
/* Stop the T2-shutdown timer. */
23022318
sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
23032319
SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
@@ -2565,6 +2581,9 @@ enum sctp_disposition sctp_sf_do_9_1_abort(
25652581
sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
25662582
return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
25672583

2584+
if (!sctp_err_chunk_valid(chunk))
2585+
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2586+
25682587
return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
25692588
}
25702589

@@ -2582,16 +2601,8 @@ static enum sctp_disposition __sctp_sf_do_9_1_abort(
25822601

25832602
/* See if we have an error cause code in the chunk. */
25842603
len = ntohs(chunk->chunk_hdr->length);
2585-
if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) {
2586-
struct sctp_errhdr *err;
2587-
2588-
sctp_walk_errors(err, chunk->chunk_hdr);
2589-
if ((void *)err != (void *)chunk->chunk_end)
2590-
return sctp_sf_pdiscard(net, ep, asoc, type, arg,
2591-
commands);
2592-
2604+
if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
25932605
error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
2594-
}
25952606

25962607
sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
25972608
/* ASSOC_FAILED will DELETE_TCB. */

0 commit comments

Comments
 (0)