0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0032
0033 #include <linux/types.h>
0034 #include <linux/kernel.h>
0035 #include <linux/ip.h>
0036 #include <linux/ipv6.h>
0037 #include <linux/net.h>
0038 #include <linux/inet.h>
0039 #include <linux/slab.h>
0040 #include <net/sock.h>
0041 #include <net/inet_ecn.h>
0042 #include <linux/skbuff.h>
0043 #include <net/sctp/sctp.h>
0044 #include <net/sctp/sm.h>
0045 #include <net/sctp/structs.h>
0046
0047 #define CREATE_TRACE_POINTS
0048 #include <trace/events/sctp.h>
0049
0050 static struct sctp_packet *sctp_abort_pkt_new(
0051 struct net *net,
0052 const struct sctp_endpoint *ep,
0053 const struct sctp_association *asoc,
0054 struct sctp_chunk *chunk,
0055 const void *payload, size_t paylen);
0056 static int sctp_eat_data(const struct sctp_association *asoc,
0057 struct sctp_chunk *chunk,
0058 struct sctp_cmd_seq *commands);
0059 static struct sctp_packet *sctp_ootb_pkt_new(
0060 struct net *net,
0061 const struct sctp_association *asoc,
0062 const struct sctp_chunk *chunk);
0063 static void sctp_send_stale_cookie_err(struct net *net,
0064 const struct sctp_endpoint *ep,
0065 const struct sctp_association *asoc,
0066 const struct sctp_chunk *chunk,
0067 struct sctp_cmd_seq *commands,
0068 struct sctp_chunk *err_chunk);
0069 static enum sctp_disposition sctp_sf_do_5_2_6_stale(
0070 struct net *net,
0071 const struct sctp_endpoint *ep,
0072 const struct sctp_association *asoc,
0073 const union sctp_subtype type,
0074 void *arg,
0075 struct sctp_cmd_seq *commands);
0076 static enum sctp_disposition sctp_sf_shut_8_4_5(
0077 struct net *net,
0078 const struct sctp_endpoint *ep,
0079 const struct sctp_association *asoc,
0080 const union sctp_subtype type,
0081 void *arg,
0082 struct sctp_cmd_seq *commands);
0083 static enum sctp_disposition sctp_sf_tabort_8_4_8(
0084 struct net *net,
0085 const struct sctp_endpoint *ep,
0086 const struct sctp_association *asoc,
0087 const union sctp_subtype type,
0088 void *arg,
0089 struct sctp_cmd_seq *commands);
0090 static enum sctp_disposition sctp_sf_new_encap_port(
0091 struct net *net,
0092 const struct sctp_endpoint *ep,
0093 const struct sctp_association *asoc,
0094 const union sctp_subtype type,
0095 void *arg,
0096 struct sctp_cmd_seq *commands);
0097 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
0098
0099 static enum sctp_disposition sctp_stop_t1_and_abort(
0100 struct net *net,
0101 struct sctp_cmd_seq *commands,
0102 __be16 error, int sk_err,
0103 const struct sctp_association *asoc,
0104 struct sctp_transport *transport);
0105
0106 static enum sctp_disposition sctp_sf_abort_violation(
0107 struct net *net,
0108 const struct sctp_endpoint *ep,
0109 const struct sctp_association *asoc,
0110 void *arg,
0111 struct sctp_cmd_seq *commands,
0112 const __u8 *payload,
0113 const size_t paylen);
0114
0115 static enum sctp_disposition sctp_sf_violation_chunklen(
0116 struct net *net,
0117 const struct sctp_endpoint *ep,
0118 const struct sctp_association *asoc,
0119 const union sctp_subtype type,
0120 void *arg,
0121 struct sctp_cmd_seq *commands);
0122
0123 static enum sctp_disposition sctp_sf_violation_paramlen(
0124 struct net *net,
0125 const struct sctp_endpoint *ep,
0126 const struct sctp_association *asoc,
0127 const union sctp_subtype type,
0128 void *arg, void *ext,
0129 struct sctp_cmd_seq *commands);
0130
0131 static enum sctp_disposition sctp_sf_violation_ctsn(
0132 struct net *net,
0133 const struct sctp_endpoint *ep,
0134 const struct sctp_association *asoc,
0135 const union sctp_subtype type,
0136 void *arg,
0137 struct sctp_cmd_seq *commands);
0138
0139 static enum sctp_disposition sctp_sf_violation_chunk(
0140 struct net *net,
0141 const struct sctp_endpoint *ep,
0142 const struct sctp_association *asoc,
0143 const union sctp_subtype type,
0144 void *arg,
0145 struct sctp_cmd_seq *commands);
0146
0147 static enum sctp_ierror sctp_sf_authenticate(
0148 const struct sctp_association *asoc,
0149 struct sctp_chunk *chunk);
0150
0151 static enum sctp_disposition __sctp_sf_do_9_1_abort(
0152 struct net *net,
0153 const struct sctp_endpoint *ep,
0154 const struct sctp_association *asoc,
0155 const union sctp_subtype type,
0156 void *arg,
0157 struct sctp_cmd_seq *commands);
0158
0159 static enum sctp_disposition
0160 __sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
0161 const struct sctp_association *asoc,
0162 const union sctp_subtype type, void *arg,
0163 struct sctp_cmd_seq *commands);
0164
0165
0166
0167
0168
0169
0170
0171
0172 static inline bool sctp_chunk_length_valid(struct sctp_chunk *chunk,
0173 __u16 required_length)
0174 {
0175 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
0176
0177
0178 if (unlikely(chunk->pdiscard))
0179 return false;
0180 if (unlikely(chunk_length < required_length))
0181 return false;
0182
0183 return true;
0184 }
0185
0186
0187 static inline bool sctp_err_chunk_valid(struct sctp_chunk *chunk)
0188 {
0189 struct sctp_errhdr *err;
0190
0191 sctp_walk_errors(err, chunk->chunk_hdr);
0192
0193 return (void *)err == (void *)chunk->chunk_end;
0194 }
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231 enum sctp_disposition sctp_sf_do_4_C(struct net *net,
0232 const struct sctp_endpoint *ep,
0233 const struct sctp_association *asoc,
0234 const union sctp_subtype type,
0235 void *arg, struct sctp_cmd_seq *commands)
0236 {
0237 struct sctp_chunk *chunk = arg;
0238 struct sctp_ulpevent *ev;
0239
0240 if (!sctp_vtag_verify_either(chunk, asoc))
0241 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0242
0243
0244
0245
0246
0247
0248 if (!chunk->singleton)
0249 return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
0250
0251
0252 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
0253 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
0254 commands);
0255
0256
0257
0258
0259
0260
0261
0262
0263 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
0264 0, 0, 0, NULL, GFP_ATOMIC);
0265 if (ev)
0266 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
0267 SCTP_ULPEVENT(ev));
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
0278 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
0279
0280 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
0281 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
0282
0283 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
0284 SCTP_STATE(SCTP_STATE_CLOSED));
0285
0286 SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
0287 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
0288
0289 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
0290
0291 return SCTP_DISPOSITION_DELETE_TCB;
0292 }
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316 enum sctp_disposition sctp_sf_do_5_1B_init(struct net *net,
0317 const struct sctp_endpoint *ep,
0318 const struct sctp_association *asoc,
0319 const union sctp_subtype type,
0320 void *arg,
0321 struct sctp_cmd_seq *commands)
0322 {
0323 struct sctp_chunk *chunk = arg, *repl, *err_chunk;
0324 struct sctp_unrecognized_param *unk_param;
0325 struct sctp_association *new_asoc;
0326 struct sctp_packet *packet;
0327 int len;
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338 if (!chunk->singleton)
0339 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0340
0341
0342
0343
0344
0345
0346 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
0347 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0348
0349
0350
0351
0352 if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
0353 SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
0354 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
0355 }
0356
0357
0358
0359
0360 if (chunk->sctp_hdr->vtag != 0)
0361 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
0362
0363
0364
0365
0366
0367
0368
0369 if (sctp_sstate(ep->base.sk, CLOSING))
0370 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
0371
0372
0373 err_chunk = NULL;
0374 if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
0375 (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
0376 &err_chunk)) {
0377
0378
0379
0380 if (err_chunk) {
0381 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
0382 (__u8 *)(err_chunk->chunk_hdr) +
0383 sizeof(struct sctp_chunkhdr),
0384 ntohs(err_chunk->chunk_hdr->length) -
0385 sizeof(struct sctp_chunkhdr));
0386
0387 sctp_chunk_free(err_chunk);
0388
0389 if (packet) {
0390 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
0391 SCTP_PACKET(packet));
0392 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
0393 return SCTP_DISPOSITION_CONSUME;
0394 } else {
0395 return SCTP_DISPOSITION_NOMEM;
0396 }
0397 } else {
0398 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
0399 commands);
0400 }
0401 }
0402
0403
0404 chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
0405
0406
0407 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
0408
0409 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
0410 if (!new_asoc)
0411 goto nomem;
0412
0413
0414 if (security_sctp_assoc_request(new_asoc, chunk->skb)) {
0415 sctp_association_free(new_asoc);
0416 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0417 }
0418
0419 if (sctp_assoc_set_bind_addr_from_ep(new_asoc,
0420 sctp_scope(sctp_source(chunk)),
0421 GFP_ATOMIC) < 0)
0422 goto nomem_init;
0423
0424
0425 if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk),
0426 (struct sctp_init_chunk *)chunk->chunk_hdr,
0427 GFP_ATOMIC))
0428 goto nomem_init;
0429
0430
0431
0432
0433
0434
0435 len = 0;
0436 if (err_chunk)
0437 len = ntohs(err_chunk->chunk_hdr->length) -
0438 sizeof(struct sctp_chunkhdr);
0439
0440 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
0441 if (!repl)
0442 goto nomem_init;
0443
0444
0445
0446
0447
0448 if (err_chunk) {
0449
0450
0451
0452
0453
0454
0455
0456 unk_param = (struct sctp_unrecognized_param *)
0457 ((__u8 *)(err_chunk->chunk_hdr) +
0458 sizeof(struct sctp_chunkhdr));
0459
0460
0461
0462 sctp_addto_chunk(repl, len, unk_param);
0463 sctp_chunk_free(err_chunk);
0464 }
0465
0466 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
0467
0468 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
0469
0470
0471
0472
0473
0474
0475
0476 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
0477
0478 return SCTP_DISPOSITION_DELETE_TCB;
0479
0480 nomem_init:
0481 sctp_association_free(new_asoc);
0482 nomem:
0483 if (err_chunk)
0484 sctp_chunk_free(err_chunk);
0485 return SCTP_DISPOSITION_NOMEM;
0486 }
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516 enum sctp_disposition sctp_sf_do_5_1C_ack(struct net *net,
0517 const struct sctp_endpoint *ep,
0518 const struct sctp_association *asoc,
0519 const union sctp_subtype type,
0520 void *arg,
0521 struct sctp_cmd_seq *commands)
0522 {
0523 struct sctp_init_chunk *initchunk;
0524 struct sctp_chunk *chunk = arg;
0525 struct sctp_chunk *err_chunk;
0526 struct sctp_packet *packet;
0527
0528 if (!sctp_vtag_verify(chunk, asoc))
0529 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0530
0531
0532
0533
0534
0535 if (!chunk->singleton)
0536 return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
0537
0538
0539 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_initack_chunk)))
0540 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
0541 commands);
0542
0543 chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
0544
0545
0546 err_chunk = NULL;
0547 if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
0548 (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
0549 &err_chunk)) {
0550
0551 enum sctp_error error = SCTP_ERROR_NO_RESOURCE;
0552
0553
0554
0555
0556
0557
0558 if (err_chunk) {
0559 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
0560 (__u8 *)(err_chunk->chunk_hdr) +
0561 sizeof(struct sctp_chunkhdr),
0562 ntohs(err_chunk->chunk_hdr->length) -
0563 sizeof(struct sctp_chunkhdr));
0564
0565 sctp_chunk_free(err_chunk);
0566
0567 if (packet) {
0568 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
0569 SCTP_PACKET(packet));
0570 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
0571 error = SCTP_ERROR_INV_PARAM;
0572 }
0573 }
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
0587 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0588
0589 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
0590 return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED,
0591 asoc, chunk->transport);
0592 }
0593
0594
0595
0596
0597 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
0598
0599 initchunk = (struct sctp_init_chunk *)chunk->chunk_hdr;
0600
0601 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
0602 SCTP_PEER_INIT(initchunk));
0603
0604
0605 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
0606
0607
0608
0609
0610
0611 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
0612 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
0613 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
0614 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
0615 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
0616 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
0617
0618
0619
0620
0621 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
0622
0623
0624
0625
0626
0627
0628
0629 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
0630 SCTP_CHUNK(err_chunk));
0631
0632 return SCTP_DISPOSITION_CONSUME;
0633 }
0634
0635 static bool sctp_auth_chunk_verify(struct net *net, struct sctp_chunk *chunk,
0636 const struct sctp_association *asoc)
0637 {
0638 struct sctp_chunk auth;
0639
0640 if (!chunk->auth_chunk)
0641 return true;
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651 if (!net->sctp.auth_enable || !asoc->peer.auth_capable)
0652 return false;
0653
0654
0655 auth.skb = chunk->auth_chunk;
0656 auth.asoc = chunk->asoc;
0657 auth.sctp_hdr = chunk->sctp_hdr;
0658 auth.chunk_hdr = (struct sctp_chunkhdr *)
0659 skb_push(chunk->auth_chunk,
0660 sizeof(struct sctp_chunkhdr));
0661 skb_pull(chunk->auth_chunk, sizeof(struct sctp_chunkhdr));
0662 auth.transport = chunk->transport;
0663
0664 return sctp_sf_authenticate(asoc, &auth) == SCTP_IERROR_NO_ERROR;
0665 }
0666
0667
0668
0669
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698 enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
0699 const struct sctp_endpoint *ep,
0700 const struct sctp_association *asoc,
0701 const union sctp_subtype type,
0702 void *arg,
0703 struct sctp_cmd_seq *commands)
0704 {
0705 struct sctp_ulpevent *ev, *ai_ev = NULL, *auth_ev = NULL;
0706 struct sctp_association *new_asoc;
0707 struct sctp_init_chunk *peer_init;
0708 struct sctp_chunk *chunk = arg;
0709 struct sctp_chunk *err_chk_p;
0710 struct sctp_chunk *repl;
0711 struct sock *sk;
0712 int error = 0;
0713
0714 if (asoc && !sctp_vtag_verify(chunk, asoc))
0715 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0716
0717
0718
0719
0720 if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
0721 SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
0722 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
0723 }
0724
0725
0726
0727
0728
0729
0730 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
0731 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
0732 commands);
0733
0734
0735
0736
0737
0738 sk = ep->base.sk;
0739 if (!sctp_sstate(sk, LISTENING) ||
0740 (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
0741 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
0742
0743
0744
0745
0746 chunk->subh.cookie_hdr =
0747 (struct sctp_signed_cookie *)chunk->skb->data;
0748 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
0749 sizeof(struct sctp_chunkhdr)))
0750 goto nomem;
0751
0752
0753
0754
0755
0756 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
0757 &err_chk_p);
0758
0759
0760
0761
0762
0763
0764
0765 if (!new_asoc) {
0766
0767
0768
0769 switch (error) {
0770 case -SCTP_IERROR_NOMEM:
0771 goto nomem;
0772
0773 case -SCTP_IERROR_STALE_COOKIE:
0774 sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
0775 err_chk_p);
0776 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0777
0778 case -SCTP_IERROR_BAD_SIG:
0779 default:
0780 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0781 }
0782 }
0783
0784 if (security_sctp_assoc_request(new_asoc, chunk->head_skb ?: chunk->skb)) {
0785 sctp_association_free(new_asoc);
0786 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0787 }
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
0798
0799 if (!sctp_process_init(new_asoc, chunk,
0800 &chunk->subh.cookie_hdr->c.peer_addr,
0801 peer_init, GFP_ATOMIC))
0802 goto nomem_init;
0803
0804
0805
0806
0807
0808 error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
0809 if (error)
0810 goto nomem_init;
0811
0812 if (!sctp_auth_chunk_verify(net, chunk, new_asoc)) {
0813 sctp_association_free(new_asoc);
0814 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0815 }
0816
0817 repl = sctp_make_cookie_ack(new_asoc, chunk);
0818 if (!repl)
0819 goto nomem_init;
0820
0821
0822
0823
0824
0825
0826
0827 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
0828 new_asoc->c.sinit_num_ostreams,
0829 new_asoc->c.sinit_max_instreams,
0830 NULL, GFP_ATOMIC);
0831 if (!ev)
0832 goto nomem_ev;
0833
0834
0835
0836
0837
0838
0839 if (new_asoc->peer.adaptation_ind) {
0840 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
0841 GFP_ATOMIC);
0842 if (!ai_ev)
0843 goto nomem_aiev;
0844 }
0845
0846 if (!new_asoc->peer.auth_capable) {
0847 auth_ev = sctp_ulpevent_make_authkey(new_asoc, 0,
0848 SCTP_AUTH_NO_AUTH,
0849 GFP_ATOMIC);
0850 if (!auth_ev)
0851 goto nomem_authev;
0852 }
0853
0854
0855
0856
0857
0858
0859 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
0860 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
0861 SCTP_STATE(SCTP_STATE_ESTABLISHED));
0862 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
0863 SCTP_INC_STATS(net, SCTP_MIB_PASSIVEESTABS);
0864 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
0865
0866 if (new_asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
0867 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
0868 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
0869
0870
0871 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
0872
0873
0874 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
0875
0876
0877 if (ai_ev)
0878 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
0879 SCTP_ULPEVENT(ai_ev));
0880
0881 if (auth_ev)
0882 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
0883 SCTP_ULPEVENT(auth_ev));
0884
0885 return SCTP_DISPOSITION_CONSUME;
0886
0887 nomem_authev:
0888 sctp_ulpevent_free(ai_ev);
0889 nomem_aiev:
0890 sctp_ulpevent_free(ev);
0891 nomem_ev:
0892 sctp_chunk_free(repl);
0893 nomem_init:
0894 sctp_association_free(new_asoc);
0895 nomem:
0896 return SCTP_DISPOSITION_NOMEM;
0897 }
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910
0911
0912
0913
0914
0915
0916
0917
0918
0919
0920 enum sctp_disposition sctp_sf_do_5_1E_ca(struct net *net,
0921 const struct sctp_endpoint *ep,
0922 const struct sctp_association *asoc,
0923 const union sctp_subtype type,
0924 void *arg,
0925 struct sctp_cmd_seq *commands)
0926 {
0927 struct sctp_chunk *chunk = arg;
0928 struct sctp_ulpevent *ev;
0929
0930 if (!sctp_vtag_verify(chunk, asoc))
0931 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0932
0933
0934 if (security_sctp_assoc_established((struct sctp_association *)asoc,
0935 chunk->head_skb ?: chunk->skb))
0936 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
0937
0938
0939
0940
0941 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
0942 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
0943 commands);
0944
0945
0946
0947
0948
0949
0950
0951 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
0952
0953
0954
0955
0956
0957
0958
0959 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
0960 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
0961 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
0962 SCTP_STATE(SCTP_STATE_ESTABLISHED));
0963 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
0964 SCTP_INC_STATS(net, SCTP_MIB_ACTIVEESTABS);
0965 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
0966 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
0967 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
0968 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
0969
0970
0971
0972
0973
0974 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
0975 0, asoc->c.sinit_num_ostreams,
0976 asoc->c.sinit_max_instreams,
0977 NULL, GFP_ATOMIC);
0978
0979 if (!ev)
0980 goto nomem;
0981
0982 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
0983
0984
0985
0986
0987
0988
0989 if (asoc->peer.adaptation_ind) {
0990 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
0991 if (!ev)
0992 goto nomem;
0993
0994 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
0995 SCTP_ULPEVENT(ev));
0996 }
0997
0998 if (!asoc->peer.auth_capable) {
0999 ev = sctp_ulpevent_make_authkey(asoc, 0, SCTP_AUTH_NO_AUTH,
1000 GFP_ATOMIC);
1001 if (!ev)
1002 goto nomem;
1003 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1004 SCTP_ULPEVENT(ev));
1005 }
1006
1007 return SCTP_DISPOSITION_CONSUME;
1008 nomem:
1009 return SCTP_DISPOSITION_NOMEM;
1010 }
1011
1012
1013 static enum sctp_disposition sctp_sf_heartbeat(
1014 const struct sctp_endpoint *ep,
1015 const struct sctp_association *asoc,
1016 const union sctp_subtype type,
1017 void *arg,
1018 struct sctp_cmd_seq *commands)
1019 {
1020 struct sctp_transport *transport = (struct sctp_transport *) arg;
1021 struct sctp_chunk *reply;
1022
1023
1024 reply = sctp_make_heartbeat(asoc, transport, 0);
1025 if (!reply)
1026 return SCTP_DISPOSITION_NOMEM;
1027
1028
1029
1030
1031 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
1032 SCTP_TRANSPORT(transport));
1033
1034 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1035 return SCTP_DISPOSITION_CONSUME;
1036 }
1037
1038
1039 enum sctp_disposition sctp_sf_sendbeat_8_3(struct net *net,
1040 const struct sctp_endpoint *ep,
1041 const struct sctp_association *asoc,
1042 const union sctp_subtype type,
1043 void *arg,
1044 struct sctp_cmd_seq *commands)
1045 {
1046 struct sctp_transport *transport = (struct sctp_transport *) arg;
1047
1048 if (asoc->overall_error_count >= asoc->max_retrans) {
1049 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
1050 SCTP_ERROR(ETIMEDOUT));
1051
1052 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
1053 SCTP_PERR(SCTP_ERROR_NO_ERROR));
1054 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
1055 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
1056 return SCTP_DISPOSITION_DELETE_TCB;
1057 }
1058
1059
1060
1061
1062
1063
1064
1065
1066 if (transport->param_flags & SPP_HB_ENABLE) {
1067 if (SCTP_DISPOSITION_NOMEM ==
1068 sctp_sf_heartbeat(ep, asoc, type, arg,
1069 commands))
1070 return SCTP_DISPOSITION_NOMEM;
1071
1072
1073
1074
1075 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
1076 SCTP_TRANSPORT(transport));
1077 }
1078 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE,
1079 SCTP_TRANSPORT(transport));
1080 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
1081 SCTP_TRANSPORT(transport));
1082
1083 return SCTP_DISPOSITION_CONSUME;
1084 }
1085
1086
1087 enum sctp_disposition sctp_sf_send_reconf(struct net *net,
1088 const struct sctp_endpoint *ep,
1089 const struct sctp_association *asoc,
1090 const union sctp_subtype type,
1091 void *arg,
1092 struct sctp_cmd_seq *commands)
1093 {
1094 struct sctp_transport *transport = arg;
1095
1096 if (asoc->overall_error_count >= asoc->max_retrans) {
1097 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
1098 SCTP_ERROR(ETIMEDOUT));
1099
1100 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
1101 SCTP_PERR(SCTP_ERROR_NO_ERROR));
1102 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
1103 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
1104 return SCTP_DISPOSITION_DELETE_TCB;
1105 }
1106
1107 sctp_chunk_hold(asoc->strreset_chunk);
1108 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1109 SCTP_CHUNK(asoc->strreset_chunk));
1110 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
1111
1112 return SCTP_DISPOSITION_CONSUME;
1113 }
1114
1115
1116 enum sctp_disposition sctp_sf_send_probe(struct net *net,
1117 const struct sctp_endpoint *ep,
1118 const struct sctp_association *asoc,
1119 const union sctp_subtype type,
1120 void *arg,
1121 struct sctp_cmd_seq *commands)
1122 {
1123 struct sctp_transport *transport = (struct sctp_transport *)arg;
1124 struct sctp_chunk *reply;
1125
1126 if (!sctp_transport_pl_enabled(transport))
1127 return SCTP_DISPOSITION_CONSUME;
1128
1129 sctp_transport_pl_send(transport);
1130 reply = sctp_make_heartbeat(asoc, transport, transport->pl.probe_size);
1131 if (!reply)
1132 return SCTP_DISPOSITION_NOMEM;
1133 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1134 sctp_add_cmd_sf(commands, SCTP_CMD_PROBE_TIMER_UPDATE,
1135 SCTP_TRANSPORT(transport));
1136
1137 return SCTP_DISPOSITION_CONSUME;
1138 }
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164 enum sctp_disposition sctp_sf_beat_8_3(struct net *net,
1165 const struct sctp_endpoint *ep,
1166 const struct sctp_association *asoc,
1167 const union sctp_subtype type,
1168 void *arg, struct sctp_cmd_seq *commands)
1169 {
1170 struct sctp_paramhdr *param_hdr;
1171 struct sctp_chunk *chunk = arg;
1172 struct sctp_chunk *reply;
1173 size_t paylen = 0;
1174
1175 if (!sctp_vtag_verify(chunk, asoc))
1176 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1177
1178
1179 if (!sctp_chunk_length_valid(chunk,
1180 sizeof(struct sctp_heartbeat_chunk)))
1181 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
1182 commands);
1183
1184
1185
1186
1187
1188 chunk->subh.hb_hdr = (struct sctp_heartbeathdr *)chunk->skb->data;
1189 param_hdr = (struct sctp_paramhdr *)chunk->subh.hb_hdr;
1190 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(struct sctp_chunkhdr);
1191
1192 if (ntohs(param_hdr->length) > paylen)
1193 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
1194 param_hdr, commands);
1195
1196 if (!pskb_pull(chunk->skb, paylen))
1197 goto nomem;
1198
1199 reply = sctp_make_heartbeat_ack(asoc, chunk, param_hdr, paylen);
1200 if (!reply)
1201 goto nomem;
1202
1203 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1204 return SCTP_DISPOSITION_CONSUME;
1205
1206 nomem:
1207 return SCTP_DISPOSITION_NOMEM;
1208 }
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238 enum sctp_disposition sctp_sf_backbeat_8_3(struct net *net,
1239 const struct sctp_endpoint *ep,
1240 const struct sctp_association *asoc,
1241 const union sctp_subtype type,
1242 void *arg,
1243 struct sctp_cmd_seq *commands)
1244 {
1245 struct sctp_sender_hb_info *hbinfo;
1246 struct sctp_chunk *chunk = arg;
1247 struct sctp_transport *link;
1248 unsigned long max_interval;
1249 union sctp_addr from_addr;
1250
1251 if (!sctp_vtag_verify(chunk, asoc))
1252 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1253
1254
1255 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr) +
1256 sizeof(*hbinfo)))
1257 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
1258 commands);
1259
1260 hbinfo = (struct sctp_sender_hb_info *)chunk->skb->data;
1261
1262 if (ntohs(hbinfo->param_hdr.length) != sizeof(*hbinfo))
1263 return SCTP_DISPOSITION_DISCARD;
1264
1265 from_addr = hbinfo->daddr;
1266 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1267
1268
1269 if (unlikely(!link)) {
1270 if (from_addr.sa.sa_family == AF_INET6) {
1271 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1272 __func__,
1273 asoc,
1274 &from_addr.v6.sin6_addr);
1275 } else {
1276 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1277 __func__,
1278 asoc,
1279 &from_addr.v4.sin_addr.s_addr);
1280 }
1281 return SCTP_DISPOSITION_DISCARD;
1282 }
1283
1284
1285 if (hbinfo->hb_nonce != link->hb_nonce)
1286 return SCTP_DISPOSITION_DISCARD;
1287
1288 if (hbinfo->probe_size) {
1289 if (hbinfo->probe_size != link->pl.probe_size ||
1290 !sctp_transport_pl_enabled(link))
1291 return SCTP_DISPOSITION_DISCARD;
1292
1293 if (sctp_transport_pl_recv(link))
1294 return SCTP_DISPOSITION_CONSUME;
1295
1296 return sctp_sf_send_probe(net, ep, asoc, type, link, commands);
1297 }
1298
1299 max_interval = link->hbinterval + link->rto;
1300
1301
1302 if (time_after(hbinfo->sent_at, jiffies) ||
1303 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1304 pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
1305 "for transport:%p\n", __func__, link);
1306
1307 return SCTP_DISPOSITION_DISCARD;
1308 }
1309
1310
1311
1312
1313
1314
1315
1316 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1317
1318 return SCTP_DISPOSITION_CONSUME;
1319 }
1320
1321
1322
1323
1324 static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa,
1325 struct sctp_chunk *init,
1326 struct sctp_cmd_seq *commands)
1327 {
1328 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1329 union sctp_addr_param *addrparm;
1330 struct sctp_errhdr *errhdr;
1331 char buffer[sizeof(*errhdr) + sizeof(*addrparm)];
1332 struct sctp_endpoint *ep;
1333 struct sctp_packet *pkt;
1334 int len;
1335
1336
1337
1338
1339 errhdr = (struct sctp_errhdr *)buffer;
1340 addrparm = (union sctp_addr_param *)errhdr->variable;
1341
1342
1343 len = af->to_addr_param(ssa, addrparm);
1344 len += sizeof(*errhdr);
1345
1346 errhdr->cause = SCTP_ERROR_RESTART;
1347 errhdr->length = htons(len);
1348
1349
1350 ep = sctp_sk(net->sctp.ctl_sock)->ep;
1351
1352
1353
1354
1355 pkt = sctp_abort_pkt_new(net, ep, NULL, init, errhdr, len);
1356
1357 if (!pkt)
1358 goto out;
1359 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1360
1361 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
1362
1363
1364 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1365
1366 out:
1367
1368
1369
1370 return 0;
1371 }
1372
1373 static bool list_has_sctp_addr(const struct list_head *list,
1374 union sctp_addr *ipaddr)
1375 {
1376 struct sctp_transport *addr;
1377
1378 list_for_each_entry(addr, list, transports) {
1379 if (sctp_cmp_addr_exact(ipaddr, &addr->ipaddr))
1380 return true;
1381 }
1382
1383 return false;
1384 }
1385
1386
1387
1388 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1389 const struct sctp_association *asoc,
1390 struct sctp_chunk *init,
1391 struct sctp_cmd_seq *commands)
1392 {
1393 struct net *net = new_asoc->base.net;
1394 struct sctp_transport *new_addr;
1395 int ret = 1;
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408 list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list,
1409 transports) {
1410 if (!list_has_sctp_addr(&asoc->peer.transport_addr_list,
1411 &new_addr->ipaddr)) {
1412 sctp_sf_send_restart_abort(net, &new_addr->ipaddr, init,
1413 commands);
1414 ret = 0;
1415 break;
1416 }
1417 }
1418
1419
1420 return ret;
1421 }
1422
1423
1424
1425
1426
1427
1428 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1429 const struct sctp_association *asoc)
1430 {
1431 switch (asoc->state) {
1432
1433
1434
1435 case SCTP_STATE_COOKIE_WAIT:
1436 new_asoc->c.my_vtag = asoc->c.my_vtag;
1437 new_asoc->c.my_ttag = asoc->c.my_vtag;
1438 new_asoc->c.peer_ttag = 0;
1439 break;
1440
1441 case SCTP_STATE_COOKIE_ECHOED:
1442 new_asoc->c.my_vtag = asoc->c.my_vtag;
1443 new_asoc->c.my_ttag = asoc->c.my_vtag;
1444 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1445 break;
1446
1447
1448
1449
1450 default:
1451 new_asoc->c.my_ttag = asoc->c.my_vtag;
1452 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1453 break;
1454 }
1455
1456
1457
1458
1459
1460 new_asoc->rwnd = asoc->rwnd;
1461 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1462 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1463 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1464 }
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1476 const struct sctp_association *asoc)
1477 {
1478
1479 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1480 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1481 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1482 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1483 return 'A';
1484
1485
1486 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1487 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1488 (0 == asoc->c.peer_vtag))) {
1489 return 'B';
1490 }
1491
1492
1493 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1494 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1495 return 'D';
1496
1497
1498 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1499 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1500 (0 == new_asoc->c.my_ttag) &&
1501 (0 == new_asoc->c.peer_ttag))
1502 return 'C';
1503
1504
1505 return 'E';
1506 }
1507
1508
1509
1510
1511 static enum sctp_disposition sctp_sf_do_unexpected_init(
1512 struct net *net,
1513 const struct sctp_endpoint *ep,
1514 const struct sctp_association *asoc,
1515 const union sctp_subtype type,
1516 void *arg,
1517 struct sctp_cmd_seq *commands)
1518 {
1519 struct sctp_chunk *chunk = arg, *repl, *err_chunk;
1520 struct sctp_unrecognized_param *unk_param;
1521 struct sctp_association *new_asoc;
1522 enum sctp_disposition retval;
1523 struct sctp_packet *packet;
1524 int len;
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535 if (!chunk->singleton)
1536 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1537
1538
1539 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
1540 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1541
1542
1543
1544
1545 if (chunk->sctp_hdr->vtag != 0)
1546 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
1547
1548 if (SCTP_INPUT_CB(chunk->skb)->encap_port != chunk->transport->encap_port)
1549 return sctp_sf_new_encap_port(net, ep, asoc, type, arg, commands);
1550
1551
1552 chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
1553
1554
1555 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
1556
1557
1558 err_chunk = NULL;
1559 if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
1560 (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
1561 &err_chunk)) {
1562
1563
1564
1565 if (err_chunk) {
1566 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
1567 (__u8 *)(err_chunk->chunk_hdr) +
1568 sizeof(struct sctp_chunkhdr),
1569 ntohs(err_chunk->chunk_hdr->length) -
1570 sizeof(struct sctp_chunkhdr));
1571
1572 if (packet) {
1573 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1574 SCTP_PACKET(packet));
1575 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
1576 retval = SCTP_DISPOSITION_CONSUME;
1577 } else {
1578 retval = SCTP_DISPOSITION_NOMEM;
1579 }
1580 goto cleanup;
1581 } else {
1582 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
1583 commands);
1584 }
1585 }
1586
1587
1588
1589
1590
1591
1592
1593
1594 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1595 if (!new_asoc)
1596 goto nomem;
1597
1598
1599 if (security_sctp_assoc_request(new_asoc, chunk->skb)) {
1600 sctp_association_free(new_asoc);
1601 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1602 }
1603
1604 if (sctp_assoc_set_bind_addr_from_ep(new_asoc,
1605 sctp_scope(sctp_source(chunk)), GFP_ATOMIC) < 0)
1606 goto nomem;
1607
1608
1609
1610
1611
1612 if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk),
1613 (struct sctp_init_chunk *)chunk->chunk_hdr,
1614 GFP_ATOMIC))
1615 goto nomem;
1616
1617
1618
1619
1620
1621
1622 if (!sctp_state(asoc, COOKIE_WAIT)) {
1623 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1624 commands)) {
1625 retval = SCTP_DISPOSITION_CONSUME;
1626 goto nomem_retval;
1627 }
1628 }
1629
1630 sctp_tietags_populate(new_asoc, asoc);
1631
1632
1633
1634
1635
1636
1637 len = 0;
1638 if (err_chunk) {
1639 len = ntohs(err_chunk->chunk_hdr->length) -
1640 sizeof(struct sctp_chunkhdr);
1641 }
1642
1643 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1644 if (!repl)
1645 goto nomem;
1646
1647
1648
1649
1650
1651 if (err_chunk) {
1652
1653
1654
1655
1656
1657
1658
1659 unk_param = (struct sctp_unrecognized_param *)
1660 ((__u8 *)(err_chunk->chunk_hdr) +
1661 sizeof(struct sctp_chunkhdr));
1662
1663
1664
1665 sctp_addto_chunk(repl, len, unk_param);
1666 }
1667
1668 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1669 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1670
1671
1672
1673
1674
1675
1676 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1677 retval = SCTP_DISPOSITION_CONSUME;
1678
1679 return retval;
1680
1681 nomem:
1682 retval = SCTP_DISPOSITION_NOMEM;
1683 nomem_retval:
1684 if (new_asoc)
1685 sctp_association_free(new_asoc);
1686 cleanup:
1687 if (err_chunk)
1688 sctp_chunk_free(err_chunk);
1689 return retval;
1690 }
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730 enum sctp_disposition sctp_sf_do_5_2_1_siminit(
1731 struct net *net,
1732 const struct sctp_endpoint *ep,
1733 const struct sctp_association *asoc,
1734 const union sctp_subtype type,
1735 void *arg,
1736 struct sctp_cmd_seq *commands)
1737 {
1738
1739
1740
1741 return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
1742 }
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785 enum sctp_disposition sctp_sf_do_5_2_2_dupinit(
1786 struct net *net,
1787 const struct sctp_endpoint *ep,
1788 const struct sctp_association *asoc,
1789 const union sctp_subtype type,
1790 void *arg,
1791 struct sctp_cmd_seq *commands)
1792 {
1793
1794
1795
1796 return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
1797 }
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809 enum sctp_disposition sctp_sf_do_5_2_3_initack(
1810 struct net *net,
1811 const struct sctp_endpoint *ep,
1812 const struct sctp_association *asoc,
1813 const union sctp_subtype type,
1814 void *arg,
1815 struct sctp_cmd_seq *commands)
1816 {
1817
1818
1819
1820 if (ep == sctp_sk(net->sctp.ctl_sock)->ep)
1821 return sctp_sf_ootb(net, ep, asoc, type, arg, commands);
1822 else
1823 return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
1824 }
1825
1826 static int sctp_sf_do_assoc_update(struct sctp_association *asoc,
1827 struct sctp_association *new,
1828 struct sctp_cmd_seq *cmds)
1829 {
1830 struct net *net = asoc->base.net;
1831 struct sctp_chunk *abort;
1832
1833 if (!sctp_assoc_update(asoc, new))
1834 return 0;
1835
1836 abort = sctp_make_abort(asoc, NULL, sizeof(struct sctp_errhdr));
1837 if (abort) {
1838 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
1839 sctp_add_cmd_sf(cmds, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
1840 }
1841 sctp_add_cmd_sf(cmds, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNABORTED));
1842 sctp_add_cmd_sf(cmds, SCTP_CMD_ASSOC_FAILED,
1843 SCTP_PERR(SCTP_ERROR_RSRC_LOW));
1844 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
1845 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
1846
1847 return -ENOMEM;
1848 }
1849
1850
1851
1852
1853
1854
1855 static enum sctp_disposition sctp_sf_do_dupcook_a(
1856 struct net *net,
1857 const struct sctp_endpoint *ep,
1858 const struct sctp_association *asoc,
1859 struct sctp_chunk *chunk,
1860 struct sctp_cmd_seq *commands,
1861 struct sctp_association *new_asoc)
1862 {
1863 struct sctp_init_chunk *peer_init;
1864 enum sctp_disposition disposition;
1865 struct sctp_ulpevent *ev;
1866 struct sctp_chunk *repl;
1867 struct sctp_chunk *err;
1868
1869
1870
1871
1872 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1873
1874 if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
1875 GFP_ATOMIC))
1876 goto nomem;
1877
1878 if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC))
1879 goto nomem;
1880
1881 if (!sctp_auth_chunk_verify(net, chunk, new_asoc))
1882 return SCTP_DISPOSITION_DISCARD;
1883
1884
1885
1886
1887
1888 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands))
1889 return SCTP_DISPOSITION_CONSUME;
1890
1891
1892
1893
1894
1895
1896
1897 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1898 disposition = __sctp_sf_do_9_2_reshutack(net, ep, asoc,
1899 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1900 chunk, commands);
1901 if (SCTP_DISPOSITION_NOMEM == disposition)
1902 goto nomem;
1903
1904 err = sctp_make_op_error(asoc, chunk,
1905 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1906 NULL, 0, 0);
1907 if (err)
1908 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1909 SCTP_CHUNK(err));
1910
1911 return SCTP_DISPOSITION_CONSUME;
1912 }
1913
1914
1915
1916
1917 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
1918 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1919 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
1920 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1921
1922
1923
1924
1925 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1926 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
1927 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_ASCONF_QUEUE, SCTP_NULL());
1928
1929
1930 if (sctp_sf_do_assoc_update((struct sctp_association *)asoc, new_asoc, commands))
1931 goto nomem;
1932
1933 repl = sctp_make_cookie_ack(asoc, chunk);
1934 if (!repl)
1935 goto nomem;
1936
1937
1938 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1939 asoc->c.sinit_num_ostreams,
1940 asoc->c.sinit_max_instreams,
1941 NULL, GFP_ATOMIC);
1942 if (!ev)
1943 goto nomem_ev;
1944
1945 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1946 if ((sctp_state(asoc, SHUTDOWN_PENDING) ||
1947 sctp_state(asoc, SHUTDOWN_SENT)) &&
1948 (sctp_sstate(asoc->base.sk, CLOSING) ||
1949 sock_flag(asoc->base.sk, SOCK_DEAD))) {
1950
1951
1952
1953
1954 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1955 return sctp_sf_do_9_2_start_shutdown(net, ep, asoc,
1956 SCTP_ST_CHUNK(0), repl,
1957 commands);
1958 } else {
1959 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1960 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1961 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1962 }
1963 return SCTP_DISPOSITION_CONSUME;
1964
1965 nomem_ev:
1966 sctp_chunk_free(repl);
1967 nomem:
1968 return SCTP_DISPOSITION_NOMEM;
1969 }
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979 static enum sctp_disposition sctp_sf_do_dupcook_b(
1980 struct net *net,
1981 const struct sctp_endpoint *ep,
1982 const struct sctp_association *asoc,
1983 struct sctp_chunk *chunk,
1984 struct sctp_cmd_seq *commands,
1985 struct sctp_association *new_asoc)
1986 {
1987 struct sctp_init_chunk *peer_init;
1988 struct sctp_chunk *repl;
1989
1990
1991
1992
1993 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1994 if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
1995 GFP_ATOMIC))
1996 goto nomem;
1997
1998 if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC))
1999 goto nomem;
2000
2001 if (!sctp_auth_chunk_verify(net, chunk, new_asoc))
2002 return SCTP_DISPOSITION_DISCARD;
2003
2004 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2005 SCTP_STATE(SCTP_STATE_ESTABLISHED));
2006 if (asoc->state < SCTP_STATE_ESTABLISHED)
2007 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
2008 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
2009
2010
2011 if (sctp_sf_do_assoc_update((struct sctp_association *)asoc, new_asoc, commands))
2012 goto nomem;
2013
2014 repl = sctp_make_cookie_ack(asoc, chunk);
2015 if (!repl)
2016 goto nomem;
2017
2018 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042 if (asoc->peer.adaptation_ind)
2043 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
2044
2045 if (!asoc->peer.auth_capable)
2046 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_NO_AUTH, SCTP_NULL());
2047
2048 return SCTP_DISPOSITION_CONSUME;
2049
2050 nomem:
2051 return SCTP_DISPOSITION_NOMEM;
2052 }
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063 static enum sctp_disposition sctp_sf_do_dupcook_c(
2064 struct net *net,
2065 const struct sctp_endpoint *ep,
2066 const struct sctp_association *asoc,
2067 struct sctp_chunk *chunk,
2068 struct sctp_cmd_seq *commands,
2069 struct sctp_association *new_asoc)
2070 {
2071
2072
2073
2074
2075 return SCTP_DISPOSITION_DISCARD;
2076 }
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086 static enum sctp_disposition sctp_sf_do_dupcook_d(
2087 struct net *net,
2088 const struct sctp_endpoint *ep,
2089 const struct sctp_association *asoc,
2090 struct sctp_chunk *chunk,
2091 struct sctp_cmd_seq *commands,
2092 struct sctp_association *new_asoc)
2093 {
2094 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL, *auth_ev = NULL;
2095 struct sctp_chunk *repl;
2096
2097
2098
2099
2100
2101
2102
2103
2104 if (!sctp_auth_chunk_verify(net, chunk, asoc))
2105 return SCTP_DISPOSITION_DISCARD;
2106
2107
2108 if (asoc->state < SCTP_STATE_ESTABLISHED) {
2109 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2110 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2111 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2112 SCTP_STATE(SCTP_STATE_ESTABLISHED));
2113 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
2114 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
2115 SCTP_NULL());
2116
2117
2118
2119
2120
2121
2122
2123
2124 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
2125 SCTP_COMM_UP, 0,
2126 asoc->c.sinit_num_ostreams,
2127 asoc->c.sinit_max_instreams,
2128 NULL, GFP_ATOMIC);
2129 if (!ev)
2130 goto nomem;
2131
2132
2133
2134
2135
2136
2137 if (asoc->peer.adaptation_ind) {
2138 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
2139 GFP_ATOMIC);
2140 if (!ai_ev)
2141 goto nomem;
2142
2143 }
2144
2145 if (!asoc->peer.auth_capable) {
2146 auth_ev = sctp_ulpevent_make_authkey(asoc, 0,
2147 SCTP_AUTH_NO_AUTH,
2148 GFP_ATOMIC);
2149 if (!auth_ev)
2150 goto nomem;
2151 }
2152 }
2153
2154 repl = sctp_make_cookie_ack(asoc, chunk);
2155 if (!repl)
2156 goto nomem;
2157
2158 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
2159
2160 if (ev)
2161 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
2162 SCTP_ULPEVENT(ev));
2163 if (ai_ev)
2164 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
2165 SCTP_ULPEVENT(ai_ev));
2166 if (auth_ev)
2167 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
2168 SCTP_ULPEVENT(auth_ev));
2169
2170 return SCTP_DISPOSITION_CONSUME;
2171
2172 nomem:
2173 if (auth_ev)
2174 sctp_ulpevent_free(auth_ev);
2175 if (ai_ev)
2176 sctp_ulpevent_free(ai_ev);
2177 if (ev)
2178 sctp_ulpevent_free(ev);
2179 return SCTP_DISPOSITION_NOMEM;
2180 }
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198 enum sctp_disposition sctp_sf_do_5_2_4_dupcook(
2199 struct net *net,
2200 const struct sctp_endpoint *ep,
2201 const struct sctp_association *asoc,
2202 const union sctp_subtype type,
2203 void *arg,
2204 struct sctp_cmd_seq *commands)
2205 {
2206 struct sctp_association *new_asoc;
2207 struct sctp_chunk *chunk = arg;
2208 enum sctp_disposition retval;
2209 struct sctp_chunk *err_chk_p;
2210 int error = 0;
2211 char action;
2212
2213
2214
2215
2216
2217
2218 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) {
2219 if (!sctp_vtag_verify(chunk, asoc))
2220 asoc = NULL;
2221 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, commands);
2222 }
2223
2224
2225
2226
2227 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
2228 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
2229 sizeof(struct sctp_chunkhdr)))
2230 goto nomem;
2231
2232
2233
2234
2235
2236
2237 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
2238 &err_chk_p);
2239
2240
2241
2242
2243
2244
2245
2246 if (!new_asoc) {
2247
2248
2249
2250 switch (error) {
2251 case -SCTP_IERROR_NOMEM:
2252 goto nomem;
2253
2254 case -SCTP_IERROR_STALE_COOKIE:
2255 sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
2256 err_chk_p);
2257 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2258 case -SCTP_IERROR_BAD_SIG:
2259 default:
2260 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2261 }
2262 }
2263
2264
2265 if (security_sctp_assoc_request(new_asoc, chunk->head_skb ?: chunk->skb)) {
2266 sctp_association_free(new_asoc);
2267 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2268 }
2269
2270
2271 new_asoc->temp = 1;
2272
2273
2274
2275
2276 action = sctp_tietags_compare(new_asoc, asoc);
2277
2278 switch (action) {
2279 case 'A':
2280 retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands,
2281 new_asoc);
2282 break;
2283
2284 case 'B':
2285 retval = sctp_sf_do_dupcook_b(net, ep, asoc, chunk, commands,
2286 new_asoc);
2287 break;
2288
2289 case 'C':
2290 retval = sctp_sf_do_dupcook_c(net, ep, asoc, chunk, commands,
2291 new_asoc);
2292 break;
2293
2294 case 'D':
2295 retval = sctp_sf_do_dupcook_d(net, ep, asoc, chunk, commands,
2296 new_asoc);
2297 break;
2298
2299 default:
2300 retval = sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2301 break;
2302 }
2303
2304
2305 sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC, SCTP_ASOC(new_asoc));
2306 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2307
2308
2309
2310
2311 sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC,
2312 SCTP_ASOC((struct sctp_association *)asoc));
2313
2314 return retval;
2315
2316 nomem:
2317 return SCTP_DISPOSITION_NOMEM;
2318 }
2319
2320
2321
2322
2323
2324
2325 enum sctp_disposition sctp_sf_shutdown_pending_abort(
2326 struct net *net,
2327 const struct sctp_endpoint *ep,
2328 const struct sctp_association *asoc,
2329 const union sctp_subtype type,
2330 void *arg,
2331 struct sctp_cmd_seq *commands)
2332 {
2333 struct sctp_chunk *chunk = arg;
2334
2335 if (!sctp_vtag_verify_either(chunk, asoc))
2336 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
2349 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2350
2351
2352
2353
2354
2355
2356 if (SCTP_ADDR_DEL ==
2357 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2358 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2359
2360 if (!sctp_err_chunk_valid(chunk))
2361 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2362
2363 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2364 }
2365
2366
2367
2368
2369
2370
2371 enum sctp_disposition sctp_sf_shutdown_sent_abort(
2372 struct net *net,
2373 const struct sctp_endpoint *ep,
2374 const struct sctp_association *asoc,
2375 const union sctp_subtype type,
2376 void *arg,
2377 struct sctp_cmd_seq *commands)
2378 {
2379 struct sctp_chunk *chunk = arg;
2380
2381 if (!sctp_vtag_verify_either(chunk, asoc))
2382 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
2395 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2396
2397
2398
2399
2400
2401
2402 if (SCTP_ADDR_DEL ==
2403 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2404 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2405
2406 if (!sctp_err_chunk_valid(chunk))
2407 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2408
2409
2410 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2411 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2412
2413
2414 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2415 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2416
2417 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2418 }
2419
2420
2421
2422
2423
2424
2425 enum sctp_disposition sctp_sf_shutdown_ack_sent_abort(
2426 struct net *net,
2427 const struct sctp_endpoint *ep,
2428 const struct sctp_association *asoc,
2429 const union sctp_subtype type,
2430 void *arg,
2431 struct sctp_cmd_seq *commands)
2432 {
2433
2434
2435
2436 return sctp_sf_shutdown_sent_abort(net, ep, asoc, type, arg, commands);
2437 }
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453 enum sctp_disposition sctp_sf_cookie_echoed_err(
2454 struct net *net,
2455 const struct sctp_endpoint *ep,
2456 const struct sctp_association *asoc,
2457 const union sctp_subtype type,
2458 void *arg,
2459 struct sctp_cmd_seq *commands)
2460 {
2461 struct sctp_chunk *chunk = arg;
2462 struct sctp_errhdr *err;
2463
2464 if (!sctp_vtag_verify(chunk, asoc))
2465 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2466
2467
2468
2469
2470 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk)))
2471 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2472 commands);
2473
2474
2475
2476
2477
2478
2479 sctp_walk_errors(err, chunk->chunk_hdr) {
2480 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2481 return sctp_sf_do_5_2_6_stale(net, ep, asoc, type,
2482 arg, commands);
2483 }
2484
2485
2486
2487
2488
2489
2490 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2491 }
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518 static enum sctp_disposition sctp_sf_do_5_2_6_stale(
2519 struct net *net,
2520 const struct sctp_endpoint *ep,
2521 const struct sctp_association *asoc,
2522 const union sctp_subtype type,
2523 void *arg,
2524 struct sctp_cmd_seq *commands)
2525 {
2526 int attempts = asoc->init_err_counter + 1;
2527 struct sctp_chunk *chunk = arg, *reply;
2528 struct sctp_cookie_preserve_param bht;
2529 struct sctp_bind_addr *bp;
2530 struct sctp_errhdr *err;
2531 u32 stale;
2532
2533 if (attempts > asoc->max_init_attempts) {
2534 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2535 SCTP_ERROR(ETIMEDOUT));
2536 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2537 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2538 return SCTP_DISPOSITION_DELETE_TCB;
2539 }
2540
2541 err = (struct sctp_errhdr *)(chunk->skb->data);
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err)));
2558 stale = (stale * 2) / 1000;
2559
2560 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2561 bht.param_hdr.length = htons(sizeof(bht));
2562 bht.lifespan_increment = htonl(stale);
2563
2564
2565 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2566 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2567 if (!reply)
2568 goto nomem;
2569
2570 sctp_addto_chunk(reply, sizeof(bht), &bht);
2571
2572
2573 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2574
2575
2576 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2577 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2578
2579
2580
2581
2582 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2583
2584
2585
2586
2587 sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN,
2588 SCTP_TRANSPORT(asoc->peer.primary_path));
2589
2590
2591
2592
2593 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2594
2595 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2596 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2597 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2598 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2599 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2600 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2601
2602 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2603
2604 return SCTP_DISPOSITION_CONSUME;
2605
2606 nomem:
2607 return SCTP_DISPOSITION_NOMEM;
2608 }
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641 enum sctp_disposition sctp_sf_do_9_1_abort(
2642 struct net *net,
2643 const struct sctp_endpoint *ep,
2644 const struct sctp_association *asoc,
2645 const union sctp_subtype type,
2646 void *arg,
2647 struct sctp_cmd_seq *commands)
2648 {
2649 struct sctp_chunk *chunk = arg;
2650
2651 if (!sctp_vtag_verify_either(chunk, asoc))
2652 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
2665 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2666
2667
2668
2669
2670
2671
2672 if (SCTP_ADDR_DEL ==
2673 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2674 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2675
2676 if (!sctp_err_chunk_valid(chunk))
2677 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2678
2679 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2680 }
2681
2682 static enum sctp_disposition __sctp_sf_do_9_1_abort(
2683 struct net *net,
2684 const struct sctp_endpoint *ep,
2685 const struct sctp_association *asoc,
2686 const union sctp_subtype type,
2687 void *arg,
2688 struct sctp_cmd_seq *commands)
2689 {
2690 __be16 error = SCTP_ERROR_NO_ERROR;
2691 struct sctp_chunk *chunk = arg;
2692 unsigned int len;
2693
2694
2695 len = ntohs(chunk->chunk_hdr->length);
2696 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2697 error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
2698
2699 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2700
2701 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2702 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
2703 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
2704
2705 return SCTP_DISPOSITION_ABORT;
2706 }
2707
2708
2709
2710
2711
2712
2713 enum sctp_disposition sctp_sf_cookie_wait_abort(
2714 struct net *net,
2715 const struct sctp_endpoint *ep,
2716 const struct sctp_association *asoc,
2717 const union sctp_subtype type,
2718 void *arg,
2719 struct sctp_cmd_seq *commands)
2720 {
2721 __be16 error = SCTP_ERROR_NO_ERROR;
2722 struct sctp_chunk *chunk = arg;
2723 unsigned int len;
2724
2725 if (!sctp_vtag_verify_either(chunk, asoc))
2726 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
2739 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2740
2741
2742 len = ntohs(chunk->chunk_hdr->length);
2743 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2744 error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
2745
2746 return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED, asoc,
2747 chunk->transport);
2748 }
2749
2750
2751
2752
2753 enum sctp_disposition sctp_sf_cookie_wait_icmp_abort(
2754 struct net *net,
2755 const struct sctp_endpoint *ep,
2756 const struct sctp_association *asoc,
2757 const union sctp_subtype type,
2758 void *arg,
2759 struct sctp_cmd_seq *commands)
2760 {
2761 return sctp_stop_t1_and_abort(net, commands, SCTP_ERROR_NO_ERROR,
2762 ENOPROTOOPT, asoc,
2763 (struct sctp_transport *)arg);
2764 }
2765
2766
2767
2768
2769 enum sctp_disposition sctp_sf_cookie_echoed_abort(
2770 struct net *net,
2771 const struct sctp_endpoint *ep,
2772 const struct sctp_association *asoc,
2773 const union sctp_subtype type,
2774 void *arg,
2775 struct sctp_cmd_seq *commands)
2776 {
2777
2778
2779
2780 return sctp_sf_cookie_wait_abort(net, ep, asoc, type, arg, commands);
2781 }
2782
2783
2784
2785
2786
2787
2788 static enum sctp_disposition sctp_stop_t1_and_abort(
2789 struct net *net,
2790 struct sctp_cmd_seq *commands,
2791 __be16 error, int sk_err,
2792 const struct sctp_association *asoc,
2793 struct sctp_transport *transport)
2794 {
2795 pr_debug("%s: ABORT received (INIT)\n", __func__);
2796
2797 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2798 SCTP_STATE(SCTP_STATE_CLOSED));
2799 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
2800 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2801 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2802 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2803
2804 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2805 SCTP_PERR(error));
2806
2807 return SCTP_DISPOSITION_ABORT;
2808 }
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843 enum sctp_disposition sctp_sf_do_9_2_shutdown(
2844 struct net *net,
2845 const struct sctp_endpoint *ep,
2846 const struct sctp_association *asoc,
2847 const union sctp_subtype type,
2848 void *arg,
2849 struct sctp_cmd_seq *commands)
2850 {
2851 enum sctp_disposition disposition;
2852 struct sctp_chunk *chunk = arg;
2853 struct sctp_shutdownhdr *sdh;
2854 struct sctp_ulpevent *ev;
2855 __u32 ctsn;
2856
2857 if (!sctp_vtag_verify(chunk, asoc))
2858 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2859
2860
2861 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk)))
2862 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2863 commands);
2864
2865
2866 sdh = (struct sctp_shutdownhdr *)chunk->skb->data;
2867 skb_pull(chunk->skb, sizeof(*sdh));
2868 chunk->subh.shutdown_hdr = sdh;
2869 ctsn = ntohl(sdh->cum_tsn_ack);
2870
2871 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2872 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
2873 asoc->ctsn_ack_point);
2874
2875 return SCTP_DISPOSITION_DISCARD;
2876 }
2877
2878
2879
2880
2881
2882 if (!TSN_lt(ctsn, asoc->next_tsn))
2883 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
2884
2885
2886
2887
2888
2889 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2890 if (!ev) {
2891 disposition = SCTP_DISPOSITION_NOMEM;
2892 goto out;
2893 }
2894 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2895
2896
2897
2898
2899
2900
2901
2902 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2903 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2904 disposition = SCTP_DISPOSITION_CONSUME;
2905
2906 if (sctp_outq_is_empty(&asoc->outqueue)) {
2907 disposition = sctp_sf_do_9_2_shutdown_ack(net, ep, asoc, type,
2908 arg, commands);
2909 }
2910
2911 if (SCTP_DISPOSITION_NOMEM == disposition)
2912 goto out;
2913
2914
2915
2916
2917
2918 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2919 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2920
2921 out:
2922 return disposition;
2923 }
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933 enum sctp_disposition sctp_sf_do_9_2_shut_ctsn(
2934 struct net *net,
2935 const struct sctp_endpoint *ep,
2936 const struct sctp_association *asoc,
2937 const union sctp_subtype type,
2938 void *arg,
2939 struct sctp_cmd_seq *commands)
2940 {
2941 struct sctp_chunk *chunk = arg;
2942 struct sctp_shutdownhdr *sdh;
2943 __u32 ctsn;
2944
2945 if (!sctp_vtag_verify(chunk, asoc))
2946 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2947
2948
2949 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk)))
2950 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2951 commands);
2952
2953 sdh = (struct sctp_shutdownhdr *)chunk->skb->data;
2954 ctsn = ntohl(sdh->cum_tsn_ack);
2955
2956 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2957 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
2958 asoc->ctsn_ack_point);
2959
2960 return SCTP_DISPOSITION_DISCARD;
2961 }
2962
2963
2964
2965
2966
2967 if (!TSN_lt(ctsn, asoc->next_tsn))
2968 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
2969
2970
2971
2972
2973
2974 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2975 SCTP_BE32(sdh->cum_tsn_ack));
2976
2977 return SCTP_DISPOSITION_CONSUME;
2978 }
2979
2980
2981
2982
2983
2984
2985
2986
2987 static enum sctp_disposition
2988 __sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
2989 const struct sctp_association *asoc,
2990 const union sctp_subtype type, void *arg,
2991 struct sctp_cmd_seq *commands)
2992 {
2993 struct sctp_chunk *chunk = arg;
2994 struct sctp_chunk *reply;
2995
2996
2997 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
2998 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2999 commands);
3000
3001
3002
3003
3004
3005 reply = sctp_make_shutdown_ack(asoc, chunk);
3006 if (NULL == reply)
3007 goto nomem;
3008
3009
3010
3011
3012 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
3013
3014
3015 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3016 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3017
3018 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3019
3020 return SCTP_DISPOSITION_CONSUME;
3021 nomem:
3022 return SCTP_DISPOSITION_NOMEM;
3023 }
3024
3025 enum sctp_disposition
3026 sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
3027 const struct sctp_association *asoc,
3028 const union sctp_subtype type, void *arg,
3029 struct sctp_cmd_seq *commands)
3030 {
3031 struct sctp_chunk *chunk = arg;
3032
3033 if (!chunk->singleton)
3034 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3035
3036 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
3037 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3038
3039 if (chunk->sctp_hdr->vtag != 0)
3040 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
3041
3042 return __sctp_sf_do_9_2_reshutack(net, ep, asoc, type, arg, commands);
3043 }
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070 enum sctp_disposition sctp_sf_do_ecn_cwr(struct net *net,
3071 const struct sctp_endpoint *ep,
3072 const struct sctp_association *asoc,
3073 const union sctp_subtype type,
3074 void *arg,
3075 struct sctp_cmd_seq *commands)
3076 {
3077 struct sctp_chunk *chunk = arg;
3078 struct sctp_cwrhdr *cwr;
3079 u32 lowest_tsn;
3080
3081 if (!sctp_vtag_verify(chunk, asoc))
3082 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3083
3084 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk)))
3085 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3086 commands);
3087
3088 cwr = (struct sctp_cwrhdr *)chunk->skb->data;
3089 skb_pull(chunk->skb, sizeof(*cwr));
3090
3091 lowest_tsn = ntohl(cwr->lowest_tsn);
3092
3093
3094 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
3095
3096 sctp_add_cmd_sf(commands,
3097 SCTP_CMD_ECN_CWR,
3098 SCTP_U32(lowest_tsn));
3099 }
3100 return SCTP_DISPOSITION_CONSUME;
3101 }
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126 enum sctp_disposition sctp_sf_do_ecne(struct net *net,
3127 const struct sctp_endpoint *ep,
3128 const struct sctp_association *asoc,
3129 const union sctp_subtype type,
3130 void *arg, struct sctp_cmd_seq *commands)
3131 {
3132 struct sctp_chunk *chunk = arg;
3133 struct sctp_ecnehdr *ecne;
3134
3135 if (!sctp_vtag_verify(chunk, asoc))
3136 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3137
3138 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk)))
3139 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3140 commands);
3141
3142 ecne = (struct sctp_ecnehdr *)chunk->skb->data;
3143 skb_pull(chunk->skb, sizeof(*ecne));
3144
3145
3146 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
3147 SCTP_U32(ntohl(ecne->lowest_tsn)));
3148
3149 return SCTP_DISPOSITION_CONSUME;
3150 }
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182 enum sctp_disposition sctp_sf_eat_data_6_2(struct net *net,
3183 const struct sctp_endpoint *ep,
3184 const struct sctp_association *asoc,
3185 const union sctp_subtype type,
3186 void *arg,
3187 struct sctp_cmd_seq *commands)
3188 {
3189 union sctp_arg force = SCTP_NOFORCE();
3190 struct sctp_chunk *chunk = arg;
3191 int error;
3192
3193 if (!sctp_vtag_verify(chunk, asoc)) {
3194 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3195 SCTP_NULL());
3196 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3197 }
3198
3199 if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream)))
3200 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3201 commands);
3202
3203 error = sctp_eat_data(asoc, chunk, commands);
3204 switch (error) {
3205 case SCTP_IERROR_NO_ERROR:
3206 break;
3207 case SCTP_IERROR_HIGH_TSN:
3208 case SCTP_IERROR_BAD_STREAM:
3209 SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
3210 goto discard_noforce;
3211 case SCTP_IERROR_DUP_TSN:
3212 case SCTP_IERROR_IGNORE_TSN:
3213 SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
3214 goto discard_force;
3215 case SCTP_IERROR_NO_DATA:
3216 return SCTP_DISPOSITION_ABORT;
3217 case SCTP_IERROR_PROTO_VIOLATION:
3218 return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
3219 (u8 *)chunk->subh.data_hdr,
3220 sctp_datahdr_len(&asoc->stream));
3221 default:
3222 BUG();
3223 }
3224
3225 if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM)
3226 force = SCTP_FORCE();
3227
3228 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
3229 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3230 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3231 }
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255 if (chunk->end_of_packet)
3256 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
3257
3258 return SCTP_DISPOSITION_CONSUME;
3259
3260 discard_force:
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275 if (chunk->end_of_packet)
3276 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3277 return SCTP_DISPOSITION_DISCARD;
3278
3279 discard_noforce:
3280 if (chunk->end_of_packet)
3281 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
3282
3283 return SCTP_DISPOSITION_DISCARD;
3284 }
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302 enum sctp_disposition sctp_sf_eat_data_fast_4_4(
3303 struct net *net,
3304 const struct sctp_endpoint *ep,
3305 const struct sctp_association *asoc,
3306 const union sctp_subtype type,
3307 void *arg,
3308 struct sctp_cmd_seq *commands)
3309 {
3310 struct sctp_chunk *chunk = arg;
3311 int error;
3312
3313 if (!sctp_vtag_verify(chunk, asoc)) {
3314 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3315 SCTP_NULL());
3316 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3317 }
3318
3319 if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream)))
3320 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3321 commands);
3322
3323 error = sctp_eat_data(asoc, chunk, commands);
3324 switch (error) {
3325 case SCTP_IERROR_NO_ERROR:
3326 case SCTP_IERROR_HIGH_TSN:
3327 case SCTP_IERROR_DUP_TSN:
3328 case SCTP_IERROR_IGNORE_TSN:
3329 case SCTP_IERROR_BAD_STREAM:
3330 break;
3331 case SCTP_IERROR_NO_DATA:
3332 return SCTP_DISPOSITION_ABORT;
3333 case SCTP_IERROR_PROTO_VIOLATION:
3334 return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
3335 (u8 *)chunk->subh.data_hdr,
3336 sctp_datahdr_len(&asoc->stream));
3337 default:
3338 BUG();
3339 }
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349 if (chunk->end_of_packet) {
3350
3351
3352
3353 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3354 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3355 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3356 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3357 }
3358
3359 return SCTP_DISPOSITION_CONSUME;
3360 }
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394 enum sctp_disposition sctp_sf_eat_sack_6_2(struct net *net,
3395 const struct sctp_endpoint *ep,
3396 const struct sctp_association *asoc,
3397 const union sctp_subtype type,
3398 void *arg,
3399 struct sctp_cmd_seq *commands)
3400 {
3401 struct sctp_chunk *chunk = arg;
3402 struct sctp_sackhdr *sackh;
3403 __u32 ctsn;
3404
3405 if (!sctp_vtag_verify(chunk, asoc))
3406 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3407
3408
3409 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_sack_chunk)))
3410 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3411 commands);
3412
3413
3414 sackh = sctp_sm_pull_sack(chunk);
3415
3416 if (!sackh)
3417 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3418 chunk->subh.sack_hdr = sackh;
3419 ctsn = ntohl(sackh->cum_tsn_ack);
3420
3421
3422
3423
3424
3425 if (TSN_lte(asoc->next_tsn, ctsn))
3426 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
3427
3428 trace_sctp_probe(ep, asoc, chunk);
3429
3430
3431
3432
3433
3434
3435
3436 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
3437 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
3438 asoc->ctsn_ack_point);
3439
3440 return SCTP_DISPOSITION_DISCARD;
3441 }
3442
3443
3444 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_CHUNK(chunk));
3445
3446
3447
3448
3449 return SCTP_DISPOSITION_CONSUME;
3450 }
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470 static enum sctp_disposition sctp_sf_tabort_8_4_8(
3471 struct net *net,
3472 const struct sctp_endpoint *ep,
3473 const struct sctp_association *asoc,
3474 const union sctp_subtype type,
3475 void *arg,
3476 struct sctp_cmd_seq *commands)
3477 {
3478 struct sctp_packet *packet = NULL;
3479 struct sctp_chunk *chunk = arg;
3480 struct sctp_chunk *abort;
3481
3482 packet = sctp_ootb_pkt_new(net, asoc, chunk);
3483 if (!packet)
3484 return SCTP_DISPOSITION_NOMEM;
3485
3486
3487
3488
3489 abort = sctp_make_abort(asoc, chunk, 0);
3490 if (!abort) {
3491 sctp_ootb_pkt_free(packet);
3492 return SCTP_DISPOSITION_NOMEM;
3493 }
3494
3495
3496 if (sctp_test_T_bit(abort))
3497 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3498
3499
3500 abort->skb->sk = ep->base.sk;
3501
3502 sctp_packet_append_chunk(packet, abort);
3503
3504 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(packet));
3505
3506 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
3507
3508 sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3509 return SCTP_DISPOSITION_CONSUME;
3510 }
3511
3512
3513
3514
3515
3516
3517 static enum sctp_disposition sctp_sf_new_encap_port(
3518 struct net *net,
3519 const struct sctp_endpoint *ep,
3520 const struct sctp_association *asoc,
3521 const union sctp_subtype type,
3522 void *arg,
3523 struct sctp_cmd_seq *commands)
3524 {
3525 struct sctp_packet *packet = NULL;
3526 struct sctp_chunk *chunk = arg;
3527 struct sctp_chunk *abort;
3528
3529 packet = sctp_ootb_pkt_new(net, asoc, chunk);
3530 if (!packet)
3531 return SCTP_DISPOSITION_NOMEM;
3532
3533 abort = sctp_make_new_encap_port(asoc, chunk);
3534 if (!abort) {
3535 sctp_ootb_pkt_free(packet);
3536 return SCTP_DISPOSITION_NOMEM;
3537 }
3538
3539 abort->skb->sk = ep->base.sk;
3540
3541 sctp_packet_append_chunk(packet, abort);
3542
3543 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3544 SCTP_PACKET(packet));
3545
3546 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
3547
3548 sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3549 return SCTP_DISPOSITION_CONSUME;
3550 }
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560 enum sctp_disposition sctp_sf_operr_notify(struct net *net,
3561 const struct sctp_endpoint *ep,
3562 const struct sctp_association *asoc,
3563 const union sctp_subtype type,
3564 void *arg,
3565 struct sctp_cmd_seq *commands)
3566 {
3567 struct sctp_chunk *chunk = arg;
3568 struct sctp_errhdr *err;
3569
3570 if (!sctp_vtag_verify(chunk, asoc))
3571 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3572
3573
3574 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk)))
3575 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3576 commands);
3577 sctp_walk_errors(err, chunk->chunk_hdr);
3578 if ((void *)err != (void *)chunk->chunk_end)
3579 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3580 (void *)err, commands);
3581
3582 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3583 SCTP_CHUNK(chunk));
3584
3585 return SCTP_DISPOSITION_CONSUME;
3586 }
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598 enum sctp_disposition sctp_sf_do_9_2_final(struct net *net,
3599 const struct sctp_endpoint *ep,
3600 const struct sctp_association *asoc,
3601 const union sctp_subtype type,
3602 void *arg,
3603 struct sctp_cmd_seq *commands)
3604 {
3605 struct sctp_chunk *chunk = arg;
3606 struct sctp_chunk *reply;
3607 struct sctp_ulpevent *ev;
3608
3609 if (!sctp_vtag_verify(chunk, asoc))
3610 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3611
3612
3613 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
3614 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3615 commands);
3616
3617
3618
3619
3620
3621 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3622 0, 0, 0, NULL, GFP_ATOMIC);
3623 if (!ev)
3624 goto nomem;
3625
3626
3627 reply = sctp_make_shutdown_complete(asoc, chunk);
3628 if (!reply)
3629 goto nomem_chunk;
3630
3631
3632
3633
3634 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3635
3636
3637
3638
3639 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3640 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3641
3642 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3643 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3644
3645 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3646 SCTP_STATE(SCTP_STATE_CLOSED));
3647 SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
3648 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
3649 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3650
3651
3652 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3653 return SCTP_DISPOSITION_DELETE_TCB;
3654
3655 nomem_chunk:
3656 sctp_ulpevent_free(ev);
3657 nomem:
3658 return SCTP_DISPOSITION_NOMEM;
3659 }
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681 enum sctp_disposition sctp_sf_ootb(struct net *net,
3682 const struct sctp_endpoint *ep,
3683 const struct sctp_association *asoc,
3684 const union sctp_subtype type,
3685 void *arg, struct sctp_cmd_seq *commands)
3686 {
3687 struct sctp_chunk *chunk = arg;
3688 struct sk_buff *skb = chunk->skb;
3689 struct sctp_chunkhdr *ch;
3690 struct sctp_errhdr *err;
3691 int ootb_cookie_ack = 0;
3692 int ootb_shut_ack = 0;
3693 __u8 *ch_end;
3694
3695 SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
3696
3697 if (asoc && !sctp_vtag_verify(chunk, asoc))
3698 asoc = NULL;
3699
3700 ch = (struct sctp_chunkhdr *)chunk->chunk_hdr;
3701 do {
3702
3703 if (ntohs(ch->length) < sizeof(*ch))
3704 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3705 commands);
3706
3707
3708 ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
3709 if (ch_end > skb_tail_pointer(skb))
3710 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3711 commands);
3712
3713
3714
3715
3716 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3717 ootb_shut_ack = 1;
3718
3719
3720
3721
3722
3723
3724 if (SCTP_CID_ABORT == ch->type)
3725 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3726
3727
3728
3729
3730
3731
3732 if (SCTP_CID_COOKIE_ACK == ch->type)
3733 ootb_cookie_ack = 1;
3734
3735 if (SCTP_CID_ERROR == ch->type) {
3736 sctp_walk_errors(err, ch) {
3737 if (SCTP_ERROR_STALE_COOKIE == err->cause) {
3738 ootb_cookie_ack = 1;
3739 break;
3740 }
3741 }
3742 }
3743
3744 ch = (struct sctp_chunkhdr *)ch_end;
3745 } while (ch_end < skb_tail_pointer(skb));
3746
3747 if (ootb_shut_ack)
3748 return sctp_sf_shut_8_4_5(net, ep, asoc, type, arg, commands);
3749 else if (ootb_cookie_ack)
3750 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3751 else
3752 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
3753 }
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776 static enum sctp_disposition sctp_sf_shut_8_4_5(
3777 struct net *net,
3778 const struct sctp_endpoint *ep,
3779 const struct sctp_association *asoc,
3780 const union sctp_subtype type,
3781 void *arg,
3782 struct sctp_cmd_seq *commands)
3783 {
3784 struct sctp_packet *packet = NULL;
3785 struct sctp_chunk *chunk = arg;
3786 struct sctp_chunk *shut;
3787
3788 packet = sctp_ootb_pkt_new(net, asoc, chunk);
3789 if (!packet)
3790 return SCTP_DISPOSITION_NOMEM;
3791
3792
3793
3794
3795 shut = sctp_make_shutdown_complete(asoc, chunk);
3796 if (!shut) {
3797 sctp_ootb_pkt_free(packet);
3798 return SCTP_DISPOSITION_NOMEM;
3799 }
3800
3801
3802 if (sctp_test_T_bit(shut))
3803 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3804
3805
3806 shut->skb->sk = ep->base.sk;
3807
3808 sctp_packet_append_chunk(packet, shut);
3809
3810 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3811 SCTP_PACKET(packet));
3812
3813 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
3814
3815
3816
3817
3818
3819 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3820 }
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833 enum sctp_disposition sctp_sf_do_8_5_1_E_sa(struct net *net,
3834 const struct sctp_endpoint *ep,
3835 const struct sctp_association *asoc,
3836 const union sctp_subtype type,
3837 void *arg,
3838 struct sctp_cmd_seq *commands)
3839 {
3840 struct sctp_chunk *chunk = arg;
3841
3842 if (!sctp_vtag_verify(chunk, asoc))
3843 asoc = NULL;
3844
3845
3846 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
3847 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3848 commands);
3849
3850
3851
3852
3853
3854
3855 SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
3856
3857 return sctp_sf_shut_8_4_5(net, ep, NULL, type, arg, commands);
3858 }
3859
3860
3861 enum sctp_disposition sctp_sf_do_asconf(struct net *net,
3862 const struct sctp_endpoint *ep,
3863 const struct sctp_association *asoc,
3864 const union sctp_subtype type,
3865 void *arg,
3866 struct sctp_cmd_seq *commands)
3867 {
3868 struct sctp_paramhdr *err_param = NULL;
3869 struct sctp_chunk *asconf_ack = NULL;
3870 struct sctp_chunk *chunk = arg;
3871 struct sctp_addiphdr *hdr;
3872 __u32 serial;
3873
3874 if (!sctp_vtag_verify(chunk, asoc)) {
3875 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3876 SCTP_NULL());
3877 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3878 }
3879
3880
3881 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_addip_chunk)))
3882 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3883 commands);
3884
3885
3886
3887
3888
3889
3890
3891 if (!asoc->peer.asconf_capable ||
3892 (!net->sctp.addip_noauth && !chunk->auth))
3893 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3894
3895 hdr = (struct sctp_addiphdr *)chunk->skb->data;
3896 serial = ntohl(hdr->serial);
3897
3898
3899 if (!sctp_verify_asconf(asoc, chunk, true, &err_param))
3900 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3901 (void *)err_param, commands);
3902
3903
3904
3905
3906
3907 if (serial == asoc->peer.addip_serial + 1) {
3908
3909
3910
3911 if (!chunk->has_asconf)
3912 sctp_assoc_clean_asconf_ack_cache(asoc);
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922 asconf_ack = sctp_process_asconf((struct sctp_association *)
3923 asoc, chunk);
3924 if (!asconf_ack)
3925 return SCTP_DISPOSITION_NOMEM;
3926 } else if (serial < asoc->peer.addip_serial + 1) {
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939 asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial);
3940 if (!asconf_ack)
3941 return SCTP_DISPOSITION_DISCARD;
3942
3943
3944
3945
3946
3947 asconf_ack->transport = NULL;
3948 } else {
3949
3950
3951
3952 return SCTP_DISPOSITION_DISCARD;
3953 }
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964 asconf_ack->dest = chunk->source;
3965 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3966 if (asoc->new_transport) {
3967 sctp_sf_heartbeat(ep, asoc, type, asoc->new_transport, commands);
3968 ((struct sctp_association *)asoc)->new_transport = NULL;
3969 }
3970
3971 return SCTP_DISPOSITION_CONSUME;
3972 }
3973
3974 static enum sctp_disposition sctp_send_next_asconf(
3975 struct net *net,
3976 const struct sctp_endpoint *ep,
3977 struct sctp_association *asoc,
3978 const union sctp_subtype type,
3979 struct sctp_cmd_seq *commands)
3980 {
3981 struct sctp_chunk *asconf;
3982 struct list_head *entry;
3983
3984 if (list_empty(&asoc->addip_chunk_list))
3985 return SCTP_DISPOSITION_CONSUME;
3986
3987 entry = asoc->addip_chunk_list.next;
3988 asconf = list_entry(entry, struct sctp_chunk, list);
3989
3990 list_del_init(entry);
3991 sctp_chunk_hold(asconf);
3992 asoc->addip_last_asconf = asconf;
3993
3994 return sctp_sf_do_prm_asconf(net, ep, asoc, type, asconf, commands);
3995 }
3996
3997
3998
3999
4000
4001
4002 enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net,
4003 const struct sctp_endpoint *ep,
4004 const struct sctp_association *asoc,
4005 const union sctp_subtype type,
4006 void *arg,
4007 struct sctp_cmd_seq *commands)
4008 {
4009 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
4010 struct sctp_paramhdr *err_param = NULL;
4011 struct sctp_chunk *asconf_ack = arg;
4012 struct sctp_addiphdr *addip_hdr;
4013 __u32 sent_serial, rcvd_serial;
4014 struct sctp_chunk *abort;
4015
4016 if (!sctp_vtag_verify(asconf_ack, asoc)) {
4017 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4018 SCTP_NULL());
4019 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4020 }
4021
4022
4023 if (!sctp_chunk_length_valid(asconf_ack,
4024 sizeof(struct sctp_addip_chunk)))
4025 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4026 commands);
4027
4028
4029
4030
4031
4032
4033
4034 if (!asoc->peer.asconf_capable ||
4035 (!net->sctp.addip_noauth && !asconf_ack->auth))
4036 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4037
4038 addip_hdr = (struct sctp_addiphdr *)asconf_ack->skb->data;
4039 rcvd_serial = ntohl(addip_hdr->serial);
4040
4041
4042 if (!sctp_verify_asconf(asoc, asconf_ack, false, &err_param))
4043 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
4044 (void *)err_param, commands);
4045
4046 if (last_asconf) {
4047 addip_hdr = (struct sctp_addiphdr *)last_asconf->subh.addip_hdr;
4048 sent_serial = ntohl(addip_hdr->serial);
4049 } else {
4050 sent_serial = asoc->addip_serial - 1;
4051 }
4052
4053
4054
4055
4056
4057
4058
4059 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
4060 !(asoc->addip_last_asconf)) {
4061 abort = sctp_make_abort(asoc, asconf_ack,
4062 sizeof(struct sctp_errhdr));
4063 if (abort) {
4064 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
4065 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4066 SCTP_CHUNK(abort));
4067 }
4068
4069
4070
4071 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4072 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4073 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
4074 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4075 SCTP_ERROR(ECONNABORTED));
4076 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4077 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
4078 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
4079 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
4080 return SCTP_DISPOSITION_ABORT;
4081 }
4082
4083 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
4084 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4085 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4086
4087 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
4088 asconf_ack))
4089 return sctp_send_next_asconf(net, ep,
4090 (struct sctp_association *)asoc,
4091 type, commands);
4092
4093 abort = sctp_make_abort(asoc, asconf_ack,
4094 sizeof(struct sctp_errhdr));
4095 if (abort) {
4096 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
4097 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4098 SCTP_CHUNK(abort));
4099 }
4100
4101
4102
4103 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
4104 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4105 SCTP_ERROR(ECONNABORTED));
4106 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4107 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
4108 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
4109 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
4110 return SCTP_DISPOSITION_ABORT;
4111 }
4112
4113 return SCTP_DISPOSITION_DISCARD;
4114 }
4115
4116
4117 enum sctp_disposition sctp_sf_do_reconf(struct net *net,
4118 const struct sctp_endpoint *ep,
4119 const struct sctp_association *asoc,
4120 const union sctp_subtype type,
4121 void *arg,
4122 struct sctp_cmd_seq *commands)
4123 {
4124 struct sctp_paramhdr *err_param = NULL;
4125 struct sctp_chunk *chunk = arg;
4126 struct sctp_reconf_chunk *hdr;
4127 union sctp_params param;
4128
4129 if (!sctp_vtag_verify(chunk, asoc)) {
4130 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4131 SCTP_NULL());
4132 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4133 }
4134
4135
4136 if (!sctp_chunk_length_valid(chunk, sizeof(*hdr)))
4137 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4138 commands);
4139
4140 if (!sctp_verify_reconf(asoc, chunk, &err_param))
4141 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
4142 (void *)err_param, commands);
4143
4144 hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
4145 sctp_walk_params(param, hdr, params) {
4146 struct sctp_chunk *reply = NULL;
4147 struct sctp_ulpevent *ev = NULL;
4148
4149 if (param.p->type == SCTP_PARAM_RESET_OUT_REQUEST)
4150 reply = sctp_process_strreset_outreq(
4151 (struct sctp_association *)asoc, param, &ev);
4152 else if (param.p->type == SCTP_PARAM_RESET_IN_REQUEST)
4153 reply = sctp_process_strreset_inreq(
4154 (struct sctp_association *)asoc, param, &ev);
4155 else if (param.p->type == SCTP_PARAM_RESET_TSN_REQUEST)
4156 reply = sctp_process_strreset_tsnreq(
4157 (struct sctp_association *)asoc, param, &ev);
4158 else if (param.p->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS)
4159 reply = sctp_process_strreset_addstrm_out(
4160 (struct sctp_association *)asoc, param, &ev);
4161 else if (param.p->type == SCTP_PARAM_RESET_ADD_IN_STREAMS)
4162 reply = sctp_process_strreset_addstrm_in(
4163 (struct sctp_association *)asoc, param, &ev);
4164 else if (param.p->type == SCTP_PARAM_RESET_RESPONSE)
4165 reply = sctp_process_strreset_resp(
4166 (struct sctp_association *)asoc, param, &ev);
4167
4168 if (ev)
4169 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
4170 SCTP_ULPEVENT(ev));
4171
4172 if (reply)
4173 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4174 SCTP_CHUNK(reply));
4175 }
4176
4177 return SCTP_DISPOSITION_CONSUME;
4178 }
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194 enum sctp_disposition sctp_sf_eat_fwd_tsn(struct net *net,
4195 const struct sctp_endpoint *ep,
4196 const struct sctp_association *asoc,
4197 const union sctp_subtype type,
4198 void *arg,
4199 struct sctp_cmd_seq *commands)
4200 {
4201 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
4202 struct sctp_chunk *chunk = arg;
4203 __u16 len;
4204 __u32 tsn;
4205
4206 if (!sctp_vtag_verify(chunk, asoc)) {
4207 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4208 SCTP_NULL());
4209 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4210 }
4211
4212 if (!asoc->peer.prsctp_capable)
4213 return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
4214
4215
4216 if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
4217 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4218 commands);
4219
4220 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
4221 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
4222 len = ntohs(chunk->chunk_hdr->length);
4223 len -= sizeof(struct sctp_chunkhdr);
4224 skb_pull(chunk->skb, len);
4225
4226 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
4227 pr_debug("%s: TSN 0x%x\n", __func__, tsn);
4228
4229
4230
4231
4232 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
4233 goto discard_noforce;
4234
4235 if (!asoc->stream.si->validate_ftsn(chunk))
4236 goto discard_noforce;
4237
4238 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
4239 if (len > sctp_ftsnhdr_len(&asoc->stream))
4240 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
4241 SCTP_CHUNK(chunk));
4242
4243
4244 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
4245 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4246 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4247 }
4248
4249
4250
4251
4252 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
4253
4254 return SCTP_DISPOSITION_CONSUME;
4255
4256 discard_noforce:
4257 return SCTP_DISPOSITION_DISCARD;
4258 }
4259
4260 enum sctp_disposition sctp_sf_eat_fwd_tsn_fast(
4261 struct net *net,
4262 const struct sctp_endpoint *ep,
4263 const struct sctp_association *asoc,
4264 const union sctp_subtype type,
4265 void *arg,
4266 struct sctp_cmd_seq *commands)
4267 {
4268 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
4269 struct sctp_chunk *chunk = arg;
4270 __u16 len;
4271 __u32 tsn;
4272
4273 if (!sctp_vtag_verify(chunk, asoc)) {
4274 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4275 SCTP_NULL());
4276 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4277 }
4278
4279 if (!asoc->peer.prsctp_capable)
4280 return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
4281
4282
4283 if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
4284 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4285 commands);
4286
4287 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
4288 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
4289 len = ntohs(chunk->chunk_hdr->length);
4290 len -= sizeof(struct sctp_chunkhdr);
4291 skb_pull(chunk->skb, len);
4292
4293 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
4294 pr_debug("%s: TSN 0x%x\n", __func__, tsn);
4295
4296
4297
4298
4299 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
4300 goto gen_shutdown;
4301
4302 if (!asoc->stream.si->validate_ftsn(chunk))
4303 goto gen_shutdown;
4304
4305 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
4306 if (len > sctp_ftsnhdr_len(&asoc->stream))
4307 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
4308 SCTP_CHUNK(chunk));
4309
4310
4311 gen_shutdown:
4312
4313
4314
4315
4316
4317
4318 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
4319 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4320 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4321 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4322
4323 return SCTP_DISPOSITION_CONSUME;
4324 }
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348 static enum sctp_ierror sctp_sf_authenticate(
4349 const struct sctp_association *asoc,
4350 struct sctp_chunk *chunk)
4351 {
4352 struct sctp_shared_key *sh_key = NULL;
4353 struct sctp_authhdr *auth_hdr;
4354 __u8 *save_digest, *digest;
4355 struct sctp_hmac *hmac;
4356 unsigned int sig_len;
4357 __u16 key_id;
4358
4359
4360 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
4361 chunk->subh.auth_hdr = auth_hdr;
4362 skb_pull(chunk->skb, sizeof(*auth_hdr));
4363
4364
4365
4366
4367 if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id))
4368 return SCTP_IERROR_AUTH_BAD_HMAC;
4369
4370
4371
4372
4373 key_id = ntohs(auth_hdr->shkey_id);
4374 if (key_id != asoc->active_key_id) {
4375 sh_key = sctp_auth_get_shkey(asoc, key_id);
4376 if (!sh_key)
4377 return SCTP_IERROR_AUTH_BAD_KEYID;
4378 }
4379
4380
4381
4382
4383 sig_len = ntohs(chunk->chunk_hdr->length) -
4384 sizeof(struct sctp_auth_chunk);
4385 hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id));
4386 if (sig_len != hmac->hmac_len)
4387 return SCTP_IERROR_PROTO_VIOLATION;
4388
4389
4390
4391
4392
4393
4394
4395
4396 digest = auth_hdr->hmac;
4397 skb_pull(chunk->skb, sig_len);
4398
4399 save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
4400 if (!save_digest)
4401 goto nomem;
4402
4403 memset(digest, 0, sig_len);
4404
4405 sctp_auth_calculate_hmac(asoc, chunk->skb,
4406 (struct sctp_auth_chunk *)chunk->chunk_hdr,
4407 sh_key, GFP_ATOMIC);
4408
4409
4410 if (memcmp(save_digest, digest, sig_len)) {
4411 kfree(save_digest);
4412 return SCTP_IERROR_BAD_SIG;
4413 }
4414
4415 kfree(save_digest);
4416 chunk->auth = 1;
4417
4418 return SCTP_IERROR_NO_ERROR;
4419 nomem:
4420 return SCTP_IERROR_NOMEM;
4421 }
4422
4423 enum sctp_disposition sctp_sf_eat_auth(struct net *net,
4424 const struct sctp_endpoint *ep,
4425 const struct sctp_association *asoc,
4426 const union sctp_subtype type,
4427 void *arg, struct sctp_cmd_seq *commands)
4428 {
4429 struct sctp_chunk *chunk = arg;
4430 struct sctp_authhdr *auth_hdr;
4431 struct sctp_chunk *err_chunk;
4432 enum sctp_ierror error;
4433
4434
4435 if (!asoc->peer.auth_capable)
4436 return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
4437
4438 if (!sctp_vtag_verify(chunk, asoc)) {
4439 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4440 SCTP_NULL());
4441 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4442 }
4443
4444
4445 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk)))
4446 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4447 commands);
4448
4449 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
4450 error = sctp_sf_authenticate(asoc, chunk);
4451 switch (error) {
4452 case SCTP_IERROR_AUTH_BAD_HMAC:
4453
4454
4455
4456 err_chunk = sctp_make_op_error(asoc, chunk,
4457 SCTP_ERROR_UNSUP_HMAC,
4458 &auth_hdr->hmac_id,
4459 sizeof(__u16), 0);
4460 if (err_chunk) {
4461 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4462 SCTP_CHUNK(err_chunk));
4463 }
4464 fallthrough;
4465 case SCTP_IERROR_AUTH_BAD_KEYID:
4466 case SCTP_IERROR_BAD_SIG:
4467 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4468
4469 case SCTP_IERROR_PROTO_VIOLATION:
4470 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4471 commands);
4472
4473 case SCTP_IERROR_NOMEM:
4474 return SCTP_DISPOSITION_NOMEM;
4475
4476 default:
4477 break;
4478 }
4479
4480 if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) {
4481 struct sctp_ulpevent *ev;
4482
4483 ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id),
4484 SCTP_AUTH_NEW_KEY, GFP_ATOMIC);
4485
4486 if (!ev)
4487 return -ENOMEM;
4488
4489 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
4490 SCTP_ULPEVENT(ev));
4491 }
4492
4493 return SCTP_DISPOSITION_CONSUME;
4494 }
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519 enum sctp_disposition sctp_sf_unk_chunk(struct net *net,
4520 const struct sctp_endpoint *ep,
4521 const struct sctp_association *asoc,
4522 const union sctp_subtype type,
4523 void *arg,
4524 struct sctp_cmd_seq *commands)
4525 {
4526 struct sctp_chunk *unk_chunk = arg;
4527 struct sctp_chunk *err_chunk;
4528 struct sctp_chunkhdr *hdr;
4529
4530 pr_debug("%s: processing unknown chunk id:%d\n", __func__, type.chunk);
4531
4532 if (!sctp_vtag_verify(unk_chunk, asoc))
4533 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4534
4535
4536
4537
4538
4539 if (!sctp_chunk_length_valid(unk_chunk, sizeof(*hdr)))
4540 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4541 commands);
4542
4543 switch (type.chunk & SCTP_CID_ACTION_MASK) {
4544 case SCTP_CID_ACTION_DISCARD:
4545
4546 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4547 case SCTP_CID_ACTION_DISCARD_ERR:
4548
4549 hdr = unk_chunk->chunk_hdr;
4550 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4551 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4552 SCTP_PAD4(ntohs(hdr->length)),
4553 0);
4554 if (err_chunk) {
4555 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4556 SCTP_CHUNK(err_chunk));
4557 }
4558
4559
4560 sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4561 return SCTP_DISPOSITION_CONSUME;
4562 case SCTP_CID_ACTION_SKIP:
4563
4564 return SCTP_DISPOSITION_DISCARD;
4565 case SCTP_CID_ACTION_SKIP_ERR:
4566
4567 hdr = unk_chunk->chunk_hdr;
4568 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4569 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4570 SCTP_PAD4(ntohs(hdr->length)),
4571 0);
4572 if (err_chunk) {
4573 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4574 SCTP_CHUNK(err_chunk));
4575 }
4576
4577 return SCTP_DISPOSITION_CONSUME;
4578 default:
4579 break;
4580 }
4581
4582 return SCTP_DISPOSITION_DISCARD;
4583 }
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599 enum sctp_disposition sctp_sf_discard_chunk(struct net *net,
4600 const struct sctp_endpoint *ep,
4601 const struct sctp_association *asoc,
4602 const union sctp_subtype type,
4603 void *arg,
4604 struct sctp_cmd_seq *commands)
4605 {
4606 struct sctp_chunk *chunk = arg;
4607
4608 if (asoc && !sctp_vtag_verify(chunk, asoc))
4609 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4610
4611
4612
4613
4614
4615 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
4616 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4617 commands);
4618
4619 pr_debug("%s: chunk:%d is discarded\n", __func__, type.chunk);
4620
4621 return SCTP_DISPOSITION_DISCARD;
4622 }
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642 enum sctp_disposition sctp_sf_pdiscard(struct net *net,
4643 const struct sctp_endpoint *ep,
4644 const struct sctp_association *asoc,
4645 const union sctp_subtype type,
4646 void *arg, struct sctp_cmd_seq *commands)
4647 {
4648 SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_DISCARDS);
4649 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
4650
4651 return SCTP_DISPOSITION_CONSUME;
4652 }
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669 enum sctp_disposition sctp_sf_violation(struct net *net,
4670 const struct sctp_endpoint *ep,
4671 const struct sctp_association *asoc,
4672 const union sctp_subtype type,
4673 void *arg,
4674 struct sctp_cmd_seq *commands)
4675 {
4676 struct sctp_chunk *chunk = arg;
4677
4678 if (!sctp_vtag_verify(chunk, asoc))
4679 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4680
4681
4682 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
4683 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4684 commands);
4685
4686 return SCTP_DISPOSITION_VIOLATION;
4687 }
4688
4689
4690
4691
4692 static enum sctp_disposition sctp_sf_abort_violation(
4693 struct net *net,
4694 const struct sctp_endpoint *ep,
4695 const struct sctp_association *asoc,
4696 void *arg,
4697 struct sctp_cmd_seq *commands,
4698 const __u8 *payload,
4699 const size_t paylen)
4700 {
4701 struct sctp_packet *packet = NULL;
4702 struct sctp_chunk *chunk = arg;
4703 struct sctp_chunk *abort = NULL;
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4717 goto discard;
4718
4719
4720 abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
4721 if (!abort)
4722 goto nomem;
4723
4724 if (asoc) {
4725
4726 if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK &&
4727 !asoc->peer.i.init_tag) {
4728 struct sctp_initack_chunk *initack;
4729
4730 initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
4731 if (!sctp_chunk_length_valid(chunk, sizeof(*initack)))
4732 abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T;
4733 else {
4734 unsigned int inittag;
4735
4736 inittag = ntohl(initack->init_hdr.init_tag);
4737 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_INITTAG,
4738 SCTP_U32(inittag));
4739 }
4740 }
4741
4742 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4743 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
4744
4745 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
4746 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4747 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4748 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4749 SCTP_ERROR(ECONNREFUSED));
4750 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4751 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4752 } else {
4753 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4754 SCTP_ERROR(ECONNABORTED));
4755 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4756 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4757 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
4758 }
4759 } else {
4760 packet = sctp_ootb_pkt_new(net, asoc, chunk);
4761
4762 if (!packet)
4763 goto nomem_pkt;
4764
4765 if (sctp_test_T_bit(abort))
4766 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
4767
4768 abort->skb->sk = ep->base.sk;
4769
4770 sctp_packet_append_chunk(packet, abort);
4771
4772 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4773 SCTP_PACKET(packet));
4774
4775 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
4776 }
4777
4778 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
4779
4780 discard:
4781 sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4782 return SCTP_DISPOSITION_ABORT;
4783
4784 nomem_pkt:
4785 sctp_chunk_free(abort);
4786 nomem:
4787 return SCTP_DISPOSITION_NOMEM;
4788 }
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809 static enum sctp_disposition sctp_sf_violation_chunklen(
4810 struct net *net,
4811 const struct sctp_endpoint *ep,
4812 const struct sctp_association *asoc,
4813 const union sctp_subtype type,
4814 void *arg,
4815 struct sctp_cmd_seq *commands)
4816 {
4817 static const char err_str[] = "The following chunk had invalid length:";
4818
4819 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4820 sizeof(err_str));
4821 }
4822
4823
4824
4825
4826
4827
4828
4829 static enum sctp_disposition sctp_sf_violation_paramlen(
4830 struct net *net,
4831 const struct sctp_endpoint *ep,
4832 const struct sctp_association *asoc,
4833 const union sctp_subtype type,
4834 void *arg, void *ext,
4835 struct sctp_cmd_seq *commands)
4836 {
4837 struct sctp_paramhdr *param = ext;
4838 struct sctp_chunk *abort = NULL;
4839 struct sctp_chunk *chunk = arg;
4840
4841 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4842 goto discard;
4843
4844
4845 abort = sctp_make_violation_paramlen(asoc, chunk, param);
4846 if (!abort)
4847 goto nomem;
4848
4849 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4850 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
4851
4852 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4853 SCTP_ERROR(ECONNABORTED));
4854 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4855 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4856 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
4857 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
4858
4859 discard:
4860 sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4861 return SCTP_DISPOSITION_ABORT;
4862 nomem:
4863 return SCTP_DISPOSITION_NOMEM;
4864 }
4865
4866
4867
4868
4869
4870
4871
4872 static enum sctp_disposition sctp_sf_violation_ctsn(
4873 struct net *net,
4874 const struct sctp_endpoint *ep,
4875 const struct sctp_association *asoc,
4876 const union sctp_subtype type,
4877 void *arg,
4878 struct sctp_cmd_seq *commands)
4879 {
4880 static const char err_str[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4881
4882 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4883 sizeof(err_str));
4884 }
4885
4886
4887
4888
4889
4890
4891
4892 static enum sctp_disposition sctp_sf_violation_chunk(
4893 struct net *net,
4894 const struct sctp_endpoint *ep,
4895 const struct sctp_association *asoc,
4896 const union sctp_subtype type,
4897 void *arg,
4898 struct sctp_cmd_seq *commands)
4899 {
4900 static const char err_str[] = "The following chunk violates protocol:";
4901
4902 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4903 sizeof(err_str));
4904 }
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965 enum sctp_disposition sctp_sf_do_prm_asoc(struct net *net,
4966 const struct sctp_endpoint *ep,
4967 const struct sctp_association *asoc,
4968 const union sctp_subtype type,
4969 void *arg,
4970 struct sctp_cmd_seq *commands)
4971 {
4972 struct sctp_association *my_asoc;
4973 struct sctp_chunk *repl;
4974
4975
4976
4977
4978
4979 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4980 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
4991 if (!repl)
4992 goto nomem;
4993
4994
4995 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4996 SCTP_CHUNK(repl));
4997
4998
4999
5000
5001 my_asoc = (struct sctp_association *)asoc;
5002 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(my_asoc));
5003
5004
5005
5006
5007 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5008 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5009 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5010 return SCTP_DISPOSITION_CONSUME;
5011
5012 nomem:
5013 return SCTP_DISPOSITION_NOMEM;
5014 }
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077 enum sctp_disposition sctp_sf_do_prm_send(struct net *net,
5078 const struct sctp_endpoint *ep,
5079 const struct sctp_association *asoc,
5080 const union sctp_subtype type,
5081 void *arg,
5082 struct sctp_cmd_seq *commands)
5083 {
5084 struct sctp_datamsg *msg = arg;
5085
5086 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_MSG, SCTP_DATAMSG(msg));
5087 return SCTP_DISPOSITION_CONSUME;
5088 }
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116 enum sctp_disposition sctp_sf_do_9_2_prm_shutdown(
5117 struct net *net,
5118 const struct sctp_endpoint *ep,
5119 const struct sctp_association *asoc,
5120 const union sctp_subtype type,
5121 void *arg,
5122 struct sctp_cmd_seq *commands)
5123 {
5124 enum sctp_disposition disposition;
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5135 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
5136
5137 disposition = SCTP_DISPOSITION_CONSUME;
5138 if (sctp_outq_is_empty(&asoc->outqueue)) {
5139 disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type,
5140 arg, commands);
5141 }
5142
5143 return disposition;
5144 }
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173 enum sctp_disposition sctp_sf_do_9_1_prm_abort(
5174 struct net *net,
5175 const struct sctp_endpoint *ep,
5176 const struct sctp_association *asoc,
5177 const union sctp_subtype type,
5178 void *arg,
5179 struct sctp_cmd_seq *commands)
5180 {
5181
5182
5183
5184
5185
5186
5187
5188
5189 struct sctp_chunk *abort = arg;
5190
5191 if (abort)
5192 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
5193
5194
5195
5196
5197
5198 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5199 SCTP_ERROR(ECONNABORTED));
5200
5201 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5202 SCTP_PERR(SCTP_ERROR_USER_ABORT));
5203
5204 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
5205 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
5206
5207 return SCTP_DISPOSITION_ABORT;
5208 }
5209
5210
5211 enum sctp_disposition sctp_sf_error_closed(struct net *net,
5212 const struct sctp_endpoint *ep,
5213 const struct sctp_association *asoc,
5214 const union sctp_subtype type,
5215 void *arg,
5216 struct sctp_cmd_seq *commands)
5217 {
5218 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
5219 return SCTP_DISPOSITION_CONSUME;
5220 }
5221
5222
5223
5224
5225 enum sctp_disposition sctp_sf_error_shutdown(
5226 struct net *net,
5227 const struct sctp_endpoint *ep,
5228 const struct sctp_association *asoc,
5229 const union sctp_subtype type,
5230 void *arg,
5231 struct sctp_cmd_seq *commands)
5232 {
5233 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
5234 SCTP_ERROR(-ESHUTDOWN));
5235 return SCTP_DISPOSITION_CONSUME;
5236 }
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252 enum sctp_disposition sctp_sf_cookie_wait_prm_shutdown(
5253 struct net *net,
5254 const struct sctp_endpoint *ep,
5255 const struct sctp_association *asoc,
5256 const union sctp_subtype type,
5257 void *arg,
5258 struct sctp_cmd_seq *commands)
5259 {
5260 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5261 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5262
5263 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5264 SCTP_STATE(SCTP_STATE_CLOSED));
5265
5266 SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
5267
5268 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
5269
5270 return SCTP_DISPOSITION_DELETE_TCB;
5271 }
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287 enum sctp_disposition sctp_sf_cookie_echoed_prm_shutdown(
5288 struct net *net,
5289 const struct sctp_endpoint *ep,
5290 const struct sctp_association *asoc,
5291 const union sctp_subtype type,
5292 void *arg,
5293 struct sctp_cmd_seq *commands)
5294 {
5295
5296
5297
5298 return sctp_sf_cookie_wait_prm_shutdown(net, ep, asoc, type, arg, commands);
5299 }
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315 enum sctp_disposition sctp_sf_cookie_wait_prm_abort(
5316 struct net *net,
5317 const struct sctp_endpoint *ep,
5318 const struct sctp_association *asoc,
5319 const union sctp_subtype type,
5320 void *arg,
5321 struct sctp_cmd_seq *commands)
5322 {
5323 struct sctp_chunk *abort = arg;
5324
5325
5326 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5327 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5328
5329 if (abort)
5330 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
5331
5332 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5333 SCTP_STATE(SCTP_STATE_CLOSED));
5334
5335 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
5336
5337
5338
5339
5340
5341 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5342 SCTP_ERROR(ECONNREFUSED));
5343
5344 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5345 SCTP_PERR(SCTP_ERROR_USER_ABORT));
5346
5347 return SCTP_DISPOSITION_ABORT;
5348 }
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364 enum sctp_disposition sctp_sf_cookie_echoed_prm_abort(
5365 struct net *net,
5366 const struct sctp_endpoint *ep,
5367 const struct sctp_association *asoc,
5368 const union sctp_subtype type,
5369 void *arg,
5370 struct sctp_cmd_seq *commands)
5371 {
5372
5373
5374
5375 return sctp_sf_cookie_wait_prm_abort(net, ep, asoc, type, arg, commands);
5376 }
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390 enum sctp_disposition sctp_sf_shutdown_pending_prm_abort(
5391 struct net *net,
5392 const struct sctp_endpoint *ep,
5393 const struct sctp_association *asoc,
5394 const union sctp_subtype type,
5395 void *arg,
5396 struct sctp_cmd_seq *commands)
5397 {
5398
5399 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5400 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5401
5402 return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands);
5403 }
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417 enum sctp_disposition sctp_sf_shutdown_sent_prm_abort(
5418 struct net *net,
5419 const struct sctp_endpoint *ep,
5420 const struct sctp_association *asoc,
5421 const union sctp_subtype type,
5422 void *arg,
5423 struct sctp_cmd_seq *commands)
5424 {
5425
5426 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5427 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5428
5429
5430 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5431 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5432
5433 return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands);
5434 }
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448 enum sctp_disposition sctp_sf_shutdown_ack_sent_prm_abort(
5449 struct net *net,
5450 const struct sctp_endpoint *ep,
5451 const struct sctp_association *asoc,
5452 const union sctp_subtype type,
5453 void *arg,
5454 struct sctp_cmd_seq *commands)
5455 {
5456
5457
5458
5459 return sctp_sf_shutdown_sent_prm_abort(net, ep, asoc, type, arg, commands);
5460 }
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484 enum sctp_disposition sctp_sf_do_prm_requestheartbeat(
5485 struct net *net,
5486 const struct sctp_endpoint *ep,
5487 const struct sctp_association *asoc,
5488 const union sctp_subtype type,
5489 void *arg,
5490 struct sctp_cmd_seq *commands)
5491 {
5492 if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
5493 (struct sctp_transport *)arg, commands))
5494 return SCTP_DISPOSITION_NOMEM;
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
5508 SCTP_TRANSPORT(arg));
5509 return SCTP_DISPOSITION_CONSUME;
5510 }
5511
5512
5513
5514
5515
5516
5517 enum sctp_disposition sctp_sf_do_prm_asconf(struct net *net,
5518 const struct sctp_endpoint *ep,
5519 const struct sctp_association *asoc,
5520 const union sctp_subtype type,
5521 void *arg,
5522 struct sctp_cmd_seq *commands)
5523 {
5524 struct sctp_chunk *chunk = arg;
5525
5526 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
5527 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5528 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5529 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
5530 return SCTP_DISPOSITION_CONSUME;
5531 }
5532
5533
5534 enum sctp_disposition sctp_sf_do_prm_reconf(struct net *net,
5535 const struct sctp_endpoint *ep,
5536 const struct sctp_association *asoc,
5537 const union sctp_subtype type,
5538 void *arg,
5539 struct sctp_cmd_seq *commands)
5540 {
5541 struct sctp_chunk *chunk = arg;
5542
5543 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
5544 return SCTP_DISPOSITION_CONSUME;
5545 }
5546
5547
5548
5549
5550
5551
5552 enum sctp_disposition sctp_sf_ignore_primitive(
5553 struct net *net,
5554 const struct sctp_endpoint *ep,
5555 const struct sctp_association *asoc,
5556 const union sctp_subtype type,
5557 void *arg,
5558 struct sctp_cmd_seq *commands)
5559 {
5560 pr_debug("%s: primitive type:%d is ignored\n", __func__,
5561 type.primitive);
5562
5563 return SCTP_DISPOSITION_DISCARD;
5564 }
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576 enum sctp_disposition sctp_sf_do_no_pending_tsn(
5577 struct net *net,
5578 const struct sctp_endpoint *ep,
5579 const struct sctp_association *asoc,
5580 const union sctp_subtype type,
5581 void *arg,
5582 struct sctp_cmd_seq *commands)
5583 {
5584 struct sctp_ulpevent *event;
5585
5586 event = sctp_ulpevent_make_sender_dry_event(asoc, GFP_ATOMIC);
5587 if (!event)
5588 return SCTP_DISPOSITION_NOMEM;
5589
5590 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(event));
5591
5592 return SCTP_DISPOSITION_CONSUME;
5593 }
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608 enum sctp_disposition sctp_sf_do_9_2_start_shutdown(
5609 struct net *net,
5610 const struct sctp_endpoint *ep,
5611 const struct sctp_association *asoc,
5612 const union sctp_subtype type,
5613 void *arg,
5614 struct sctp_cmd_seq *commands)
5615 {
5616 struct sctp_chunk *reply;
5617
5618
5619
5620
5621
5622
5623 reply = sctp_make_shutdown(asoc, arg);
5624 if (!reply)
5625 goto nomem;
5626
5627
5628
5629
5630 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5631
5632
5633 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5634 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5635
5636
5637
5638
5639
5640 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5641 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5642
5643 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
5644 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5645 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
5646
5647
5648 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5649 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
5650
5651
5652
5653
5654
5655
5656 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
5657
5658 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5659
5660 return SCTP_DISPOSITION_CONSUME;
5661
5662 nomem:
5663 return SCTP_DISPOSITION_NOMEM;
5664 }
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678 enum sctp_disposition sctp_sf_do_9_2_shutdown_ack(
5679 struct net *net,
5680 const struct sctp_endpoint *ep,
5681 const struct sctp_association *asoc,
5682 const union sctp_subtype type,
5683 void *arg,
5684 struct sctp_cmd_seq *commands)
5685 {
5686 struct sctp_chunk *chunk = arg;
5687 struct sctp_chunk *reply;
5688
5689
5690
5691
5692
5693
5694
5695
5696 if (chunk) {
5697 if (!sctp_vtag_verify(chunk, asoc))
5698 return sctp_sf_pdiscard(net, ep, asoc, type, arg,
5699 commands);
5700
5701
5702 if (!sctp_chunk_length_valid(
5703 chunk, sizeof(struct sctp_shutdown_chunk)))
5704 return sctp_sf_violation_chunklen(net, ep, asoc, type,
5705 arg, commands);
5706 }
5707
5708
5709
5710
5711 reply = sctp_make_shutdown_ack(asoc, chunk);
5712 if (!reply)
5713 goto nomem;
5714
5715
5716
5717
5718 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5719
5720
5721 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5722 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5723
5724 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
5725 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5726 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
5727
5728
5729 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5730 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
5731
5732
5733
5734
5735
5736
5737 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
5738
5739 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5740
5741 return SCTP_DISPOSITION_CONSUME;
5742
5743 nomem:
5744 return SCTP_DISPOSITION_NOMEM;
5745 }
5746
5747
5748
5749
5750
5751
5752 enum sctp_disposition sctp_sf_ignore_other(struct net *net,
5753 const struct sctp_endpoint *ep,
5754 const struct sctp_association *asoc,
5755 const union sctp_subtype type,
5756 void *arg,
5757 struct sctp_cmd_seq *commands)
5758 {
5759 pr_debug("%s: the event other type:%d is ignored\n",
5760 __func__, type.other);
5761
5762 return SCTP_DISPOSITION_DISCARD;
5763 }
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780 enum sctp_disposition sctp_sf_do_6_3_3_rtx(struct net *net,
5781 const struct sctp_endpoint *ep,
5782 const struct sctp_association *asoc,
5783 const union sctp_subtype type,
5784 void *arg,
5785 struct sctp_cmd_seq *commands)
5786 {
5787 struct sctp_transport *transport = arg;
5788
5789 SCTP_INC_STATS(net, SCTP_MIB_T3_RTX_EXPIREDS);
5790
5791 if (asoc->overall_error_count >= asoc->max_retrans) {
5792 if (asoc->peer.zero_window_announced &&
5793 asoc->state == SCTP_STATE_SHUTDOWN_PENDING) {
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START_ONCE,
5804 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5805 } else {
5806 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5807 SCTP_ERROR(ETIMEDOUT));
5808
5809 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5810 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5811 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
5812 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
5813 return SCTP_DISPOSITION_DELETE_TCB;
5814 }
5815 }
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5846
5847
5848 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
5849
5850 return SCTP_DISPOSITION_CONSUME;
5851 }
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868 enum sctp_disposition sctp_sf_do_6_2_sack(struct net *net,
5869 const struct sctp_endpoint *ep,
5870 const struct sctp_association *asoc,
5871 const union sctp_subtype type,
5872 void *arg,
5873 struct sctp_cmd_seq *commands)
5874 {
5875 SCTP_INC_STATS(net, SCTP_MIB_DELAY_SACK_EXPIREDS);
5876 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
5877 return SCTP_DISPOSITION_CONSUME;
5878 }
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899 enum sctp_disposition sctp_sf_t1_init_timer_expire(
5900 struct net *net,
5901 const struct sctp_endpoint *ep,
5902 const struct sctp_association *asoc,
5903 const union sctp_subtype type,
5904 void *arg,
5905 struct sctp_cmd_seq *commands)
5906 {
5907 int attempts = asoc->init_err_counter + 1;
5908 struct sctp_chunk *repl = NULL;
5909 struct sctp_bind_addr *bp;
5910
5911 pr_debug("%s: timer T1 expired (INIT)\n", __func__);
5912
5913 SCTP_INC_STATS(net, SCTP_MIB_T1_INIT_EXPIREDS);
5914
5915 if (attempts <= asoc->max_init_attempts) {
5916 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
5917 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
5918 if (!repl)
5919 return SCTP_DISPOSITION_NOMEM;
5920
5921
5922 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
5923 SCTP_CHUNK(repl));
5924
5925
5926 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
5927 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5928
5929 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5930 } else {
5931 pr_debug("%s: giving up on INIT, attempts:%d "
5932 "max_init_attempts:%d\n", __func__, attempts,
5933 asoc->max_init_attempts);
5934
5935 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5936 SCTP_ERROR(ETIMEDOUT));
5937 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5938 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5939 return SCTP_DISPOSITION_DELETE_TCB;
5940 }
5941
5942 return SCTP_DISPOSITION_CONSUME;
5943 }
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964 enum sctp_disposition sctp_sf_t1_cookie_timer_expire(
5965 struct net *net,
5966 const struct sctp_endpoint *ep,
5967 const struct sctp_association *asoc,
5968 const union sctp_subtype type,
5969 void *arg,
5970 struct sctp_cmd_seq *commands)
5971 {
5972 int attempts = asoc->init_err_counter + 1;
5973 struct sctp_chunk *repl = NULL;
5974
5975 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__);
5976
5977 SCTP_INC_STATS(net, SCTP_MIB_T1_COOKIE_EXPIREDS);
5978
5979 if (attempts <= asoc->max_init_attempts) {
5980 repl = sctp_make_cookie_echo(asoc, NULL);
5981 if (!repl)
5982 return SCTP_DISPOSITION_NOMEM;
5983
5984 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
5985 SCTP_CHUNK(repl));
5986
5987 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
5988 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
5989
5990 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5991 } else {
5992 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5993 SCTP_ERROR(ETIMEDOUT));
5994 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5995 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5996 return SCTP_DISPOSITION_DELETE_TCB;
5997 }
5998
5999 return SCTP_DISPOSITION_CONSUME;
6000 }
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015 enum sctp_disposition sctp_sf_t2_timer_expire(
6016 struct net *net,
6017 const struct sctp_endpoint *ep,
6018 const struct sctp_association *asoc,
6019 const union sctp_subtype type,
6020 void *arg,
6021 struct sctp_cmd_seq *commands)
6022 {
6023 struct sctp_chunk *reply = NULL;
6024
6025 pr_debug("%s: timer T2 expired\n", __func__);
6026
6027 SCTP_INC_STATS(net, SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
6028
6029 ((struct sctp_association *)asoc)->shutdown_retries++;
6030
6031 if (asoc->overall_error_count >= asoc->max_retrans) {
6032 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
6033 SCTP_ERROR(ETIMEDOUT));
6034
6035 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
6036 SCTP_PERR(SCTP_ERROR_NO_ERROR));
6037 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
6038 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
6039 return SCTP_DISPOSITION_DELETE_TCB;
6040 }
6041
6042 switch (asoc->state) {
6043 case SCTP_STATE_SHUTDOWN_SENT:
6044 reply = sctp_make_shutdown(asoc, NULL);
6045 break;
6046
6047 case SCTP_STATE_SHUTDOWN_ACK_SENT:
6048 reply = sctp_make_shutdown_ack(asoc, NULL);
6049 break;
6050
6051 default:
6052 BUG();
6053 break;
6054 }
6055
6056 if (!reply)
6057 goto nomem;
6058
6059
6060
6061
6062
6063 if (asoc->shutdown_last_sent_to)
6064 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
6065 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
6066
6067
6068
6069
6070 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
6071
6072
6073 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
6074 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
6075 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
6076 return SCTP_DISPOSITION_CONSUME;
6077
6078 nomem:
6079 return SCTP_DISPOSITION_NOMEM;
6080 }
6081
6082
6083
6084
6085
6086 enum sctp_disposition sctp_sf_t4_timer_expire(
6087 struct net *net,
6088 const struct sctp_endpoint *ep,
6089 const struct sctp_association *asoc,
6090 const union sctp_subtype type,
6091 void *arg,
6092 struct sctp_cmd_seq *commands)
6093 {
6094 struct sctp_chunk *chunk = asoc->addip_last_asconf;
6095 struct sctp_transport *transport = chunk->transport;
6096
6097 SCTP_INC_STATS(net, SCTP_MIB_T4_RTO_EXPIREDS);
6098
6099
6100
6101
6102
6103 if (transport)
6104 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
6105 SCTP_TRANSPORT(transport));
6106
6107
6108 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
6109
6110
6111
6112
6113
6114
6115 if (asoc->overall_error_count >= asoc->max_retrans) {
6116 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
6117 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
6118 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
6119 SCTP_ERROR(ETIMEDOUT));
6120 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
6121 SCTP_PERR(SCTP_ERROR_NO_ERROR));
6122 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
6123 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
6124 return SCTP_DISPOSITION_ABORT;
6125 }
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138 sctp_chunk_hold(asoc->addip_last_asconf);
6139 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
6140 SCTP_CHUNK(asoc->addip_last_asconf));
6141
6142
6143
6144
6145
6146 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
6147 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
6148
6149 return SCTP_DISPOSITION_CONSUME;
6150 }
6151
6152
6153
6154
6155
6156
6157
6158 enum sctp_disposition sctp_sf_t5_timer_expire(
6159 struct net *net,
6160 const struct sctp_endpoint *ep,
6161 const struct sctp_association *asoc,
6162 const union sctp_subtype type,
6163 void *arg,
6164 struct sctp_cmd_seq *commands)
6165 {
6166 struct sctp_chunk *reply = NULL;
6167
6168 pr_debug("%s: timer T5 expired\n", __func__);
6169
6170 SCTP_INC_STATS(net, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
6171
6172 reply = sctp_make_abort(asoc, NULL, 0);
6173 if (!reply)
6174 goto nomem;
6175
6176 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
6177 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
6178 SCTP_ERROR(ETIMEDOUT));
6179 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
6180 SCTP_PERR(SCTP_ERROR_NO_ERROR));
6181
6182 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
6183 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
6184
6185 return SCTP_DISPOSITION_DELETE_TCB;
6186 nomem:
6187 return SCTP_DISPOSITION_NOMEM;
6188 }
6189
6190
6191
6192
6193
6194
6195 enum sctp_disposition sctp_sf_autoclose_timer_expire(
6196 struct net *net,
6197 const struct sctp_endpoint *ep,
6198 const struct sctp_association *asoc,
6199 const union sctp_subtype type,
6200 void *arg,
6201 struct sctp_cmd_seq *commands)
6202 {
6203 enum sctp_disposition disposition;
6204
6205 SCTP_INC_STATS(net, SCTP_MIB_AUTOCLOSE_EXPIREDS);
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
6216 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
6217
6218 disposition = SCTP_DISPOSITION_CONSUME;
6219 if (sctp_outq_is_empty(&asoc->outqueue)) {
6220 disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type,
6221 NULL, commands);
6222 }
6223
6224 return disposition;
6225 }
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239 enum sctp_disposition sctp_sf_not_impl(struct net *net,
6240 const struct sctp_endpoint *ep,
6241 const struct sctp_association *asoc,
6242 const union sctp_subtype type,
6243 void *arg, struct sctp_cmd_seq *commands)
6244 {
6245 return SCTP_DISPOSITION_NOT_IMPL;
6246 }
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256 enum sctp_disposition sctp_sf_bug(struct net *net,
6257 const struct sctp_endpoint *ep,
6258 const struct sctp_association *asoc,
6259 const union sctp_subtype type,
6260 void *arg, struct sctp_cmd_seq *commands)
6261 {
6262 return SCTP_DISPOSITION_BUG;
6263 }
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276 enum sctp_disposition sctp_sf_timer_ignore(struct net *net,
6277 const struct sctp_endpoint *ep,
6278 const struct sctp_association *asoc,
6279 const union sctp_subtype type,
6280 void *arg,
6281 struct sctp_cmd_seq *commands)
6282 {
6283 pr_debug("%s: timer %d ignored\n", __func__, type.chunk);
6284
6285 return SCTP_DISPOSITION_CONSUME;
6286 }
6287
6288
6289
6290
6291
6292
6293 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
6294 {
6295 struct sctp_sackhdr *sack;
6296 __u16 num_dup_tsns;
6297 unsigned int len;
6298 __u16 num_blocks;
6299
6300
6301
6302
6303 sack = (struct sctp_sackhdr *) chunk->skb->data;
6304
6305 num_blocks = ntohs(sack->num_gap_ack_blocks);
6306 num_dup_tsns = ntohs(sack->num_dup_tsns);
6307 len = sizeof(struct sctp_sackhdr);
6308 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
6309 if (len > chunk->skb->len)
6310 return NULL;
6311
6312 skb_pull(chunk->skb, len);
6313
6314 return sack;
6315 }
6316
6317
6318
6319
6320 static struct sctp_packet *sctp_abort_pkt_new(
6321 struct net *net,
6322 const struct sctp_endpoint *ep,
6323 const struct sctp_association *asoc,
6324 struct sctp_chunk *chunk,
6325 const void *payload, size_t paylen)
6326 {
6327 struct sctp_packet *packet;
6328 struct sctp_chunk *abort;
6329
6330 packet = sctp_ootb_pkt_new(net, asoc, chunk);
6331
6332 if (packet) {
6333
6334
6335
6336 abort = sctp_make_abort(asoc, chunk, paylen);
6337 if (!abort) {
6338 sctp_ootb_pkt_free(packet);
6339 return NULL;
6340 }
6341
6342
6343 if (sctp_test_T_bit(abort))
6344 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
6345
6346
6347
6348
6349 sctp_addto_chunk(abort, paylen, payload);
6350
6351
6352 abort->skb->sk = ep->base.sk;
6353
6354 sctp_packet_append_chunk(packet, abort);
6355
6356 }
6357
6358 return packet;
6359 }
6360
6361
6362 static struct sctp_packet *sctp_ootb_pkt_new(
6363 struct net *net,
6364 const struct sctp_association *asoc,
6365 const struct sctp_chunk *chunk)
6366 {
6367 struct sctp_transport *transport;
6368 struct sctp_packet *packet;
6369 __u16 sport, dport;
6370 __u32 vtag;
6371
6372
6373 sport = ntohs(chunk->sctp_hdr->dest);
6374 dport = ntohs(chunk->sctp_hdr->source);
6375
6376
6377
6378
6379 if (asoc) {
6380
6381
6382
6383 switch (chunk->chunk_hdr->type) {
6384 case SCTP_CID_INIT:
6385 case SCTP_CID_INIT_ACK:
6386 {
6387 struct sctp_initack_chunk *initack;
6388
6389 initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
6390 vtag = ntohl(initack->init_hdr.init_tag);
6391 break;
6392 }
6393 default:
6394 vtag = asoc->peer.i.init_tag;
6395 break;
6396 }
6397 } else {
6398
6399
6400
6401 switch (chunk->chunk_hdr->type) {
6402 case SCTP_CID_INIT:
6403 {
6404 struct sctp_init_chunk *init;
6405
6406 init = (struct sctp_init_chunk *)chunk->chunk_hdr;
6407 vtag = ntohl(init->init_hdr.init_tag);
6408 break;
6409 }
6410 default:
6411 vtag = ntohl(chunk->sctp_hdr->vtag);
6412 break;
6413 }
6414 }
6415
6416
6417 transport = sctp_transport_new(net, sctp_source(chunk), GFP_ATOMIC);
6418 if (!transport)
6419 goto nomem;
6420
6421 transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
6422
6423
6424
6425
6426 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
6427 sctp_sk(net->sctp.ctl_sock));
6428
6429 packet = &transport->packet;
6430 sctp_packet_init(packet, transport, sport, dport);
6431 sctp_packet_config(packet, vtag, 0);
6432
6433 return packet;
6434
6435 nomem:
6436 return NULL;
6437 }
6438
6439
6440 void sctp_ootb_pkt_free(struct sctp_packet *packet)
6441 {
6442 sctp_transport_free(packet->transport);
6443 }
6444
6445
6446 static void sctp_send_stale_cookie_err(struct net *net,
6447 const struct sctp_endpoint *ep,
6448 const struct sctp_association *asoc,
6449 const struct sctp_chunk *chunk,
6450 struct sctp_cmd_seq *commands,
6451 struct sctp_chunk *err_chunk)
6452 {
6453 struct sctp_packet *packet;
6454
6455 if (err_chunk) {
6456 packet = sctp_ootb_pkt_new(net, asoc, chunk);
6457 if (packet) {
6458 struct sctp_signed_cookie *cookie;
6459
6460
6461 cookie = chunk->subh.cookie_hdr;
6462 packet->vtag = cookie->c.peer_vtag;
6463
6464
6465 err_chunk->skb->sk = ep->base.sk;
6466 sctp_packet_append_chunk(packet, err_chunk);
6467 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
6468 SCTP_PACKET(packet));
6469 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
6470 } else
6471 sctp_chunk_free (err_chunk);
6472 }
6473 }
6474
6475
6476
6477 static int sctp_eat_data(const struct sctp_association *asoc,
6478 struct sctp_chunk *chunk,
6479 struct sctp_cmd_seq *commands)
6480 {
6481 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
6482 struct sock *sk = asoc->base.sk;
6483 struct net *net = sock_net(sk);
6484 struct sctp_datahdr *data_hdr;
6485 struct sctp_chunk *err;
6486 enum sctp_verb deliver;
6487 size_t datalen;
6488 __u32 tsn;
6489 int tmp;
6490
6491 data_hdr = (struct sctp_datahdr *)chunk->skb->data;
6492 chunk->subh.data_hdr = data_hdr;
6493 skb_pull(chunk->skb, sctp_datahdr_len(&asoc->stream));
6494
6495 tsn = ntohl(data_hdr->tsn);
6496 pr_debug("%s: TSN 0x%x\n", __func__, tsn);
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510 if (asoc->peer.ecn_capable && !chunk->ecn_ce_done) {
6511 struct sctp_af *af = SCTP_INPUT_CB(chunk->skb)->af;
6512 chunk->ecn_ce_done = 1;
6513
6514 if (af->is_ce(sctp_gso_headskb(chunk->skb))) {
6515
6516 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
6517 SCTP_U32(tsn));
6518 }
6519 }
6520
6521 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
6522 if (tmp < 0) {
6523
6524
6525
6526 if (chunk->asoc)
6527 chunk->asoc->stats.outofseqtsns++;
6528 return SCTP_IERROR_HIGH_TSN;
6529 } else if (tmp > 0) {
6530
6531 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
6532 return SCTP_IERROR_DUP_TSN;
6533 }
6534
6535
6536
6537
6538
6539
6540 datalen = ntohs(chunk->chunk_hdr->length);
6541 datalen -= sctp_datachk_len(&asoc->stream);
6542
6543 deliver = SCTP_CMD_CHUNK_ULP;
6544
6545
6546 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
6547
6548
6549
6550
6551 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
6552 }
6553
6554
6555
6556
6557
6558
6559 if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over ||
6560 (datalen > asoc->rwnd + asoc->frag_point))) {
6561
6562
6563
6564
6565
6566
6567
6568 if (sctp_tsnmap_has_gap(map) &&
6569 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
6570 pr_debug("%s: reneging for tsn:%u\n", __func__, tsn);
6571 deliver = SCTP_CMD_RENEGE;
6572 } else {
6573 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6574 __func__, tsn, datalen, asoc->rwnd);
6575
6576 return SCTP_IERROR_IGNORE_TSN;
6577 }
6578 }
6579
6580
6581
6582
6583
6584
6585
6586
6587 if (sk_under_memory_pressure(sk)) {
6588 if (sctp_tsnmap_has_gap(map) &&
6589 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
6590 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6591 __func__, tsn);
6592 deliver = SCTP_CMD_RENEGE;
6593 }
6594 }
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604 if (unlikely(0 == datalen)) {
6605 err = sctp_make_abort_no_data(asoc, chunk, tsn);
6606 if (err) {
6607 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
6608 SCTP_CHUNK(err));
6609 }
6610
6611
6612
6613 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
6614 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
6615 SCTP_ERROR(ECONNABORTED));
6616 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
6617 SCTP_PERR(SCTP_ERROR_NO_DATA));
6618 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
6619 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
6620 return SCTP_IERROR_NO_DATA;
6621 }
6622
6623 chunk->data_accepted = 1;
6624
6625
6626
6627
6628 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
6629 SCTP_INC_STATS(net, SCTP_MIB_INUNORDERCHUNKS);
6630 if (chunk->asoc)
6631 chunk->asoc->stats.iuodchunks++;
6632 } else {
6633 SCTP_INC_STATS(net, SCTP_MIB_INORDERCHUNKS);
6634 if (chunk->asoc)
6635 chunk->asoc->stats.iodchunks++;
6636 }
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646 if (ntohs(data_hdr->stream) >= asoc->stream.incnt) {
6647
6648 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
6649
6650 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
6651 &data_hdr->stream,
6652 sizeof(data_hdr->stream),
6653 sizeof(u16));
6654 if (err)
6655 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
6656 SCTP_CHUNK(err));
6657 return SCTP_IERROR_BAD_STREAM;
6658 }
6659
6660
6661
6662
6663
6664
6665
6666
6667 if (!asoc->stream.si->validate_data(chunk))
6668 return SCTP_IERROR_PROTO_VIOLATION;
6669
6670
6671
6672
6673
6674 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
6675
6676 return SCTP_IERROR_NO_ERROR;
6677 }