53 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
61 #include <linux/slab.h>
81 static void sctp_send_stale_cookie_err(
struct net *
net,
120 const size_t paylen);
176 __u16 required_length)
180 if (
unlikely(chunk_length < required_length))
231 if (!sctp_vtag_verify_either(chunk, asoc))
240 return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
244 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
337 if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
339 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
346 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
363 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
374 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
384 SCTP_PACKET(packet));
391 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
515 if (!sctp_vtag_verify(chunk, asoc))
523 return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
527 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
546 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
556 SCTP_PACKET(packet));
577 return sctp_stop_t1_and_abort(net, commands, error,
ECONNREFUSED,
589 SCTP_PEER_INIT(initchunk));
617 SCTP_CHUNK(err_chunk));
671 if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
673 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
691 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
724 sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
777 ret = sctp_sf_authenticate(net, ep, new_asoc, type, &auth);
799 new_asoc->
c.sinit_num_ostreams,
800 new_asoc->
c.sinit_max_instreams,
810 if (new_asoc->
peer.adaptation_ind) {
842 SCTP_ULPEVENT(ai_ev));
886 if (!sctp_vtag_verify(chunk, asoc))
893 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
926 0, asoc->
c.sinit_num_ostreams,
927 asoc->
c.sinit_max_instreams,
940 if (asoc->
peer.adaptation_ind) {
973 SCTP_TRANSPORT(transport));
1009 sctp_sf_heartbeat(ep, asoc, type, arg,
1017 SCTP_TRANSPORT(transport));
1020 SCTP_TRANSPORT(transport));
1022 SCTP_TRANSPORT(transport));
1062 if (!sctp_vtag_verify(chunk, asoc))
1067 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
1076 if (!pskb_pull(chunk->
skb, paylen))
1130 unsigned long max_interval;
1132 if (!sctp_vtag_verify(chunk, asoc))
1138 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
1148 from_addr = hbinfo->
daddr;
1157 &from_addr.
v6.sin6_addr);
1162 &from_addr.
v4.sin_addr.s_addr);
1177 "received for transport: %p\n",
1196 static int sctp_sf_send_restart_abort(
struct net *
net,
union sctp_addr *ssa,
1222 ep = sctp_sk(net->sctp.ctl_sock)->ep;
1227 pkt = sctp_abort_pkt_new(net, ep,
NULL, init, errhdr, len);
1245 static bool list_has_sctp_addr(
const struct list_head *
list,
1260 static int sctp_sf_check_restart_addrs(
const struct sctp_association *new_asoc,
1265 struct net *net = sock_net(new_asoc->
base.sk);
1282 if (!list_has_sctp_addr(&asoc->
peer.transport_addr_list,
1284 sctp_sf_send_restart_abort(net, &new_addr->
ipaddr, init,
1303 switch (asoc->
state) {
1308 new_asoc->
c.my_vtag = asoc->
c.my_vtag;
1309 new_asoc->
c.my_ttag = asoc->
c.my_vtag;
1310 new_asoc->
c.peer_ttag = 0;
1314 new_asoc->
c.my_vtag = asoc->
c.my_vtag;
1315 new_asoc->
c.my_ttag = asoc->
c.my_vtag;
1316 new_asoc->
c.peer_ttag = asoc->
c.peer_vtag;
1323 new_asoc->
c.my_ttag = asoc->
c.my_vtag;
1324 new_asoc->
c.peer_ttag = asoc->
c.peer_vtag;
1333 new_asoc->
c.sinit_num_ostreams = asoc->
c.sinit_num_ostreams;
1334 new_asoc->
c.sinit_max_instreams = asoc->
c.sinit_max_instreams;
1335 new_asoc->
c.initial_tsn = asoc->
c.initial_tsn;
1351 if ((asoc->
c.my_vtag != new_asoc->
c.my_vtag) &&
1352 (asoc->
c.peer_vtag != new_asoc->
c.peer_vtag) &&
1353 (asoc->
c.my_vtag == new_asoc->
c.my_ttag) &&
1354 (asoc->
c.peer_vtag == new_asoc->
c.peer_ttag))
1358 if ((asoc->
c.my_vtag == new_asoc->
c.my_vtag) &&
1359 ((asoc->
c.peer_vtag != new_asoc->
c.peer_vtag) ||
1360 (0 == asoc->
c.peer_vtag))) {
1365 if ((asoc->
c.my_vtag == new_asoc->
c.my_vtag) &&
1366 (asoc->
c.peer_vtag == new_asoc->
c.peer_vtag))
1370 if ((asoc->
c.my_vtag != new_asoc->
c.my_vtag) &&
1371 (asoc->
c.peer_vtag == new_asoc->
c.peer_vtag) &&
1372 (0 == new_asoc->
c.my_ttag) &&
1373 (0 == new_asoc->
c.peer_ttag))
1415 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
1422 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
1439 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
1447 SCTP_PACKET(packet));
1455 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
1490 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1497 sctp_tietags_populate(new_asoc, asoc);
1607 return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
1661 return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
1683 if (ep == sctp_sk(net->sctp.ctl_sock)->ep)
1684 return sctp_sf_ootb(net, ep, asoc, type, arg, commands);
1720 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1768 new_asoc->
c.sinit_num_ostreams,
1769 new_asoc->
c.sinit_max_instreams,
1847 if (asoc->
peer.adaptation_ind)
1923 asoc->
c.sinit_num_ostreams,
1924 asoc->
c.sinit_max_instreams,
1934 if (asoc->
peer.adaptation_ind) {
1954 SCTP_ULPEVENT(ai_ev));
2002 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2036 sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
2048 action = sctp_tietags_compare(new_asoc, asoc);
2052 retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands,
2057 retval = sctp_sf_do_dupcook_b(net, ep, asoc, chunk, commands,
2062 retval = sctp_sf_do_dupcook_c(net, ep, asoc, chunk, commands,
2067 retval = sctp_sf_do_dupcook_d(net, ep, asoc, chunk, commands,
2107 if (!sctp_vtag_verify_either(chunk, asoc))
2132 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2149 if (!sctp_vtag_verify_either(chunk, asoc))
2182 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2228 if (!sctp_vtag_verify(chunk, asoc))
2235 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2245 return sctp_sf_do_5_2_6_stale(net, ep, asoc, type,
2322 stale = (stale * 2) / 1000;
2352 SCTP_TRANSPORT(asoc->
peer.primary_path));
2414 if (!sctp_vtag_verify_either(chunk, asoc))
2439 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2459 if ((
void *)err != (
void *)chunk->
chunk_end)
2490 if (!sctp_vtag_verify_either(chunk, asoc))
2511 return sctp_stop_t1_and_abort(net, commands, error,
ECONNREFUSED, asoc,
2553 __be16 error,
int sk_err,
2616 if (!sctp_vtag_verify(chunk, asoc))
2620 if (!sctp_chunk_length_valid(chunk,
2622 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2642 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
2703 if (!sctp_vtag_verify(chunk, asoc))
2707 if (!sctp_chunk_length_valid(chunk,
2709 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2726 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
2757 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2820 if (!sctp_vtag_verify(chunk, asoc))
2824 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2837 SCTP_U32(lowest_tsn));
2875 if (!sctp_vtag_verify(chunk, asoc))
2879 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2933 if (!sctp_vtag_verify(chunk, asoc)) {
2940 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2943 error = sctp_eat_data(asoc, chunk, commands );
2950 goto discard_noforce;
2958 return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
2965 force = SCTP_FORCE();
3054 if (!sctp_vtag_verify(chunk, asoc)) {
3061 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3064 error = sctp_eat_data(asoc, chunk, commands );
3075 return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
3146 if (!sctp_vtag_verify(chunk, asoc))
3151 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3155 sackh = sctp_sm_pull_sack(chunk);
3179 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
3219 packet = sctp_ootb_pkt_new(net, asoc, chunk);
3241 SCTP_PACKET(packet));
3270 if (!sctp_vtag_verify(chunk, asoc))
3275 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3278 if ((
void *)err != (
void *)chunk->
chunk_end)
3279 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3280 (
void *)err, commands);
3309 if (!sctp_vtag_verify(chunk, asoc))
3314 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3393 int ootb_shut_ack = 0;
3394 int ootb_cookie_ack = 0;
3402 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3425 ootb_cookie_ack = 1;
3430 ootb_cookie_ack = 1;
3438 if (ch_end > skb_tail_pointer(skb))
3439 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3443 }
while (ch_end < skb_tail_pointer(
skb));
3446 return sctp_sf_shut_8_4_5(net, ep, asoc, type, arg, commands);
3447 else if (ootb_cookie_ack)
3450 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
3485 packet = sctp_ootb_pkt_new(net, asoc, chunk);
3507 SCTP_PACKET(packet));
3549 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3559 return sctp_sf_shut_8_4_5(net, ep,
NULL, type, arg, commands);
3577 if (!sctp_vtag_verify(chunk, asoc)) {
3589 if (!net->sctp.addip_noauth && !chunk->
auth)
3594 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3601 length =
ntohs(addr_param->
p.length);
3603 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3611 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3618 if (serial == asoc->
peer.addip_serial + 1) {
3637 }
else if (serial < asoc->peer.addip_serial + 1) {
3702 __u32 sent_serial, rcvd_serial;
3704 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3716 if (!net->sctp.addip_noauth && !asconf_ack->
auth)
3721 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3732 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3748 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3836 if (!sctp_vtag_verify(chunk, asoc)) {
3844 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3860 goto discard_noforce;
3864 if (
ntohs(skip->
stream) >= asoc->
c.sinit_max_instreams)
3865 goto discard_noforce;
3904 if (!sctp_vtag_verify(chunk, asoc)) {
3912 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3932 if (
ntohs(skip->
stream) >= asoc->
c.sinit_max_instreams)
3987 unsigned int sig_len;
4026 digest = auth_hdr->
hmac;
4033 memset(digest, 0, sig_len);
4040 if (
memcmp(save_digest, digest, sig_len)) {
4066 if (!asoc->
peer.auth_capable)
4069 if (!sctp_vtag_verify(chunk, asoc)) {
4077 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4081 error = sctp_sf_authenticate(net, ep, asoc, type, chunk);
4093 SCTP_CHUNK(err_chunk));
4101 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4163 if (!sctp_vtag_verify(unk_chunk, asoc))
4171 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4188 SCTP_CHUNK(err_chunk));
4208 SCTP_CHUNK(err_chunk));
4248 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4312 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4328 const size_t paylen)
4356 !asoc->
peer.i.init_tag) {
4360 if (!sctp_chunk_length_valid(chunk,
4364 unsigned int inittag;
4390 packet = sctp_ootb_pkt_new(net, asoc, chunk);
4403 SCTP_PACKET(packet));
4447 static const char err_str[]=
"The following chunk had invalid length:";
4449 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4464 void *arg,
void *
ext,
4510 static const char err_str[]=
"The cumulative tsn ack beyond the max tsn currently sent:";
4512 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4530 static const char err_str[]=
"The following chunk violates protocol:";
4535 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
5141 SCTP_TRANSPORT(arg));
5314 if (!sctp_vtag_verify(chunk, asoc))
5319 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
5525 if (attempts <= asoc->max_init_attempts) {
5542 " max_init_attempts: %d\n",
5586 if (attempts <= asoc->max_init_attempts) {
5647 switch (asoc->
state) {
5710 SCTP_TRANSPORT(transport));
5912 if (len > chunk->
skb->len)
5923 static struct sctp_packet *sctp_abort_pkt_new(
struct net *net,
5927 const void *payload,
5933 packet = sctp_ootb_pkt_new(net, asoc, chunk);
5965 static struct sctp_packet *sctp_ootb_pkt_new(
struct net *net,
5996 vtag = asoc->
peer.i.init_tag;
6027 sctp_sk(net->sctp.ctl_sock));
6045 static void sctp_send_stale_cookie_err(
struct net *net,
6055 packet = sctp_ootb_pkt_new(net, asoc, chunk);
6061 packet->
vtag = cookie->
c.peer_vtag;
6064 err_chunk->
skb->sk = ep->
base.sk;
6067 SCTP_PACKET(packet));
6088 struct net *net = sock_net(
sk);
6116 ipver2af(ip_hdr(chunk->
skb)->version));
6118 if (af && af->
is_ce(chunk->
skb) && asoc->
peer.ecn_capable) {
6131 }
else if (tmp > 0) {
6148 if ((datalen >= asoc->
rwnd) && (!asoc->
ulpq.pd_mode)) {
6170 if (sctp_tsnmap_has_gap(map) &&
6171 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
6176 "rwnd: %d\n", tsn, datalen,
6189 if (*
sk->sk_prot_creator->memory_pressure) {
6190 if (sctp_tsnmap_has_gap(map) &&
6191 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
6245 if (sid >= asoc->
c.sinit_max_instreams) {
6251 sizeof(data_hdr->
stream),
6267 if (ordered && SSN_lt(ssn, sctp_ssn_peek(&asoc->
ssnmap->in, sid))) {