@@ -156,6 +156,12 @@ static enum sctp_disposition __sctp_sf_do_9_1_abort(
156156 void * arg ,
157157 struct sctp_cmd_seq * commands );
158158
159+ static enum sctp_disposition
160+ __sctp_sf_do_9_2_reshutack (struct net * net , const struct sctp_endpoint * ep ,
161+ const struct sctp_association * asoc ,
162+ const union sctp_subtype type , void * arg ,
163+ struct sctp_cmd_seq * commands );
164+
159165/* Small helper function that checks if the chunk length
160166 * is of the appropriate length. The 'required_length' argument
161167 * is set to be the size of a specific chunk we are testing.
@@ -337,6 +343,14 @@ enum sctp_disposition sctp_sf_do_5_1B_init(struct net *net,
337343 if (!chunk -> singleton )
338344 return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
339345
346+ /* Make sure that the INIT chunk has a valid length.
347+ * Normally, this would cause an ABORT with a Protocol Violation
348+ * error, but since we don't have an association, we'll
349+ * just discard the packet.
350+ */
351+ if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_init_chunk )))
352+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
353+
340354 /* If the packet is an OOTB packet which is temporarily on the
341355 * control endpoint, respond with an ABORT.
342356 */
@@ -351,14 +365,6 @@ enum sctp_disposition sctp_sf_do_5_1B_init(struct net *net,
351365 if (chunk -> sctp_hdr -> vtag != 0 )
352366 return sctp_sf_tabort_8_4_8 (net , ep , asoc , type , arg , commands );
353367
354- /* Make sure that the INIT chunk has a valid length.
355- * Normally, this would cause an ABORT with a Protocol Violation
356- * error, but since we don't have an association, we'll
357- * just discard the packet.
358- */
359- if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_init_chunk )))
360- return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
361-
362368 /* If the INIT is coming toward a closing socket, we'll send back
363369 * and ABORT. Essentially, this catches the race of INIT being
364370 * backloged to the socket at the same time as the user issues close().
@@ -704,6 +710,9 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
704710 struct sock * sk ;
705711 int error = 0 ;
706712
713+ if (asoc && !sctp_vtag_verify (chunk , asoc ))
714+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
715+
707716 /* If the packet is an OOTB packet which is temporarily on the
708717 * control endpoint, respond with an ABORT.
709718 */
@@ -718,7 +727,8 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
718727 * in sctp_unpack_cookie().
719728 */
720729 if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_chunkhdr )))
721- return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
730+ return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
731+ commands );
722732
723733 /* If the endpoint is not listening or if the number of associations
724734 * on the TCP-style socket exceed the max backlog, respond with an
@@ -1524,20 +1534,16 @@ static enum sctp_disposition sctp_sf_do_unexpected_init(
15241534 if (!chunk -> singleton )
15251535 return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
15261536
1537+ /* Make sure that the INIT chunk has a valid length. */
1538+ if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_init_chunk )))
1539+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
1540+
15271541 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
15281542 * Tag.
15291543 */
15301544 if (chunk -> sctp_hdr -> vtag != 0 )
15311545 return sctp_sf_tabort_8_4_8 (net , ep , asoc , type , arg , commands );
15321546
1533- /* Make sure that the INIT chunk has a valid length.
1534- * In this case, we generate a protocol violation since we have
1535- * an association established.
1536- */
1537- if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_init_chunk )))
1538- return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
1539- commands );
1540-
15411547 if (SCTP_INPUT_CB (chunk -> skb )-> encap_port != chunk -> transport -> encap_port )
15421548 return sctp_sf_new_encap_port (net , ep , asoc , type , arg , commands );
15431549
@@ -1882,9 +1888,9 @@ static enum sctp_disposition sctp_sf_do_dupcook_a(
18821888 * its peer.
18831889 */
18841890 if (sctp_state (asoc , SHUTDOWN_ACK_SENT )) {
1885- disposition = sctp_sf_do_9_2_reshutack (net , ep , asoc ,
1886- SCTP_ST_CHUNK (chunk -> chunk_hdr -> type ),
1887- chunk , commands );
1891+ disposition = __sctp_sf_do_9_2_reshutack (net , ep , asoc ,
1892+ SCTP_ST_CHUNK (chunk -> chunk_hdr -> type ),
1893+ chunk , commands );
18881894 if (SCTP_DISPOSITION_NOMEM == disposition )
18891895 goto nomem ;
18901896
@@ -2202,9 +2208,11 @@ enum sctp_disposition sctp_sf_do_5_2_4_dupcook(
22022208 * enough for the chunk header. Cookie length verification is
22032209 * done later.
22042210 */
2205- if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_chunkhdr )))
2206- return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
2207- commands );
2211+ if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_chunkhdr ))) {
2212+ if (!sctp_vtag_verify (chunk , asoc ))
2213+ asoc = NULL ;
2214+ return sctp_sf_violation_chunklen (net , ep , asoc , type , arg , commands );
2215+ }
22082216
22092217 /* "Decode" the chunk. We have no optional parameters so we
22102218 * are in good shape.
@@ -2341,7 +2349,7 @@ enum sctp_disposition sctp_sf_shutdown_pending_abort(
23412349 */
23422350 if (SCTP_ADDR_DEL ==
23432351 sctp_bind_addr_state (& asoc -> base .bind_addr , & chunk -> dest ))
2344- return sctp_sf_discard_chunk (net , ep , asoc , type , arg , commands );
2352+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
23452353
23462354 if (!sctp_err_chunk_valid (chunk ))
23472355 return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
@@ -2387,7 +2395,7 @@ enum sctp_disposition sctp_sf_shutdown_sent_abort(
23872395 */
23882396 if (SCTP_ADDR_DEL ==
23892397 sctp_bind_addr_state (& asoc -> base .bind_addr , & chunk -> dest ))
2390- return sctp_sf_discard_chunk (net , ep , asoc , type , arg , commands );
2398+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
23912399
23922400 if (!sctp_err_chunk_valid (chunk ))
23932401 return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
@@ -2657,7 +2665,7 @@ enum sctp_disposition sctp_sf_do_9_1_abort(
26572665 */
26582666 if (SCTP_ADDR_DEL ==
26592667 sctp_bind_addr_state (& asoc -> base .bind_addr , & chunk -> dest ))
2660- return sctp_sf_discard_chunk (net , ep , asoc , type , arg , commands );
2668+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
26612669
26622670 if (!sctp_err_chunk_valid (chunk ))
26632671 return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
@@ -2970,13 +2978,11 @@ enum sctp_disposition sctp_sf_do_9_2_shut_ctsn(
29702978 * that belong to this association, it should discard the INIT chunk and
29712979 * retransmit the SHUTDOWN ACK chunk.
29722980 */
2973- enum sctp_disposition sctp_sf_do_9_2_reshutack (
2974- struct net * net ,
2975- const struct sctp_endpoint * ep ,
2976- const struct sctp_association * asoc ,
2977- const union sctp_subtype type ,
2978- void * arg ,
2979- struct sctp_cmd_seq * commands )
2981+ static enum sctp_disposition
2982+ __sctp_sf_do_9_2_reshutack (struct net * net , const struct sctp_endpoint * ep ,
2983+ const struct sctp_association * asoc ,
2984+ const union sctp_subtype type , void * arg ,
2985+ struct sctp_cmd_seq * commands )
29802986{
29812987 struct sctp_chunk * chunk = arg ;
29822988 struct sctp_chunk * reply ;
@@ -3010,6 +3016,26 @@ enum sctp_disposition sctp_sf_do_9_2_reshutack(
30103016 return SCTP_DISPOSITION_NOMEM ;
30113017}
30123018
3019+ enum sctp_disposition
3020+ sctp_sf_do_9_2_reshutack (struct net * net , const struct sctp_endpoint * ep ,
3021+ const struct sctp_association * asoc ,
3022+ const union sctp_subtype type , void * arg ,
3023+ struct sctp_cmd_seq * commands )
3024+ {
3025+ struct sctp_chunk * chunk = arg ;
3026+
3027+ if (!chunk -> singleton )
3028+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
3029+
3030+ if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_init_chunk )))
3031+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
3032+
3033+ if (chunk -> sctp_hdr -> vtag != 0 )
3034+ return sctp_sf_tabort_8_4_8 (net , ep , asoc , type , arg , commands );
3035+
3036+ return __sctp_sf_do_9_2_reshutack (net , ep , asoc , type , arg , commands );
3037+ }
3038+
30133039/*
30143040 * sctp_sf_do_ecn_cwr
30153041 *
@@ -3662,6 +3688,9 @@ enum sctp_disposition sctp_sf_ootb(struct net *net,
36623688
36633689 SCTP_INC_STATS (net , SCTP_MIB_OUTOFBLUES );
36643690
3691+ if (asoc && !sctp_vtag_verify (chunk , asoc ))
3692+ asoc = NULL ;
3693+
36653694 ch = (struct sctp_chunkhdr * )chunk -> chunk_hdr ;
36663695 do {
36673696 /* Report violation if the chunk is less then minimal */
@@ -3777,12 +3806,6 @@ static enum sctp_disposition sctp_sf_shut_8_4_5(
37773806
37783807 SCTP_INC_STATS (net , SCTP_MIB_OUTCTRLCHUNKS );
37793808
3780- /* If the chunk length is invalid, we don't want to process
3781- * the reset of the packet.
3782- */
3783- if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_chunkhdr )))
3784- return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
3785-
37863809 /* We need to discard the rest of the packet to prevent
37873810 * potential boomming attacks from additional bundled chunks.
37883811 * This is documented in SCTP Threats ID.
@@ -3810,6 +3833,9 @@ enum sctp_disposition sctp_sf_do_8_5_1_E_sa(struct net *net,
38103833{
38113834 struct sctp_chunk * chunk = arg ;
38123835
3836+ if (!sctp_vtag_verify (chunk , asoc ))
3837+ asoc = NULL ;
3838+
38133839 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
38143840 if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_chunkhdr )))
38153841 return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
@@ -3845,6 +3871,11 @@ enum sctp_disposition sctp_sf_do_asconf(struct net *net,
38453871 return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
38463872 }
38473873
3874+ /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3875+ if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_addip_chunk )))
3876+ return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
3877+ commands );
3878+
38483879 /* ADD-IP: Section 4.1.1
38493880 * This chunk MUST be sent in an authenticated way by using
38503881 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
@@ -3853,13 +3884,7 @@ enum sctp_disposition sctp_sf_do_asconf(struct net *net,
38533884 */
38543885 if (!asoc -> peer .asconf_capable ||
38553886 (!net -> sctp .addip_noauth && !chunk -> auth ))
3856- return sctp_sf_discard_chunk (net , ep , asoc , type , arg ,
3857- commands );
3858-
3859- /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3860- if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_addip_chunk )))
3861- return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
3862- commands );
3887+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
38633888
38643889 hdr = (struct sctp_addiphdr * )chunk -> skb -> data ;
38653890 serial = ntohl (hdr -> serial );
@@ -3988,6 +4013,12 @@ enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net,
39884013 return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
39894014 }
39904015
4016+ /* Make sure that the ADDIP chunk has a valid length. */
4017+ if (!sctp_chunk_length_valid (asconf_ack ,
4018+ sizeof (struct sctp_addip_chunk )))
4019+ return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
4020+ commands );
4021+
39914022 /* ADD-IP, Section 4.1.2:
39924023 * This chunk MUST be sent in an authenticated way by using
39934024 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
@@ -3996,14 +4027,7 @@ enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net,
39964027 */
39974028 if (!asoc -> peer .asconf_capable ||
39984029 (!net -> sctp .addip_noauth && !asconf_ack -> auth ))
3999- return sctp_sf_discard_chunk (net , ep , asoc , type , arg ,
4000- commands );
4001-
4002- /* Make sure that the ADDIP chunk has a valid length. */
4003- if (!sctp_chunk_length_valid (asconf_ack ,
4004- sizeof (struct sctp_addip_chunk )))
4005- return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
4006- commands );
4030+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
40074031
40084032 addip_hdr = (struct sctp_addiphdr * )asconf_ack -> skb -> data ;
40094033 rcvd_serial = ntohl (addip_hdr -> serial );
@@ -4575,6 +4599,9 @@ enum sctp_disposition sctp_sf_discard_chunk(struct net *net,
45754599{
45764600 struct sctp_chunk * chunk = arg ;
45774601
4602+ if (asoc && !sctp_vtag_verify (chunk , asoc ))
4603+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
4604+
45784605 /* Make sure that the chunk has a valid length.
45794606 * Since we don't know the chunk type, we use a general
45804607 * chunkhdr structure to make a comparison.
@@ -4642,6 +4669,9 @@ enum sctp_disposition sctp_sf_violation(struct net *net,
46424669{
46434670 struct sctp_chunk * chunk = arg ;
46444671
4672+ if (!sctp_vtag_verify (chunk , asoc ))
4673+ return sctp_sf_pdiscard (net , ep , asoc , type , arg , commands );
4674+
46454675 /* Make sure that the chunk has a valid length. */
46464676 if (!sctp_chunk_length_valid (chunk , sizeof (struct sctp_chunkhdr )))
46474677 return sctp_sf_violation_chunklen (net , ep , asoc , type , arg ,
@@ -6348,6 +6378,7 @@ static struct sctp_packet *sctp_ootb_pkt_new(
63486378 * yet.
63496379 */
63506380 switch (chunk -> chunk_hdr -> type ) {
6381+ case SCTP_CID_INIT :
63516382 case SCTP_CID_INIT_ACK :
63526383 {
63536384 struct sctp_initack_chunk * initack ;
0 commit comments