Skip to content

Commit

Permalink
sctp: fix the processing for COOKIE_ECHO chunk
Browse files Browse the repository at this point in the history
1. In closed state: in sctp_sf_do_5_1D_ce():

  When asoc is NULL, making packet for abort will use chunk's vtag
  in sctp_ootb_pkt_new(). But when asoc exists, vtag from the chunk
  should be verified before using peer.i.init_tag to make packet
  for abort in sctp_ootb_pkt_new(), and just discard it if vtag is
  not correct.

2. In the other states: in sctp_sf_do_5_2_4_dupcook():

  asoc always exists, but duplicate cookie_echo's vtag will be
  handled by sctp_tietags_compare() and then take actions, so before
  that we only verify the vtag for the abort sent for invalid chunk
  length.

Fixes: 1da177e ("Linux-2.6.12-rc2")
Signed-off-by: Xin Long <[email protected]>
Acked-by: Marcelo Ricardo Leitner <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
lxin authored and kuba-moo committed Oct 22, 2021
1 parent 438b95a commit a64b341
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions net/sctp/sm_statefuns.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,9 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
struct sock *sk;
int error = 0;

if (asoc && !sctp_vtag_verify(chunk, asoc))
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);

/* If the packet is an OOTB packet which is temporarily on the
* control endpoint, respond with an ABORT.
*/
Expand All @@ -724,7 +727,8 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
* in sctp_unpack_cookie().
*/
if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
commands);

/* If the endpoint is not listening or if the number of associations
* on the TCP-style socket exceed the max backlog, respond with an
Expand Down Expand Up @@ -2204,9 +2208,11 @@ enum sctp_disposition sctp_sf_do_5_2_4_dupcook(
* enough for the chunk header. Cookie length verification is
* done later.
*/
if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
commands);
if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) {
if (!sctp_vtag_verify(chunk, asoc))
asoc = NULL;
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, commands);
}

/* "Decode" the chunk. We have no optional parameters so we
* are in good shape.
Expand Down

0 comments on commit a64b341

Please sign in to comment.