Thomas Gleixner | 47505b8 | 2019-05-23 11:14:41 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 2 | /* SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * (C) Copyright IBM Corp. 2001, 2004 |
| 4 | * Copyright (c) 1999-2000 Cisco, Inc. |
| 5 | * Copyright (c) 1999-2001 Motorola, Inc. |
| 6 | * Copyright (c) 2001-2002 Intel Corp. |
| 7 | * Copyright (c) 2002 Nokia Corp. |
| 8 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 9 | * This is part of the SCTP Linux Kernel Implementation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * These are the state functions for the state machine. |
| 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * Please send any bug reports or fixes you make to the |
| 14 | * email address(es): |
Daniel Borkmann | 91705c6 | 2013-07-23 14:51:47 +0200 | [diff] [blame] | 15 | * lksctp developers <linux-sctp@vger.kernel.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * Written or modified by: |
| 18 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 19 | * Karl Knutson <karl@athena.chicago.il.us> |
| 20 | * Mathew Kotowsky <kotowsky@sctp.org> |
| 21 | * Sridhar Samudrala <samudrala@us.ibm.com> |
| 22 | * Jon Grimm <jgrimm@us.ibm.com> |
| 23 | * Hui Huang <hui.huang@nokia.com> |
| 24 | * Dajiang Zhang <dajiang.zhang@nokia.com> |
| 25 | * Daisy Chang <daisyc@us.ibm.com> |
| 26 | * Ardelle Fan <ardelle.fan@intel.com> |
| 27 | * Ryan Layer <rmlayer@us.ibm.com> |
| 28 | * Kevin Gao <kevin.gao@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
| 30 | |
Joe Perches | 145ce50 | 2010-08-24 13:21:08 +0000 | [diff] [blame] | 31 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/types.h> |
| 34 | #include <linux/kernel.h> |
| 35 | #include <linux/ip.h> |
| 36 | #include <linux/ipv6.h> |
| 37 | #include <linux/net.h> |
| 38 | #include <linux/inet.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 39 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <net/sock.h> |
| 41 | #include <net/inet_ecn.h> |
| 42 | #include <linux/skbuff.h> |
| 43 | #include <net/sctp/sctp.h> |
| 44 | #include <net/sctp/sm.h> |
| 45 | #include <net/sctp/structs.h> |
| 46 | |
Masami Hiramatsu | 103d750 | 2017-12-29 11:46:51 +0900 | [diff] [blame] | 47 | #define CREATE_TRACE_POINTS |
| 48 | #include <trace/events/sctp.h> |
| 49 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 50 | static struct sctp_packet *sctp_abort_pkt_new( |
| 51 | struct net *net, |
| 52 | const struct sctp_endpoint *ep, |
| 53 | const struct sctp_association *asoc, |
| 54 | struct sctp_chunk *chunk, |
| 55 | const void *payload, size_t paylen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | static int sctp_eat_data(const struct sctp_association *asoc, |
| 57 | struct sctp_chunk *chunk, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 58 | struct sctp_cmd_seq *commands); |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 59 | static struct sctp_packet *sctp_ootb_pkt_new( |
| 60 | struct net *net, |
| 61 | const struct sctp_association *asoc, |
| 62 | const struct sctp_chunk *chunk); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 63 | static void sctp_send_stale_cookie_err(struct net *net, |
| 64 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | const struct sctp_association *asoc, |
| 66 | const struct sctp_chunk *chunk, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 67 | struct sctp_cmd_seq *commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | struct sctp_chunk *err_chunk); |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 69 | static enum sctp_disposition sctp_sf_do_5_2_6_stale( |
| 70 | struct net *net, |
| 71 | const struct sctp_endpoint *ep, |
| 72 | const struct sctp_association *asoc, |
| 73 | const union sctp_subtype type, |
| 74 | void *arg, |
| 75 | struct sctp_cmd_seq *commands); |
| 76 | static enum sctp_disposition sctp_sf_shut_8_4_5( |
| 77 | struct net *net, |
| 78 | const struct sctp_endpoint *ep, |
| 79 | const struct sctp_association *asoc, |
| 80 | const union sctp_subtype type, |
| 81 | void *arg, |
| 82 | struct sctp_cmd_seq *commands); |
| 83 | static enum sctp_disposition sctp_sf_tabort_8_4_8( |
| 84 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 85 | const struct sctp_endpoint *ep, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 86 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 87 | const union sctp_subtype type, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 88 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 89 | struct sctp_cmd_seq *commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk); |
| 91 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 92 | static enum sctp_disposition sctp_stop_t1_and_abort( |
| 93 | struct net *net, |
| 94 | struct sctp_cmd_seq *commands, |
| 95 | __be16 error, int sk_err, |
| 96 | const struct sctp_association *asoc, |
| 97 | struct sctp_transport *transport); |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 98 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 99 | static enum sctp_disposition sctp_sf_abort_violation( |
| 100 | struct net *net, |
| 101 | const struct sctp_endpoint *ep, |
| 102 | const struct sctp_association *asoc, |
| 103 | void *arg, |
| 104 | struct sctp_cmd_seq *commands, |
| 105 | const __u8 *payload, |
| 106 | const size_t paylen); |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 107 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 108 | static enum sctp_disposition sctp_sf_violation_chunklen( |
| 109 | struct net *net, |
| 110 | const struct sctp_endpoint *ep, |
| 111 | const struct sctp_association *asoc, |
| 112 | const union sctp_subtype type, |
| 113 | void *arg, |
| 114 | struct sctp_cmd_seq *commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 116 | static enum sctp_disposition sctp_sf_violation_paramlen( |
| 117 | struct net *net, |
| 118 | const struct sctp_endpoint *ep, |
| 119 | const struct sctp_association *asoc, |
| 120 | const union sctp_subtype type, |
| 121 | void *arg, void *ext, |
| 122 | struct sctp_cmd_seq *commands); |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 123 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 124 | static enum sctp_disposition sctp_sf_violation_ctsn( |
| 125 | struct net *net, |
| 126 | const struct sctp_endpoint *ep, |
| 127 | const struct sctp_association *asoc, |
| 128 | const union sctp_subtype type, |
| 129 | void *arg, |
| 130 | struct sctp_cmd_seq *commands); |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 131 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 132 | static enum sctp_disposition sctp_sf_violation_chunk( |
| 133 | struct net *net, |
| 134 | const struct sctp_endpoint *ep, |
| 135 | const struct sctp_association *asoc, |
| 136 | const union sctp_subtype type, |
| 137 | void *arg, |
| 138 | struct sctp_cmd_seq *commands); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 139 | |
Xin Long | 4785c7a | 2017-08-05 19:59:58 +0800 | [diff] [blame] | 140 | static enum sctp_ierror sctp_sf_authenticate( |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 141 | const struct sctp_association *asoc, |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 142 | struct sctp_chunk *chunk); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 143 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 144 | static enum sctp_disposition __sctp_sf_do_9_1_abort( |
| 145 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 146 | const struct sctp_endpoint *ep, |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 147 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 148 | const union sctp_subtype type, |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 149 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 150 | struct sctp_cmd_seq *commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* Small helper function that checks if the chunk length |
| 153 | * is of the appropriate length. The 'required_length' argument |
| 154 | * is set to be the size of a specific chunk we are testing. |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 155 | * Return Values: true = Valid length |
| 156 | * false = Invalid length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | * |
| 158 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 159 | static inline bool sctp_chunk_length_valid(struct sctp_chunk *chunk, |
| 160 | __u16 required_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
| 162 | __u16 chunk_length = ntohs(chunk->chunk_hdr->length); |
| 163 | |
Daniel Borkmann | 26b87c7 | 2014-10-09 22:55:33 +0200 | [diff] [blame] | 164 | /* Previously already marked? */ |
| 165 | if (unlikely(chunk->pdiscard)) |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 166 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | if (unlikely(chunk_length < required_length)) |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 168 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 170 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /********************************************************** |
| 174 | * These are the state functions for handling chunk events. |
| 175 | **********************************************************/ |
| 176 | |
| 177 | /* |
| 178 | * Process the final SHUTDOWN COMPLETE. |
| 179 | * |
| 180 | * Section: 4 (C) (diagram), 9.2 |
| 181 | * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify |
| 182 | * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be |
| 183 | * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint |
| 184 | * should stop the T2-shutdown timer and remove all knowledge of the |
| 185 | * association (and thus the association enters the CLOSED state). |
| 186 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 187 | * Verification Tag: 8.5.1(C), sctpimpguide 2.41. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | * C) Rules for packet carrying SHUTDOWN COMPLETE: |
| 189 | * ... |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 190 | * - The receiver of a SHUTDOWN COMPLETE shall accept the packet |
| 191 | * if the Verification Tag field of the packet matches its own tag and |
| 192 | * the T bit is not set |
| 193 | * OR |
| 194 | * it is set to its peer's tag and the T bit is set in the Chunk |
| 195 | * Flags. |
| 196 | * Otherwise, the receiver MUST silently discard the packet |
| 197 | * and take no further action. An endpoint MUST ignore the |
| 198 | * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | * |
| 200 | * Inputs |
| 201 | * (endpoint, asoc, chunk) |
| 202 | * |
| 203 | * Outputs |
| 204 | * (asoc, reply_msg, msg_up, timers, counters) |
| 205 | * |
| 206 | * The return value is the disposition of the chunk. |
| 207 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 208 | enum sctp_disposition sctp_sf_do_4_C(struct net *net, |
| 209 | const struct sctp_endpoint *ep, |
| 210 | const struct sctp_association *asoc, |
| 211 | const union sctp_subtype type, |
| 212 | void *arg, struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
| 214 | struct sctp_chunk *chunk = arg; |
| 215 | struct sctp_ulpevent *ev; |
| 216 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 217 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 218 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | /* RFC 2960 6.10 Bundling |
| 221 | * |
| 222 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 223 | * SHUTDOWN COMPLETE with any other chunks. |
| 224 | */ |
| 225 | if (!chunk->singleton) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 226 | return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 228 | /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 229 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 230 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 231 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | /* RFC 2960 10.2 SCTP-to-ULP |
| 234 | * |
| 235 | * H) SHUTDOWN COMPLETE notification |
| 236 | * |
| 237 | * When SCTP completes the shutdown procedures (section 9.2) this |
| 238 | * notification is passed to the upper layer. |
| 239 | */ |
| 240 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 241 | 0, 0, 0, NULL, GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 242 | if (ev) |
| 243 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 244 | SCTP_ULPEVENT(ev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint |
| 247 | * will verify that it is in SHUTDOWN-ACK-SENT state, if it is |
| 248 | * not the chunk should be discarded. If the endpoint is in |
| 249 | * the SHUTDOWN-ACK-SENT state the endpoint should stop the |
| 250 | * T2-shutdown timer and remove all knowledge of the |
| 251 | * association (and thus the association enters the CLOSED |
| 252 | * state). |
| 253 | */ |
| 254 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 255 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 256 | |
| 257 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 258 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 259 | |
| 260 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 261 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 262 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 263 | SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS); |
| 264 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 267 | |
| 268 | return SCTP_DISPOSITION_DELETE_TCB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Respond to a normal INIT chunk. |
| 273 | * We are the side that is being asked for an association. |
| 274 | * |
| 275 | * Section: 5.1 Normal Establishment of an Association, B |
| 276 | * B) "Z" shall respond immediately with an INIT ACK chunk. The |
| 277 | * destination IP address of the INIT ACK MUST be set to the source |
| 278 | * IP address of the INIT to which this INIT ACK is responding. In |
| 279 | * the response, besides filling in other parameters, "Z" must set the |
| 280 | * Verification Tag field to Tag_A, and also provide its own |
| 281 | * Verification Tag (Tag_Z) in the Initiate Tag field. |
| 282 | * |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 283 | * Verification Tag: Must be 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | * |
| 285 | * Inputs |
| 286 | * (endpoint, asoc, chunk) |
| 287 | * |
| 288 | * Outputs |
| 289 | * (asoc, reply_msg, msg_up, timers, counters) |
| 290 | * |
| 291 | * The return value is the disposition of the chunk. |
| 292 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 293 | enum sctp_disposition sctp_sf_do_5_1B_init(struct net *net, |
| 294 | const struct sctp_endpoint *ep, |
| 295 | const struct sctp_association *asoc, |
| 296 | const union sctp_subtype type, |
| 297 | void *arg, |
| 298 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 300 | struct sctp_chunk *chunk = arg, *repl, *err_chunk; |
| 301 | struct sctp_unrecognized_param *unk_param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | struct sctp_association *new_asoc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | struct sctp_packet *packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | int len; |
| 305 | |
Richard Haines | 2277c7c | 2018-02-13 20:56:24 +0000 | [diff] [blame] | 306 | /* Update socket peer label if first association. */ |
| 307 | if (security_sctp_assoc_request((struct sctp_endpoint *)ep, |
| 308 | chunk->skb)) |
| 309 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | /* 6.10 Bundling |
| 312 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 313 | * SHUTDOWN COMPLETE with any other chunks. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 314 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | * IG Section 2.11.2 |
| 316 | * Furthermore, we require that the receiver of an INIT chunk MUST |
| 317 | * enforce these rules by silently discarding an arriving packet |
| 318 | * with an INIT chunk that is bundled with other chunks. |
| 319 | */ |
| 320 | if (!chunk->singleton) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 321 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | /* If the packet is an OOTB packet which is temporarily on the |
| 324 | * control endpoint, respond with an ABORT. |
| 325 | */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 326 | if (ep == sctp_sk(net->sctp.ctl_sock)->ep) { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 327 | SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 328 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | /* 3.1 A packet containing an INIT chunk MUST have a zero Verification |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 332 | * Tag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | */ |
| 334 | if (chunk->sctp_hdr->vtag != 0) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 335 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | /* Make sure that the INIT chunk has a valid length. |
| 338 | * Normally, this would cause an ABORT with a Protocol Violation |
| 339 | * error, but since we don't have an association, we'll |
| 340 | * just discard the packet. |
| 341 | */ |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 342 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 343 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Vlad Yasevich | bec9640 | 2009-07-30 18:08:28 -0400 | [diff] [blame] | 345 | /* If the INIT is coming toward a closing socket, we'll send back |
| 346 | * and ABORT. Essentially, this catches the race of INIT being |
| 347 | * backloged to the socket at the same time as the user isses close(). |
| 348 | * Since the socket and all its associations are going away, we |
| 349 | * can treat this OOTB |
| 350 | */ |
| 351 | if (sctp_sstate(ep->base.sk, CLOSING)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 352 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | bec9640 | 2009-07-30 18:08:28 -0400 | [diff] [blame] | 353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | /* Verify the INIT chunk before processing it. */ |
| 355 | err_chunk = NULL; |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 356 | if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type, |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 357 | (struct sctp_init_chunk *)chunk->chunk_hdr, chunk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | &err_chunk)) { |
| 359 | /* This chunk contains fatal error. It is to be discarded. |
| 360 | * Send an ABORT, with causes if there is any. |
| 361 | */ |
| 362 | if (err_chunk) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 363 | packet = sctp_abort_pkt_new(net, ep, asoc, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | (__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 365 | sizeof(struct sctp_chunkhdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 367 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | sctp_chunk_free(err_chunk); |
| 370 | |
| 371 | if (packet) { |
| 372 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 373 | SCTP_PACKET(packet)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 374 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return SCTP_DISPOSITION_CONSUME; |
| 376 | } else { |
| 377 | return SCTP_DISPOSITION_NOMEM; |
| 378 | } |
| 379 | } else { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 380 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | commands); |
| 382 | } |
| 383 | } |
| 384 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 385 | /* Grab the INIT header. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 386 | chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | /* Tag the variable length parameters. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 389 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); |
| 392 | if (!new_asoc) |
| 393 | goto nomem; |
| 394 | |
Vlad Yasevich | 409b95a | 2009-11-10 08:57:34 +0000 | [diff] [blame] | 395 | if (sctp_assoc_set_bind_addr_from_ep(new_asoc, |
| 396 | sctp_scope(sctp_source(chunk)), |
| 397 | GFP_ATOMIC) < 0) |
| 398 | goto nomem_init; |
| 399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | /* The call, sctp_process_init(), can fail on memory allocation. */ |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 401 | if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 402 | (struct sctp_init_chunk *)chunk->chunk_hdr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | GFP_ATOMIC)) |
| 404 | goto nomem_init; |
| 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | /* B) "Z" shall respond immediately with an INIT ACK chunk. */ |
| 407 | |
| 408 | /* If there are errors need to be reported for unknown parameters, |
| 409 | * make sure to reserve enough room in the INIT ACK for them. |
| 410 | */ |
| 411 | len = 0; |
| 412 | if (err_chunk) |
| 413 | len = ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 414 | sizeof(struct sctp_chunkhdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); |
| 417 | if (!repl) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 418 | goto nomem_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | /* If there are errors need to be reported for unknown parameters, |
| 421 | * include them in the outgoing INIT ACK as "Unrecognized parameter" |
| 422 | * parameter. |
| 423 | */ |
| 424 | if (err_chunk) { |
| 425 | /* Get the "Unrecognized parameter" parameter(s) out of the |
| 426 | * ERROR chunk generated by sctp_verify_init(). Since the |
| 427 | * error cause code for "unknown parameter" and the |
| 428 | * "Unrecognized parameter" type is the same, we can |
| 429 | * construct the parameters in INIT ACK by copying the |
| 430 | * ERROR causes over. |
| 431 | */ |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 432 | unk_param = (struct sctp_unrecognized_param *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | ((__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 434 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | /* Replace the cause code with the "Unrecognized parameter" |
| 436 | * parameter type. |
| 437 | */ |
| 438 | sctp_addto_chunk(repl, len, unk_param); |
| 439 | sctp_chunk_free(err_chunk); |
| 440 | } |
| 441 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 442 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 445 | |
| 446 | /* |
| 447 | * Note: After sending out INIT ACK with the State Cookie parameter, |
| 448 | * "Z" MUST NOT allocate any resources, nor keep any states for the |
| 449 | * new association. Otherwise, "Z" will be vulnerable to resource |
| 450 | * attacks. |
| 451 | */ |
| 452 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 453 | |
| 454 | return SCTP_DISPOSITION_DELETE_TCB; |
| 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | nomem_init: |
| 457 | sctp_association_free(new_asoc); |
| 458 | nomem: |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 459 | if (err_chunk) |
| 460 | sctp_chunk_free(err_chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | return SCTP_DISPOSITION_NOMEM; |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Respond to a normal INIT ACK chunk. |
| 466 | * We are the side that is initiating the association. |
| 467 | * |
| 468 | * Section: 5.1 Normal Establishment of an Association, C |
| 469 | * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init |
| 470 | * timer and leave COOKIE-WAIT state. "A" shall then send the State |
| 471 | * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start |
| 472 | * the T1-cookie timer, and enter the COOKIE-ECHOED state. |
| 473 | * |
| 474 | * Note: The COOKIE ECHO chunk can be bundled with any pending outbound |
| 475 | * DATA chunks, but it MUST be the first chunk in the packet and |
| 476 | * until the COOKIE ACK is returned the sender MUST NOT send any |
| 477 | * other packets to the peer. |
| 478 | * |
| 479 | * Verification Tag: 3.3.3 |
| 480 | * If the value of the Initiate Tag in a received INIT ACK chunk is |
| 481 | * found to be 0, the receiver MUST treat it as an error and close the |
| 482 | * association by transmitting an ABORT. |
| 483 | * |
| 484 | * Inputs |
| 485 | * (endpoint, asoc, chunk) |
| 486 | * |
| 487 | * Outputs |
| 488 | * (asoc, reply_msg, msg_up, timers, counters) |
| 489 | * |
| 490 | * The return value is the disposition of the chunk. |
| 491 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 492 | enum sctp_disposition sctp_sf_do_5_1C_ack(struct net *net, |
| 493 | const struct sctp_endpoint *ep, |
| 494 | const struct sctp_association *asoc, |
| 495 | const union sctp_subtype type, |
| 496 | void *arg, |
| 497 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 499 | struct sctp_init_chunk *initchunk; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 500 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | struct sctp_chunk *err_chunk; |
| 502 | struct sctp_packet *packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 505 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* 6.10 Bundling |
| 508 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 509 | * SHUTDOWN COMPLETE with any other chunks. |
| 510 | */ |
| 511 | if (!chunk->singleton) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 512 | return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 514 | /* Make sure that the INIT-ACK chunk has a valid length */ |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 515 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_initack_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 516 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 517 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | /* Grab the INIT header. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 519 | chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* Verify the INIT chunk before processing it. */ |
| 522 | err_chunk = NULL; |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 523 | if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type, |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 524 | (struct sctp_init_chunk *)chunk->chunk_hdr, chunk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | &err_chunk)) { |
| 526 | |
Xin Long | 2a49321 | 2017-08-03 15:42:13 +0800 | [diff] [blame] | 527 | enum sctp_error error = SCTP_ERROR_NO_RESOURCE; |
Vlad Yasevich | 853f4b5 | 2008-01-20 06:10:46 -0800 | [diff] [blame] | 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | /* This chunk contains fatal error. It is to be discarded. |
Vlad Yasevich | d670119 | 2007-12-20 14:13:31 -0800 | [diff] [blame] | 530 | * Send an ABORT, with causes. If there are no causes, |
| 531 | * then there wasn't enough memory. Just terminate |
| 532 | * the association. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | */ |
| 534 | if (err_chunk) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 535 | packet = sctp_abort_pkt_new(net, ep, asoc, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | (__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 537 | sizeof(struct sctp_chunkhdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 539 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | sctp_chunk_free(err_chunk); |
| 542 | |
| 543 | if (packet) { |
| 544 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 545 | SCTP_PACKET(packet)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 546 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 547 | error = SCTP_ERROR_INV_PARAM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 550 | |
| 551 | /* SCTP-AUTH, Section 6.3: |
| 552 | * It should be noted that if the receiver wants to tear |
| 553 | * down an association in an authenticated way only, the |
| 554 | * handling of malformed packets should not result in |
| 555 | * tearing down the association. |
| 556 | * |
| 557 | * This means that if we only want to abort associations |
| 558 | * in an authenticated way (i.e AUTH+ABORT), then we |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 559 | * can't destroy this association just because the packet |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 560 | * was malformed. |
| 561 | */ |
| 562 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 563 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 564 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 565 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 566 | return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED, |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 567 | asoc, chunk->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /* Tag the variable length parameters. Note that we never |
| 571 | * convert the parameters in an INIT chunk. |
| 572 | */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 573 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 575 | initchunk = (struct sctp_init_chunk *)chunk->chunk_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT, |
| 578 | SCTP_PEER_INIT(initchunk)); |
| 579 | |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 580 | /* Reset init error count upon receipt of INIT-ACK. */ |
| 581 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); |
| 582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | /* 5.1 C) "A" shall stop the T1-init timer and leave |
| 584 | * COOKIE-WAIT state. "A" shall then ... start the T1-cookie |
| 585 | * timer, and enter the COOKIE-ECHOED state. |
| 586 | */ |
| 587 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 588 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 589 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 590 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 591 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 592 | SCTP_STATE(SCTP_STATE_COOKIE_ECHOED)); |
| 593 | |
Vlad Yasevich | 730fc3d | 2007-09-16 19:32:11 -0700 | [diff] [blame] | 594 | /* SCTP-AUTH: genereate the assocition shared keys so that |
| 595 | * we can potentially signe the COOKIE-ECHO. |
| 596 | */ |
| 597 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL()); |
| 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* 5.1 C) "A" shall then send the State Cookie received in the |
| 600 | * INIT ACK chunk in a COOKIE ECHO chunk, ... |
| 601 | */ |
| 602 | /* If there is any errors to report, send the ERROR chunk generated |
| 603 | * for unknown parameters as well. |
| 604 | */ |
| 605 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO, |
| 606 | SCTP_CHUNK(err_chunk)); |
| 607 | |
| 608 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Xin Long | 59d8d44 | 2018-05-05 14:59:47 +0800 | [diff] [blame] | 611 | static bool sctp_auth_chunk_verify(struct net *net, struct sctp_chunk *chunk, |
| 612 | const struct sctp_association *asoc) |
| 613 | { |
| 614 | struct sctp_chunk auth; |
| 615 | |
| 616 | if (!chunk->auth_chunk) |
| 617 | return true; |
| 618 | |
| 619 | /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo |
| 620 | * is supposed to be authenticated and we have to do delayed |
| 621 | * authentication. We've just recreated the association using |
| 622 | * the information in the cookie and now it's much easier to |
| 623 | * do the authentication. |
| 624 | */ |
| 625 | |
| 626 | /* Make sure that we and the peer are AUTH capable */ |
| 627 | if (!net->sctp.auth_enable || !asoc->peer.auth_capable) |
| 628 | return false; |
| 629 | |
| 630 | /* set-up our fake chunk so that we can process it */ |
| 631 | auth.skb = chunk->auth_chunk; |
| 632 | auth.asoc = chunk->asoc; |
| 633 | auth.sctp_hdr = chunk->sctp_hdr; |
| 634 | auth.chunk_hdr = (struct sctp_chunkhdr *) |
| 635 | skb_push(chunk->auth_chunk, |
| 636 | sizeof(struct sctp_chunkhdr)); |
| 637 | skb_pull(chunk->auth_chunk, sizeof(struct sctp_chunkhdr)); |
| 638 | auth.transport = chunk->transport; |
| 639 | |
| 640 | return sctp_sf_authenticate(asoc, &auth) == SCTP_IERROR_NO_ERROR; |
| 641 | } |
| 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | /* |
| 644 | * Respond to a normal COOKIE ECHO chunk. |
| 645 | * We are the side that is being asked for an association. |
| 646 | * |
| 647 | * Section: 5.1 Normal Establishment of an Association, D |
| 648 | * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply |
| 649 | * with a COOKIE ACK chunk after building a TCB and moving to |
| 650 | * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with |
| 651 | * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK |
| 652 | * chunk MUST be the first chunk in the packet. |
| 653 | * |
| 654 | * IMPLEMENTATION NOTE: An implementation may choose to send the |
| 655 | * Communication Up notification to the SCTP user upon reception |
| 656 | * of a valid COOKIE ECHO chunk. |
| 657 | * |
| 658 | * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules |
| 659 | * D) Rules for packet carrying a COOKIE ECHO |
| 660 | * |
| 661 | * - When sending a COOKIE ECHO, the endpoint MUST use the value of the |
| 662 | * Initial Tag received in the INIT ACK. |
| 663 | * |
| 664 | * - The receiver of a COOKIE ECHO follows the procedures in Section 5. |
| 665 | * |
| 666 | * Inputs |
| 667 | * (endpoint, asoc, chunk) |
| 668 | * |
| 669 | * Outputs |
| 670 | * (asoc, reply_msg, msg_up, timers, counters) |
| 671 | * |
| 672 | * The return value is the disposition of the chunk. |
| 673 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 674 | enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net, |
| 675 | const struct sctp_endpoint *ep, |
| 676 | const struct sctp_association *asoc, |
| 677 | const union sctp_subtype type, |
| 678 | void *arg, |
| 679 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 681 | struct sctp_ulpevent *ev, *ai_ev = NULL, *auth_ev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | struct sctp_association *new_asoc; |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 683 | struct sctp_init_chunk *peer_init; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 684 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | struct sctp_chunk *err_chk_p; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 686 | struct sctp_chunk *repl; |
Vlad Yasevich | 609ee46 | 2007-08-31 03:10:59 +0900 | [diff] [blame] | 687 | struct sock *sk; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 688 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | /* If the packet is an OOTB packet which is temporarily on the |
| 691 | * control endpoint, respond with an ABORT. |
| 692 | */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 693 | if (ep == sctp_sk(net->sctp.ctl_sock)->ep) { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 694 | SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 695 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 696 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
| 698 | /* Make sure that the COOKIE_ECHO chunk has a valid length. |
| 699 | * In this case, we check that we have enough for at least a |
| 700 | * chunk header. More detailed verification is done |
| 701 | * in sctp_unpack_cookie(). |
| 702 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 703 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 704 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Vlad Yasevich | 609ee46 | 2007-08-31 03:10:59 +0900 | [diff] [blame] | 706 | /* If the endpoint is not listening or if the number of associations |
| 707 | * on the TCP-style socket exceed the max backlog, respond with an |
| 708 | * ABORT. |
| 709 | */ |
| 710 | sk = ep->base.sk; |
| 711 | if (!sctp_sstate(sk, LISTENING) || |
| 712 | (sctp_style(sk, TCP) && sk_acceptq_is_full(sk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 713 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 609ee46 | 2007-08-31 03:10:59 +0900 | [diff] [blame] | 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | /* "Decode" the chunk. We have no optional parameters so we |
| 716 | * are in good shape. |
| 717 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 718 | chunk->subh.cookie_hdr = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | (struct sctp_signed_cookie *)chunk->skb->data; |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 720 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 721 | sizeof(struct sctp_chunkhdr))) |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 722 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint |
| 725 | * "Z" will reply with a COOKIE ACK chunk after building a TCB |
| 726 | * and moving to the ESTABLISHED state. |
| 727 | */ |
| 728 | new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, |
| 729 | &err_chk_p); |
| 730 | |
| 731 | /* FIXME: |
| 732 | * If the re-build failed, what is the proper error path |
| 733 | * from here? |
| 734 | * |
| 735 | * [We should abort the association. --piggy] |
| 736 | */ |
| 737 | if (!new_asoc) { |
| 738 | /* FIXME: Several errors are possible. A bad cookie should |
| 739 | * be silently discarded, but think about logging it too. |
| 740 | */ |
| 741 | switch (error) { |
| 742 | case -SCTP_IERROR_NOMEM: |
| 743 | goto nomem; |
| 744 | |
| 745 | case -SCTP_IERROR_STALE_COOKIE: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 746 | sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | err_chk_p); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 748 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | case -SCTP_IERROR_BAD_SIG: |
| 751 | default: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 752 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 753 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 757 | /* Delay state machine commands until later. |
| 758 | * |
| 759 | * Re-build the bind address for the association is done in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | * the sctp_unpack_cookie() already. |
| 761 | */ |
| 762 | /* This is a brand-new association, so these are not yet side |
| 763 | * effects--it is safe to run them here. |
| 764 | */ |
| 765 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
| 766 | |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 767 | if (!sctp_process_init(new_asoc, chunk, |
Al Viro | 6a1e5f3 | 2006-11-20 17:12:25 -0800 | [diff] [blame] | 768 | &chunk->subh.cookie_hdr->c.peer_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | peer_init, GFP_ATOMIC)) |
| 770 | goto nomem_init; |
| 771 | |
Vlad Yasevich | 730fc3d | 2007-09-16 19:32:11 -0700 | [diff] [blame] | 772 | /* SCTP-AUTH: Now that we've populate required fields in |
| 773 | * sctp_process_init, set up the assocaition shared keys as |
| 774 | * necessary so that we can potentially authenticate the ACK |
| 775 | */ |
| 776 | error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC); |
| 777 | if (error) |
| 778 | goto nomem_init; |
| 779 | |
Xin Long | 59d8d44 | 2018-05-05 14:59:47 +0800 | [diff] [blame] | 780 | if (!sctp_auth_chunk_verify(net, chunk, new_asoc)) { |
| 781 | sctp_association_free(new_asoc); |
| 782 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 786 | if (!repl) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 787 | goto nomem_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
| 789 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 790 | * |
| 791 | * D) IMPLEMENTATION NOTE: An implementation may choose to |
| 792 | * send the Communication Up notification to the SCTP user |
| 793 | * upon reception of a valid COOKIE ECHO chunk. |
| 794 | */ |
| 795 | ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0, |
| 796 | new_asoc->c.sinit_num_ostreams, |
| 797 | new_asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 798 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | if (!ev) |
| 800 | goto nomem_ev; |
| 801 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 802 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 803 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 805 | * peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 807 | if (new_asoc->peer.adaptation_ind) { |
| 808 | ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 810 | if (!ai_ev) |
| 811 | goto nomem_aiev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 814 | if (!new_asoc->peer.auth_capable) { |
| 815 | auth_ev = sctp_ulpevent_make_authkey(new_asoc, 0, |
| 816 | SCTP_AUTH_NO_AUTH, |
| 817 | GFP_ATOMIC); |
| 818 | if (!auth_ev) |
| 819 | goto nomem_authev; |
| 820 | } |
| 821 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 822 | /* Add all the state machine commands now since we've created |
| 823 | * everything. This way we don't introduce memory corruptions |
| 824 | * during side-effect processing and correclty count established |
| 825 | * associations. |
| 826 | */ |
| 827 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 828 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 829 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 830 | SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); |
| 831 | SCTP_INC_STATS(net, SCTP_MIB_PASSIVEESTABS); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 832 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
| 833 | |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 834 | if (new_asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 835 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 836 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 837 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 838 | /* This will send the COOKIE ACK */ |
| 839 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 840 | |
| 841 | /* Queue the ASSOC_CHANGE event */ |
| 842 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 843 | |
| 844 | /* Send up the Adaptation Layer Indication event */ |
| 845 | if (ai_ev) |
| 846 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 847 | SCTP_ULPEVENT(ai_ev)); |
| 848 | |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 849 | if (auth_ev) |
| 850 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 851 | SCTP_ULPEVENT(auth_ev)); |
| 852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | return SCTP_DISPOSITION_CONSUME; |
| 854 | |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 855 | nomem_authev: |
| 856 | sctp_ulpevent_free(ai_ev); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 857 | nomem_aiev: |
| 858 | sctp_ulpevent_free(ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | nomem_ev: |
| 860 | sctp_chunk_free(repl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | nomem_init: |
| 862 | sctp_association_free(new_asoc); |
| 863 | nomem: |
| 864 | return SCTP_DISPOSITION_NOMEM; |
| 865 | } |
| 866 | |
| 867 | /* |
| 868 | * Respond to a normal COOKIE ACK chunk. |
Marcelo Ricardo Leitner | b52effd | 2015-07-17 13:50:21 -0300 | [diff] [blame] | 869 | * We are the side that is asking for an association. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | * |
| 871 | * RFC 2960 5.1 Normal Establishment of an Association |
| 872 | * |
| 873 | * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the |
| 874 | * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie |
| 875 | * timer. It may also notify its ULP about the successful |
| 876 | * establishment of the association with a Communication Up |
| 877 | * notification (see Section 10). |
| 878 | * |
| 879 | * Verification Tag: |
| 880 | * Inputs |
| 881 | * (endpoint, asoc, chunk) |
| 882 | * |
| 883 | * Outputs |
| 884 | * (asoc, reply_msg, msg_up, timers, counters) |
| 885 | * |
| 886 | * The return value is the disposition of the chunk. |
| 887 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 888 | enum sctp_disposition sctp_sf_do_5_1E_ca(struct net *net, |
| 889 | const struct sctp_endpoint *ep, |
| 890 | const struct sctp_association *asoc, |
| 891 | const union sctp_subtype type, |
| 892 | void *arg, |
| 893 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | { |
| 895 | struct sctp_chunk *chunk = arg; |
| 896 | struct sctp_ulpevent *ev; |
| 897 | |
| 898 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 899 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | /* Verify that the chunk length for the COOKIE-ACK is OK. |
| 902 | * If we don't do this, any bundled chunks may be junked. |
| 903 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 904 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 905 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | commands); |
| 907 | |
| 908 | /* Reset init error count upon receipt of COOKIE-ACK, |
| 909 | * to avoid problems with the managemement of this |
| 910 | * counter in stale cookie situations when a transition back |
| 911 | * from the COOKIE-ECHOED state to the COOKIE-WAIT |
| 912 | * state is performed. |
| 913 | */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 914 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Richard Haines | 2277c7c | 2018-02-13 20:56:24 +0000 | [diff] [blame] | 916 | /* Set peer label for connection. */ |
| 917 | security_inet_conn_established(ep->base.sk, chunk->skb); |
| 918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 920 | * |
| 921 | * E) Upon reception of the COOKIE ACK, endpoint "A" will move |
| 922 | * from the COOKIE-ECHOED state to the ESTABLISHED state, |
| 923 | * stopping the T1-cookie timer. |
| 924 | */ |
| 925 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 926 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 927 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 928 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 929 | SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); |
| 930 | SCTP_INC_STATS(net, SCTP_MIB_ACTIVEESTABS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 932 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 934 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
| 936 | /* It may also notify its ULP about the successful |
| 937 | * establishment of the association with a Communication Up |
| 938 | * notification (see Section 10). |
| 939 | */ |
| 940 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, |
| 941 | 0, asoc->c.sinit_num_ostreams, |
| 942 | asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 943 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
| 945 | if (!ev) |
| 946 | goto nomem; |
| 947 | |
| 948 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 949 | |
| 950 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 951 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 953 | * peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 955 | if (asoc->peer.adaptation_ind) { |
| 956 | ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | if (!ev) |
| 958 | goto nomem; |
| 959 | |
| 960 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 961 | SCTP_ULPEVENT(ev)); |
| 962 | } |
| 963 | |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 964 | if (!asoc->peer.auth_capable) { |
| 965 | ev = sctp_ulpevent_make_authkey(asoc, 0, SCTP_AUTH_NO_AUTH, |
| 966 | GFP_ATOMIC); |
| 967 | if (!ev) |
| 968 | goto nomem; |
| 969 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 970 | SCTP_ULPEVENT(ev)); |
| 971 | } |
| 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | return SCTP_DISPOSITION_CONSUME; |
| 974 | nomem: |
| 975 | return SCTP_DISPOSITION_NOMEM; |
| 976 | } |
| 977 | |
| 978 | /* Generate and sendout a heartbeat packet. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 979 | static enum sctp_disposition sctp_sf_heartbeat( |
| 980 | const struct sctp_endpoint *ep, |
| 981 | const struct sctp_association *asoc, |
| 982 | const union sctp_subtype type, |
| 983 | void *arg, |
| 984 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | { |
| 986 | struct sctp_transport *transport = (struct sctp_transport *) arg; |
| 987 | struct sctp_chunk *reply; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
| 989 | /* Send a heartbeat to our peer. */ |
Wei Yongjun | 92c73af | 2011-04-19 21:31:47 +0000 | [diff] [blame] | 990 | reply = sctp_make_heartbeat(asoc, transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | if (!reply) |
| 992 | return SCTP_DISPOSITION_NOMEM; |
| 993 | |
| 994 | /* Set rto_pending indicating that an RTT measurement |
| 995 | * is started with this heartbeat chunk. |
| 996 | */ |
| 997 | sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING, |
| 998 | SCTP_TRANSPORT(transport)); |
| 999 | |
| 1000 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 1001 | return SCTP_DISPOSITION_CONSUME; |
| 1002 | } |
| 1003 | |
| 1004 | /* Generate a HEARTBEAT packet on the given transport. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1005 | enum sctp_disposition sctp_sf_sendbeat_8_3(struct net *net, |
| 1006 | const struct sctp_endpoint *ep, |
| 1007 | const struct sctp_association *asoc, |
| 1008 | const union sctp_subtype type, |
| 1009 | void *arg, |
| 1010 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
| 1012 | struct sctp_transport *transport = (struct sctp_transport *) arg; |
| 1013 | |
Vlad Yasevich | b9f8478 | 2009-08-26 09:36:25 -0400 | [diff] [blame] | 1014 | if (asoc->overall_error_count >= asoc->max_retrans) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 1015 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 1016 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 1018 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 1019 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 1020 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 1021 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | return SCTP_DISPOSITION_DELETE_TCB; |
| 1023 | } |
| 1024 | |
| 1025 | /* Section 3.3.5. |
| 1026 | * The Sender-specific Heartbeat Info field should normally include |
| 1027 | * information about the sender's current time when this HEARTBEAT |
| 1028 | * chunk is sent and the destination transport address to which this |
| 1029 | * HEARTBEAT is sent (see Section 8.3). |
| 1030 | */ |
| 1031 | |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 1032 | if (transport->param_flags & SPP_HB_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | if (SCTP_DISPOSITION_NOMEM == |
| 1034 | sctp_sf_heartbeat(ep, asoc, type, arg, |
| 1035 | commands)) |
| 1036 | return SCTP_DISPOSITION_NOMEM; |
Vlad Yasevich | 245cba7 | 2009-11-23 15:53:58 -0500 | [diff] [blame] | 1037 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | /* Set transport error counter and association error counter |
| 1039 | * when sending heartbeat. |
| 1040 | */ |
Vlad Yasevich | 7e99013 | 2009-03-02 09:46:14 +0000 | [diff] [blame] | 1041 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | SCTP_TRANSPORT(transport)); |
| 1043 | } |
Vlad Yasevich | 245cba7 | 2009-11-23 15:53:58 -0500 | [diff] [blame] | 1044 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE, |
| 1045 | SCTP_TRANSPORT(transport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE, |
| 1047 | SCTP_TRANSPORT(transport)); |
| 1048 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1049 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Xin Long | 7b9438d | 2017-01-18 00:44:43 +0800 | [diff] [blame] | 1052 | /* resend asoc strreset_chunk. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1053 | enum sctp_disposition sctp_sf_send_reconf(struct net *net, |
| 1054 | const struct sctp_endpoint *ep, |
| 1055 | const struct sctp_association *asoc, |
| 1056 | const union sctp_subtype type, |
| 1057 | void *arg, |
| 1058 | struct sctp_cmd_seq *commands) |
Xin Long | 7b9438d | 2017-01-18 00:44:43 +0800 | [diff] [blame] | 1059 | { |
| 1060 | struct sctp_transport *transport = arg; |
| 1061 | |
| 1062 | if (asoc->overall_error_count >= asoc->max_retrans) { |
| 1063 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 1064 | SCTP_ERROR(ETIMEDOUT)); |
| 1065 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 1066 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 1067 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
| 1068 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 1069 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
| 1070 | return SCTP_DISPOSITION_DELETE_TCB; |
| 1071 | } |
| 1072 | |
| 1073 | sctp_chunk_hold(asoc->strreset_chunk); |
| 1074 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 1075 | SCTP_CHUNK(asoc->strreset_chunk)); |
| 1076 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); |
| 1077 | |
| 1078 | return SCTP_DISPOSITION_CONSUME; |
| 1079 | } |
| 1080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | /* |
| 1082 | * Process an heartbeat request. |
| 1083 | * |
| 1084 | * Section: 8.3 Path Heartbeat |
| 1085 | * The receiver of the HEARTBEAT should immediately respond with a |
| 1086 | * HEARTBEAT ACK that contains the Heartbeat Information field copied |
| 1087 | * from the received HEARTBEAT chunk. |
| 1088 | * |
| 1089 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 1090 | * When receiving an SCTP packet, the endpoint MUST ensure that the |
| 1091 | * value in the Verification Tag field of the received SCTP packet |
| 1092 | * matches its own Tag. If the received Verification Tag value does not |
| 1093 | * match the receiver's own tag value, the receiver shall silently |
| 1094 | * discard the packet and shall not process it any further except for |
| 1095 | * those cases listed in Section 8.5.1 below. |
| 1096 | * |
| 1097 | * Inputs |
| 1098 | * (endpoint, asoc, chunk) |
| 1099 | * |
| 1100 | * Outputs |
| 1101 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1102 | * |
| 1103 | * The return value is the disposition of the chunk. |
| 1104 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1105 | enum sctp_disposition sctp_sf_beat_8_3(struct net *net, |
| 1106 | const struct sctp_endpoint *ep, |
| 1107 | const struct sctp_association *asoc, |
| 1108 | const union sctp_subtype type, |
| 1109 | void *arg, struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | { |
Xin Long | 3c91870 | 2017-06-30 11:52:16 +0800 | [diff] [blame] | 1111 | struct sctp_paramhdr *param_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | struct sctp_chunk *chunk = arg; |
| 1113 | struct sctp_chunk *reply; |
| 1114 | size_t paylen = 0; |
| 1115 | |
| 1116 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1117 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | |
| 1119 | /* Make sure that the HEARTBEAT chunk has a valid length. */ |
Xin Long | 38c00f7 | 2017-07-23 09:34:35 +0800 | [diff] [blame] | 1120 | if (!sctp_chunk_length_valid(chunk, |
| 1121 | sizeof(struct sctp_heartbeat_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1122 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | commands); |
| 1124 | |
| 1125 | /* 8.3 The receiver of the HEARTBEAT should immediately |
| 1126 | * respond with a HEARTBEAT ACK that contains the Heartbeat |
| 1127 | * Information field copied from the received HEARTBEAT chunk. |
| 1128 | */ |
Xin Long | 4d2dcdf | 2017-07-23 09:34:34 +0800 | [diff] [blame] | 1129 | chunk->subh.hb_hdr = (struct sctp_heartbeathdr *)chunk->skb->data; |
Xin Long | 3c91870 | 2017-06-30 11:52:16 +0800 | [diff] [blame] | 1130 | param_hdr = (struct sctp_paramhdr *)chunk->subh.hb_hdr; |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1131 | paylen = ntohs(chunk->chunk_hdr->length) - sizeof(struct sctp_chunkhdr); |
Thomas Graf | 06a31e2 | 2012-11-30 02:16:27 +0000 | [diff] [blame] | 1132 | |
| 1133 | if (ntohs(param_hdr->length) > paylen) |
| 1134 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
| 1135 | param_hdr, commands); |
| 1136 | |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 1137 | if (!pskb_pull(chunk->skb, paylen)) |
| 1138 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | |
Thomas Graf | 06a31e2 | 2012-11-30 02:16:27 +0000 | [diff] [blame] | 1140 | reply = sctp_make_heartbeat_ack(asoc, chunk, param_hdr, paylen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | if (!reply) |
| 1142 | goto nomem; |
| 1143 | |
| 1144 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 1145 | return SCTP_DISPOSITION_CONSUME; |
| 1146 | |
| 1147 | nomem: |
| 1148 | return SCTP_DISPOSITION_NOMEM; |
| 1149 | } |
| 1150 | |
| 1151 | /* |
| 1152 | * Process the returning HEARTBEAT ACK. |
| 1153 | * |
| 1154 | * Section: 8.3 Path Heartbeat |
| 1155 | * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT |
| 1156 | * should clear the error counter of the destination transport |
| 1157 | * address to which the HEARTBEAT was sent, and mark the destination |
| 1158 | * transport address as active if it is not so marked. The endpoint may |
| 1159 | * optionally report to the upper layer when an inactive destination |
| 1160 | * address is marked as active due to the reception of the latest |
| 1161 | * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also |
| 1162 | * clear the association overall error count as well (as defined |
| 1163 | * in section 8.1). |
| 1164 | * |
| 1165 | * The receiver of the HEARTBEAT ACK should also perform an RTT |
| 1166 | * measurement for that destination transport address using the time |
| 1167 | * value carried in the HEARTBEAT ACK chunk. |
| 1168 | * |
| 1169 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 1170 | * |
| 1171 | * Inputs |
| 1172 | * (endpoint, asoc, chunk) |
| 1173 | * |
| 1174 | * Outputs |
| 1175 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1176 | * |
| 1177 | * The return value is the disposition of the chunk. |
| 1178 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1179 | enum sctp_disposition sctp_sf_backbeat_8_3(struct net *net, |
| 1180 | const struct sctp_endpoint *ep, |
| 1181 | const struct sctp_association *asoc, |
| 1182 | const union sctp_subtype type, |
| 1183 | void *arg, |
| 1184 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | { |
Xin Long | edf903f | 2017-08-11 10:23:46 +0800 | [diff] [blame] | 1186 | struct sctp_sender_hb_info *hbinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | struct sctp_transport *link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | unsigned long max_interval; |
Xin Long | edf903f | 2017-08-11 10:23:46 +0800 | [diff] [blame] | 1190 | union sctp_addr from_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
| 1192 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1193 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
| 1195 | /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1196 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr) + |
Xin Long | edf903f | 2017-08-11 10:23:46 +0800 | [diff] [blame] | 1197 | sizeof(*hbinfo))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1198 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | commands); |
| 1200 | |
Xin Long | edf903f | 2017-08-11 10:23:46 +0800 | [diff] [blame] | 1201 | hbinfo = (struct sctp_sender_hb_info *)chunk->skb->data; |
Vladislav Yasevich | a601266 | 2006-05-19 14:25:53 -0700 | [diff] [blame] | 1202 | /* Make sure that the length of the parameter is what we expect */ |
Xin Long | edf903f | 2017-08-11 10:23:46 +0800 | [diff] [blame] | 1203 | if (ntohs(hbinfo->param_hdr.length) != sizeof(*hbinfo)) |
Vladislav Yasevich | a601266 | 2006-05-19 14:25:53 -0700 | [diff] [blame] | 1204 | return SCTP_DISPOSITION_DISCARD; |
Vladislav Yasevich | a601266 | 2006-05-19 14:25:53 -0700 | [diff] [blame] | 1205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | from_addr = hbinfo->daddr; |
Al Viro | 63de08f | 2006-11-20 17:07:25 -0800 | [diff] [blame] | 1207 | link = sctp_assoc_lookup_paddr(asoc, &from_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
| 1209 | /* This should never happen, but lets log it if so. */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1210 | if (unlikely(!link)) { |
| 1211 | if (from_addr.sa.sa_family == AF_INET6) { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 1212 | net_warn_ratelimited("%s association %p could not find address %pI6\n", |
| 1213 | __func__, |
| 1214 | asoc, |
| 1215 | &from_addr.v6.sin6_addr); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1216 | } else { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 1217 | net_warn_ratelimited("%s association %p could not find address %pI4\n", |
| 1218 | __func__, |
| 1219 | asoc, |
| 1220 | &from_addr.v4.sin_addr.s_addr); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1221 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | return SCTP_DISPOSITION_DISCARD; |
| 1223 | } |
| 1224 | |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 1225 | /* Validate the 64-bit random nonce. */ |
| 1226 | if (hbinfo->hb_nonce != link->hb_nonce) |
| 1227 | return SCTP_DISPOSITION_DISCARD; |
| 1228 | |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 1229 | max_interval = link->hbinterval + link->rto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
| 1231 | /* Check if the timestamp looks valid. */ |
| 1232 | if (time_after(hbinfo->sent_at, jiffies) || |
| 1233 | time_after(jiffies, hbinfo->sent_at + max_interval)) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 1234 | pr_debug("%s: HEARTBEAT ACK with invalid timestamp received " |
| 1235 | "for transport:%p\n", __func__, link); |
| 1236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | return SCTP_DISPOSITION_DISCARD; |
| 1238 | } |
| 1239 | |
| 1240 | /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of |
| 1241 | * the HEARTBEAT should clear the error counter of the |
| 1242 | * destination transport address to which the HEARTBEAT was |
| 1243 | * sent and mark the destination transport address as active if |
| 1244 | * it is not so marked. |
| 1245 | */ |
| 1246 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link)); |
| 1247 | |
| 1248 | return SCTP_DISPOSITION_CONSUME; |
| 1249 | } |
| 1250 | |
| 1251 | /* Helper function to send out an abort for the restart |
| 1252 | * condition. |
| 1253 | */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1254 | static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | struct sctp_chunk *init, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 1256 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1258 | struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | union sctp_addr_param *addrparm; |
| 1260 | struct sctp_errhdr *errhdr; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 1261 | char buffer[sizeof(*errhdr) + sizeof(*addrparm)]; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1262 | struct sctp_endpoint *ep; |
| 1263 | struct sctp_packet *pkt; |
| 1264 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
| 1266 | /* Build the error on the stack. We are way to malloc crazy |
| 1267 | * throughout the code today. |
| 1268 | */ |
| 1269 | errhdr = (struct sctp_errhdr *)buffer; |
| 1270 | addrparm = (union sctp_addr_param *)errhdr->variable; |
| 1271 | |
| 1272 | /* Copy into a parm format. */ |
| 1273 | len = af->to_addr_param(ssa, addrparm); |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 1274 | len += sizeof(*errhdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
| 1276 | errhdr->cause = SCTP_ERROR_RESTART; |
| 1277 | errhdr->length = htons(len); |
| 1278 | |
| 1279 | /* Assign to the control socket. */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1280 | ep = sctp_sk(net->sctp.ctl_sock)->ep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | |
| 1282 | /* Association is NULL since this may be a restart attack and we |
| 1283 | * want to send back the attacker's vtag. |
| 1284 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1285 | pkt = sctp_abort_pkt_new(net, ep, NULL, init, errhdr, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
| 1287 | if (!pkt) |
| 1288 | goto out; |
| 1289 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt)); |
| 1290 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 1291 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
| 1293 | /* Discard the rest of the inbound packet. */ |
| 1294 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
| 1295 | |
| 1296 | out: |
| 1297 | /* Even if there is no memory, treat as a failure so |
| 1298 | * the packet will get dropped. |
| 1299 | */ |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1303 | static bool list_has_sctp_addr(const struct list_head *list, |
| 1304 | union sctp_addr *ipaddr) |
| 1305 | { |
| 1306 | struct sctp_transport *addr; |
| 1307 | |
| 1308 | list_for_each_entry(addr, list, transports) { |
| 1309 | if (sctp_cmp_addr_exact(ipaddr, &addr->ipaddr)) |
| 1310 | return true; |
| 1311 | } |
| 1312 | |
| 1313 | return false; |
| 1314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | /* A restart is occurring, check to make sure no new addresses |
| 1316 | * are being added as we may be under a takeover attack. |
| 1317 | */ |
| 1318 | static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc, |
| 1319 | const struct sctp_association *asoc, |
| 1320 | struct sctp_chunk *init, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 1321 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | { |
Xin Long | 4e7696d | 2019-12-09 13:45:18 +0800 | [diff] [blame] | 1323 | struct net *net = new_asoc->base.net; |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1324 | struct sctp_transport *new_addr; |
| 1325 | int ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1327 | /* Implementor's Guide - Section 5.2.2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | * ... |
| 1329 | * Before responding the endpoint MUST check to see if the |
| 1330 | * unexpected INIT adds new addresses to the association. If new |
| 1331 | * addresses are added to the association, the endpoint MUST respond |
| 1332 | * with an ABORT.. |
| 1333 | */ |
| 1334 | |
| 1335 | /* Search through all current addresses and make sure |
| 1336 | * we aren't adding any new ones. |
| 1337 | */ |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1338 | list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list, |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1339 | transports) { |
| 1340 | if (!list_has_sctp_addr(&asoc->peer.transport_addr_list, |
| 1341 | &new_addr->ipaddr)) { |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1342 | sctp_sf_send_restart_abort(net, &new_addr->ipaddr, init, |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1343 | commands); |
| 1344 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | break; |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | /* Return success if all addresses were found. */ |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1350 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | /* Populate the verification/tie tags based on overlapping INIT |
| 1354 | * scenario. |
| 1355 | * |
| 1356 | * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state. |
| 1357 | */ |
| 1358 | static void sctp_tietags_populate(struct sctp_association *new_asoc, |
| 1359 | const struct sctp_association *asoc) |
| 1360 | { |
| 1361 | switch (asoc->state) { |
| 1362 | |
| 1363 | /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */ |
| 1364 | |
| 1365 | case SCTP_STATE_COOKIE_WAIT: |
| 1366 | new_asoc->c.my_vtag = asoc->c.my_vtag; |
| 1367 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1368 | new_asoc->c.peer_ttag = 0; |
| 1369 | break; |
| 1370 | |
| 1371 | case SCTP_STATE_COOKIE_ECHOED: |
| 1372 | new_asoc->c.my_vtag = asoc->c.my_vtag; |
| 1373 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1374 | new_asoc->c.peer_ttag = asoc->c.peer_vtag; |
| 1375 | break; |
| 1376 | |
| 1377 | /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED, |
| 1378 | * COOKIE-WAIT and SHUTDOWN-ACK-SENT |
| 1379 | */ |
| 1380 | default: |
| 1381 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1382 | new_asoc->c.peer_ttag = asoc->c.peer_vtag; |
| 1383 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1384 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
| 1386 | /* Other parameters for the endpoint SHOULD be copied from the |
| 1387 | * existing parameters of the association (e.g. number of |
| 1388 | * outbound streams) into the INIT ACK and cookie. |
| 1389 | */ |
| 1390 | new_asoc->rwnd = asoc->rwnd; |
| 1391 | new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams; |
| 1392 | new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams; |
| 1393 | new_asoc->c.initial_tsn = asoc->c.initial_tsn; |
| 1394 | } |
| 1395 | |
| 1396 | /* |
| 1397 | * Compare vtag/tietag values to determine unexpected COOKIE-ECHO |
| 1398 | * handling action. |
| 1399 | * |
| 1400 | * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists. |
| 1401 | * |
| 1402 | * Returns value representing action to be taken. These action values |
| 1403 | * correspond to Action/Description values in RFC 2960, Table 2. |
| 1404 | */ |
| 1405 | static char sctp_tietags_compare(struct sctp_association *new_asoc, |
| 1406 | const struct sctp_association *asoc) |
| 1407 | { |
| 1408 | /* In this case, the peer may have restarted. */ |
| 1409 | if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && |
| 1410 | (asoc->c.peer_vtag != new_asoc->c.peer_vtag) && |
| 1411 | (asoc->c.my_vtag == new_asoc->c.my_ttag) && |
| 1412 | (asoc->c.peer_vtag == new_asoc->c.peer_ttag)) |
| 1413 | return 'A'; |
| 1414 | |
| 1415 | /* Collision case B. */ |
| 1416 | if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && |
| 1417 | ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) || |
| 1418 | (0 == asoc->c.peer_vtag))) { |
| 1419 | return 'B'; |
| 1420 | } |
| 1421 | |
| 1422 | /* Collision case D. */ |
| 1423 | if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && |
| 1424 | (asoc->c.peer_vtag == new_asoc->c.peer_vtag)) |
| 1425 | return 'D'; |
| 1426 | |
| 1427 | /* Collision case C. */ |
| 1428 | if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && |
| 1429 | (asoc->c.peer_vtag == new_asoc->c.peer_vtag) && |
| 1430 | (0 == new_asoc->c.my_ttag) && |
| 1431 | (0 == new_asoc->c.peer_ttag)) |
| 1432 | return 'C'; |
| 1433 | |
| 1434 | /* No match to any of the special cases; discard this packet. */ |
| 1435 | return 'E'; |
| 1436 | } |
| 1437 | |
| 1438 | /* Common helper routine for both duplicate and simulataneous INIT |
| 1439 | * chunk handling. |
| 1440 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1441 | static enum sctp_disposition sctp_sf_do_unexpected_init( |
| 1442 | struct net *net, |
| 1443 | const struct sctp_endpoint *ep, |
| 1444 | const struct sctp_association *asoc, |
| 1445 | const union sctp_subtype type, |
| 1446 | void *arg, |
| 1447 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | { |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 1449 | struct sctp_chunk *chunk = arg, *repl, *err_chunk; |
| 1450 | struct sctp_unrecognized_param *unk_param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | struct sctp_association *new_asoc; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1452 | enum sctp_disposition retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | struct sctp_packet *packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | int len; |
| 1455 | |
Richard Haines | 2277c7c | 2018-02-13 20:56:24 +0000 | [diff] [blame] | 1456 | /* Update socket peer label if first association. */ |
| 1457 | if (security_sctp_assoc_request((struct sctp_endpoint *)ep, |
| 1458 | chunk->skb)) |
| 1459 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 1460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | /* 6.10 Bundling |
| 1462 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 1463 | * SHUTDOWN COMPLETE with any other chunks. |
| 1464 | * |
| 1465 | * IG Section 2.11.2 |
| 1466 | * Furthermore, we require that the receiver of an INIT chunk MUST |
| 1467 | * enforce these rules by silently discarding an arriving packet |
| 1468 | * with an INIT chunk that is bundled with other chunks. |
| 1469 | */ |
| 1470 | if (!chunk->singleton) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1471 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
| 1473 | /* 3.1 A packet containing an INIT chunk MUST have a zero Verification |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1474 | * Tag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | */ |
| 1476 | if (chunk->sctp_hdr->vtag != 0) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1477 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | |
| 1479 | /* Make sure that the INIT chunk has a valid length. |
| 1480 | * In this case, we generate a protocol violation since we have |
| 1481 | * an association established. |
| 1482 | */ |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1483 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1484 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | commands); |
| 1486 | /* Grab the INIT header. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 1487 | chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
| 1489 | /* Tag the variable length parameters. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 1490 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | |
| 1492 | /* Verify the INIT chunk before processing it. */ |
| 1493 | err_chunk = NULL; |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 1494 | if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type, |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1495 | (struct sctp_init_chunk *)chunk->chunk_hdr, chunk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | &err_chunk)) { |
| 1497 | /* This chunk contains fatal error. It is to be discarded. |
| 1498 | * Send an ABORT, with causes if there is any. |
| 1499 | */ |
| 1500 | if (err_chunk) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1501 | packet = sctp_abort_pkt_new(net, ep, asoc, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | (__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1503 | sizeof(struct sctp_chunkhdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1505 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | |
| 1507 | if (packet) { |
| 1508 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 1509 | SCTP_PACKET(packet)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1510 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | retval = SCTP_DISPOSITION_CONSUME; |
| 1512 | } else { |
| 1513 | retval = SCTP_DISPOSITION_NOMEM; |
| 1514 | } |
| 1515 | goto cleanup; |
| 1516 | } else { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1517 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | commands); |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | /* |
| 1523 | * Other parameters for the endpoint SHOULD be copied from the |
| 1524 | * existing parameters of the association (e.g. number of |
| 1525 | * outbound streams) into the INIT ACK and cookie. |
| 1526 | * FIXME: We are copying parameters from the endpoint not the |
| 1527 | * association. |
| 1528 | */ |
| 1529 | new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); |
| 1530 | if (!new_asoc) |
| 1531 | goto nomem; |
| 1532 | |
Vlad Yasevich | 409b95a | 2009-11-10 08:57:34 +0000 | [diff] [blame] | 1533 | if (sctp_assoc_set_bind_addr_from_ep(new_asoc, |
| 1534 | sctp_scope(sctp_source(chunk)), GFP_ATOMIC) < 0) |
| 1535 | goto nomem; |
| 1536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | /* In the outbound INIT ACK the endpoint MUST copy its current |
| 1538 | * Verification Tag and Peers Verification tag into a reserved |
| 1539 | * place (local tie-tag and per tie-tag) within the state cookie. |
| 1540 | */ |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 1541 | if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1542 | (struct sctp_init_chunk *)chunk->chunk_hdr, |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1543 | GFP_ATOMIC)) |
| 1544 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | |
| 1546 | /* Make sure no new addresses are being added during the |
| 1547 | * restart. Do not do this check for COOKIE-WAIT state, |
| 1548 | * since there are no peer addresses to check against. |
| 1549 | * Upon return an ABORT will have been sent if needed. |
| 1550 | */ |
| 1551 | if (!sctp_state(asoc, COOKIE_WAIT)) { |
| 1552 | if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, |
| 1553 | commands)) { |
| 1554 | retval = SCTP_DISPOSITION_CONSUME; |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1555 | goto nomem_retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | sctp_tietags_populate(new_asoc, asoc); |
| 1560 | |
| 1561 | /* B) "Z" shall respond immediately with an INIT ACK chunk. */ |
| 1562 | |
| 1563 | /* If there are errors need to be reported for unknown parameters, |
| 1564 | * make sure to reserve enough room in the INIT ACK for them. |
| 1565 | */ |
| 1566 | len = 0; |
| 1567 | if (err_chunk) { |
| 1568 | len = ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1569 | sizeof(struct sctp_chunkhdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); |
| 1573 | if (!repl) |
| 1574 | goto nomem; |
| 1575 | |
| 1576 | /* If there are errors need to be reported for unknown parameters, |
| 1577 | * include them in the outgoing INIT ACK as "Unrecognized parameter" |
| 1578 | * parameter. |
| 1579 | */ |
| 1580 | if (err_chunk) { |
| 1581 | /* Get the "Unrecognized parameter" parameter(s) out of the |
| 1582 | * ERROR chunk generated by sctp_verify_init(). Since the |
| 1583 | * error cause code for "unknown parameter" and the |
| 1584 | * "Unrecognized parameter" type is the same, we can |
| 1585 | * construct the parameters in INIT ACK by copying the |
| 1586 | * ERROR causes over. |
| 1587 | */ |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 1588 | unk_param = (struct sctp_unrecognized_param *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | ((__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1590 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | /* Replace the cause code with the "Unrecognized parameter" |
| 1592 | * parameter type. |
| 1593 | */ |
| 1594 | sctp_addto_chunk(repl, len, unk_param); |
| 1595 | } |
| 1596 | |
| 1597 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 1598 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1599 | |
| 1600 | /* |
| 1601 | * Note: After sending out INIT ACK with the State Cookie parameter, |
| 1602 | * "Z" MUST NOT allocate any resources for this new association. |
| 1603 | * Otherwise, "Z" will be vulnerable to resource attacks. |
| 1604 | */ |
| 1605 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 1606 | retval = SCTP_DISPOSITION_CONSUME; |
| 1607 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1608 | return retval; |
| 1609 | |
| 1610 | nomem: |
| 1611 | retval = SCTP_DISPOSITION_NOMEM; |
| 1612 | nomem_retval: |
| 1613 | if (new_asoc) |
| 1614 | sctp_association_free(new_asoc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | cleanup: |
| 1616 | if (err_chunk) |
| 1617 | sctp_chunk_free(err_chunk); |
| 1618 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1622 | * Handle simultaneous INIT. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | * This means we started an INIT and then we got an INIT request from |
| 1624 | * our peer. |
| 1625 | * |
| 1626 | * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B) |
| 1627 | * This usually indicates an initialization collision, i.e., each |
| 1628 | * endpoint is attempting, at about the same time, to establish an |
| 1629 | * association with the other endpoint. |
| 1630 | * |
| 1631 | * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an |
| 1632 | * endpoint MUST respond with an INIT ACK using the same parameters it |
| 1633 | * sent in its original INIT chunk (including its Verification Tag, |
| 1634 | * unchanged). These original parameters are combined with those from the |
| 1635 | * newly received INIT chunk. The endpoint shall also generate a State |
| 1636 | * Cookie with the INIT ACK. The endpoint uses the parameters sent in its |
| 1637 | * INIT to calculate the State Cookie. |
| 1638 | * |
| 1639 | * After that, the endpoint MUST NOT change its state, the T1-init |
| 1640 | * timer shall be left running and the corresponding TCB MUST NOT be |
| 1641 | * destroyed. The normal procedures for handling State Cookies when |
| 1642 | * a TCB exists will resolve the duplicate INITs to a single association. |
| 1643 | * |
| 1644 | * For an endpoint that is in the COOKIE-ECHOED state it MUST populate |
| 1645 | * its Tie-Tags with the Tag information of itself and its peer (see |
| 1646 | * section 5.2.2 for a description of the Tie-Tags). |
| 1647 | * |
| 1648 | * Verification Tag: Not explicit, but an INIT can not have a valid |
| 1649 | * verification tag, so we skip the check. |
| 1650 | * |
| 1651 | * Inputs |
| 1652 | * (endpoint, asoc, chunk) |
| 1653 | * |
| 1654 | * Outputs |
| 1655 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1656 | * |
| 1657 | * The return value is the disposition of the chunk. |
| 1658 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1659 | enum sctp_disposition sctp_sf_do_5_2_1_siminit( |
| 1660 | struct net *net, |
| 1661 | const struct sctp_endpoint *ep, |
| 1662 | const struct sctp_association *asoc, |
| 1663 | const union sctp_subtype type, |
| 1664 | void *arg, |
| 1665 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | { |
| 1667 | /* Call helper to do the real work for both simulataneous and |
| 1668 | * duplicate INIT chunk handling. |
| 1669 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1670 | return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | /* |
| 1674 | * Handle duplicated INIT messages. These are usually delayed |
| 1675 | * restransmissions. |
| 1676 | * |
| 1677 | * Section: 5.2.2 Unexpected INIT in States Other than CLOSED, |
| 1678 | * COOKIE-ECHOED and COOKIE-WAIT |
| 1679 | * |
| 1680 | * Unless otherwise stated, upon reception of an unexpected INIT for |
| 1681 | * this association, the endpoint shall generate an INIT ACK with a |
| 1682 | * State Cookie. In the outbound INIT ACK the endpoint MUST copy its |
| 1683 | * current Verification Tag and peer's Verification Tag into a reserved |
| 1684 | * place within the state cookie. We shall refer to these locations as |
| 1685 | * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet |
| 1686 | * containing this INIT ACK MUST carry a Verification Tag value equal to |
| 1687 | * the Initiation Tag found in the unexpected INIT. And the INIT ACK |
| 1688 | * MUST contain a new Initiation Tag (randomly generated see Section |
| 1689 | * 5.3.1). Other parameters for the endpoint SHOULD be copied from the |
| 1690 | * existing parameters of the association (e.g. number of outbound |
| 1691 | * streams) into the INIT ACK and cookie. |
| 1692 | * |
| 1693 | * After sending out the INIT ACK, the endpoint shall take no further |
| 1694 | * actions, i.e., the existing association, including its current state, |
| 1695 | * and the corresponding TCB MUST NOT be changed. |
| 1696 | * |
| 1697 | * Note: Only when a TCB exists and the association is not in a COOKIE- |
| 1698 | * WAIT state are the Tie-Tags populated. For a normal association INIT |
| 1699 | * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be |
| 1700 | * set to 0 (indicating that no previous TCB existed). The INIT ACK and |
| 1701 | * State Cookie are populated as specified in section 5.2.1. |
| 1702 | * |
| 1703 | * Verification Tag: Not specified, but an INIT has no way of knowing |
| 1704 | * what the verification tag could be, so we ignore it. |
| 1705 | * |
| 1706 | * Inputs |
| 1707 | * (endpoint, asoc, chunk) |
| 1708 | * |
| 1709 | * Outputs |
| 1710 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1711 | * |
| 1712 | * The return value is the disposition of the chunk. |
| 1713 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1714 | enum sctp_disposition sctp_sf_do_5_2_2_dupinit( |
| 1715 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1716 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 1718 | const union sctp_subtype type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 1720 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | { |
| 1722 | /* Call helper to do the real work for both simulataneous and |
| 1723 | * duplicate INIT chunk handling. |
| 1724 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1725 | return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1729 | /* |
| 1730 | * Unexpected INIT-ACK handler. |
| 1731 | * |
| 1732 | * Section 5.2.3 |
| 1733 | * If an INIT ACK received by an endpoint in any state other than the |
| 1734 | * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk. |
| 1735 | * An unexpected INIT ACK usually indicates the processing of an old or |
| 1736 | * duplicated INIT chunk. |
| 1737 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1738 | enum sctp_disposition sctp_sf_do_5_2_3_initack( |
| 1739 | struct net *net, |
| 1740 | const struct sctp_endpoint *ep, |
| 1741 | const struct sctp_association *asoc, |
| 1742 | const union sctp_subtype type, |
| 1743 | void *arg, |
| 1744 | struct sctp_cmd_seq *commands) |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1745 | { |
| 1746 | /* Per the above section, we'll discard the chunk if we have an |
| 1747 | * endpoint. If this is an OOTB INIT-ACK, treat it as such. |
| 1748 | */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1749 | if (ep == sctp_sk(net->sctp.ctl_sock)->ep) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1750 | return sctp_sf_ootb(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1751 | else |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1752 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1753 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | |
| 1755 | /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A') |
| 1756 | * |
| 1757 | * Section 5.2.4 |
| 1758 | * A) In this case, the peer may have restarted. |
| 1759 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1760 | static enum sctp_disposition sctp_sf_do_dupcook_a( |
| 1761 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1762 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | const struct sctp_association *asoc, |
| 1764 | struct sctp_chunk *chunk, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 1765 | struct sctp_cmd_seq *commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | struct sctp_association *new_asoc) |
| 1767 | { |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1768 | struct sctp_init_chunk *peer_init; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1769 | enum sctp_disposition disposition; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | struct sctp_ulpevent *ev; |
| 1771 | struct sctp_chunk *repl; |
| 1772 | struct sctp_chunk *err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | |
| 1774 | /* new_asoc is a brand-new association, so these are not yet |
| 1775 | * side effects--it is safe to run them here. |
| 1776 | */ |
| 1777 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
| 1778 | |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 1779 | if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | GFP_ATOMIC)) |
| 1781 | goto nomem; |
| 1782 | |
Xin Long | 4842a08 | 2018-05-02 13:37:44 +0800 | [diff] [blame] | 1783 | if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC)) |
| 1784 | goto nomem; |
| 1785 | |
Xin Long | 59d8d44 | 2018-05-05 14:59:47 +0800 | [diff] [blame] | 1786 | if (!sctp_auth_chunk_verify(net, chunk, new_asoc)) |
| 1787 | return SCTP_DISPOSITION_DISCARD; |
| 1788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | /* Make sure no new addresses are being added during the |
| 1790 | * restart. Though this is a pretty complicated attack |
| 1791 | * since you'd have to get inside the cookie. |
| 1792 | */ |
Xin Long | 59d8d44 | 2018-05-05 14:59:47 +0800 | [diff] [blame] | 1793 | if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | |
| 1796 | /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes |
| 1797 | * the peer has restarted (Action A), it MUST NOT setup a new |
| 1798 | * association but instead resend the SHUTDOWN ACK and send an ERROR |
| 1799 | * chunk with a "Cookie Received while Shutting Down" error cause to |
| 1800 | * its peer. |
| 1801 | */ |
| 1802 | if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1803 | disposition = sctp_sf_do_9_2_reshutack(net, ep, asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | SCTP_ST_CHUNK(chunk->chunk_hdr->type), |
| 1805 | chunk, commands); |
| 1806 | if (SCTP_DISPOSITION_NOMEM == disposition) |
| 1807 | goto nomem; |
| 1808 | |
| 1809 | err = sctp_make_op_error(asoc, chunk, |
| 1810 | SCTP_ERROR_COOKIE_IN_SHUTDOWN, |
Vlad Yasevich | 6383cfb | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 1811 | NULL, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | if (err) |
| 1813 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 1814 | SCTP_CHUNK(err)); |
| 1815 | |
| 1816 | return SCTP_DISPOSITION_CONSUME; |
| 1817 | } |
| 1818 | |
Wei Yongjun | a000c01 | 2011-05-29 23:23:36 +0000 | [diff] [blame] | 1819 | /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked |
| 1820 | * data. Consider the optional choice of resending of this data. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | */ |
Wei Yongjun | a000c01 | 2011-05-29 23:23:36 +0000 | [diff] [blame] | 1822 | sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL()); |
| 1823 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 1824 | SCTP_TO(SCTP_EVENT_TIMEOUT_SACK)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL()); |
| 1826 | |
Wei Yongjun | a000c01 | 2011-05-29 23:23:36 +0000 | [diff] [blame] | 1827 | /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue |
| 1828 | * and ASCONF-ACK cache. |
| 1829 | */ |
| 1830 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 1831 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 1832 | sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_ASCONF_QUEUE, SCTP_NULL()); |
| 1833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 1835 | if (!repl) |
| 1836 | goto nomem; |
| 1837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | /* Report association restart to upper layer. */ |
| 1839 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0, |
| 1840 | new_asoc->c.sinit_num_ostreams, |
| 1841 | new_asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 1842 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | if (!ev) |
| 1844 | goto nomem_ev; |
| 1845 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1846 | /* Update the content of current association. */ |
| 1847 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
Vlad Yasevich | bdf6fa5 | 2014-10-03 18:16:20 -0400 | [diff] [blame] | 1849 | if (sctp_state(asoc, SHUTDOWN_PENDING) && |
| 1850 | (sctp_sstate(asoc->base.sk, CLOSING) || |
| 1851 | sock_flag(asoc->base.sk, SOCK_DEAD))) { |
| 1852 | /* if were currently in SHUTDOWN_PENDING, but the socket |
| 1853 | * has been closed by user, don't transition to ESTABLISHED. |
| 1854 | * Instead trigger SHUTDOWN bundled with COOKIE_ACK. |
| 1855 | */ |
| 1856 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1857 | return sctp_sf_do_9_2_start_shutdown(net, ep, asoc, |
| 1858 | SCTP_ST_CHUNK(0), NULL, |
| 1859 | commands); |
| 1860 | } else { |
| 1861 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 1862 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
| 1863 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | return SCTP_DISPOSITION_CONSUME; |
| 1866 | |
| 1867 | nomem_ev: |
| 1868 | sctp_chunk_free(repl); |
| 1869 | nomem: |
| 1870 | return SCTP_DISPOSITION_NOMEM; |
| 1871 | } |
| 1872 | |
| 1873 | /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B') |
| 1874 | * |
| 1875 | * Section 5.2.4 |
| 1876 | * B) In this case, both sides may be attempting to start an association |
| 1877 | * at about the same time but the peer endpoint started its INIT |
| 1878 | * after responding to the local endpoint's INIT |
| 1879 | */ |
| 1880 | /* This case represents an initialization collision. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1881 | static enum sctp_disposition sctp_sf_do_dupcook_b( |
| 1882 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1883 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | const struct sctp_association *asoc, |
| 1885 | struct sctp_chunk *chunk, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 1886 | struct sctp_cmd_seq *commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | struct sctp_association *new_asoc) |
| 1888 | { |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1889 | struct sctp_init_chunk *peer_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | struct sctp_chunk *repl; |
| 1891 | |
| 1892 | /* new_asoc is a brand-new association, so these are not yet |
| 1893 | * side effects--it is safe to run them here. |
| 1894 | */ |
| 1895 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 1896 | if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | GFP_ATOMIC)) |
| 1898 | goto nomem; |
| 1899 | |
Xin Long | 4842a08 | 2018-05-02 13:37:44 +0800 | [diff] [blame] | 1900 | if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC)) |
| 1901 | goto nomem; |
| 1902 | |
Xin Long | 59d8d44 | 2018-05-05 14:59:47 +0800 | [diff] [blame] | 1903 | if (!sctp_auth_chunk_verify(net, chunk, new_asoc)) |
| 1904 | return SCTP_DISPOSITION_DISCARD; |
| 1905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | /* Update the content of current association. */ |
| 1907 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); |
| 1908 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 1909 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1910 | SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
| 1912 | |
| 1913 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 1914 | if (!repl) |
| 1915 | goto nomem; |
| 1916 | |
| 1917 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
| 1919 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 1920 | * |
| 1921 | * D) IMPLEMENTATION NOTE: An implementation may choose to |
| 1922 | * send the Communication Up notification to the SCTP user |
| 1923 | * upon reception of a valid COOKIE ECHO chunk. |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1924 | * |
| 1925 | * Sadly, this needs to be implemented as a side-effect, because |
| 1926 | * we are not guaranteed to have set the association id of the real |
| 1927 | * association and so these notifications need to be delayed until |
| 1928 | * the association id is allocated. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1931 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | |
| 1933 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1934 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1936 | * peers requested adaptation layer. |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1937 | * |
| 1938 | * This also needs to be done as a side effect for the same reason as |
| 1939 | * above. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | */ |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1941 | if (asoc->peer.adaptation_ind) |
| 1942 | sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 1944 | if (!asoc->peer.auth_capable) |
| 1945 | sctp_add_cmd_sf(commands, SCTP_CMD_PEER_NO_AUTH, SCTP_NULL()); |
| 1946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | return SCTP_DISPOSITION_CONSUME; |
| 1948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | nomem: |
| 1950 | return SCTP_DISPOSITION_NOMEM; |
| 1951 | } |
| 1952 | |
| 1953 | /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C') |
| 1954 | * |
| 1955 | * Section 5.2.4 |
| 1956 | * C) In this case, the local endpoint's cookie has arrived late. |
| 1957 | * Before it arrived, the local endpoint sent an INIT and received an |
| 1958 | * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag |
| 1959 | * but a new tag of its own. |
| 1960 | */ |
| 1961 | /* This case represents an initialization collision. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1962 | static enum sctp_disposition sctp_sf_do_dupcook_c( |
| 1963 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1964 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | const struct sctp_association *asoc, |
| 1966 | struct sctp_chunk *chunk, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 1967 | struct sctp_cmd_seq *commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | struct sctp_association *new_asoc) |
| 1969 | { |
| 1970 | /* The cookie should be silently discarded. |
| 1971 | * The endpoint SHOULD NOT change states and should leave |
| 1972 | * any timers running. |
| 1973 | */ |
| 1974 | return SCTP_DISPOSITION_DISCARD; |
| 1975 | } |
| 1976 | |
| 1977 | /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D') |
| 1978 | * |
| 1979 | * Section 5.2.4 |
| 1980 | * |
| 1981 | * D) When both local and remote tags match the endpoint should always |
| 1982 | * enter the ESTABLISHED state, if it has not already done so. |
| 1983 | */ |
| 1984 | /* This case represents an initialization collision. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 1985 | static enum sctp_disposition sctp_sf_do_dupcook_d( |
| 1986 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1987 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | const struct sctp_association *asoc, |
| 1989 | struct sctp_chunk *chunk, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 1990 | struct sctp_cmd_seq *commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | struct sctp_association *new_asoc) |
| 1992 | { |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 1993 | struct sctp_ulpevent *ev = NULL, *ai_ev = NULL, *auth_ev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | struct sctp_chunk *repl; |
| 1995 | |
| 1996 | /* Clarification from Implementor's Guide: |
| 1997 | * D) When both local and remote tags match the endpoint should |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1998 | * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state. |
| 1999 | * It should stop any cookie timer that may be running and send |
| 2000 | * a COOKIE ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | */ |
| 2002 | |
Xin Long | 59d8d44 | 2018-05-05 14:59:47 +0800 | [diff] [blame] | 2003 | if (!sctp_auth_chunk_verify(net, chunk, asoc)) |
| 2004 | return SCTP_DISPOSITION_DISCARD; |
| 2005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | /* Don't accidentally move back into established state. */ |
| 2007 | if (asoc->state < SCTP_STATE_ESTABLISHED) { |
| 2008 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2009 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 2010 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2011 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2012 | SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, |
| 2014 | SCTP_NULL()); |
| 2015 | |
| 2016 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 2017 | * |
| 2018 | * D) IMPLEMENTATION NOTE: An implementation may choose |
| 2019 | * to send the Communication Up notification to the |
| 2020 | * SCTP user upon reception of a valid COOKIE |
| 2021 | * ECHO chunk. |
| 2022 | */ |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 2023 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | SCTP_COMM_UP, 0, |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 2025 | asoc->c.sinit_num_ostreams, |
| 2026 | asoc->c.sinit_max_instreams, |
YOSHIFUJI Hideaki | 9cbcbf4 | 2007-07-19 10:44:50 +0900 | [diff] [blame] | 2027 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | if (!ev) |
| 2029 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | |
| 2031 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 2032 | * When a peer sends a Adaptation Layer Indication parameter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | * SCTP delivers this notification to inform the application |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 2034 | * that of the peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 2036 | if (asoc->peer.adaptation_ind) { |
| 2037 | ai_ev = sctp_ulpevent_make_adaptation_indication(asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 2039 | if (!ai_ev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | goto nomem; |
| 2041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | } |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 2043 | |
| 2044 | if (!asoc->peer.auth_capable) { |
| 2045 | auth_ev = sctp_ulpevent_make_authkey(asoc, 0, |
| 2046 | SCTP_AUTH_NO_AUTH, |
| 2047 | GFP_ATOMIC); |
| 2048 | if (!auth_ev) |
| 2049 | goto nomem; |
| 2050 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | |
Xin Long | 46e16d4 | 2018-05-02 13:39:46 +0800 | [diff] [blame] | 2053 | repl = sctp_make_cookie_ack(asoc, chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | if (!repl) |
| 2055 | goto nomem; |
| 2056 | |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 2057 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 2058 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 2059 | if (ev) |
| 2060 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 2061 | SCTP_ULPEVENT(ev)); |
| 2062 | if (ai_ev) |
| 2063 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 2064 | SCTP_ULPEVENT(ai_ev)); |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 2065 | if (auth_ev) |
| 2066 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 2067 | SCTP_ULPEVENT(auth_ev)); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 2068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | return SCTP_DISPOSITION_CONSUME; |
| 2070 | |
| 2071 | nomem: |
Xin Long | 30f6ebf | 2018-03-14 19:05:34 +0800 | [diff] [blame] | 2072 | if (auth_ev) |
| 2073 | sctp_ulpevent_free(auth_ev); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 2074 | if (ai_ev) |
| 2075 | sctp_ulpevent_free(ai_ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | if (ev) |
| 2077 | sctp_ulpevent_free(ev); |
| 2078 | return SCTP_DISPOSITION_NOMEM; |
| 2079 | } |
| 2080 | |
| 2081 | /* |
| 2082 | * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying |
| 2083 | * chunk was retransmitted and then delayed in the network. |
| 2084 | * |
| 2085 | * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists |
| 2086 | * |
| 2087 | * Verification Tag: None. Do cookie validation. |
| 2088 | * |
| 2089 | * Inputs |
| 2090 | * (endpoint, asoc, chunk) |
| 2091 | * |
| 2092 | * Outputs |
| 2093 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2094 | * |
| 2095 | * The return value is the disposition of the chunk. |
| 2096 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2097 | enum sctp_disposition sctp_sf_do_5_2_4_dupcook( |
| 2098 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2099 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 2101 | const union sctp_subtype type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 2103 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | struct sctp_association *new_asoc; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2106 | struct sctp_chunk *chunk = arg; |
| 2107 | enum sctp_disposition retval; |
| 2108 | struct sctp_chunk *err_chk_p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | int error = 0; |
| 2110 | char action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | |
| 2112 | /* Make sure that the chunk has a valid length from the protocol |
| 2113 | * perspective. In this case check to make sure we have at least |
| 2114 | * enough for the chunk header. Cookie length verification is |
| 2115 | * done later. |
| 2116 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 2117 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2118 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | commands); |
| 2120 | |
| 2121 | /* "Decode" the chunk. We have no optional parameters so we |
| 2122 | * are in good shape. |
| 2123 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2124 | chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data; |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 2125 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 2126 | sizeof(struct sctp_chunkhdr))) |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 2127 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
| 2129 | /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie |
| 2130 | * of a duplicate COOKIE ECHO match the Verification Tags of the |
| 2131 | * current association, consider the State Cookie valid even if |
| 2132 | * the lifespan is exceeded. |
| 2133 | */ |
| 2134 | new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, |
| 2135 | &err_chk_p); |
| 2136 | |
| 2137 | /* FIXME: |
| 2138 | * If the re-build failed, what is the proper error path |
| 2139 | * from here? |
| 2140 | * |
| 2141 | * [We should abort the association. --piggy] |
| 2142 | */ |
| 2143 | if (!new_asoc) { |
| 2144 | /* FIXME: Several errors are possible. A bad cookie should |
| 2145 | * be silently discarded, but think about logging it too. |
| 2146 | */ |
| 2147 | switch (error) { |
| 2148 | case -SCTP_IERROR_NOMEM: |
| 2149 | goto nomem; |
| 2150 | |
| 2151 | case -SCTP_IERROR_STALE_COOKIE: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2152 | sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | err_chk_p); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2154 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | case -SCTP_IERROR_BAD_SIG: |
| 2156 | default: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2157 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
Richard Haines | 2277c7c | 2018-02-13 20:56:24 +0000 | [diff] [blame] | 2161 | /* Update socket peer label if first association. */ |
| 2162 | if (security_sctp_assoc_request((struct sctp_endpoint *)ep, |
Navid Emamdoost | b6631c6 | 2019-11-22 16:17:56 -0600 | [diff] [blame] | 2163 | chunk->skb)) { |
| 2164 | sctp_association_free(new_asoc); |
Richard Haines | 2277c7c | 2018-02-13 20:56:24 +0000 | [diff] [blame] | 2165 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Navid Emamdoost | b6631c6 | 2019-11-22 16:17:56 -0600 | [diff] [blame] | 2166 | } |
Richard Haines | 2277c7c | 2018-02-13 20:56:24 +0000 | [diff] [blame] | 2167 | |
Xin Long | 7e06297 | 2017-05-23 13:28:55 +0800 | [diff] [blame] | 2168 | /* Set temp so that it won't be added into hashtable */ |
| 2169 | new_asoc->temp = 1; |
| 2170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | /* Compare the tie_tag in cookie with the verification tag of |
| 2172 | * current association. |
| 2173 | */ |
| 2174 | action = sctp_tietags_compare(new_asoc, asoc); |
| 2175 | |
| 2176 | switch (action) { |
| 2177 | case 'A': /* Association restart. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2178 | retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | new_asoc); |
| 2180 | break; |
| 2181 | |
| 2182 | case 'B': /* Collision case B. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2183 | retval = sctp_sf_do_dupcook_b(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | new_asoc); |
| 2185 | break; |
| 2186 | |
| 2187 | case 'C': /* Collision case C. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2188 | retval = sctp_sf_do_dupcook_c(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | new_asoc); |
| 2190 | break; |
| 2191 | |
| 2192 | case 'D': /* Collision case D. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2193 | retval = sctp_sf_do_dupcook_d(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | new_asoc); |
| 2195 | break; |
| 2196 | |
| 2197 | default: /* Discard packet for all others. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2198 | retval = sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | |
| 2202 | /* Delete the tempory new association. */ |
Vlad Yasevich | f281563 | 2013-03-12 15:53:23 +0000 | [diff] [blame] | 2203 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC, SCTP_ASOC(new_asoc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 2205 | |
Max Matveev | d5ccd49 | 2011-08-29 21:02:24 +0000 | [diff] [blame] | 2206 | /* Restore association pointer to provide SCTP command interpeter |
| 2207 | * with a valid context in case it needs to manipulate |
| 2208 | * the queues */ |
| 2209 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC, |
| 2210 | SCTP_ASOC((struct sctp_association *)asoc)); |
| 2211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | return retval; |
| 2213 | |
| 2214 | nomem: |
| 2215 | return SCTP_DISPOSITION_NOMEM; |
| 2216 | } |
| 2217 | |
| 2218 | /* |
| 2219 | * Process an ABORT. (SHUTDOWN-PENDING state) |
| 2220 | * |
| 2221 | * See sctp_sf_do_9_1_abort(). |
| 2222 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2223 | enum sctp_disposition sctp_sf_shutdown_pending_abort( |
| 2224 | struct net *net, |
| 2225 | const struct sctp_endpoint *ep, |
| 2226 | const struct sctp_association *asoc, |
| 2227 | const union sctp_subtype type, |
| 2228 | void *arg, |
| 2229 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | { |
| 2231 | struct sctp_chunk *chunk = arg; |
| 2232 | |
| 2233 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2234 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | |
| 2236 | /* Make sure that the ABORT chunk has a valid length. |
| 2237 | * Since this is an ABORT chunk, we have to discard it |
| 2238 | * because of the following text: |
| 2239 | * RFC 2960, Section 3.3.7 |
| 2240 | * If an endpoint receives an ABORT with a format error or for an |
| 2241 | * association that doesn't exist, it MUST silently discard it. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2242 | * Because the length is "invalid", we can't really discard just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | * as we do not know its true length. So, to be safe, discard the |
| 2244 | * packet. |
| 2245 | */ |
Xin Long | 441ae65 | 2017-07-23 09:34:36 +0800 | [diff] [blame] | 2246 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2247 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2249 | /* ADD-IP: Special case for ABORT chunks |
| 2250 | * F4) One special consideration is that ABORT Chunks arriving |
| 2251 | * destined to the IP address being deleted MUST be |
| 2252 | * ignored (see Section 5.3.1 for further details). |
| 2253 | */ |
| 2254 | if (SCTP_ADDR_DEL == |
| 2255 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2256 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2257 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2258 | return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | /* |
| 2262 | * Process an ABORT. (SHUTDOWN-SENT state) |
| 2263 | * |
| 2264 | * See sctp_sf_do_9_1_abort(). |
| 2265 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2266 | enum sctp_disposition sctp_sf_shutdown_sent_abort( |
| 2267 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2268 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 2270 | const union sctp_subtype type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 2272 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | { |
| 2274 | struct sctp_chunk *chunk = arg; |
| 2275 | |
| 2276 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2277 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | |
| 2279 | /* Make sure that the ABORT chunk has a valid length. |
| 2280 | * Since this is an ABORT chunk, we have to discard it |
| 2281 | * because of the following text: |
| 2282 | * RFC 2960, Section 3.3.7 |
| 2283 | * If an endpoint receives an ABORT with a format error or for an |
| 2284 | * association that doesn't exist, it MUST silently discard it. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2285 | * Because the length is "invalid", we can't really discard just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | * as we do not know its true length. So, to be safe, discard the |
| 2287 | * packet. |
| 2288 | */ |
Xin Long | 441ae65 | 2017-07-23 09:34:36 +0800 | [diff] [blame] | 2289 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2290 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2292 | /* ADD-IP: Special case for ABORT chunks |
| 2293 | * F4) One special consideration is that ABORT Chunks arriving |
| 2294 | * destined to the IP address being deleted MUST be |
| 2295 | * ignored (see Section 5.3.1 for further details). |
| 2296 | */ |
| 2297 | if (SCTP_ADDR_DEL == |
| 2298 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2299 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | /* Stop the T2-shutdown timer. */ |
| 2302 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2303 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 2304 | |
| 2305 | /* Stop the T5-shutdown guard timer. */ |
| 2306 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2307 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 2308 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2309 | return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | /* |
| 2313 | * Process an ABORT. (SHUTDOWN-ACK-SENT state) |
| 2314 | * |
| 2315 | * See sctp_sf_do_9_1_abort(). |
| 2316 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2317 | enum sctp_disposition sctp_sf_shutdown_ack_sent_abort( |
| 2318 | struct net *net, |
| 2319 | const struct sctp_endpoint *ep, |
| 2320 | const struct sctp_association *asoc, |
| 2321 | const union sctp_subtype type, |
| 2322 | void *arg, |
| 2323 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | { |
| 2325 | /* The same T2 timer, so we should be able to use |
| 2326 | * common function with the SHUTDOWN-SENT state. |
| 2327 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2328 | return sctp_sf_shutdown_sent_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | /* |
| 2332 | * Handle an Error received in COOKIE_ECHOED state. |
| 2333 | * |
| 2334 | * Only handle the error type of stale COOKIE Error, the other errors will |
| 2335 | * be ignored. |
| 2336 | * |
| 2337 | * Inputs |
| 2338 | * (endpoint, asoc, chunk) |
| 2339 | * |
| 2340 | * Outputs |
| 2341 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2342 | * |
| 2343 | * The return value is the disposition of the chunk. |
| 2344 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2345 | enum sctp_disposition sctp_sf_cookie_echoed_err( |
| 2346 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2347 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 2349 | const union sctp_subtype type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 2351 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | { |
| 2353 | struct sctp_chunk *chunk = arg; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2354 | struct sctp_errhdr *err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | |
| 2356 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2357 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | |
| 2359 | /* Make sure that the ERROR chunk has a valid length. |
| 2360 | * The parameter walking depends on this as well. |
| 2361 | */ |
Xin Long | 87caeba | 2017-08-03 15:42:12 +0800 | [diff] [blame] | 2362 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2363 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | commands); |
| 2365 | |
| 2366 | /* Process the error here */ |
| 2367 | /* FUTURE FIXME: When PR-SCTP related and other optional |
| 2368 | * parms are emitted, this will have to change to handle multiple |
| 2369 | * errors. |
| 2370 | */ |
| 2371 | sctp_walk_errors(err, chunk->chunk_hdr) { |
| 2372 | if (SCTP_ERROR_STALE_COOKIE == err->cause) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2373 | return sctp_sf_do_5_2_6_stale(net, ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | arg, commands); |
| 2375 | } |
| 2376 | |
| 2377 | /* It is possible to have malformed error causes, and that |
| 2378 | * will cause us to end the walk early. However, since |
| 2379 | * we are discarding the packet, there should be no adverse |
| 2380 | * affects. |
| 2381 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2382 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | /* |
| 2386 | * Handle a Stale COOKIE Error |
| 2387 | * |
| 2388 | * Section: 5.2.6 Handle Stale COOKIE Error |
| 2389 | * If the association is in the COOKIE-ECHOED state, the endpoint may elect |
| 2390 | * one of the following three alternatives. |
| 2391 | * ... |
| 2392 | * 3) Send a new INIT chunk to the endpoint, adding a Cookie |
| 2393 | * Preservative parameter requesting an extension to the lifetime of |
| 2394 | * the State Cookie. When calculating the time extension, an |
| 2395 | * implementation SHOULD use the RTT information measured based on the |
| 2396 | * previous COOKIE ECHO / ERROR exchange, and should add no more |
| 2397 | * than 1 second beyond the measured RTT, due to long State Cookie |
| 2398 | * lifetimes making the endpoint more subject to a replay attack. |
| 2399 | * |
| 2400 | * Verification Tag: Not explicit, but safe to ignore. |
| 2401 | * |
| 2402 | * Inputs |
| 2403 | * (endpoint, asoc, chunk) |
| 2404 | * |
| 2405 | * Outputs |
| 2406 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2407 | * |
| 2408 | * The return value is the disposition of the chunk. |
| 2409 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2410 | static enum sctp_disposition sctp_sf_do_5_2_6_stale( |
| 2411 | struct net *net, |
| 2412 | const struct sctp_endpoint *ep, |
| 2413 | const struct sctp_association *asoc, |
| 2414 | const union sctp_subtype type, |
| 2415 | void *arg, |
| 2416 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2418 | int attempts = asoc->init_err_counter + 1; |
Xin Long | 365ddb6 | 2017-07-17 11:29:51 +0800 | [diff] [blame] | 2419 | struct sctp_chunk *chunk = arg, *reply; |
| 2420 | struct sctp_cookie_preserve_param bht; |
| 2421 | struct sctp_bind_addr *bp; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2422 | struct sctp_errhdr *err; |
Xin Long | 365ddb6 | 2017-07-17 11:29:51 +0800 | [diff] [blame] | 2423 | u32 stale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 2425 | if (attempts > asoc->max_init_attempts) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2426 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 2427 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 2429 | SCTP_PERR(SCTP_ERROR_STALE_COOKIE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | return SCTP_DISPOSITION_DELETE_TCB; |
| 2431 | } |
| 2432 | |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2433 | err = (struct sctp_errhdr *)(chunk->skb->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | |
| 2435 | /* When calculating the time extension, an implementation |
| 2436 | * SHOULD use the RTT information measured based on the |
| 2437 | * previous COOKIE ECHO / ERROR exchange, and should add no |
| 2438 | * more than 1 second beyond the measured RTT, due to long |
| 2439 | * State Cookie lifetimes making the endpoint more subject to |
| 2440 | * a replay attack. |
| 2441 | * Measure of Staleness's unit is usec. (1/1000000 sec) |
| 2442 | * Suggested Cookie Life-span Increment's unit is msec. |
| 2443 | * (1/1000 sec) |
| 2444 | * In general, if you use the suggested cookie life, the value |
| 2445 | * found in the field of measure of staleness should be doubled |
| 2446 | * to give ample time to retransmit the new cookie and thus |
| 2447 | * yield a higher probability of success on the reattempt. |
| 2448 | */ |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2449 | stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | stale = (stale * 2) / 1000; |
| 2451 | |
| 2452 | bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE; |
| 2453 | bht.param_hdr.length = htons(sizeof(bht)); |
| 2454 | bht.lifespan_increment = htonl(stale); |
| 2455 | |
| 2456 | /* Build that new INIT chunk. */ |
| 2457 | bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; |
| 2458 | reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht)); |
| 2459 | if (!reply) |
| 2460 | goto nomem; |
| 2461 | |
| 2462 | sctp_addto_chunk(reply, sizeof(bht), &bht); |
| 2463 | |
| 2464 | /* Clear peer's init_tag cached in assoc as we are sending a new INIT */ |
| 2465 | sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL()); |
| 2466 | |
| 2467 | /* Stop pending T3-rtx and heartbeat timers */ |
| 2468 | sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL()); |
| 2469 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 2470 | |
| 2471 | /* Delete non-primary peer ip addresses since we are transitioning |
| 2472 | * back to the COOKIE-WAIT state |
| 2473 | */ |
| 2474 | sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL()); |
| 2475 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2476 | /* If we've sent any data bundled with COOKIE-ECHO we will need to |
| 2477 | * resend |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | */ |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 2479 | sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | SCTP_TRANSPORT(asoc->peer.primary_path)); |
| 2481 | |
| 2482 | /* Cast away the const modifier, as we want to just |
| 2483 | * rerun it through as a sideffect. |
| 2484 | */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2485 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | |
| 2487 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2488 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 2489 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2490 | SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); |
| 2491 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 2492 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 2493 | |
| 2494 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 2495 | |
| 2496 | return SCTP_DISPOSITION_CONSUME; |
| 2497 | |
| 2498 | nomem: |
| 2499 | return SCTP_DISPOSITION_NOMEM; |
| 2500 | } |
| 2501 | |
| 2502 | /* |
| 2503 | * Process an ABORT. |
| 2504 | * |
| 2505 | * Section: 9.1 |
| 2506 | * After checking the Verification Tag, the receiving endpoint shall |
| 2507 | * remove the association from its record, and shall report the |
| 2508 | * termination to its upper layer. |
| 2509 | * |
| 2510 | * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules |
| 2511 | * B) Rules for packet carrying ABORT: |
| 2512 | * |
| 2513 | * - The endpoint shall always fill in the Verification Tag field of the |
| 2514 | * outbound packet with the destination endpoint's tag value if it |
| 2515 | * is known. |
| 2516 | * |
| 2517 | * - If the ABORT is sent in response to an OOTB packet, the endpoint |
| 2518 | * MUST follow the procedure described in Section 8.4. |
| 2519 | * |
| 2520 | * - The receiver MUST accept the packet if the Verification Tag |
| 2521 | * matches either its own tag, OR the tag of its peer. Otherwise, the |
| 2522 | * receiver MUST silently discard the packet and take no further |
| 2523 | * action. |
| 2524 | * |
| 2525 | * Inputs |
| 2526 | * (endpoint, asoc, chunk) |
| 2527 | * |
| 2528 | * Outputs |
| 2529 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2530 | * |
| 2531 | * The return value is the disposition of the chunk. |
| 2532 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2533 | enum sctp_disposition sctp_sf_do_9_1_abort( |
| 2534 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2535 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 2537 | const union sctp_subtype type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 2539 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | { |
| 2541 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | |
| 2543 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2544 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | |
| 2546 | /* Make sure that the ABORT chunk has a valid length. |
| 2547 | * Since this is an ABORT chunk, we have to discard it |
| 2548 | * because of the following text: |
| 2549 | * RFC 2960, Section 3.3.7 |
| 2550 | * If an endpoint receives an ABORT with a format error or for an |
| 2551 | * association that doesn't exist, it MUST silently discard it. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2552 | * Because the length is "invalid", we can't really discard just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | * as we do not know its true length. So, to be safe, discard the |
| 2554 | * packet. |
| 2555 | */ |
Xin Long | 441ae65 | 2017-07-23 09:34:36 +0800 | [diff] [blame] | 2556 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2557 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2559 | /* ADD-IP: Special case for ABORT chunks |
| 2560 | * F4) One special consideration is that ABORT Chunks arriving |
| 2561 | * destined to the IP address being deleted MUST be |
| 2562 | * ignored (see Section 5.3.1 for further details). |
| 2563 | */ |
| 2564 | if (SCTP_ADDR_DEL == |
| 2565 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2566 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2567 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2568 | return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2569 | } |
| 2570 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2571 | static enum sctp_disposition __sctp_sf_do_9_1_abort( |
| 2572 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2573 | const struct sctp_endpoint *ep, |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2574 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 2575 | const union sctp_subtype type, |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2576 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 2577 | struct sctp_cmd_seq *commands) |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2578 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2579 | __be16 error = SCTP_ERROR_NO_ERROR; |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2580 | struct sctp_chunk *chunk = arg; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 2581 | unsigned int len; |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | /* See if we have an error cause code in the chunk. */ |
| 2584 | len = ntohs(chunk->chunk_hdr->length); |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2585 | if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) { |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2586 | struct sctp_errhdr *err; |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2587 | |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2588 | sctp_walk_errors(err, chunk->chunk_hdr); |
| 2589 | if ((void *)err != (void *)chunk->chunk_end) |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2590 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, |
| 2591 | commands); |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2592 | |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2593 | error = ((struct sctp_errhdr *)chunk->skb->data)->cause; |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2596 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2597 | /* ASSOC_FAILED will DELETE_TCB. */ |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 2598 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 2599 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 2600 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | |
| 2602 | return SCTP_DISPOSITION_ABORT; |
| 2603 | } |
| 2604 | |
| 2605 | /* |
| 2606 | * Process an ABORT. (COOKIE-WAIT state) |
| 2607 | * |
| 2608 | * See sctp_sf_do_9_1_abort() above. |
| 2609 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2610 | enum sctp_disposition sctp_sf_cookie_wait_abort( |
| 2611 | struct net *net, |
| 2612 | const struct sctp_endpoint *ep, |
| 2613 | const struct sctp_association *asoc, |
| 2614 | const union sctp_subtype type, |
| 2615 | void *arg, |
| 2616 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2618 | __be16 error = SCTP_ERROR_NO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | struct sctp_chunk *chunk = arg; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 2620 | unsigned int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | |
| 2622 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2623 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | |
| 2625 | /* Make sure that the ABORT chunk has a valid length. |
| 2626 | * Since this is an ABORT chunk, we have to discard it |
| 2627 | * because of the following text: |
| 2628 | * RFC 2960, Section 3.3.7 |
| 2629 | * If an endpoint receives an ABORT with a format error or for an |
| 2630 | * association that doesn't exist, it MUST silently discard it. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2631 | * Because the length is "invalid", we can't really discard just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | * as we do not know its true length. So, to be safe, discard the |
| 2633 | * packet. |
| 2634 | */ |
Xin Long | 441ae65 | 2017-07-23 09:34:36 +0800 | [diff] [blame] | 2635 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2636 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | |
| 2638 | /* See if we have an error cause code in the chunk. */ |
| 2639 | len = ntohs(chunk->chunk_hdr->length); |
| 2640 | if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2641 | error = ((struct sctp_errhdr *)chunk->skb->data)->cause; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2643 | return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED, asoc, |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2644 | chunk->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | /* |
| 2648 | * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state) |
| 2649 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2650 | enum sctp_disposition sctp_sf_cookie_wait_icmp_abort( |
| 2651 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2652 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 2654 | const union sctp_subtype type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 2656 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2658 | return sctp_stop_t1_and_abort(net, commands, SCTP_ERROR_NO_ERROR, |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2659 | ENOPROTOOPT, asoc, |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2660 | (struct sctp_transport *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | /* |
| 2664 | * Process an ABORT. (COOKIE-ECHOED state) |
| 2665 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2666 | enum sctp_disposition sctp_sf_cookie_echoed_abort( |
| 2667 | struct net *net, |
| 2668 | const struct sctp_endpoint *ep, |
| 2669 | const struct sctp_association *asoc, |
| 2670 | const union sctp_subtype type, |
| 2671 | void *arg, |
| 2672 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | { |
| 2674 | /* There is a single T1 timer, so we should be able to use |
| 2675 | * common function with the COOKIE-WAIT state. |
| 2676 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2677 | return sctp_sf_cookie_wait_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | /* |
| 2681 | * Stop T1 timer and abort association with "INIT failed". |
| 2682 | * |
| 2683 | * This is common code called by several sctp_sf_*_abort() functions above. |
| 2684 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2685 | static enum sctp_disposition sctp_stop_t1_and_abort( |
| 2686 | struct net *net, |
| 2687 | struct sctp_cmd_seq *commands, |
| 2688 | __be16 error, int sk_err, |
| 2689 | const struct sctp_association *asoc, |
| 2690 | struct sctp_transport *transport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 2692 | pr_debug("%s: ABORT received (INIT)\n", __func__); |
| 2693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2695 | SCTP_STATE(SCTP_STATE_CLOSED)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2696 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2698 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2699 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | /* CMD_INIT_FAILED will DELETE_TCB. */ |
| 2701 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 2702 | SCTP_PERR(error)); |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 2703 | |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2704 | return SCTP_DISPOSITION_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | /* |
| 2708 | * sctp_sf_do_9_2_shut |
| 2709 | * |
| 2710 | * Section: 9.2 |
| 2711 | * Upon the reception of the SHUTDOWN, the peer endpoint shall |
| 2712 | * - enter the SHUTDOWN-RECEIVED state, |
| 2713 | * |
| 2714 | * - stop accepting new data from its SCTP user |
| 2715 | * |
| 2716 | * - verify, by checking the Cumulative TSN Ack field of the chunk, |
| 2717 | * that all its outstanding DATA chunks have been received by the |
| 2718 | * SHUTDOWN sender. |
| 2719 | * |
| 2720 | * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT |
| 2721 | * send a SHUTDOWN in response to a ULP request. And should discard |
| 2722 | * subsequent SHUTDOWN chunks. |
| 2723 | * |
| 2724 | * If there are still outstanding DATA chunks left, the SHUTDOWN |
| 2725 | * receiver shall continue to follow normal data transmission |
| 2726 | * procedures defined in Section 6 until all outstanding DATA chunks |
| 2727 | * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept |
| 2728 | * new data from its SCTP user. |
| 2729 | * |
| 2730 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2731 | * |
| 2732 | * Inputs |
| 2733 | * (endpoint, asoc, chunk) |
| 2734 | * |
| 2735 | * Outputs |
| 2736 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2737 | * |
| 2738 | * The return value is the disposition of the chunk. |
| 2739 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2740 | enum sctp_disposition sctp_sf_do_9_2_shutdown( |
| 2741 | struct net *net, |
| 2742 | const struct sctp_endpoint *ep, |
| 2743 | const struct sctp_association *asoc, |
| 2744 | const union sctp_subtype type, |
| 2745 | void *arg, |
| 2746 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2748 | enum sctp_disposition disposition; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | struct sctp_chunk *chunk = arg; |
Xin Long | e61e405 | 2017-08-03 15:42:09 +0800 | [diff] [blame] | 2750 | struct sctp_shutdownhdr *sdh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | struct sctp_ulpevent *ev; |
Wei Yongjun | df10eec | 2008-10-23 01:00:21 -0700 | [diff] [blame] | 2752 | __u32 ctsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | |
| 2754 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2755 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | |
| 2757 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
Xin Long | ac23e68 | 2017-08-03 15:42:10 +0800 | [diff] [blame] | 2758 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2759 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | commands); |
| 2761 | |
| 2762 | /* Convert the elaborate header. */ |
Xin Long | e61e405 | 2017-08-03 15:42:09 +0800 | [diff] [blame] | 2763 | sdh = (struct sctp_shutdownhdr *)chunk->skb->data; |
| 2764 | skb_pull(chunk->skb, sizeof(*sdh)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | chunk->subh.shutdown_hdr = sdh; |
Wei Yongjun | df10eec | 2008-10-23 01:00:21 -0700 | [diff] [blame] | 2766 | ctsn = ntohl(sdh->cum_tsn_ack); |
| 2767 | |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2768 | if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 2769 | pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn, |
| 2770 | asoc->ctsn_ack_point); |
| 2771 | |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2772 | return SCTP_DISPOSITION_DISCARD; |
| 2773 | } |
| 2774 | |
Wei Yongjun | df10eec | 2008-10-23 01:00:21 -0700 | [diff] [blame] | 2775 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 2776 | * send, terminating the association and respond to the |
| 2777 | * sender with an ABORT. |
| 2778 | */ |
| 2779 | if (!TSN_lt(ctsn, asoc->next_tsn)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2780 | return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | |
Sridhar Samudrala | eb0e007 | 2005-09-22 23:48:38 -0700 | [diff] [blame] | 2782 | /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT |
| 2783 | * When a peer sends a SHUTDOWN, SCTP delivers this notification to |
| 2784 | * inform the application that it should cease sending data. |
| 2785 | */ |
| 2786 | ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC); |
| 2787 | if (!ev) { |
| 2788 | disposition = SCTP_DISPOSITION_NOMEM; |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2789 | goto out; |
Sridhar Samudrala | eb0e007 | 2005-09-22 23:48:38 -0700 | [diff] [blame] | 2790 | } |
| 2791 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 2792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | /* Upon the reception of the SHUTDOWN, the peer endpoint shall |
| 2794 | * - enter the SHUTDOWN-RECEIVED state, |
| 2795 | * - stop accepting new data from its SCTP user |
| 2796 | * |
| 2797 | * [This is implicit in the new state.] |
| 2798 | */ |
| 2799 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2800 | SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED)); |
| 2801 | disposition = SCTP_DISPOSITION_CONSUME; |
| 2802 | |
| 2803 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2804 | disposition = sctp_sf_do_9_2_shutdown_ack(net, ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | arg, commands); |
| 2806 | } |
| 2807 | |
| 2808 | if (SCTP_DISPOSITION_NOMEM == disposition) |
| 2809 | goto out; |
| 2810 | |
| 2811 | /* - verify, by checking the Cumulative TSN Ack field of the |
| 2812 | * chunk, that all its outstanding DATA chunks have been |
| 2813 | * received by the SHUTDOWN sender. |
| 2814 | */ |
| 2815 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN, |
Al Viro | 2178eda | 2006-11-20 17:26:53 -0800 | [diff] [blame] | 2816 | SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | out: |
| 2819 | return disposition; |
| 2820 | } |
| 2821 | |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2822 | /* |
| 2823 | * sctp_sf_do_9_2_shut_ctsn |
| 2824 | * |
| 2825 | * Once an endpoint has reached the SHUTDOWN-RECEIVED state, |
| 2826 | * it MUST NOT send a SHUTDOWN in response to a ULP request. |
| 2827 | * The Cumulative TSN Ack of the received SHUTDOWN chunk |
| 2828 | * MUST be processed. |
| 2829 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2830 | enum sctp_disposition sctp_sf_do_9_2_shut_ctsn( |
| 2831 | struct net *net, |
| 2832 | const struct sctp_endpoint *ep, |
| 2833 | const struct sctp_association *asoc, |
| 2834 | const union sctp_subtype type, |
| 2835 | void *arg, |
| 2836 | struct sctp_cmd_seq *commands) |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2837 | { |
| 2838 | struct sctp_chunk *chunk = arg; |
Xin Long | e61e405 | 2017-08-03 15:42:09 +0800 | [diff] [blame] | 2839 | struct sctp_shutdownhdr *sdh; |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2840 | __u32 ctsn; |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2841 | |
| 2842 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2843 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2844 | |
| 2845 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
Xin Long | ac23e68 | 2017-08-03 15:42:10 +0800 | [diff] [blame] | 2846 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2847 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2848 | commands); |
| 2849 | |
Xin Long | e61e405 | 2017-08-03 15:42:09 +0800 | [diff] [blame] | 2850 | sdh = (struct sctp_shutdownhdr *)chunk->skb->data; |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2851 | ctsn = ntohl(sdh->cum_tsn_ack); |
| 2852 | |
| 2853 | if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 2854 | pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn, |
| 2855 | asoc->ctsn_ack_point); |
| 2856 | |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2857 | return SCTP_DISPOSITION_DISCARD; |
| 2858 | } |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2859 | |
| 2860 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 2861 | * send, terminating the association and respond to the |
| 2862 | * sender with an ABORT. |
| 2863 | */ |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2864 | if (!TSN_lt(ctsn, asoc->next_tsn)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2865 | return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands); |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2866 | |
| 2867 | /* verify, by checking the Cumulative TSN Ack field of the |
| 2868 | * chunk, that all its outstanding DATA chunks have been |
| 2869 | * received by the SHUTDOWN sender. |
| 2870 | */ |
| 2871 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN, |
| 2872 | SCTP_BE32(sdh->cum_tsn_ack)); |
| 2873 | |
| 2874 | return SCTP_DISPOSITION_CONSUME; |
| 2875 | } |
| 2876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | /* RFC 2960 9.2 |
| 2878 | * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk |
| 2879 | * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination |
| 2880 | * transport addresses (either in the IP addresses or in the INIT chunk) |
| 2881 | * that belong to this association, it should discard the INIT chunk and |
| 2882 | * retransmit the SHUTDOWN ACK chunk. |
| 2883 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2884 | enum sctp_disposition sctp_sf_do_9_2_reshutack( |
| 2885 | struct net *net, |
| 2886 | const struct sctp_endpoint *ep, |
| 2887 | const struct sctp_association *asoc, |
| 2888 | const union sctp_subtype type, |
| 2889 | void *arg, |
| 2890 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2892 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | struct sctp_chunk *reply; |
| 2894 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 2895 | /* Make sure that the chunk has a valid length */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 2896 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2897 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 2898 | commands); |
| 2899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | /* Since we are not going to really process this INIT, there |
| 2901 | * is no point in verifying chunk boundries. Just generate |
| 2902 | * the SHUTDOWN ACK. |
| 2903 | */ |
| 2904 | reply = sctp_make_shutdown_ack(asoc, chunk); |
| 2905 | if (NULL == reply) |
| 2906 | goto nomem; |
| 2907 | |
| 2908 | /* Set the transport for the SHUTDOWN ACK chunk and the timeout for |
| 2909 | * the T2-SHUTDOWN timer. |
| 2910 | */ |
| 2911 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 2912 | |
| 2913 | /* and restart the T2-shutdown timer. */ |
| 2914 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 2915 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 2916 | |
| 2917 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 2918 | |
| 2919 | return SCTP_DISPOSITION_CONSUME; |
| 2920 | nomem: |
| 2921 | return SCTP_DISPOSITION_NOMEM; |
| 2922 | } |
| 2923 | |
| 2924 | /* |
| 2925 | * sctp_sf_do_ecn_cwr |
| 2926 | * |
| 2927 | * Section: Appendix A: Explicit Congestion Notification |
| 2928 | * |
| 2929 | * CWR: |
| 2930 | * |
| 2931 | * RFC 2481 details a specific bit for a sender to send in the header of |
| 2932 | * its next outbound TCP segment to indicate to its peer that it has |
| 2933 | * reduced its congestion window. This is termed the CWR bit. For |
| 2934 | * SCTP the same indication is made by including the CWR chunk. |
| 2935 | * This chunk contains one data element, i.e. the TSN number that |
| 2936 | * was sent in the ECNE chunk. This element represents the lowest |
| 2937 | * TSN number in the datagram that was originally marked with the |
| 2938 | * CE bit. |
| 2939 | * |
| 2940 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2941 | * Inputs |
| 2942 | * (endpoint, asoc, chunk) |
| 2943 | * |
| 2944 | * Outputs |
| 2945 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2946 | * |
| 2947 | * The return value is the disposition of the chunk. |
| 2948 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 2949 | enum sctp_disposition sctp_sf_do_ecn_cwr(struct net *net, |
| 2950 | const struct sctp_endpoint *ep, |
| 2951 | const struct sctp_association *asoc, |
| 2952 | const union sctp_subtype type, |
| 2953 | void *arg, |
| 2954 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | struct sctp_chunk *chunk = arg; |
Xin Long | 65f7710 | 2017-08-03 15:42:16 +0800 | [diff] [blame] | 2957 | struct sctp_cwrhdr *cwr; |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2958 | u32 lowest_tsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | |
| 2960 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2961 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | |
Xin Long | b515fd2 | 2017-08-03 15:42:15 +0800 | [diff] [blame] | 2963 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2964 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2966 | |
Xin Long | 65f7710 | 2017-08-03 15:42:16 +0800 | [diff] [blame] | 2967 | cwr = (struct sctp_cwrhdr *)chunk->skb->data; |
| 2968 | skb_pull(chunk->skb, sizeof(*cwr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2970 | lowest_tsn = ntohl(cwr->lowest_tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | |
| 2972 | /* Does this CWR ack the last sent congestion notification? */ |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2973 | if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | /* Stop sending ECNE. */ |
| 2975 | sctp_add_cmd_sf(commands, |
| 2976 | SCTP_CMD_ECN_CWR, |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2977 | SCTP_U32(lowest_tsn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | } |
| 2979 | return SCTP_DISPOSITION_CONSUME; |
| 2980 | } |
| 2981 | |
| 2982 | /* |
| 2983 | * sctp_sf_do_ecne |
| 2984 | * |
| 2985 | * Section: Appendix A: Explicit Congestion Notification |
| 2986 | * |
| 2987 | * ECN-Echo |
| 2988 | * |
| 2989 | * RFC 2481 details a specific bit for a receiver to send back in its |
| 2990 | * TCP acknowledgements to notify the sender of the Congestion |
| 2991 | * Experienced (CE) bit having arrived from the network. For SCTP this |
| 2992 | * same indication is made by including the ECNE chunk. This chunk |
| 2993 | * contains one data element, i.e. the lowest TSN associated with the IP |
| 2994 | * datagram marked with the CE bit..... |
| 2995 | * |
| 2996 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2997 | * Inputs |
| 2998 | * (endpoint, asoc, chunk) |
| 2999 | * |
| 3000 | * Outputs |
| 3001 | * (asoc, reply_msg, msg_up, timers, counters) |
| 3002 | * |
| 3003 | * The return value is the disposition of the chunk. |
| 3004 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3005 | enum sctp_disposition sctp_sf_do_ecne(struct net *net, |
| 3006 | const struct sctp_endpoint *ep, |
| 3007 | const struct sctp_association *asoc, |
| 3008 | const union sctp_subtype type, |
| 3009 | void *arg, struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | struct sctp_chunk *chunk = arg; |
Xin Long | 1fb6d83 | 2017-08-03 15:42:14 +0800 | [diff] [blame] | 3012 | struct sctp_ecnehdr *ecne; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | |
| 3014 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3015 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | |
Xin Long | b515fd2 | 2017-08-03 15:42:15 +0800 | [diff] [blame] | 3017 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3018 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | commands); |
| 3020 | |
Xin Long | 1fb6d83 | 2017-08-03 15:42:14 +0800 | [diff] [blame] | 3021 | ecne = (struct sctp_ecnehdr *)chunk->skb->data; |
| 3022 | skb_pull(chunk->skb, sizeof(*ecne)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | |
| 3024 | /* If this is a newer ECNE than the last CWR packet we sent out */ |
| 3025 | sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE, |
| 3026 | SCTP_U32(ntohl(ecne->lowest_tsn))); |
| 3027 | |
| 3028 | return SCTP_DISPOSITION_CONSUME; |
| 3029 | } |
| 3030 | |
| 3031 | /* |
| 3032 | * Section: 6.2 Acknowledgement on Reception of DATA Chunks |
| 3033 | * |
| 3034 | * The SCTP endpoint MUST always acknowledge the reception of each valid |
| 3035 | * DATA chunk. |
| 3036 | * |
| 3037 | * The guidelines on delayed acknowledgement algorithm specified in |
| 3038 | * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an |
| 3039 | * acknowledgement SHOULD be generated for at least every second packet |
| 3040 | * (not every second DATA chunk) received, and SHOULD be generated within |
| 3041 | * 200 ms of the arrival of any unacknowledged DATA chunk. In some |
| 3042 | * situations it may be beneficial for an SCTP transmitter to be more |
| 3043 | * conservative than the algorithms detailed in this document allow. |
| 3044 | * However, an SCTP transmitter MUST NOT be more aggressive than the |
| 3045 | * following algorithms allow. |
| 3046 | * |
| 3047 | * A SCTP receiver MUST NOT generate more than one SACK for every |
| 3048 | * incoming packet, other than to update the offered window as the |
| 3049 | * receiving application consumes new data. |
| 3050 | * |
| 3051 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3052 | * |
| 3053 | * Inputs |
| 3054 | * (endpoint, asoc, chunk) |
| 3055 | * |
| 3056 | * Outputs |
| 3057 | * (asoc, reply_msg, msg_up, timers, counters) |
| 3058 | * |
| 3059 | * The return value is the disposition of the chunk. |
| 3060 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3061 | enum sctp_disposition sctp_sf_eat_data_6_2(struct net *net, |
| 3062 | const struct sctp_endpoint *ep, |
| 3063 | const struct sctp_association *asoc, |
| 3064 | const union sctp_subtype type, |
| 3065 | void *arg, |
| 3066 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | { |
Xin Long | c488b77 | 2017-08-11 10:23:53 +0800 | [diff] [blame] | 3068 | union sctp_arg force = SCTP_NOFORCE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | struct sctp_chunk *chunk = arg; |
| 3070 | int error; |
| 3071 | |
| 3072 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3073 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3074 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3075 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3076 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | |
Xin Long | 9d4ceaf | 2017-12-08 21:04:03 +0800 | [diff] [blame] | 3078 | if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3079 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | commands); |
| 3081 | |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 3082 | error = sctp_eat_data(asoc, chunk, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | switch (error) { |
| 3084 | case SCTP_IERROR_NO_ERROR: |
| 3085 | break; |
| 3086 | case SCTP_IERROR_HIGH_TSN: |
| 3087 | case SCTP_IERROR_BAD_STREAM: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3088 | SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | goto discard_noforce; |
| 3090 | case SCTP_IERROR_DUP_TSN: |
| 3091 | case SCTP_IERROR_IGNORE_TSN: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3092 | SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | goto discard_force; |
| 3094 | case SCTP_IERROR_NO_DATA: |
Marcelo Ricardo Leitner | 649621e | 2016-01-08 11:00:54 -0200 | [diff] [blame] | 3095 | return SCTP_DISPOSITION_ABORT; |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 3096 | case SCTP_IERROR_PROTO_VIOLATION: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3097 | return sctp_sf_abort_violation(net, ep, asoc, chunk, commands, |
Xin Long | 3583df1 | 2017-06-30 11:52:19 +0800 | [diff] [blame] | 3098 | (u8 *)chunk->subh.data_hdr, |
Xin Long | 9d4ceaf | 2017-12-08 21:04:03 +0800 | [diff] [blame] | 3099 | sctp_datahdr_len(&asoc->stream)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | default: |
| 3101 | BUG(); |
| 3102 | } |
| 3103 | |
Wei Yongjun | 6dc7694 | 2009-11-23 15:53:53 -0500 | [diff] [blame] | 3104 | if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM) |
| 3105 | force = SCTP_FORCE(); |
| 3106 | |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 3107 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 3109 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 3110 | } |
| 3111 | |
| 3112 | /* If this is the last chunk in a packet, we need to count it |
| 3113 | * toward sack generation. Note that we need to SACK every |
| 3114 | * OTHER packet containing data chunks, EVEN IF WE DISCARD |
| 3115 | * THEM. We elect to NOT generate SACK's if the chunk fails |
| 3116 | * the verification tag test. |
| 3117 | * |
| 3118 | * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks |
| 3119 | * |
| 3120 | * The SCTP endpoint MUST always acknowledge the reception of |
| 3121 | * each valid DATA chunk. |
| 3122 | * |
| 3123 | * The guidelines on delayed acknowledgement algorithm |
| 3124 | * specified in Section 4.2 of [RFC2581] SHOULD be followed. |
| 3125 | * Specifically, an acknowledgement SHOULD be generated for at |
| 3126 | * least every second packet (not every second DATA chunk) |
| 3127 | * received, and SHOULD be generated within 200 ms of the |
| 3128 | * arrival of any unacknowledged DATA chunk. In some |
| 3129 | * situations it may be beneficial for an SCTP transmitter to |
| 3130 | * be more conservative than the algorithms detailed in this |
| 3131 | * document allow. However, an SCTP transmitter MUST NOT be |
| 3132 | * more aggressive than the following algorithms allow. |
| 3133 | */ |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 3134 | if (chunk->end_of_packet) |
Wei Yongjun | 6dc7694 | 2009-11-23 15:53:53 -0500 | [diff] [blame] | 3135 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | return SCTP_DISPOSITION_CONSUME; |
| 3138 | |
| 3139 | discard_force: |
| 3140 | /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks |
| 3141 | * |
| 3142 | * When a packet arrives with duplicate DATA chunk(s) and with |
| 3143 | * no new DATA chunk(s), the endpoint MUST immediately send a |
| 3144 | * SACK with no delay. If a packet arrives with duplicate |
| 3145 | * DATA chunk(s) bundled with new DATA chunks, the endpoint |
| 3146 | * MAY immediately send a SACK. Normally receipt of duplicate |
| 3147 | * DATA chunks will occur when the original SACK chunk was lost |
| 3148 | * and the peer's RTO has expired. The duplicate TSN number(s) |
| 3149 | * SHOULD be reported in the SACK as duplicate. |
| 3150 | */ |
| 3151 | /* In our case, we split the MAY SACK advice up whether or not |
| 3152 | * the last chunk is a duplicate.' |
| 3153 | */ |
| 3154 | if (chunk->end_of_packet) |
| 3155 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 3156 | return SCTP_DISPOSITION_DISCARD; |
| 3157 | |
| 3158 | discard_noforce: |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 3159 | if (chunk->end_of_packet) |
Wei Yongjun | 6dc7694 | 2009-11-23 15:53:53 -0500 | [diff] [blame] | 3160 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | return SCTP_DISPOSITION_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | /* |
| 3166 | * sctp_sf_eat_data_fast_4_4 |
| 3167 | * |
| 3168 | * Section: 4 (4) |
| 3169 | * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received |
| 3170 | * DATA chunks without delay. |
| 3171 | * |
| 3172 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3173 | * Inputs |
| 3174 | * (endpoint, asoc, chunk) |
| 3175 | * |
| 3176 | * Outputs |
| 3177 | * (asoc, reply_msg, msg_up, timers, counters) |
| 3178 | * |
| 3179 | * The return value is the disposition of the chunk. |
| 3180 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3181 | enum sctp_disposition sctp_sf_eat_data_fast_4_4( |
| 3182 | 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | { |
| 3189 | struct sctp_chunk *chunk = arg; |
| 3190 | int error; |
| 3191 | |
| 3192 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3193 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3194 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3195 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
Xin Long | 9d4ceaf | 2017-12-08 21:04:03 +0800 | [diff] [blame] | 3198 | if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3199 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | commands); |
| 3201 | |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 3202 | error = sctp_eat_data(asoc, chunk, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | switch (error) { |
| 3204 | case SCTP_IERROR_NO_ERROR: |
| 3205 | case SCTP_IERROR_HIGH_TSN: |
| 3206 | case SCTP_IERROR_DUP_TSN: |
| 3207 | case SCTP_IERROR_IGNORE_TSN: |
| 3208 | case SCTP_IERROR_BAD_STREAM: |
| 3209 | break; |
| 3210 | case SCTP_IERROR_NO_DATA: |
Marcelo Ricardo Leitner | 649621e | 2016-01-08 11:00:54 -0200 | [diff] [blame] | 3211 | return SCTP_DISPOSITION_ABORT; |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 3212 | case SCTP_IERROR_PROTO_VIOLATION: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3213 | return sctp_sf_abort_violation(net, ep, asoc, chunk, commands, |
Xin Long | 3583df1 | 2017-06-30 11:52:19 +0800 | [diff] [blame] | 3214 | (u8 *)chunk->subh.data_hdr, |
Xin Long | 9d4ceaf | 2017-12-08 21:04:03 +0800 | [diff] [blame] | 3215 | sctp_datahdr_len(&asoc->stream)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | default: |
| 3217 | BUG(); |
| 3218 | } |
| 3219 | |
| 3220 | /* Go a head and force a SACK, since we are shutting down. */ |
| 3221 | |
| 3222 | /* Implementor's Guide. |
| 3223 | * |
| 3224 | * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately |
| 3225 | * respond to each received packet containing one or more DATA chunk(s) |
| 3226 | * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer |
| 3227 | */ |
| 3228 | if (chunk->end_of_packet) { |
| 3229 | /* We must delay the chunk creation since the cumulative |
| 3230 | * TSN has not been updated yet. |
| 3231 | */ |
| 3232 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); |
| 3233 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 3234 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 3235 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 3236 | } |
| 3237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | return SCTP_DISPOSITION_CONSUME; |
| 3239 | } |
| 3240 | |
| 3241 | /* |
| 3242 | * Section: 6.2 Processing a Received SACK |
| 3243 | * D) Any time a SACK arrives, the endpoint performs the following: |
| 3244 | * |
| 3245 | * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point, |
| 3246 | * then drop the SACK. Since Cumulative TSN Ack is monotonically |
| 3247 | * increasing, a SACK whose Cumulative TSN Ack is less than the |
| 3248 | * Cumulative TSN Ack Point indicates an out-of-order SACK. |
| 3249 | * |
| 3250 | * ii) Set rwnd equal to the newly received a_rwnd minus the number |
| 3251 | * of bytes still outstanding after processing the Cumulative TSN Ack |
| 3252 | * and the Gap Ack Blocks. |
| 3253 | * |
| 3254 | * iii) If the SACK is missing a TSN that was previously |
| 3255 | * acknowledged via a Gap Ack Block (e.g., the data receiver |
| 3256 | * reneged on the data), then mark the corresponding DATA chunk |
| 3257 | * as available for retransmit: Mark it as missing for fast |
| 3258 | * retransmit as described in Section 7.2.4 and if no retransmit |
| 3259 | * timer is running for the destination address to which the DATA |
| 3260 | * chunk was originally transmitted, then T3-rtx is started for |
| 3261 | * that destination address. |
| 3262 | * |
| 3263 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3264 | * |
| 3265 | * Inputs |
| 3266 | * (endpoint, asoc, chunk) |
| 3267 | * |
| 3268 | * Outputs |
| 3269 | * (asoc, reply_msg, msg_up, timers, counters) |
| 3270 | * |
| 3271 | * The return value is the disposition of the chunk. |
| 3272 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3273 | enum sctp_disposition sctp_sf_eat_sack_6_2(struct net *net, |
| 3274 | const struct sctp_endpoint *ep, |
| 3275 | const struct sctp_association *asoc, |
| 3276 | const union sctp_subtype type, |
| 3277 | void *arg, |
| 3278 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | { |
| 3280 | struct sctp_chunk *chunk = arg; |
Xin Long | 7873108 | 2017-07-23 09:34:32 +0800 | [diff] [blame] | 3281 | struct sctp_sackhdr *sackh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | __u32 ctsn; |
| 3283 | |
| 3284 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3285 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | |
| 3287 | /* Make sure that the SACK chunk has a valid length. */ |
Xin Long | d4d6c61 | 2017-07-23 09:34:33 +0800 | [diff] [blame] | 3288 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_sack_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3289 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | commands); |
| 3291 | |
| 3292 | /* Pull the SACK chunk from the data buffer */ |
| 3293 | sackh = sctp_sm_pull_sack(chunk); |
| 3294 | /* Was this a bogus SACK? */ |
| 3295 | if (!sackh) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3296 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | chunk->subh.sack_hdr = sackh; |
| 3298 | ctsn = ntohl(sackh->cum_tsn_ack); |
| 3299 | |
Kevin Kou | 356b23c | 2019-12-25 08:27:25 +0000 | [diff] [blame] | 3300 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 3301 | * send, terminating the association and respond to the |
| 3302 | * sender with an ABORT. |
| 3303 | */ |
| 3304 | if (TSN_lte(asoc->next_tsn, ctsn)) |
| 3305 | return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands); |
| 3306 | |
| 3307 | trace_sctp_probe(ep, asoc, chunk); |
| 3308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | /* i) If Cumulative TSN Ack is less than the Cumulative TSN |
| 3310 | * Ack Point, then drop the SACK. Since Cumulative TSN |
| 3311 | * Ack is monotonically increasing, a SACK whose |
| 3312 | * Cumulative TSN Ack is less than the Cumulative TSN Ack |
| 3313 | * Point indicates an out-of-order SACK. |
| 3314 | */ |
| 3315 | if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 3316 | pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn, |
| 3317 | asoc->ctsn_ack_point); |
| 3318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | return SCTP_DISPOSITION_DISCARD; |
| 3320 | } |
| 3321 | |
| 3322 | /* Return this SACK for further processing. */ |
Nicolas Dichtel | edfee03 | 2012-10-03 05:43:22 +0000 | [diff] [blame] | 3323 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_CHUNK(chunk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | |
| 3325 | /* Note: We do the rest of the work on the PROCESS_SACK |
| 3326 | * sideeffect. |
| 3327 | */ |
| 3328 | return SCTP_DISPOSITION_CONSUME; |
| 3329 | } |
| 3330 | |
| 3331 | /* |
| 3332 | * Generate an ABORT in response to a packet. |
| 3333 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3334 | * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3336 | * 8) The receiver should respond to the sender of the OOTB packet with |
| 3337 | * an ABORT. When sending the ABORT, the receiver of the OOTB packet |
| 3338 | * MUST fill in the Verification Tag field of the outbound packet |
| 3339 | * with the value found in the Verification Tag field of the OOTB |
| 3340 | * packet and set the T-bit in the Chunk Flags to indicate that the |
| 3341 | * Verification Tag is reflected. After sending this ABORT, the |
| 3342 | * receiver of the OOTB packet shall discard the OOTB packet and take |
| 3343 | * no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | * |
| 3345 | * Verification Tag: |
| 3346 | * |
| 3347 | * The return value is the disposition of the chunk. |
| 3348 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3349 | static enum sctp_disposition sctp_sf_tabort_8_4_8( |
| 3350 | struct net *net, |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3351 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 3353 | const union sctp_subtype type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 3355 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | { |
| 3357 | struct sctp_packet *packet = NULL; |
| 3358 | struct sctp_chunk *chunk = arg; |
| 3359 | struct sctp_chunk *abort; |
| 3360 | |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 3361 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Marcelo Ricardo Leitner | eab5907 | 2016-12-28 09:26:31 -0200 | [diff] [blame] | 3362 | if (!packet) |
| 3363 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | |
Marcelo Ricardo Leitner | eab5907 | 2016-12-28 09:26:31 -0200 | [diff] [blame] | 3365 | /* Make an ABORT. The T bit will be set if the asoc |
| 3366 | * is NULL. |
| 3367 | */ |
| 3368 | abort = sctp_make_abort(asoc, chunk, 0); |
| 3369 | if (!abort) { |
| 3370 | sctp_ootb_pkt_free(packet); |
| 3371 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | } |
| 3373 | |
Marcelo Ricardo Leitner | eab5907 | 2016-12-28 09:26:31 -0200 | [diff] [blame] | 3374 | /* Reflect vtag if T-Bit is set */ |
| 3375 | if (sctp_test_T_bit(abort)) |
| 3376 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 3377 | |
| 3378 | /* Set the skb to the belonging sock for accounting. */ |
| 3379 | abort->skb->sk = ep->base.sk; |
| 3380 | |
| 3381 | sctp_packet_append_chunk(packet, abort); |
| 3382 | |
| 3383 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 3384 | SCTP_PACKET(packet)); |
| 3385 | |
| 3386 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
| 3387 | |
| 3388 | sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 3389 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | /* |
| 3393 | * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR |
| 3394 | * event as ULP notification for each cause included in the chunk. |
| 3395 | * |
| 3396 | * API 5.3.1.3 - SCTP_REMOTE_ERROR |
| 3397 | * |
| 3398 | * The return value is the disposition of the chunk. |
| 3399 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3400 | enum sctp_disposition sctp_sf_operr_notify(struct net *net, |
| 3401 | const struct sctp_endpoint *ep, |
| 3402 | const struct sctp_association *asoc, |
| 3403 | const union sctp_subtype type, |
| 3404 | void *arg, |
| 3405 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | { |
| 3407 | struct sctp_chunk *chunk = arg; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 3408 | struct sctp_errhdr *err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | |
| 3410 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3411 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | |
| 3413 | /* Make sure that the ERROR chunk has a valid length. */ |
Xin Long | 87caeba | 2017-08-03 15:42:12 +0800 | [diff] [blame] | 3414 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3415 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | commands); |
Shan Wei | 8a00be1 | 2011-04-19 21:25:40 +0000 | [diff] [blame] | 3417 | sctp_walk_errors(err, chunk->chunk_hdr); |
| 3418 | if ((void *)err != (void *)chunk->chunk_end) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3419 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
Shan Wei | 8a00be1 | 2011-04-19 21:25:40 +0000 | [diff] [blame] | 3420 | (void *)err, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | |
Wei Yongjun | 3df26787 | 2009-03-02 06:46:51 +0000 | [diff] [blame] | 3422 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR, |
| 3423 | SCTP_CHUNK(chunk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
| 3428 | /* |
| 3429 | * Process an inbound SHUTDOWN ACK. |
| 3430 | * |
| 3431 | * From Section 9.2: |
| 3432 | * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall |
| 3433 | * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its |
| 3434 | * peer, and remove all record of the association. |
| 3435 | * |
| 3436 | * The return value is the disposition. |
| 3437 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3438 | enum sctp_disposition sctp_sf_do_9_2_final(struct net *net, |
| 3439 | const struct sctp_endpoint *ep, |
| 3440 | const struct sctp_association *asoc, |
| 3441 | const union sctp_subtype type, |
| 3442 | void *arg, |
| 3443 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | { |
| 3445 | struct sctp_chunk *chunk = arg; |
| 3446 | struct sctp_chunk *reply; |
| 3447 | struct sctp_ulpevent *ev; |
| 3448 | |
| 3449 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3450 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | |
| 3452 | /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3453 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3454 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | /* 10.2 H) SHUTDOWN COMPLETE notification |
| 3457 | * |
| 3458 | * When SCTP completes the shutdown procedures (section 9.2) this |
| 3459 | * notification is passed to the upper layer. |
| 3460 | */ |
| 3461 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 3462 | 0, 0, 0, NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | if (!ev) |
| 3464 | goto nomem; |
| 3465 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 3466 | /* ...send a SHUTDOWN COMPLETE chunk to its peer, */ |
| 3467 | reply = sctp_make_shutdown_complete(asoc, chunk); |
| 3468 | if (!reply) |
| 3469 | goto nomem_chunk; |
| 3470 | |
| 3471 | /* Do all the commands now (after allocation), so that we |
| 3472 | * have consistent state if memory allocation failes |
| 3473 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 3475 | |
| 3476 | /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall |
| 3477 | * stop the T2-shutdown timer, |
| 3478 | */ |
| 3479 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3480 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 3481 | |
| 3482 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3483 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 3484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 3486 | SCTP_STATE(SCTP_STATE_CLOSED)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 3487 | SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS); |
| 3488 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 3490 | |
| 3491 | /* ...and remove all record of the association. */ |
| 3492 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 3493 | return SCTP_DISPOSITION_DELETE_TCB; |
| 3494 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 3495 | nomem_chunk: |
| 3496 | sctp_ulpevent_free(ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | nomem: |
| 3498 | return SCTP_DISPOSITION_NOMEM; |
| 3499 | } |
| 3500 | |
| 3501 | /* |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3502 | * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41. |
| 3503 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should |
| 3505 | * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. |
| 3506 | * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB |
| 3507 | * packet must fill in the Verification Tag field of the outbound |
| 3508 | * packet with the Verification Tag received in the SHUTDOWN ACK and |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3509 | * set the T-bit in the Chunk Flags to indicate that the Verification |
| 3510 | * Tag is reflected. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | * |
| 3512 | * 8) The receiver should respond to the sender of the OOTB packet with |
| 3513 | * an ABORT. When sending the ABORT, the receiver of the OOTB packet |
| 3514 | * MUST fill in the Verification Tag field of the outbound packet |
| 3515 | * with the value found in the Verification Tag field of the OOTB |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3516 | * packet and set the T-bit in the Chunk Flags to indicate that the |
| 3517 | * Verification Tag is reflected. After sending this ABORT, the |
| 3518 | * receiver of the OOTB packet shall discard the OOTB packet and take |
| 3519 | * no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3521 | enum sctp_disposition sctp_sf_ootb(struct net *net, |
| 3522 | const struct sctp_endpoint *ep, |
| 3523 | const struct sctp_association *asoc, |
| 3524 | const union sctp_subtype type, |
| 3525 | void *arg, struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | { |
| 3527 | struct sctp_chunk *chunk = arg; |
| 3528 | struct sk_buff *skb = chunk->skb; |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3529 | struct sctp_chunkhdr *ch; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 3530 | struct sctp_errhdr *err; |
Shan Wei | 85c5ed4 | 2011-04-19 21:30:01 +0000 | [diff] [blame] | 3531 | int ootb_cookie_ack = 0; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3532 | int ootb_shut_ack = 0; |
| 3533 | __u8 *ch_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 3535 | SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3537 | ch = (struct sctp_chunkhdr *)chunk->chunk_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | do { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3539 | /* Report violation if the chunk is less then minimal */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3540 | if (ntohs(ch->length) < sizeof(*ch)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3541 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3542 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | |
Marcelo Ricardo Leitner | bf911e9 | 2016-10-25 14:27:39 -0200 | [diff] [blame] | 3544 | /* Report violation if chunk len overflows */ |
| 3545 | ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length)); |
| 3546 | if (ch_end > skb_tail_pointer(skb)) |
| 3547 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
| 3548 | commands); |
| 3549 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3550 | /* Now that we know we at least have a chunk header, |
| 3551 | * do things that are type appropriate. |
| 3552 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | if (SCTP_CID_SHUTDOWN_ACK == ch->type) |
| 3554 | ootb_shut_ack = 1; |
| 3555 | |
| 3556 | /* RFC 2960, Section 3.3.7 |
| 3557 | * Moreover, under any circumstances, an endpoint that |
| 3558 | * receives an ABORT MUST NOT respond to that ABORT by |
| 3559 | * sending an ABORT of its own. |
| 3560 | */ |
| 3561 | if (SCTP_CID_ABORT == ch->type) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3562 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3563 | |
Shan Wei | 85c5ed4 | 2011-04-19 21:30:01 +0000 | [diff] [blame] | 3564 | /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR |
| 3565 | * or a COOKIE ACK the SCTP Packet should be silently |
| 3566 | * discarded. |
| 3567 | */ |
| 3568 | |
| 3569 | if (SCTP_CID_COOKIE_ACK == ch->type) |
| 3570 | ootb_cookie_ack = 1; |
| 3571 | |
| 3572 | if (SCTP_CID_ERROR == ch->type) { |
| 3573 | sctp_walk_errors(err, ch) { |
| 3574 | if (SCTP_ERROR_STALE_COOKIE == err->cause) { |
| 3575 | ootb_cookie_ack = 1; |
| 3576 | break; |
| 3577 | } |
| 3578 | } |
| 3579 | } |
| 3580 | |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3581 | ch = (struct sctp_chunkhdr *)ch_end; |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3582 | } while (ch_end < skb_tail_pointer(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | |
| 3584 | if (ootb_shut_ack) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3585 | return sctp_sf_shut_8_4_5(net, ep, asoc, type, arg, commands); |
Shan Wei | 85c5ed4 | 2011-04-19 21:30:01 +0000 | [diff] [blame] | 3586 | else if (ootb_cookie_ack) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3587 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | else |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3589 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | /* |
| 3593 | * Handle an "Out of the blue" SHUTDOWN ACK. |
| 3594 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3595 | * Section: 8.4 5, sctpimpguide 2.41. |
| 3596 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3598 | * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. |
| 3599 | * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB |
| 3600 | * packet must fill in the Verification Tag field of the outbound |
| 3601 | * packet with the Verification Tag received in the SHUTDOWN ACK and |
| 3602 | * set the T-bit in the Chunk Flags to indicate that the Verification |
| 3603 | * Tag is reflected. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | * |
| 3605 | * Inputs |
| 3606 | * (endpoint, asoc, type, arg, commands) |
| 3607 | * |
| 3608 | * Outputs |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3609 | * (enum sctp_disposition) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | * |
| 3611 | * The return value is the disposition of the chunk. |
| 3612 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3613 | static enum sctp_disposition sctp_sf_shut_8_4_5( |
| 3614 | struct net *net, |
| 3615 | const struct sctp_endpoint *ep, |
| 3616 | const struct sctp_association *asoc, |
| 3617 | const union sctp_subtype type, |
| 3618 | void *arg, |
| 3619 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | { |
| 3621 | struct sctp_packet *packet = NULL; |
| 3622 | struct sctp_chunk *chunk = arg; |
| 3623 | struct sctp_chunk *shut; |
| 3624 | |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 3625 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Marcelo Ricardo Leitner | 1ff0156 | 2016-12-28 09:26:32 -0200 | [diff] [blame] | 3626 | if (!packet) |
| 3627 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | |
Marcelo Ricardo Leitner | 1ff0156 | 2016-12-28 09:26:32 -0200 | [diff] [blame] | 3629 | /* Make an SHUTDOWN_COMPLETE. |
| 3630 | * The T bit will be set if the asoc is NULL. |
| 3631 | */ |
| 3632 | shut = sctp_make_shutdown_complete(asoc, chunk); |
| 3633 | if (!shut) { |
| 3634 | sctp_ootb_pkt_free(packet); |
| 3635 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
Marcelo Ricardo Leitner | 1ff0156 | 2016-12-28 09:26:32 -0200 | [diff] [blame] | 3638 | /* Reflect vtag if T-Bit is set */ |
| 3639 | if (sctp_test_T_bit(shut)) |
| 3640 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 3641 | |
| 3642 | /* Set the skb to the belonging sock for accounting. */ |
| 3643 | shut->skb->sk = ep->base.sk; |
| 3644 | |
| 3645 | sctp_packet_append_chunk(packet, shut); |
| 3646 | |
| 3647 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 3648 | SCTP_PACKET(packet)); |
| 3649 | |
| 3650 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
| 3651 | |
| 3652 | /* If the chunk length is invalid, we don't want to process |
| 3653 | * the reset of the packet. |
| 3654 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3655 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Marcelo Ricardo Leitner | 1ff0156 | 2016-12-28 09:26:32 -0200 | [diff] [blame] | 3656 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 3657 | |
| 3658 | /* We need to discard the rest of the packet to prevent |
| 3659 | * potential bomming attacks from additional bundled chunks. |
| 3660 | * This is documented in SCTP Threats ID. |
| 3661 | */ |
| 3662 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | /* |
| 3666 | * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state. |
| 3667 | * |
| 3668 | * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK |
| 3669 | * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the |
| 3670 | * procedures in section 8.4 SHOULD be followed, in other words it |
| 3671 | * should be treated as an Out Of The Blue packet. |
| 3672 | * [This means that we do NOT check the Verification Tag on these |
| 3673 | * chunks. --piggy ] |
| 3674 | * |
| 3675 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3676 | enum sctp_disposition sctp_sf_do_8_5_1_E_sa(struct net *net, |
| 3677 | const struct sctp_endpoint *ep, |
| 3678 | const struct sctp_association *asoc, |
| 3679 | const union sctp_subtype type, |
| 3680 | void *arg, |
| 3681 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3683 | struct sctp_chunk *chunk = arg; |
| 3684 | |
| 3685 | /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3686 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3687 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3688 | commands); |
| 3689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | /* Although we do have an association in this case, it corresponds |
| 3691 | * to a restarted association. So the packet is treated as an OOTB |
| 3692 | * packet and the state function that handles OOTB SHUTDOWN_ACK is |
| 3693 | * called with a NULL association. |
| 3694 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3695 | SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES); |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 3696 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3697 | return sctp_sf_shut_8_4_5(net, ep, NULL, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3701 | enum sctp_disposition sctp_sf_do_asconf(struct net *net, |
| 3702 | const struct sctp_endpoint *ep, |
| 3703 | const struct sctp_association *asoc, |
| 3704 | const union sctp_subtype type, |
| 3705 | void *arg, |
| 3706 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3708 | struct sctp_paramhdr *err_param = NULL; |
| 3709 | struct sctp_chunk *asconf_ack = NULL; |
| 3710 | struct sctp_chunk *chunk = arg; |
| 3711 | struct sctp_addiphdr *hdr; |
| 3712 | __u32 serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | |
| 3714 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3715 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3716 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3717 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3720 | /* ADD-IP: Section 4.1.1 |
| 3721 | * This chunk MUST be sent in an authenticated way by using |
| 3722 | * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk |
| 3723 | * is received unauthenticated it MUST be silently discarded as |
| 3724 | * described in [I-D.ietf-tsvwg-sctp-auth]. |
| 3725 | */ |
Xin Long | a2eeacc | 2019-08-19 22:02:45 +0800 | [diff] [blame] | 3726 | if (!asoc->peer.asconf_capable || |
| 3727 | (!net->sctp.addip_noauth && !chunk->auth)) |
Xin Long | 68d7546 | 2017-08-03 15:42:20 +0800 | [diff] [blame] | 3728 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, |
| 3729 | commands); |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | /* Make sure that the ASCONF ADDIP chunk has a valid length. */ |
Xin Long | 68d7546 | 2017-08-03 15:42:20 +0800 | [diff] [blame] | 3732 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_addip_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3733 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | commands); |
| 3735 | |
Xin Long | 65205cc | 2017-08-03 15:42:19 +0800 | [diff] [blame] | 3736 | hdr = (struct sctp_addiphdr *)chunk->skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | serial = ntohl(hdr->serial); |
| 3738 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3739 | /* Verify the ASCONF chunk before processing it. */ |
Daniel Borkmann | 9de7922 | 2014-10-09 22:55:31 +0200 | [diff] [blame] | 3740 | if (!sctp_verify_asconf(asoc, chunk, true, &err_param)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3741 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 3742 | (void *)err_param, commands); |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3743 | |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3744 | /* ADDIP 5.2 E1) Compare the value of the serial number to the value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | * the endpoint stored in a new association variable |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3746 | * 'Peer-Serial-Number'. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | */ |
| 3748 | if (serial == asoc->peer.addip_serial + 1) { |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3749 | /* If this is the first instance of ASCONF in the packet, |
| 3750 | * we can clean our old ASCONF-ACKs. |
| 3751 | */ |
| 3752 | if (!chunk->has_asconf) |
| 3753 | sctp_assoc_clean_asconf_ack_cache(asoc); |
| 3754 | |
| 3755 | /* ADDIP 5.2 E4) When the Sequence Number matches the next one |
| 3756 | * expected, process the ASCONF as described below and after |
| 3757 | * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to |
| 3758 | * the response packet and cache a copy of it (in the event it |
| 3759 | * later needs to be retransmitted). |
| 3760 | * |
| 3761 | * Essentially, do V1-V5. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | */ |
| 3763 | asconf_ack = sctp_process_asconf((struct sctp_association *) |
| 3764 | asoc, chunk); |
| 3765 | if (!asconf_ack) |
| 3766 | return SCTP_DISPOSITION_NOMEM; |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3767 | } else if (serial < asoc->peer.addip_serial + 1) { |
| 3768 | /* ADDIP 5.2 E2) |
| 3769 | * If the value found in the Sequence Number is less than the |
| 3770 | * ('Peer- Sequence-Number' + 1), simply skip to the next |
| 3771 | * ASCONF, and include in the outbound response packet |
| 3772 | * any previously cached ASCONF-ACK response that was |
| 3773 | * sent and saved that matches the Sequence Number of the |
| 3774 | * ASCONF. Note: It is possible that no cached ASCONF-ACK |
| 3775 | * Chunk exists. This will occur when an older ASCONF |
| 3776 | * arrives out of order. In such a case, the receiver |
| 3777 | * should skip the ASCONF Chunk and not include ASCONF-ACK |
| 3778 | * Chunk for that chunk. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | */ |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3780 | asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial); |
| 3781 | if (!asconf_ack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | return SCTP_DISPOSITION_DISCARD; |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 3783 | |
| 3784 | /* Reset the transport so that we select the correct one |
| 3785 | * this time around. This is to make sure that we don't |
| 3786 | * accidentally use a stale transport that's been removed. |
| 3787 | */ |
| 3788 | asconf_ack->transport = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | } else { |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3790 | /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | * it must be either a stale packet or from an attacker. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3792 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | return SCTP_DISPOSITION_DISCARD; |
| 3794 | } |
| 3795 | |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3796 | /* ADDIP 5.2 E6) The destination address of the SCTP packet |
| 3797 | * containing the ASCONF-ACK Chunks MUST be the source address of |
| 3798 | * the SCTP packet that held the ASCONF Chunks. |
| 3799 | * |
| 3800 | * To do this properly, we'll set the destination address of the chunk |
| 3801 | * and at the transmit time, will try look up the transport to use. |
| 3802 | * Since ASCONFs may be bundled, the correct transport may not be |
Thadeu Lima de Souza Cascardo | 94e2bd6 | 2009-10-16 15:20:49 +0200 | [diff] [blame] | 3803 | * created until we process the entire packet, thus this workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | */ |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3805 | asconf_ack->dest = chunk->source; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack)); |
Michio Honda | 6af29cc | 2011-06-16 17:14:34 +0900 | [diff] [blame] | 3807 | if (asoc->new_transport) { |
wangweidong | f7010e6 | 2013-12-23 12:16:52 +0800 | [diff] [blame] | 3808 | sctp_sf_heartbeat(ep, asoc, type, asoc->new_transport, commands); |
Michio Honda | 6af29cc | 2011-06-16 17:14:34 +0900 | [diff] [blame] | 3809 | ((struct sctp_association *)asoc)->new_transport = NULL; |
| 3810 | } |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | return SCTP_DISPOSITION_CONSUME; |
| 3813 | } |
| 3814 | |
Xin Long | fbd0197 | 2019-04-29 14:16:19 +0800 | [diff] [blame] | 3815 | static enum sctp_disposition sctp_send_next_asconf( |
| 3816 | struct net *net, |
| 3817 | const struct sctp_endpoint *ep, |
| 3818 | struct sctp_association *asoc, |
| 3819 | const union sctp_subtype type, |
| 3820 | struct sctp_cmd_seq *commands) |
| 3821 | { |
| 3822 | struct sctp_chunk *asconf; |
| 3823 | struct list_head *entry; |
| 3824 | |
| 3825 | if (list_empty(&asoc->addip_chunk_list)) |
| 3826 | return SCTP_DISPOSITION_CONSUME; |
| 3827 | |
| 3828 | entry = asoc->addip_chunk_list.next; |
| 3829 | asconf = list_entry(entry, struct sctp_chunk, list); |
| 3830 | |
| 3831 | list_del_init(entry); |
| 3832 | sctp_chunk_hold(asconf); |
| 3833 | asoc->addip_last_asconf = asconf; |
| 3834 | |
| 3835 | return sctp_sf_do_prm_asconf(net, ep, asoc, type, asconf, commands); |
| 3836 | } |
| 3837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | /* |
| 3839 | * ADDIP Section 4.3 General rules for address manipulation |
| 3840 | * When building TLV parameters for the ASCONF Chunk that will add or |
| 3841 | * delete IP addresses the D0 to D13 rules should be applied: |
| 3842 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3843 | enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net, |
| 3844 | const struct sctp_endpoint *ep, |
| 3845 | const struct sctp_association *asoc, |
| 3846 | const union sctp_subtype type, |
| 3847 | void *arg, |
| 3848 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3850 | struct sctp_chunk *last_asconf = asoc->addip_last_asconf; |
| 3851 | struct sctp_paramhdr *err_param = NULL; |
| 3852 | struct sctp_chunk *asconf_ack = arg; |
| 3853 | struct sctp_addiphdr *addip_hdr; |
| 3854 | __u32 sent_serial, rcvd_serial; |
| 3855 | struct sctp_chunk *abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | |
| 3857 | if (!sctp_vtag_verify(asconf_ack, asoc)) { |
| 3858 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3859 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3860 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | } |
| 3862 | |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3863 | /* ADD-IP, Section 4.1.2: |
| 3864 | * This chunk MUST be sent in an authenticated way by using |
| 3865 | * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk |
| 3866 | * is received unauthenticated it MUST be silently discarded as |
| 3867 | * described in [I-D.ietf-tsvwg-sctp-auth]. |
| 3868 | */ |
Xin Long | a2eeacc | 2019-08-19 22:02:45 +0800 | [diff] [blame] | 3869 | if (!asoc->peer.asconf_capable || |
| 3870 | (!net->sctp.addip_noauth && !asconf_ack->auth)) |
Xin Long | 68d7546 | 2017-08-03 15:42:20 +0800 | [diff] [blame] | 3871 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, |
| 3872 | commands); |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | /* Make sure that the ADDIP chunk has a valid length. */ |
Xin Long | 68d7546 | 2017-08-03 15:42:20 +0800 | [diff] [blame] | 3875 | if (!sctp_chunk_length_valid(asconf_ack, |
| 3876 | sizeof(struct sctp_addip_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3877 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | commands); |
| 3879 | |
Xin Long | 65205cc | 2017-08-03 15:42:19 +0800 | [diff] [blame] | 3880 | addip_hdr = (struct sctp_addiphdr *)asconf_ack->skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | rcvd_serial = ntohl(addip_hdr->serial); |
| 3882 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3883 | /* Verify the ASCONF-ACK chunk before processing it. */ |
Daniel Borkmann | 9de7922 | 2014-10-09 22:55:31 +0200 | [diff] [blame] | 3884 | if (!sctp_verify_asconf(asoc, asconf_ack, false, &err_param)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3885 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 3886 | (void *)err_param, commands); |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | if (last_asconf) { |
Xin Long | 65205cc | 2017-08-03 15:42:19 +0800 | [diff] [blame] | 3889 | addip_hdr = (struct sctp_addiphdr *)last_asconf->subh.addip_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | sent_serial = ntohl(addip_hdr->serial); |
| 3891 | } else { |
| 3892 | sent_serial = asoc->addip_serial - 1; |
| 3893 | } |
| 3894 | |
| 3895 | /* D0) If an endpoint receives an ASCONF-ACK that is greater than or |
| 3896 | * equal to the next serial number to be used but no ASCONF chunk is |
| 3897 | * outstanding the endpoint MUST ABORT the association. Note that a |
| 3898 | * sequence number is greater than if it is no more than 2^^31-1 |
| 3899 | * larger than the current sequence number (using serial arithmetic). |
| 3900 | */ |
| 3901 | if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) && |
| 3902 | !(asoc->addip_last_asconf)) { |
| 3903 | abort = sctp_make_abort(asoc, asconf_ack, |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 3904 | sizeof(struct sctp_errhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | if (abort) { |
Wei Yongjun | 00f1c2d | 2007-08-21 15:50:01 +0800 | [diff] [blame] | 3906 | sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 3908 | SCTP_CHUNK(abort)); |
| 3909 | } |
| 3910 | /* We are going to ABORT, so we might as well stop |
| 3911 | * processing the rest of the chunks in the packet. |
| 3912 | */ |
| 3913 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3914 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 3915 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 3916 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3917 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 3919 | SCTP_PERR(SCTP_ERROR_ASCONF_ACK)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 3920 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 3921 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | return SCTP_DISPOSITION_ABORT; |
| 3923 | } |
| 3924 | |
| 3925 | if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) { |
| 3926 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3927 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 3928 | |
| 3929 | if (!sctp_process_asconf_ack((struct sctp_association *)asoc, |
Xin Long | fbd0197 | 2019-04-29 14:16:19 +0800 | [diff] [blame] | 3930 | asconf_ack)) |
| 3931 | return sctp_send_next_asconf(net, ep, |
| 3932 | (struct sctp_association *)asoc, |
| 3933 | type, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | |
| 3935 | abort = sctp_make_abort(asoc, asconf_ack, |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 3936 | sizeof(struct sctp_errhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | if (abort) { |
Wei Yongjun | 00f1c2d | 2007-08-21 15:50:01 +0800 | [diff] [blame] | 3938 | sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 3940 | SCTP_CHUNK(abort)); |
| 3941 | } |
| 3942 | /* We are going to ABORT, so we might as well stop |
| 3943 | * processing the rest of the chunks in the packet. |
| 3944 | */ |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 3945 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 3946 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3947 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 3949 | SCTP_PERR(SCTP_ERROR_ASCONF_ACK)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 3950 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 3951 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | return SCTP_DISPOSITION_ABORT; |
| 3953 | } |
| 3954 | |
| 3955 | return SCTP_DISPOSITION_DISCARD; |
| 3956 | } |
| 3957 | |
Xin Long | 2040d3d | 2017-02-17 12:45:42 +0800 | [diff] [blame] | 3958 | /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 3959 | enum sctp_disposition sctp_sf_do_reconf(struct net *net, |
| 3960 | const struct sctp_endpoint *ep, |
| 3961 | const struct sctp_association *asoc, |
| 3962 | const union sctp_subtype type, |
| 3963 | void *arg, |
| 3964 | struct sctp_cmd_seq *commands) |
Xin Long | 2040d3d | 2017-02-17 12:45:42 +0800 | [diff] [blame] | 3965 | { |
| 3966 | struct sctp_paramhdr *err_param = NULL; |
| 3967 | struct sctp_chunk *chunk = arg; |
| 3968 | struct sctp_reconf_chunk *hdr; |
| 3969 | union sctp_params param; |
| 3970 | |
| 3971 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3972 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3973 | SCTP_NULL()); |
| 3974 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 3975 | } |
| 3976 | |
| 3977 | /* Make sure that the RECONF chunk has a valid length. */ |
| 3978 | if (!sctp_chunk_length_valid(chunk, sizeof(*hdr))) |
| 3979 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
| 3980 | commands); |
| 3981 | |
| 3982 | if (!sctp_verify_reconf(asoc, chunk, &err_param)) |
| 3983 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
| 3984 | (void *)err_param, commands); |
| 3985 | |
| 3986 | hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr; |
| 3987 | sctp_walk_params(param, hdr, params) { |
| 3988 | struct sctp_chunk *reply = NULL; |
| 3989 | struct sctp_ulpevent *ev = NULL; |
| 3990 | |
| 3991 | if (param.p->type == SCTP_PARAM_RESET_OUT_REQUEST) |
| 3992 | reply = sctp_process_strreset_outreq( |
| 3993 | (struct sctp_association *)asoc, param, &ev); |
| 3994 | else if (param.p->type == SCTP_PARAM_RESET_IN_REQUEST) |
| 3995 | reply = sctp_process_strreset_inreq( |
| 3996 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 3997 | else if (param.p->type == SCTP_PARAM_RESET_TSN_REQUEST) |
| 3998 | reply = sctp_process_strreset_tsnreq( |
| 3999 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 4000 | else if (param.p->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) |
| 4001 | reply = sctp_process_strreset_addstrm_out( |
| 4002 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 4003 | else if (param.p->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) |
| 4004 | reply = sctp_process_strreset_addstrm_in( |
| 4005 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 4006 | else if (param.p->type == SCTP_PARAM_RESET_RESPONSE) |
| 4007 | reply = sctp_process_strreset_resp( |
| 4008 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | 2040d3d | 2017-02-17 12:45:42 +0800 | [diff] [blame] | 4009 | |
| 4010 | if (ev) |
| 4011 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 4012 | SCTP_ULPEVENT(ev)); |
| 4013 | |
| 4014 | if (reply) |
| 4015 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4016 | SCTP_CHUNK(reply)); |
| 4017 | } |
| 4018 | |
| 4019 | return SCTP_DISPOSITION_CONSUME; |
| 4020 | } |
| 4021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | /* |
| 4023 | * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP |
| 4024 | * |
| 4025 | * When a FORWARD TSN chunk arrives, the data receiver MUST first update |
| 4026 | * its cumulative TSN point to the value carried in the FORWARD TSN |
| 4027 | * chunk, and then MUST further advance its cumulative TSN point locally |
| 4028 | * if possible. |
| 4029 | * After the above processing, the data receiver MUST stop reporting any |
| 4030 | * missing TSNs earlier than or equal to the new cumulative TSN point. |
| 4031 | * |
| 4032 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 4033 | * |
| 4034 | * The return value is the disposition of the chunk. |
| 4035 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4036 | enum sctp_disposition sctp_sf_eat_fwd_tsn(struct net *net, |
| 4037 | const struct sctp_endpoint *ep, |
| 4038 | const struct sctp_association *asoc, |
| 4039 | const union sctp_subtype type, |
| 4040 | void *arg, |
| 4041 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | struct sctp_fwdtsn_hdr *fwdtsn_hdr; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4044 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | __u16 len; |
| 4046 | __u32 tsn; |
| 4047 | |
| 4048 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 4049 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 4050 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4051 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
Xin Long | d15c9ed | 2017-02-03 17:37:06 +0800 | [diff] [blame] | 4054 | if (!asoc->peer.prsctp_capable) |
| 4055 | return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands); |
| 4056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | /* Make sure that the FORWARD_TSN chunk has valid length. */ |
Xin Long | 0fc2ea9 | 2017-12-15 00:41:27 +0800 | [diff] [blame] | 4058 | if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4059 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | commands); |
| 4061 | |
| 4062 | fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; |
| 4063 | chunk->subh.fwdtsn_hdr = fwdtsn_hdr; |
| 4064 | len = ntohs(chunk->chunk_hdr->length); |
| 4065 | len -= sizeof(struct sctp_chunkhdr); |
| 4066 | skb_pull(chunk->skb, len); |
| 4067 | |
| 4068 | tsn = ntohl(fwdtsn_hdr->new_cum_tsn); |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 4069 | pr_debug("%s: TSN 0x%x\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | |
| 4071 | /* The TSN is too high--silently discard the chunk and count on it |
| 4072 | * getting retransmitted later. |
| 4073 | */ |
| 4074 | if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) |
| 4075 | goto discard_noforce; |
| 4076 | |
Xin Long | 0fc2ea9 | 2017-12-15 00:41:27 +0800 | [diff] [blame] | 4077 | if (!asoc->stream.si->validate_ftsn(chunk)) |
| 4078 | goto discard_noforce; |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 4079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); |
Xin Long | 0fc2ea9 | 2017-12-15 00:41:27 +0800 | [diff] [blame] | 4081 | if (len > sctp_ftsnhdr_len(&asoc->stream)) |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4082 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | SCTP_CHUNK(chunk)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | /* Count this as receiving DATA. */ |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 4086 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 4088 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 4089 | } |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | /* FIXME: For now send a SACK, but DATA processing may |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4092 | * send another. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | */ |
| 4094 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4095 | |
| 4096 | return SCTP_DISPOSITION_CONSUME; |
| 4097 | |
| 4098 | discard_noforce: |
| 4099 | return SCTP_DISPOSITION_DISCARD; |
| 4100 | } |
| 4101 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4102 | enum sctp_disposition sctp_sf_eat_fwd_tsn_fast( |
| 4103 | struct net *net, |
| 4104 | const struct sctp_endpoint *ep, |
| 4105 | const struct sctp_association *asoc, |
| 4106 | const union sctp_subtype type, |
| 4107 | void *arg, |
| 4108 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | struct sctp_fwdtsn_hdr *fwdtsn_hdr; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4111 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4112 | __u16 len; |
| 4113 | __u32 tsn; |
| 4114 | |
| 4115 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 4116 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 4117 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4118 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | } |
| 4120 | |
Xin Long | d15c9ed | 2017-02-03 17:37:06 +0800 | [diff] [blame] | 4121 | if (!asoc->peer.prsctp_capable) |
| 4122 | return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands); |
| 4123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | /* Make sure that the FORWARD_TSN chunk has a valid length. */ |
Xin Long | 0fc2ea9 | 2017-12-15 00:41:27 +0800 | [diff] [blame] | 4125 | if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4126 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | commands); |
| 4128 | |
| 4129 | fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; |
| 4130 | chunk->subh.fwdtsn_hdr = fwdtsn_hdr; |
| 4131 | len = ntohs(chunk->chunk_hdr->length); |
| 4132 | len -= sizeof(struct sctp_chunkhdr); |
| 4133 | skb_pull(chunk->skb, len); |
| 4134 | |
| 4135 | tsn = ntohl(fwdtsn_hdr->new_cum_tsn); |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 4136 | pr_debug("%s: TSN 0x%x\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | |
| 4138 | /* The TSN is too high--silently discard the chunk and count on it |
| 4139 | * getting retransmitted later. |
| 4140 | */ |
| 4141 | if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) |
| 4142 | goto gen_shutdown; |
| 4143 | |
Xin Long | 0fc2ea9 | 2017-12-15 00:41:27 +0800 | [diff] [blame] | 4144 | if (!asoc->stream.si->validate_ftsn(chunk)) |
| 4145 | goto gen_shutdown; |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 4146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); |
Xin Long | 0fc2ea9 | 2017-12-15 00:41:27 +0800 | [diff] [blame] | 4148 | if (len > sctp_ftsnhdr_len(&asoc->stream)) |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4149 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | SCTP_CHUNK(chunk)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | /* Go a head and force a SACK, since we are shutting down. */ |
| 4153 | gen_shutdown: |
| 4154 | /* Implementor's Guide. |
| 4155 | * |
| 4156 | * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately |
| 4157 | * respond to each received packet containing one or more DATA chunk(s) |
| 4158 | * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer |
| 4159 | */ |
| 4160 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); |
| 4161 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 4162 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 4163 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 4164 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4165 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4169 | * SCTP-AUTH Section 6.3 Receiving authenticated chukns |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4170 | * |
| 4171 | * The receiver MUST use the HMAC algorithm indicated in the HMAC |
| 4172 | * Identifier field. If this algorithm was not specified by the |
| 4173 | * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk |
| 4174 | * during association setup, the AUTH chunk and all chunks after it MUST |
| 4175 | * be discarded and an ERROR chunk SHOULD be sent with the error cause |
| 4176 | * defined in Section 4.1. |
| 4177 | * |
| 4178 | * If an endpoint with no shared key receives a Shared Key Identifier |
| 4179 | * other than 0, it MUST silently discard all authenticated chunks. If |
| 4180 | * the endpoint has at least one endpoint pair shared key for the peer, |
| 4181 | * it MUST use the key specified by the Shared Key Identifier if a |
| 4182 | * key has been configured for that Shared Key Identifier. If no |
| 4183 | * endpoint pair shared key has been configured for that Shared Key |
| 4184 | * Identifier, all authenticated chunks MUST be silently discarded. |
| 4185 | * |
| 4186 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 4187 | * |
| 4188 | * The return value is the disposition of the chunk. |
| 4189 | */ |
Xin Long | 4785c7a | 2017-08-05 19:59:58 +0800 | [diff] [blame] | 4190 | static enum sctp_ierror sctp_sf_authenticate( |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4191 | const struct sctp_association *asoc, |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4192 | struct sctp_chunk *chunk) |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4193 | { |
Xin Long | 1b1e0bc | 2018-03-14 19:05:30 +0800 | [diff] [blame] | 4194 | struct sctp_shared_key *sh_key = NULL; |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4195 | struct sctp_authhdr *auth_hdr; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4196 | __u8 *save_digest, *digest; |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4197 | struct sctp_hmac *hmac; |
| 4198 | unsigned int sig_len; |
| 4199 | __u16 key_id; |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4200 | |
| 4201 | /* Pull in the auth header, so we can do some more verification */ |
| 4202 | auth_hdr = (struct sctp_authhdr *)chunk->skb->data; |
| 4203 | chunk->subh.auth_hdr = auth_hdr; |
Xin Long | bb96dec | 2017-08-03 15:42:22 +0800 | [diff] [blame] | 4204 | skb_pull(chunk->skb, sizeof(*auth_hdr)); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4205 | |
Masanari Iida | 02582e9 | 2012-08-22 19:11:26 +0900 | [diff] [blame] | 4206 | /* Make sure that we support the HMAC algorithm from the auth |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4207 | * chunk. |
| 4208 | */ |
| 4209 | if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id)) |
| 4210 | return SCTP_IERROR_AUTH_BAD_HMAC; |
| 4211 | |
| 4212 | /* Make sure that the provided shared key identifier has been |
| 4213 | * configured |
| 4214 | */ |
| 4215 | key_id = ntohs(auth_hdr->shkey_id); |
Xin Long | 1b1e0bc | 2018-03-14 19:05:30 +0800 | [diff] [blame] | 4216 | if (key_id != asoc->active_key_id) { |
| 4217 | sh_key = sctp_auth_get_shkey(asoc, key_id); |
| 4218 | if (!sh_key) |
| 4219 | return SCTP_IERROR_AUTH_BAD_KEYID; |
| 4220 | } |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4221 | |
| 4222 | /* Make sure that the length of the signature matches what |
| 4223 | * we expect. |
| 4224 | */ |
Xin Long | bb96dec | 2017-08-03 15:42:22 +0800 | [diff] [blame] | 4225 | sig_len = ntohs(chunk->chunk_hdr->length) - |
| 4226 | sizeof(struct sctp_auth_chunk); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4227 | hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id)); |
| 4228 | if (sig_len != hmac->hmac_len) |
| 4229 | return SCTP_IERROR_PROTO_VIOLATION; |
| 4230 | |
| 4231 | /* Now that we've done validation checks, we can compute and |
| 4232 | * verify the hmac. The steps involved are: |
| 4233 | * 1. Save the digest from the chunk. |
| 4234 | * 2. Zero out the digest in the chunk. |
| 4235 | * 3. Compute the new digest |
| 4236 | * 4. Compare saved and new digests. |
| 4237 | */ |
| 4238 | digest = auth_hdr->hmac; |
| 4239 | skb_pull(chunk->skb, sig_len); |
| 4240 | |
| 4241 | save_digest = kmemdup(digest, sig_len, GFP_ATOMIC); |
| 4242 | if (!save_digest) |
| 4243 | goto nomem; |
| 4244 | |
| 4245 | memset(digest, 0, sig_len); |
| 4246 | |
| 4247 | sctp_auth_calculate_hmac(asoc, chunk->skb, |
Xin Long | bb96dec | 2017-08-03 15:42:22 +0800 | [diff] [blame] | 4248 | (struct sctp_auth_chunk *)chunk->chunk_hdr, |
Xin Long | 1b1e0bc | 2018-03-14 19:05:30 +0800 | [diff] [blame] | 4249 | sh_key, GFP_ATOMIC); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4250 | |
| 4251 | /* Discard the packet if the digests do not match */ |
| 4252 | if (memcmp(save_digest, digest, sig_len)) { |
| 4253 | kfree(save_digest); |
| 4254 | return SCTP_IERROR_BAD_SIG; |
| 4255 | } |
| 4256 | |
| 4257 | kfree(save_digest); |
| 4258 | chunk->auth = 1; |
| 4259 | |
| 4260 | return SCTP_IERROR_NO_ERROR; |
| 4261 | nomem: |
| 4262 | return SCTP_IERROR_NOMEM; |
| 4263 | } |
| 4264 | |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4265 | enum sctp_disposition sctp_sf_eat_auth(struct net *net, |
| 4266 | const struct sctp_endpoint *ep, |
| 4267 | const struct sctp_association *asoc, |
| 4268 | const union sctp_subtype type, |
| 4269 | void *arg, struct sctp_cmd_seq *commands) |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4270 | { |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4271 | struct sctp_chunk *chunk = arg; |
Xin Long | 4785c7a | 2017-08-05 19:59:58 +0800 | [diff] [blame] | 4272 | struct sctp_authhdr *auth_hdr; |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4273 | struct sctp_chunk *err_chunk; |
Xin Long | 4785c7a | 2017-08-05 19:59:58 +0800 | [diff] [blame] | 4274 | enum sctp_ierror error; |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4275 | |
Wei Yongjun | d2f19fa | 2008-02-05 03:02:26 -0800 | [diff] [blame] | 4276 | /* Make sure that the peer has AUTH capable */ |
| 4277 | if (!asoc->peer.auth_capable) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4278 | return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands); |
Wei Yongjun | d2f19fa | 2008-02-05 03:02:26 -0800 | [diff] [blame] | 4279 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4280 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 4281 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 4282 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4283 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | /* Make sure that the AUTH chunk has valid length. */ |
| 4287 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4288 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4289 | commands); |
| 4290 | |
| 4291 | auth_hdr = (struct sctp_authhdr *)chunk->skb->data; |
Xin Long | 59d8d44 | 2018-05-05 14:59:47 +0800 | [diff] [blame] | 4292 | error = sctp_sf_authenticate(asoc, chunk); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4293 | switch (error) { |
Joe Perches | 7fd71b1 | 2011-07-01 09:43:11 +0000 | [diff] [blame] | 4294 | case SCTP_IERROR_AUTH_BAD_HMAC: |
| 4295 | /* Generate the ERROR chunk and discard the rest |
| 4296 | * of the packet |
| 4297 | */ |
| 4298 | err_chunk = sctp_make_op_error(asoc, chunk, |
| 4299 | SCTP_ERROR_UNSUP_HMAC, |
| 4300 | &auth_hdr->hmac_id, |
| 4301 | sizeof(__u16), 0); |
| 4302 | if (err_chunk) { |
| 4303 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4304 | SCTP_CHUNK(err_chunk)); |
| 4305 | } |
| 4306 | /* Fall Through */ |
| 4307 | case SCTP_IERROR_AUTH_BAD_KEYID: |
| 4308 | case SCTP_IERROR_BAD_SIG: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4309 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Joe Perches | 7fd71b1 | 2011-07-01 09:43:11 +0000 | [diff] [blame] | 4310 | |
| 4311 | case SCTP_IERROR_PROTO_VIOLATION: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4312 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Joe Perches | 7fd71b1 | 2011-07-01 09:43:11 +0000 | [diff] [blame] | 4313 | commands); |
| 4314 | |
| 4315 | case SCTP_IERROR_NOMEM: |
| 4316 | return SCTP_DISPOSITION_NOMEM; |
| 4317 | |
| 4318 | default: /* Prevent gcc warnings */ |
| 4319 | break; |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4320 | } |
| 4321 | |
Vlad Yasevich | 65b07e5 | 2007-09-16 19:34:00 -0700 | [diff] [blame] | 4322 | if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) { |
| 4323 | struct sctp_ulpevent *ev; |
| 4324 | |
| 4325 | ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id), |
Xin Long | ec2e506 | 2018-03-14 19:05:33 +0800 | [diff] [blame] | 4326 | SCTP_AUTH_NEW_KEY, GFP_ATOMIC); |
Vlad Yasevich | 65b07e5 | 2007-09-16 19:34:00 -0700 | [diff] [blame] | 4327 | |
| 4328 | if (!ev) |
| 4329 | return -ENOMEM; |
| 4330 | |
| 4331 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 4332 | SCTP_ULPEVENT(ev)); |
| 4333 | } |
| 4334 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4335 | return SCTP_DISPOSITION_CONSUME; |
| 4336 | } |
| 4337 | |
| 4338 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | * Process an unknown chunk. |
| 4340 | * |
| 4341 | * Section: 3.2. Also, 2.1 in the implementor's guide. |
| 4342 | * |
| 4343 | * Chunk Types are encoded such that the highest-order two bits specify |
| 4344 | * the action that must be taken if the processing endpoint does not |
| 4345 | * recognize the Chunk Type. |
| 4346 | * |
| 4347 | * 00 - Stop processing this SCTP packet and discard it, do not process |
| 4348 | * any further chunks within it. |
| 4349 | * |
| 4350 | * 01 - Stop processing this SCTP packet and discard it, do not process |
| 4351 | * any further chunks within it, and report the unrecognized |
| 4352 | * chunk in an 'Unrecognized Chunk Type'. |
| 4353 | * |
| 4354 | * 10 - Skip this chunk and continue processing. |
| 4355 | * |
| 4356 | * 11 - Skip this chunk and continue processing, but report in an ERROR |
| 4357 | * Chunk using the 'Unrecognized Chunk Type' cause of error. |
| 4358 | * |
| 4359 | * The return value is the disposition of the chunk. |
| 4360 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4361 | enum sctp_disposition sctp_sf_unk_chunk(struct net *net, |
| 4362 | const struct sctp_endpoint *ep, |
| 4363 | const struct sctp_association *asoc, |
| 4364 | const union sctp_subtype type, |
| 4365 | void *arg, |
| 4366 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | { |
| 4368 | struct sctp_chunk *unk_chunk = arg; |
| 4369 | struct sctp_chunk *err_chunk; |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 4370 | struct sctp_chunkhdr *hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 4372 | pr_debug("%s: processing unknown chunk id:%d\n", __func__, type.chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | |
| 4374 | if (!sctp_vtag_verify(unk_chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4375 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | |
| 4377 | /* Make sure that the chunk has a valid length. |
| 4378 | * Since we don't know the chunk type, we use a general |
| 4379 | * chunkhdr structure to make a comparison. |
| 4380 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 4381 | if (!sctp_chunk_length_valid(unk_chunk, sizeof(*hdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4382 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | commands); |
| 4384 | |
| 4385 | switch (type.chunk & SCTP_CID_ACTION_MASK) { |
| 4386 | case SCTP_CID_ACTION_DISCARD: |
| 4387 | /* Discard the packet. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4388 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | case SCTP_CID_ACTION_DISCARD_ERR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | /* Generate an ERROR chunk as response. */ |
| 4391 | hdr = unk_chunk->chunk_hdr; |
| 4392 | err_chunk = sctp_make_op_error(asoc, unk_chunk, |
| 4393 | SCTP_ERROR_UNKNOWN_CHUNK, hdr, |
Marcelo Ricardo Leitner | e2f036a | 2016-09-21 08:45:55 -0300 | [diff] [blame] | 4394 | SCTP_PAD4(ntohs(hdr->length)), |
Vlad Yasevich | 6383cfb | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 4395 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | if (err_chunk) { |
| 4397 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4398 | SCTP_CHUNK(err_chunk)); |
| 4399 | } |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 4400 | |
| 4401 | /* Discard the packet. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4402 | sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | case SCTP_CID_ACTION_SKIP: |
| 4405 | /* Skip the chunk. */ |
| 4406 | return SCTP_DISPOSITION_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | case SCTP_CID_ACTION_SKIP_ERR: |
| 4408 | /* Generate an ERROR chunk as response. */ |
| 4409 | hdr = unk_chunk->chunk_hdr; |
| 4410 | err_chunk = sctp_make_op_error(asoc, unk_chunk, |
| 4411 | SCTP_ERROR_UNKNOWN_CHUNK, hdr, |
Marcelo Ricardo Leitner | e2f036a | 2016-09-21 08:45:55 -0300 | [diff] [blame] | 4412 | SCTP_PAD4(ntohs(hdr->length)), |
Vlad Yasevich | 6383cfb | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 4413 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | if (err_chunk) { |
| 4415 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4416 | SCTP_CHUNK(err_chunk)); |
| 4417 | } |
| 4418 | /* Skip the chunk. */ |
| 4419 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | default: |
| 4421 | break; |
| 4422 | } |
| 4423 | |
| 4424 | return SCTP_DISPOSITION_DISCARD; |
| 4425 | } |
| 4426 | |
| 4427 | /* |
| 4428 | * Discard the chunk. |
| 4429 | * |
| 4430 | * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2 |
| 4431 | * [Too numerous to mention...] |
| 4432 | * Verification Tag: No verification needed. |
| 4433 | * Inputs |
| 4434 | * (endpoint, asoc, chunk) |
| 4435 | * |
| 4436 | * Outputs |
| 4437 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4438 | * |
| 4439 | * The return value is the disposition of the chunk. |
| 4440 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4441 | enum sctp_disposition sctp_sf_discard_chunk(struct net *net, |
| 4442 | const struct sctp_endpoint *ep, |
| 4443 | const struct sctp_association *asoc, |
| 4444 | const union sctp_subtype type, |
| 4445 | void *arg, |
| 4446 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4448 | struct sctp_chunk *chunk = arg; |
| 4449 | |
| 4450 | /* Make sure that the chunk has a valid length. |
| 4451 | * Since we don't know the chunk type, we use a general |
| 4452 | * chunkhdr structure to make a comparison. |
| 4453 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 4454 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4455 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4456 | commands); |
| 4457 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 4458 | pr_debug("%s: chunk:%d is discarded\n", __func__, type.chunk); |
| 4459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | return SCTP_DISPOSITION_DISCARD; |
| 4461 | } |
| 4462 | |
| 4463 | /* |
| 4464 | * Discard the whole packet. |
| 4465 | * |
| 4466 | * Section: 8.4 2) |
| 4467 | * |
| 4468 | * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST |
| 4469 | * silently discard the OOTB packet and take no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | * |
| 4471 | * Verification Tag: No verification necessary |
| 4472 | * |
| 4473 | * Inputs |
| 4474 | * (endpoint, asoc, chunk) |
| 4475 | * |
| 4476 | * Outputs |
| 4477 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4478 | * |
| 4479 | * The return value is the disposition of the chunk. |
| 4480 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4481 | enum sctp_disposition sctp_sf_pdiscard(struct net *net, |
| 4482 | const struct sctp_endpoint *ep, |
| 4483 | const struct sctp_association *asoc, |
| 4484 | const union sctp_subtype type, |
| 4485 | void *arg, struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4487 | SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
| 4489 | |
| 4490 | return SCTP_DISPOSITION_CONSUME; |
| 4491 | } |
| 4492 | |
| 4493 | |
| 4494 | /* |
| 4495 | * The other end is violating protocol. |
| 4496 | * |
| 4497 | * Section: Not specified |
| 4498 | * Verification Tag: Not specified |
| 4499 | * Inputs |
| 4500 | * (endpoint, asoc, chunk) |
| 4501 | * |
| 4502 | * Outputs |
| 4503 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4504 | * |
| 4505 | * We simply tag the chunk as a violation. The state machine will log |
| 4506 | * the violation and continue. |
| 4507 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4508 | enum sctp_disposition sctp_sf_violation(struct net *net, |
| 4509 | const struct sctp_endpoint *ep, |
| 4510 | const struct sctp_association *asoc, |
| 4511 | const union sctp_subtype type, |
| 4512 | void *arg, |
| 4513 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4515 | struct sctp_chunk *chunk = arg; |
| 4516 | |
| 4517 | /* Make sure that the chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 4518 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4519 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4520 | commands); |
| 4521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | return SCTP_DISPOSITION_VIOLATION; |
| 4523 | } |
| 4524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | /* |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4526 | * Common function to handle a protocol violation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4528 | static enum sctp_disposition sctp_sf_abort_violation( |
| 4529 | struct net *net, |
| 4530 | const struct sctp_endpoint *ep, |
| 4531 | const struct sctp_association *asoc, |
| 4532 | void *arg, |
| 4533 | struct sctp_cmd_seq *commands, |
| 4534 | const __u8 *payload, |
| 4535 | const size_t paylen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4537 | struct sctp_packet *packet = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | struct sctp_chunk *chunk = arg; |
| 4539 | struct sctp_chunk *abort = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4541 | /* SCTP-AUTH, Section 6.3: |
| 4542 | * It should be noted that if the receiver wants to tear |
| 4543 | * down an association in an authenticated way only, the |
| 4544 | * handling of malformed packets should not result in |
| 4545 | * tearing down the association. |
| 4546 | * |
| 4547 | * This means that if we only want to abort associations |
| 4548 | * in an authenticated way (i.e AUTH+ABORT), then we |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4549 | * can't destroy this association just because the packet |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4550 | * was malformed. |
| 4551 | */ |
| 4552 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
| 4553 | goto discard; |
| 4554 | |
Jesper Juhl | 9abed24 | 2007-11-11 23:57:49 +0100 | [diff] [blame] | 4555 | /* Make the abort chunk. */ |
| 4556 | abort = sctp_make_abort_violation(asoc, chunk, payload, paylen); |
| 4557 | if (!abort) |
| 4558 | goto nomem; |
| 4559 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4560 | if (asoc) { |
Gui Jianfeng | f4ad85c | 2008-04-12 18:39:34 -0700 | [diff] [blame] | 4561 | /* Treat INIT-ACK as a special case during COOKIE-WAIT. */ |
| 4562 | if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK && |
| 4563 | !asoc->peer.i.init_tag) { |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 4564 | struct sctp_initack_chunk *initack; |
Gui Jianfeng | f4ad85c | 2008-04-12 18:39:34 -0700 | [diff] [blame] | 4565 | |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 4566 | initack = (struct sctp_initack_chunk *)chunk->chunk_hdr; |
| 4567 | if (!sctp_chunk_length_valid(chunk, sizeof(*initack))) |
Gui Jianfeng | f4ad85c | 2008-04-12 18:39:34 -0700 | [diff] [blame] | 4568 | abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T; |
| 4569 | else { |
| 4570 | unsigned int inittag; |
| 4571 | |
| 4572 | inittag = ntohl(initack->init_hdr.init_tag); |
| 4573 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_INITTAG, |
| 4574 | SCTP_U32(inittag)); |
| 4575 | } |
| 4576 | } |
| 4577 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4578 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4579 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4581 | if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) { |
| 4582 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4583 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4584 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4585 | SCTP_ERROR(ECONNREFUSED)); |
| 4586 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
| 4587 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
| 4588 | } else { |
| 4589 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4590 | SCTP_ERROR(ECONNABORTED)); |
| 4591 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 4592 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4593 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | } else { |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 4596 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4597 | |
| 4598 | if (!packet) |
| 4599 | goto nomem_pkt; |
| 4600 | |
| 4601 | if (sctp_test_T_bit(abort)) |
| 4602 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 4603 | |
| 4604 | abort->skb->sk = ep->base.sk; |
| 4605 | |
| 4606 | sctp_packet_append_chunk(packet, abort); |
| 4607 | |
| 4608 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 4609 | SCTP_PACKET(packet)); |
| 4610 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4611 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4614 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4615 | |
Vlad Yasevich | 56eb82b | 2008-10-09 14:33:01 -0700 | [diff] [blame] | 4616 | discard: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4617 | sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | return SCTP_DISPOSITION_ABORT; |
| 4619 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4620 | nomem_pkt: |
| 4621 | sctp_chunk_free(abort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | nomem: |
| 4623 | return SCTP_DISPOSITION_NOMEM; |
| 4624 | } |
| 4625 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4626 | /* |
| 4627 | * Handle a protocol violation when the chunk length is invalid. |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4628 | * "Invalid" length is identified as smaller than the minimal length a |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4629 | * given chunk can be. For example, a SACK chunk has invalid length |
Xin Long | d4d6c61 | 2017-07-23 09:34:33 +0800 | [diff] [blame] | 4630 | * if its length is set to be smaller than the size of struct sctp_sack_chunk. |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4631 | * |
| 4632 | * We inform the other end by sending an ABORT with a Protocol Violation |
| 4633 | * error code. |
| 4634 | * |
| 4635 | * Section: Not specified |
| 4636 | * Verification Tag: Nothing to do |
| 4637 | * Inputs |
| 4638 | * (endpoint, asoc, chunk) |
| 4639 | * |
| 4640 | * Outputs |
| 4641 | * (reply_msg, msg_up, counters) |
| 4642 | * |
| 4643 | * Generate an ABORT chunk and terminate the association. |
| 4644 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4645 | static enum sctp_disposition sctp_sf_violation_chunklen( |
| 4646 | struct net *net, |
| 4647 | const struct sctp_endpoint *ep, |
| 4648 | const struct sctp_association *asoc, |
| 4649 | const union sctp_subtype type, |
| 4650 | void *arg, |
| 4651 | struct sctp_cmd_seq *commands) |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4652 | { |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 4653 | static const char err_str[] = "The following chunk had invalid length:"; |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4654 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4655 | return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str, |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4656 | sizeof(err_str)); |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4657 | } |
| 4658 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4659 | /* |
| 4660 | * Handle a protocol violation when the parameter length is invalid. |
Shan Wei | 33c7cfd | 2011-04-18 19:11:01 +0000 | [diff] [blame] | 4661 | * If the length is smaller than the minimum length of a given parameter, |
| 4662 | * or accumulated length in multi parameters exceeds the end of the chunk, |
| 4663 | * the length is considered as invalid. |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4664 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4665 | static enum sctp_disposition sctp_sf_violation_paramlen( |
| 4666 | struct net *net, |
| 4667 | const struct sctp_endpoint *ep, |
| 4668 | const struct sctp_association *asoc, |
| 4669 | const union sctp_subtype type, |
| 4670 | void *arg, void *ext, |
| 4671 | struct sctp_cmd_seq *commands) |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4672 | { |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4673 | struct sctp_paramhdr *param = ext; |
| 4674 | struct sctp_chunk *abort = NULL; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4675 | struct sctp_chunk *chunk = arg; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4676 | |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4677 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
| 4678 | goto discard; |
| 4679 | |
| 4680 | /* Make the abort chunk. */ |
| 4681 | abort = sctp_make_violation_paramlen(asoc, chunk, param); |
| 4682 | if (!abort) |
| 4683 | goto nomem; |
| 4684 | |
| 4685 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4686 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4687 | |
| 4688 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4689 | SCTP_ERROR(ECONNABORTED)); |
| 4690 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 4691 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4692 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
| 4693 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4694 | |
| 4695 | discard: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4696 | sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands); |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4697 | return SCTP_DISPOSITION_ABORT; |
| 4698 | nomem: |
| 4699 | return SCTP_DISPOSITION_NOMEM; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4700 | } |
| 4701 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4702 | /* Handle a protocol violation when the peer trying to advance the |
| 4703 | * cumulative tsn ack to a point beyond the max tsn currently sent. |
| 4704 | * |
| 4705 | * We inform the other end by sending an ABORT with a Protocol Violation |
| 4706 | * error code. |
| 4707 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4708 | static enum sctp_disposition sctp_sf_violation_ctsn( |
| 4709 | struct net *net, |
| 4710 | const struct sctp_endpoint *ep, |
| 4711 | const struct sctp_association *asoc, |
| 4712 | const union sctp_subtype type, |
| 4713 | void *arg, |
| 4714 | struct sctp_cmd_seq *commands) |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4715 | { |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 4716 | static const char err_str[] = "The cumulative tsn ack beyond the max tsn currently sent:"; |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4717 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4718 | return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str, |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4719 | sizeof(err_str)); |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4720 | } |
| 4721 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4722 | /* Handle protocol violation of an invalid chunk bundling. For example, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4723 | * when we have an association and we receive bundled INIT-ACK, or |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4724 | * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle" |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4725 | * statement from the specs. Additionally, there might be an attacker |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4726 | * on the path and we may not want to continue this communication. |
| 4727 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4728 | static enum sctp_disposition sctp_sf_violation_chunk( |
| 4729 | struct net *net, |
| 4730 | const struct sctp_endpoint *ep, |
| 4731 | const struct sctp_association *asoc, |
| 4732 | const union sctp_subtype type, |
| 4733 | void *arg, |
| 4734 | struct sctp_cmd_seq *commands) |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4735 | { |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 4736 | static const char err_str[] = "The following chunk violates protocol:"; |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4737 | |
| 4738 | if (!asoc) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4739 | return sctp_sf_violation(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4740 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4741 | return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str, |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4742 | sizeof(err_str)); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4743 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | /*************************************************************************** |
| 4745 | * These are the state functions for handling primitive (Section 10) events. |
| 4746 | ***************************************************************************/ |
| 4747 | /* |
| 4748 | * sctp_sf_do_prm_asoc |
| 4749 | * |
| 4750 | * Section: 10.1 ULP-to-SCTP |
| 4751 | * B) Associate |
| 4752 | * |
| 4753 | * Format: ASSOCIATE(local SCTP instance name, destination transport addr, |
| 4754 | * outbound stream count) |
| 4755 | * -> association id [,destination transport addr list] [,outbound stream |
| 4756 | * count] |
| 4757 | * |
| 4758 | * This primitive allows the upper layer to initiate an association to a |
| 4759 | * specific peer endpoint. |
| 4760 | * |
| 4761 | * The peer endpoint shall be specified by one of the transport addresses |
| 4762 | * which defines the endpoint (see Section 1.4). If the local SCTP |
| 4763 | * instance has not been initialized, the ASSOCIATE is considered an |
| 4764 | * error. |
| 4765 | * [This is not relevant for the kernel implementation since we do all |
| 4766 | * initialization at boot time. It we hadn't initialized we wouldn't |
| 4767 | * get anywhere near this code.] |
| 4768 | * |
| 4769 | * An association id, which is a local handle to the SCTP association, |
| 4770 | * will be returned on successful establishment of the association. If |
| 4771 | * SCTP is not able to open an SCTP association with the peer endpoint, |
| 4772 | * an error is returned. |
| 4773 | * [In the kernel implementation, the struct sctp_association needs to |
| 4774 | * be created BEFORE causing this primitive to run.] |
| 4775 | * |
| 4776 | * Other association parameters may be returned, including the |
| 4777 | * complete destination transport addresses of the peer as well as the |
| 4778 | * outbound stream count of the local endpoint. One of the transport |
| 4779 | * address from the returned destination addresses will be selected by |
| 4780 | * the local endpoint as default primary path for sending SCTP packets |
| 4781 | * to this peer. The returned "destination transport addr list" can |
| 4782 | * be used by the ULP to change the default primary path or to force |
| 4783 | * sending a packet to a specific transport address. [All of this |
| 4784 | * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING |
| 4785 | * function.] |
| 4786 | * |
| 4787 | * Mandatory attributes: |
| 4788 | * |
| 4789 | * o local SCTP instance name - obtained from the INITIALIZE operation. |
| 4790 | * [This is the argument asoc.] |
| 4791 | * o destination transport addr - specified as one of the transport |
| 4792 | * addresses of the peer endpoint with which the association is to be |
| 4793 | * established. |
| 4794 | * [This is asoc->peer.active_path.] |
| 4795 | * o outbound stream count - the number of outbound streams the ULP |
| 4796 | * would like to open towards this peer endpoint. |
| 4797 | * [BUG: This is not currently implemented.] |
| 4798 | * Optional attributes: |
| 4799 | * |
| 4800 | * None. |
| 4801 | * |
| 4802 | * The return value is a disposition. |
| 4803 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4804 | enum sctp_disposition sctp_sf_do_prm_asoc(struct net *net, |
| 4805 | const struct sctp_endpoint *ep, |
| 4806 | const struct sctp_association *asoc, |
| 4807 | const union sctp_subtype type, |
| 4808 | void *arg, |
| 4809 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | { |
wangweidong | 26ac8e5 | 2013-12-23 12:16:51 +0800 | [diff] [blame] | 4811 | struct sctp_association *my_asoc; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4812 | struct sctp_chunk *repl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | |
| 4814 | /* The comment below says that we enter COOKIE-WAIT AFTER |
| 4815 | * sending the INIT, but that doesn't actually work in our |
| 4816 | * implementation... |
| 4817 | */ |
| 4818 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4819 | SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); |
| 4820 | |
| 4821 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 4822 | * |
| 4823 | * A) "A" first sends an INIT chunk to "Z". In the INIT, "A" |
| 4824 | * must provide its Verification Tag (Tag_A) in the Initiate |
| 4825 | * Tag field. Tag_A SHOULD be a random number in the range of |
| 4826 | * 1 to 4294967295 (see 5.3.1 for Tag value selection). ... |
| 4827 | */ |
| 4828 | |
| 4829 | repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0); |
| 4830 | if (!repl) |
| 4831 | goto nomem; |
| 4832 | |
Daniel Borkmann | 405426f | 2013-06-14 18:24:05 +0200 | [diff] [blame] | 4833 | /* Choose transport for INIT. */ |
| 4834 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 4835 | SCTP_CHUNK(repl)); |
| 4836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | /* Cast away the const modifier, as we want to just |
| 4838 | * rerun it through as a sideffect. |
| 4839 | */ |
Vlad Yasevich | ab38fb0 | 2008-04-12 18:40:06 -0700 | [diff] [blame] | 4840 | my_asoc = (struct sctp_association *)asoc; |
| 4841 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(my_asoc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | |
| 4843 | /* After sending the INIT, "A" starts the T1-init timer and |
| 4844 | * enters the COOKIE-WAIT state. |
| 4845 | */ |
| 4846 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 4847 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4848 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 4849 | return SCTP_DISPOSITION_CONSUME; |
| 4850 | |
| 4851 | nomem: |
| 4852 | return SCTP_DISPOSITION_NOMEM; |
| 4853 | } |
| 4854 | |
| 4855 | /* |
| 4856 | * Process the SEND primitive. |
| 4857 | * |
| 4858 | * Section: 10.1 ULP-to-SCTP |
| 4859 | * E) Send |
| 4860 | * |
| 4861 | * Format: SEND(association id, buffer address, byte count [,context] |
| 4862 | * [,stream id] [,life time] [,destination transport address] |
| 4863 | * [,unorder flag] [,no-bundle flag] [,payload protocol-id] ) |
| 4864 | * -> result |
| 4865 | * |
| 4866 | * This is the main method to send user data via SCTP. |
| 4867 | * |
| 4868 | * Mandatory attributes: |
| 4869 | * |
| 4870 | * o association id - local handle to the SCTP association |
| 4871 | * |
| 4872 | * o buffer address - the location where the user message to be |
| 4873 | * transmitted is stored; |
| 4874 | * |
| 4875 | * o byte count - The size of the user data in number of bytes; |
| 4876 | * |
| 4877 | * Optional attributes: |
| 4878 | * |
| 4879 | * o context - an optional 32 bit integer that will be carried in the |
| 4880 | * sending failure notification to the ULP if the transportation of |
| 4881 | * this User Message fails. |
| 4882 | * |
| 4883 | * o stream id - to indicate which stream to send the data on. If not |
| 4884 | * specified, stream 0 will be used. |
| 4885 | * |
| 4886 | * o life time - specifies the life time of the user data. The user data |
| 4887 | * will not be sent by SCTP after the life time expires. This |
| 4888 | * parameter can be used to avoid efforts to transmit stale |
| 4889 | * user messages. SCTP notifies the ULP if the data cannot be |
| 4890 | * initiated to transport (i.e. sent to the destination via SCTP's |
| 4891 | * send primitive) within the life time variable. However, the |
| 4892 | * user data will be transmitted if SCTP has attempted to transmit a |
| 4893 | * chunk before the life time expired. |
| 4894 | * |
| 4895 | * o destination transport address - specified as one of the destination |
| 4896 | * transport addresses of the peer endpoint to which this packet |
| 4897 | * should be sent. Whenever possible, SCTP should use this destination |
| 4898 | * transport address for sending the packets, instead of the current |
| 4899 | * primary path. |
| 4900 | * |
| 4901 | * o unorder flag - this flag, if present, indicates that the user |
| 4902 | * would like the data delivered in an unordered fashion to the peer |
| 4903 | * (i.e., the U flag is set to 1 on all DATA chunks carrying this |
| 4904 | * message). |
| 4905 | * |
| 4906 | * o no-bundle flag - instructs SCTP not to bundle this user data with |
| 4907 | * other outbound DATA chunks. SCTP MAY still bundle even when |
| 4908 | * this flag is present, when faced with network congestion. |
| 4909 | * |
| 4910 | * o payload protocol-id - A 32 bit unsigned integer that is to be |
| 4911 | * passed to the peer indicating the type of payload protocol data |
| 4912 | * being transmitted. This value is passed as opaque data by SCTP. |
| 4913 | * |
| 4914 | * The return value is the disposition. |
| 4915 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4916 | enum sctp_disposition sctp_sf_do_prm_send(struct net *net, |
| 4917 | const struct sctp_endpoint *ep, |
| 4918 | const struct sctp_association *asoc, |
| 4919 | const union sctp_subtype type, |
| 4920 | void *arg, |
| 4921 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | { |
Vlad Yasevich | 9c5c62b | 2009-08-10 13:51:03 -0400 | [diff] [blame] | 4923 | struct sctp_datamsg *msg = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | |
Vlad Yasevich | 9c5c62b | 2009-08-10 13:51:03 -0400 | [diff] [blame] | 4925 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_MSG, SCTP_DATAMSG(msg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | return SCTP_DISPOSITION_CONSUME; |
| 4927 | } |
| 4928 | |
| 4929 | /* |
| 4930 | * Process the SHUTDOWN primitive. |
| 4931 | * |
| 4932 | * Section: 10.1: |
| 4933 | * C) Shutdown |
| 4934 | * |
| 4935 | * Format: SHUTDOWN(association id) |
| 4936 | * -> result |
| 4937 | * |
| 4938 | * Gracefully closes an association. Any locally queued user data |
| 4939 | * will be delivered to the peer. The association will be terminated only |
| 4940 | * after the peer acknowledges all the SCTP packets sent. A success code |
| 4941 | * will be returned on successful termination of the association. If |
| 4942 | * attempting to terminate the association results in a failure, an error |
| 4943 | * code shall be returned. |
| 4944 | * |
| 4945 | * Mandatory attributes: |
| 4946 | * |
| 4947 | * o association id - local handle to the SCTP association |
| 4948 | * |
| 4949 | * Optional attributes: |
| 4950 | * |
| 4951 | * None. |
| 4952 | * |
| 4953 | * The return value is the disposition. |
| 4954 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4955 | enum sctp_disposition sctp_sf_do_9_2_prm_shutdown( |
| 4956 | struct net *net, |
| 4957 | const struct sctp_endpoint *ep, |
| 4958 | const struct sctp_association *asoc, |
| 4959 | const union sctp_subtype type, |
| 4960 | void *arg, |
| 4961 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4963 | enum sctp_disposition disposition; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4964 | |
| 4965 | /* From 9.2 Shutdown of an Association |
| 4966 | * Upon receipt of the SHUTDOWN primitive from its upper |
| 4967 | * layer, the endpoint enters SHUTDOWN-PENDING state and |
| 4968 | * remains there until all outstanding data has been |
| 4969 | * acknowledged by its peer. The endpoint accepts no new data |
| 4970 | * from its upper layer, but retransmits data to the far end |
| 4971 | * if necessary to fill gaps. |
| 4972 | */ |
| 4973 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4974 | SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); |
| 4975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4976 | disposition = SCTP_DISPOSITION_CONSUME; |
| 4977 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4978 | disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | arg, commands); |
| 4980 | } |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 4981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | return disposition; |
| 4983 | } |
| 4984 | |
| 4985 | /* |
| 4986 | * Process the ABORT primitive. |
| 4987 | * |
| 4988 | * Section: 10.1: |
| 4989 | * C) Abort |
| 4990 | * |
| 4991 | * Format: Abort(association id [, cause code]) |
| 4992 | * -> result |
| 4993 | * |
| 4994 | * Ungracefully closes an association. Any locally queued user data |
| 4995 | * will be discarded and an ABORT chunk is sent to the peer. A success code |
| 4996 | * will be returned on successful abortion of the association. If |
| 4997 | * attempting to abort the association results in a failure, an error |
| 4998 | * code shall be returned. |
| 4999 | * |
| 5000 | * Mandatory attributes: |
| 5001 | * |
| 5002 | * o association id - local handle to the SCTP association |
| 5003 | * |
| 5004 | * Optional attributes: |
| 5005 | * |
| 5006 | * o cause code - reason of the abort to be passed to the peer |
| 5007 | * |
| 5008 | * None. |
| 5009 | * |
| 5010 | * The return value is the disposition. |
| 5011 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5012 | enum sctp_disposition sctp_sf_do_9_1_prm_abort( |
| 5013 | struct net *net, |
| 5014 | const struct sctp_endpoint *ep, |
| 5015 | const struct sctp_association *asoc, |
| 5016 | const union sctp_subtype type, |
| 5017 | void *arg, |
| 5018 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | { |
| 5020 | /* From 9.1 Abort of an Association |
| 5021 | * Upon receipt of the ABORT primitive from its upper |
| 5022 | * layer, the endpoint enters CLOSED state and |
| 5023 | * discard all outstanding data has been |
| 5024 | * acknowledged by its peer. The endpoint accepts no new data |
| 5025 | * from its upper layer, but retransmits data to the far end |
| 5026 | * if necessary to fill gaps. |
| 5027 | */ |
Sridhar Samudrala | c164a9b | 2006-08-22 11:50:39 -0700 | [diff] [blame] | 5028 | struct sctp_chunk *abort = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | |
Xin Long | 068d8bd | 2015-12-29 17:49:25 +0800 | [diff] [blame] | 5030 | if (abort) |
| 5031 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | |
| 5033 | /* Even if we can't send the ABORT due to low memory delete the |
| 5034 | * TCB. This is a departure from our typical NOMEM handling. |
| 5035 | */ |
| 5036 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5037 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5038 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | /* Delete the established association. */ |
| 5040 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5041 | SCTP_PERR(SCTP_ERROR_USER_ABORT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5043 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 5044 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | |
Marcelo Ricardo Leitner | 649621e | 2016-01-08 11:00:54 -0200 | [diff] [blame] | 5046 | return SCTP_DISPOSITION_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
| 5049 | /* We tried an illegal operation on an association which is closed. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5050 | enum sctp_disposition sctp_sf_error_closed(struct net *net, |
| 5051 | const struct sctp_endpoint *ep, |
| 5052 | const struct sctp_association *asoc, |
| 5053 | const union sctp_subtype type, |
| 5054 | void *arg, |
| 5055 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | { |
| 5057 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL)); |
| 5058 | return SCTP_DISPOSITION_CONSUME; |
| 5059 | } |
| 5060 | |
| 5061 | /* We tried an illegal operation on an association which is shutting |
| 5062 | * down. |
| 5063 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5064 | enum sctp_disposition sctp_sf_error_shutdown( |
| 5065 | struct net *net, |
| 5066 | const struct sctp_endpoint *ep, |
| 5067 | const struct sctp_association *asoc, |
| 5068 | const union sctp_subtype type, |
| 5069 | void *arg, |
| 5070 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | { |
| 5072 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, |
| 5073 | SCTP_ERROR(-ESHUTDOWN)); |
| 5074 | return SCTP_DISPOSITION_CONSUME; |
| 5075 | } |
| 5076 | |
| 5077 | /* |
| 5078 | * sctp_cookie_wait_prm_shutdown |
| 5079 | * |
| 5080 | * Section: 4 Note: 2 |
| 5081 | * Verification Tag: |
| 5082 | * Inputs |
| 5083 | * (endpoint, asoc) |
| 5084 | * |
| 5085 | * The RFC does not explicitly address this issue, but is the route through the |
| 5086 | * state table when someone issues a shutdown while in COOKIE_WAIT state. |
| 5087 | * |
| 5088 | * Outputs |
| 5089 | * (timers) |
| 5090 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5091 | enum sctp_disposition sctp_sf_cookie_wait_prm_shutdown( |
| 5092 | struct net *net, |
| 5093 | const struct sctp_endpoint *ep, |
| 5094 | const struct sctp_association *asoc, |
| 5095 | const union sctp_subtype type, |
| 5096 | void *arg, |
| 5097 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | { |
| 5099 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5100 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 5101 | |
| 5102 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5103 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 5104 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5105 | SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | |
| 5107 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 5108 | |
| 5109 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5110 | } |
| 5111 | |
| 5112 | /* |
| 5113 | * sctp_cookie_echoed_prm_shutdown |
| 5114 | * |
| 5115 | * Section: 4 Note: 2 |
| 5116 | * Verification Tag: |
| 5117 | * Inputs |
| 5118 | * (endpoint, asoc) |
| 5119 | * |
| 5120 | * The RFC does not explcitly address this issue, but is the route through the |
| 5121 | * state table when someone issues a shutdown while in COOKIE_ECHOED state. |
| 5122 | * |
| 5123 | * Outputs |
| 5124 | * (timers) |
| 5125 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5126 | enum sctp_disposition sctp_sf_cookie_echoed_prm_shutdown( |
| 5127 | struct net *net, |
| 5128 | const struct sctp_endpoint *ep, |
| 5129 | const struct sctp_association *asoc, |
| 5130 | const union sctp_subtype type, |
| 5131 | void *arg, |
| 5132 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | { |
| 5134 | /* There is a single T1 timer, so we should be able to use |
| 5135 | * common function with the COOKIE-WAIT state. |
| 5136 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5137 | return sctp_sf_cookie_wait_prm_shutdown(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | /* |
| 5141 | * sctp_sf_cookie_wait_prm_abort |
| 5142 | * |
| 5143 | * Section: 4 Note: 2 |
| 5144 | * Verification Tag: |
| 5145 | * Inputs |
| 5146 | * (endpoint, asoc) |
| 5147 | * |
| 5148 | * The RFC does not explicitly address this issue, but is the route through the |
| 5149 | * state table when someone issues an abort while in COOKIE_WAIT state. |
| 5150 | * |
| 5151 | * Outputs |
| 5152 | * (timers) |
| 5153 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5154 | enum sctp_disposition sctp_sf_cookie_wait_prm_abort( |
| 5155 | struct net *net, |
| 5156 | const struct sctp_endpoint *ep, |
| 5157 | const struct sctp_association *asoc, |
| 5158 | const union sctp_subtype type, |
| 5159 | void *arg, |
| 5160 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | { |
Sridhar Samudrala | c164a9b | 2006-08-22 11:50:39 -0700 | [diff] [blame] | 5162 | struct sctp_chunk *abort = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5163 | |
| 5164 | /* Stop T1-init timer */ |
| 5165 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5166 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | |
Xin Long | 068d8bd | 2015-12-29 17:49:25 +0800 | [diff] [blame] | 5168 | if (abort) |
| 5169 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5170 | |
| 5171 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5172 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 5173 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5174 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5175 | |
| 5176 | /* Even if we can't send the ABORT due to low memory delete the |
| 5177 | * TCB. This is a departure from our typical NOMEM handling. |
| 5178 | */ |
| 5179 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5180 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5181 | SCTP_ERROR(ECONNREFUSED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | /* Delete the established association. */ |
| 5183 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 5184 | SCTP_PERR(SCTP_ERROR_USER_ABORT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | |
Marcelo Ricardo Leitner | 649621e | 2016-01-08 11:00:54 -0200 | [diff] [blame] | 5186 | return SCTP_DISPOSITION_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | /* |
| 5190 | * sctp_sf_cookie_echoed_prm_abort |
| 5191 | * |
| 5192 | * Section: 4 Note: 3 |
| 5193 | * Verification Tag: |
| 5194 | * Inputs |
| 5195 | * (endpoint, asoc) |
| 5196 | * |
| 5197 | * The RFC does not explcitly address this issue, but is the route through the |
| 5198 | * state table when someone issues an abort while in COOKIE_ECHOED state. |
| 5199 | * |
| 5200 | * Outputs |
| 5201 | * (timers) |
| 5202 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5203 | enum sctp_disposition sctp_sf_cookie_echoed_prm_abort( |
| 5204 | struct net *net, |
| 5205 | const struct sctp_endpoint *ep, |
| 5206 | const struct sctp_association *asoc, |
| 5207 | const union sctp_subtype type, |
| 5208 | void *arg, |
| 5209 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | { |
| 5211 | /* There is a single T1 timer, so we should be able to use |
| 5212 | * common function with the COOKIE-WAIT state. |
| 5213 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5214 | return sctp_sf_cookie_wait_prm_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | /* |
| 5218 | * sctp_sf_shutdown_pending_prm_abort |
| 5219 | * |
| 5220 | * Inputs |
| 5221 | * (endpoint, asoc) |
| 5222 | * |
| 5223 | * The RFC does not explicitly address this issue, but is the route through the |
| 5224 | * state table when someone issues an abort while in SHUTDOWN-PENDING state. |
| 5225 | * |
| 5226 | * Outputs |
| 5227 | * (timers) |
| 5228 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5229 | enum sctp_disposition sctp_sf_shutdown_pending_prm_abort( |
| 5230 | struct net *net, |
| 5231 | const struct sctp_endpoint *ep, |
| 5232 | const struct sctp_association *asoc, |
| 5233 | const union sctp_subtype type, |
| 5234 | void *arg, |
| 5235 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | { |
| 5237 | /* Stop the T5-shutdown guard timer. */ |
| 5238 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5239 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5240 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5241 | return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | /* |
| 5245 | * sctp_sf_shutdown_sent_prm_abort |
| 5246 | * |
| 5247 | * Inputs |
| 5248 | * (endpoint, asoc) |
| 5249 | * |
| 5250 | * The RFC does not explicitly address this issue, but is the route through the |
| 5251 | * state table when someone issues an abort while in SHUTDOWN-SENT state. |
| 5252 | * |
| 5253 | * Outputs |
| 5254 | * (timers) |
| 5255 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5256 | enum sctp_disposition sctp_sf_shutdown_sent_prm_abort( |
| 5257 | struct net *net, |
| 5258 | const struct sctp_endpoint *ep, |
| 5259 | const struct sctp_association *asoc, |
| 5260 | const union sctp_subtype type, |
| 5261 | void *arg, |
| 5262 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 | { |
| 5264 | /* Stop the T2-shutdown timer. */ |
| 5265 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5266 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5267 | |
| 5268 | /* Stop the T5-shutdown guard timer. */ |
| 5269 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5270 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5271 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5272 | return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | /* |
| 5276 | * sctp_sf_cookie_echoed_prm_abort |
| 5277 | * |
| 5278 | * Inputs |
| 5279 | * (endpoint, asoc) |
| 5280 | * |
| 5281 | * The RFC does not explcitly address this issue, but is the route through the |
| 5282 | * state table when someone issues an abort while in COOKIE_ECHOED state. |
| 5283 | * |
| 5284 | * Outputs |
| 5285 | * (timers) |
| 5286 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5287 | enum sctp_disposition sctp_sf_shutdown_ack_sent_prm_abort( |
| 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | { |
| 5295 | /* The same T2 timer, so we should be able to use |
| 5296 | * common function with the SHUTDOWN-SENT state. |
| 5297 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5298 | return sctp_sf_shutdown_sent_prm_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | /* |
| 5302 | * Process the REQUESTHEARTBEAT primitive |
| 5303 | * |
| 5304 | * 10.1 ULP-to-SCTP |
| 5305 | * J) Request Heartbeat |
| 5306 | * |
| 5307 | * Format: REQUESTHEARTBEAT(association id, destination transport address) |
| 5308 | * |
| 5309 | * -> result |
| 5310 | * |
| 5311 | * Instructs the local endpoint to perform a HeartBeat on the specified |
| 5312 | * destination transport address of the given association. The returned |
| 5313 | * result should indicate whether the transmission of the HEARTBEAT |
| 5314 | * chunk to the destination address is successful. |
| 5315 | * |
| 5316 | * Mandatory attributes: |
| 5317 | * |
| 5318 | * o association id - local handle to the SCTP association |
| 5319 | * |
| 5320 | * o destination transport address - the transport address of the |
| 5321 | * association on which a heartbeat should be issued. |
| 5322 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5323 | enum sctp_disposition sctp_sf_do_prm_requestheartbeat( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5324 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | const struct sctp_endpoint *ep, |
| 5326 | const struct sctp_association *asoc, |
Xin Long | bfc6f82 | 2017-08-05 20:00:04 +0800 | [diff] [blame] | 5327 | const union sctp_subtype type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5328 | void *arg, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 5329 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5330 | { |
Vlad Yasevich | fb78525 | 2007-03-19 17:02:03 -0700 | [diff] [blame] | 5331 | if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type, |
| 5332 | (struct sctp_transport *)arg, commands)) |
| 5333 | return SCTP_DISPOSITION_NOMEM; |
| 5334 | |
| 5335 | /* |
| 5336 | * RFC 2960 (bis), section 8.3 |
| 5337 | * |
| 5338 | * D) Request an on-demand HEARTBEAT on a specific destination |
| 5339 | * transport address of a given association. |
| 5340 | * |
| 5341 | * The endpoint should increment the respective error counter of |
| 5342 | * the destination transport address each time a HEARTBEAT is sent |
| 5343 | * to that address and not acknowledged within one RTO. |
| 5344 | * |
| 5345 | */ |
Vlad Yasevich | 7e99013 | 2009-03-02 09:46:14 +0000 | [diff] [blame] | 5346 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT, |
Vlad Yasevich | fb78525 | 2007-03-19 17:02:03 -0700 | [diff] [blame] | 5347 | SCTP_TRANSPORT(arg)); |
| 5348 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | /* |
| 5352 | * ADDIP Section 4.1 ASCONF Chunk Procedures |
| 5353 | * When an endpoint has an ASCONF signaled change to be sent to the |
| 5354 | * remote endpoint it should do A1 to A9 |
| 5355 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5356 | enum sctp_disposition sctp_sf_do_prm_asconf(struct net *net, |
| 5357 | const struct sctp_endpoint *ep, |
| 5358 | const struct sctp_association *asoc, |
| 5359 | const union sctp_subtype type, |
| 5360 | void *arg, |
| 5361 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | { |
| 5363 | struct sctp_chunk *chunk = arg; |
| 5364 | |
| 5365 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); |
| 5366 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 5367 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 5368 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); |
| 5369 | return SCTP_DISPOSITION_CONSUME; |
| 5370 | } |
| 5371 | |
Xin Long | 7a090b0 | 2017-01-18 00:44:44 +0800 | [diff] [blame] | 5372 | /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5373 | enum sctp_disposition sctp_sf_do_prm_reconf(struct net *net, |
| 5374 | const struct sctp_endpoint *ep, |
| 5375 | const struct sctp_association *asoc, |
| 5376 | const union sctp_subtype type, |
| 5377 | void *arg, |
| 5378 | struct sctp_cmd_seq *commands) |
Xin Long | 7a090b0 | 2017-01-18 00:44:44 +0800 | [diff] [blame] | 5379 | { |
| 5380 | struct sctp_chunk *chunk = arg; |
| 5381 | |
| 5382 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); |
| 5383 | return SCTP_DISPOSITION_CONSUME; |
| 5384 | } |
| 5385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | /* |
| 5387 | * Ignore the primitive event |
| 5388 | * |
| 5389 | * The return value is the disposition of the primitive. |
| 5390 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5391 | enum sctp_disposition sctp_sf_ignore_primitive( |
| 5392 | struct net *net, |
| 5393 | const struct sctp_endpoint *ep, |
| 5394 | const struct sctp_association *asoc, |
| 5395 | const union sctp_subtype type, |
| 5396 | void *arg, |
| 5397 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5398 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5399 | pr_debug("%s: primitive type:%d is ignored\n", __func__, |
| 5400 | type.primitive); |
| 5401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 | return SCTP_DISPOSITION_DISCARD; |
| 5403 | } |
| 5404 | |
| 5405 | /*************************************************************************** |
| 5406 | * These are the state functions for the OTHER events. |
| 5407 | ***************************************************************************/ |
| 5408 | |
| 5409 | /* |
Wei Yongjun | e1cdd55 | 2011-04-17 17:29:03 +0000 | [diff] [blame] | 5410 | * When the SCTP stack has no more user data to send or retransmit, this |
| 5411 | * notification is given to the user. Also, at the time when a user app |
| 5412 | * subscribes to this event, if there is no data to be sent or |
| 5413 | * retransmit, the stack will immediately send up this notification. |
| 5414 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5415 | enum sctp_disposition sctp_sf_do_no_pending_tsn( |
| 5416 | struct net *net, |
| 5417 | const struct sctp_endpoint *ep, |
| 5418 | const struct sctp_association *asoc, |
| 5419 | const union sctp_subtype type, |
| 5420 | void *arg, |
| 5421 | struct sctp_cmd_seq *commands) |
Wei Yongjun | e1cdd55 | 2011-04-17 17:29:03 +0000 | [diff] [blame] | 5422 | { |
| 5423 | struct sctp_ulpevent *event; |
| 5424 | |
| 5425 | event = sctp_ulpevent_make_sender_dry_event(asoc, GFP_ATOMIC); |
| 5426 | if (!event) |
| 5427 | return SCTP_DISPOSITION_NOMEM; |
| 5428 | |
| 5429 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(event)); |
| 5430 | |
| 5431 | return SCTP_DISPOSITION_CONSUME; |
| 5432 | } |
| 5433 | |
| 5434 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5435 | * Start the shutdown negotiation. |
| 5436 | * |
| 5437 | * From Section 9.2: |
| 5438 | * Once all its outstanding data has been acknowledged, the endpoint |
| 5439 | * shall send a SHUTDOWN chunk to its peer including in the Cumulative |
| 5440 | * TSN Ack field the last sequential TSN it has received from the peer. |
| 5441 | * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT |
| 5442 | * state. If the timer expires, the endpoint must re-send the SHUTDOWN |
| 5443 | * with the updated last sequential TSN received from its peer. |
| 5444 | * |
| 5445 | * The return value is the disposition. |
| 5446 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5447 | enum sctp_disposition sctp_sf_do_9_2_start_shutdown( |
| 5448 | struct net *net, |
| 5449 | const struct sctp_endpoint *ep, |
| 5450 | const struct sctp_association *asoc, |
| 5451 | const union sctp_subtype type, |
| 5452 | void *arg, |
| 5453 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5454 | { |
| 5455 | struct sctp_chunk *reply; |
| 5456 | |
| 5457 | /* Once all its outstanding data has been acknowledged, the |
| 5458 | * endpoint shall send a SHUTDOWN chunk to its peer including |
| 5459 | * in the Cumulative TSN Ack field the last sequential TSN it |
| 5460 | * has received from the peer. |
| 5461 | */ |
| 5462 | reply = sctp_make_shutdown(asoc, NULL); |
| 5463 | if (!reply) |
| 5464 | goto nomem; |
| 5465 | |
| 5466 | /* Set the transport for the SHUTDOWN chunk and the timeout for the |
| 5467 | * T2-shutdown timer. |
| 5468 | */ |
| 5469 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5470 | |
| 5471 | /* It shall then start the T2-shutdown timer */ |
| 5472 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 5473 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5474 | |
Wei Yongjun | 536428a | 2008-09-05 08:55:26 +0800 | [diff] [blame] | 5475 | /* RFC 4960 Section 9.2 |
| 5476 | * The sender of the SHUTDOWN MAY also start an overall guard timer |
| 5477 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. |
| 5478 | */ |
Thomas Graf | f8d9605 | 2011-07-07 00:28:35 +0000 | [diff] [blame] | 5479 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
Wei Yongjun | 536428a | 2008-09-05 08:55:26 +0800 | [diff] [blame] | 5480 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5481 | |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 5482 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5484 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 5485 | |
| 5486 | /* and enter the SHUTDOWN-SENT state. */ |
| 5487 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5488 | SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT)); |
| 5489 | |
| 5490 | /* sctp-implguide 2.10 Issues with Heartbeating and failover |
| 5491 | * |
| 5492 | * HEARTBEAT ... is discontinued after sending either SHUTDOWN |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5493 | * or SHUTDOWN-ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | */ |
| 5495 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 5496 | |
| 5497 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5498 | |
| 5499 | return SCTP_DISPOSITION_CONSUME; |
| 5500 | |
| 5501 | nomem: |
| 5502 | return SCTP_DISPOSITION_NOMEM; |
| 5503 | } |
| 5504 | |
| 5505 | /* |
| 5506 | * Generate a SHUTDOWN ACK now that everything is SACK'd. |
| 5507 | * |
| 5508 | * From Section 9.2: |
| 5509 | * |
| 5510 | * If it has no more outstanding DATA chunks, the SHUTDOWN receiver |
| 5511 | * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own, |
| 5512 | * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the |
| 5513 | * endpoint must re-send the SHUTDOWN ACK. |
| 5514 | * |
| 5515 | * The return value is the disposition. |
| 5516 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5517 | enum sctp_disposition sctp_sf_do_9_2_shutdown_ack( |
| 5518 | struct net *net, |
| 5519 | const struct sctp_endpoint *ep, |
| 5520 | const struct sctp_association *asoc, |
| 5521 | const union sctp_subtype type, |
| 5522 | void *arg, |
| 5523 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5525 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | struct sctp_chunk *reply; |
| 5527 | |
| 5528 | /* There are 2 ways of getting here: |
| 5529 | * 1) called in response to a SHUTDOWN chunk |
| 5530 | * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued. |
| 5531 | * |
| 5532 | * For the case (2), the arg parameter is set to NULL. We need |
| 5533 | * to check that we have a chunk before accessing it's fields. |
| 5534 | */ |
| 5535 | if (chunk) { |
| 5536 | if (!sctp_vtag_verify(chunk, asoc)) |
Xin Long | ac23e68 | 2017-08-03 15:42:10 +0800 | [diff] [blame] | 5537 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, |
| 5538 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | |
| 5540 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
Xin Long | ac23e68 | 2017-08-03 15:42:10 +0800 | [diff] [blame] | 5541 | if (!sctp_chunk_length_valid( |
| 5542 | chunk, sizeof(struct sctp_shutdown_chunk))) |
| 5543 | return sctp_sf_violation_chunklen(net, ep, asoc, type, |
| 5544 | arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver |
| 5548 | * shall send a SHUTDOWN ACK ... |
| 5549 | */ |
| 5550 | reply = sctp_make_shutdown_ack(asoc, chunk); |
| 5551 | if (!reply) |
| 5552 | goto nomem; |
| 5553 | |
| 5554 | /* Set the transport for the SHUTDOWN ACK chunk and the timeout for |
| 5555 | * the T2-shutdown timer. |
| 5556 | */ |
| 5557 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5558 | |
| 5559 | /* and start/restart a T2-shutdown timer of its own, */ |
| 5560 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5561 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5562 | |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 5563 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5565 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 5566 | |
| 5567 | /* Enter the SHUTDOWN-ACK-SENT state. */ |
| 5568 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5569 | SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT)); |
| 5570 | |
| 5571 | /* sctp-implguide 2.10 Issues with Heartbeating and failover |
| 5572 | * |
| 5573 | * HEARTBEAT ... is discontinued after sending either SHUTDOWN |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5574 | * or SHUTDOWN-ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | */ |
| 5576 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 5577 | |
| 5578 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5579 | |
| 5580 | return SCTP_DISPOSITION_CONSUME; |
| 5581 | |
| 5582 | nomem: |
| 5583 | return SCTP_DISPOSITION_NOMEM; |
| 5584 | } |
| 5585 | |
| 5586 | /* |
| 5587 | * Ignore the event defined as other |
| 5588 | * |
| 5589 | * The return value is the disposition of the event. |
| 5590 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5591 | enum sctp_disposition sctp_sf_ignore_other(struct net *net, |
| 5592 | const struct sctp_endpoint *ep, |
| 5593 | const struct sctp_association *asoc, |
| 5594 | const union sctp_subtype type, |
| 5595 | void *arg, |
| 5596 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5598 | pr_debug("%s: the event other type:%d is ignored\n", |
| 5599 | __func__, type.other); |
| 5600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | return SCTP_DISPOSITION_DISCARD; |
| 5602 | } |
| 5603 | |
| 5604 | /************************************************************ |
| 5605 | * These are the state functions for handling timeout events. |
| 5606 | ************************************************************/ |
| 5607 | |
| 5608 | /* |
| 5609 | * RTX Timeout |
| 5610 | * |
| 5611 | * Section: 6.3.3 Handle T3-rtx Expiration |
| 5612 | * |
| 5613 | * Whenever the retransmission timer T3-rtx expires for a destination |
| 5614 | * address, do the following: |
| 5615 | * [See below] |
| 5616 | * |
| 5617 | * The return value is the disposition of the chunk. |
| 5618 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5619 | enum sctp_disposition sctp_sf_do_6_3_3_rtx(struct net *net, |
| 5620 | const struct sctp_endpoint *ep, |
| 5621 | const struct sctp_association *asoc, |
| 5622 | const union sctp_subtype type, |
| 5623 | void *arg, |
| 5624 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | { |
| 5626 | struct sctp_transport *transport = arg; |
| 5627 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5628 | SCTP_INC_STATS(net, SCTP_MIB_T3_RTX_EXPIREDS); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | if (asoc->overall_error_count >= asoc->max_retrans) { |
lucien | 8a0d19c | 2015-12-05 15:35:36 +0800 | [diff] [blame] | 5631 | if (asoc->peer.zero_window_announced && |
| 5632 | asoc->state == SCTP_STATE_SHUTDOWN_PENDING) { |
Thomas Graf | f8d9605 | 2011-07-07 00:28:35 +0000 | [diff] [blame] | 5633 | /* |
| 5634 | * We are here likely because the receiver had its rwnd |
| 5635 | * closed for a while and we have not been able to |
| 5636 | * transmit the locally queued data within the maximum |
| 5637 | * retransmission attempts limit. Start the T5 |
| 5638 | * shutdown guard timer to give the receiver one last |
| 5639 | * chance and some additional time to recover before |
| 5640 | * aborting. |
| 5641 | */ |
| 5642 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START_ONCE, |
| 5643 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5644 | } else { |
| 5645 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5646 | SCTP_ERROR(ETIMEDOUT)); |
| 5647 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 5648 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 5649 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5650 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 5651 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Thomas Graf | f8d9605 | 2011-07-07 00:28:35 +0000 | [diff] [blame] | 5652 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | /* E1) For the destination address for which the timer |
| 5657 | * expires, adjust its ssthresh with rules defined in Section |
| 5658 | * 7.2.3 and set the cwnd <- MTU. |
| 5659 | */ |
| 5660 | |
| 5661 | /* E2) For the destination address for which the timer |
| 5662 | * expires, set RTO <- RTO * 2 ("back off the timer"). The |
| 5663 | * maximum value discussed in rule C7 above (RTO.max) may be |
| 5664 | * used to provide an upper bound to this doubling operation. |
| 5665 | */ |
| 5666 | |
| 5667 | /* E3) Determine how many of the earliest (i.e., lowest TSN) |
| 5668 | * outstanding DATA chunks for the address for which the |
| 5669 | * T3-rtx has expired will fit into a single packet, subject |
| 5670 | * to the MTU constraint for the path corresponding to the |
| 5671 | * destination transport address to which the retransmission |
| 5672 | * is being sent (this may be different from the address for |
| 5673 | * which the timer expires [see Section 6.4]). Call this |
| 5674 | * value K. Bundle and retransmit those K DATA chunks in a |
| 5675 | * single packet to the destination endpoint. |
| 5676 | * |
| 5677 | * Note: Any DATA chunks that were sent to the address for |
| 5678 | * which the T3-rtx timer expired but did not fit in one MTU |
| 5679 | * (rule E3 above), should be marked for retransmission and |
| 5680 | * sent as soon as cwnd allows (normally when a SACK arrives). |
| 5681 | */ |
| 5682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | /* Do some failure management (Section 8.2). */ |
| 5684 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); |
| 5685 | |
Vlad Yasevich | 1845a57 | 2007-02-21 02:06:19 -0800 | [diff] [blame] | 5686 | /* NB: Rules E4 and F1 are implicit in R1. */ |
| 5687 | sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport)); |
| 5688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5689 | return SCTP_DISPOSITION_CONSUME; |
| 5690 | } |
| 5691 | |
| 5692 | /* |
| 5693 | * Generate delayed SACK on timeout |
| 5694 | * |
| 5695 | * Section: 6.2 Acknowledgement on Reception of DATA Chunks |
| 5696 | * |
| 5697 | * The guidelines on delayed acknowledgement algorithm specified in |
| 5698 | * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an |
| 5699 | * acknowledgement SHOULD be generated for at least every second packet |
| 5700 | * (not every second DATA chunk) received, and SHOULD be generated |
| 5701 | * within 200 ms of the arrival of any unacknowledged DATA chunk. In |
| 5702 | * some situations it may be beneficial for an SCTP transmitter to be |
| 5703 | * more conservative than the algorithms detailed in this document |
| 5704 | * allow. However, an SCTP transmitter MUST NOT be more aggressive than |
| 5705 | * the following algorithms allow. |
| 5706 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5707 | enum sctp_disposition sctp_sf_do_6_2_sack(struct net *net, |
| 5708 | const struct sctp_endpoint *ep, |
| 5709 | const struct sctp_association *asoc, |
| 5710 | const union sctp_subtype type, |
| 5711 | void *arg, |
| 5712 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5714 | SCTP_INC_STATS(net, SCTP_MIB_DELAY_SACK_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 5716 | return SCTP_DISPOSITION_CONSUME; |
| 5717 | } |
| 5718 | |
| 5719 | /* |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5720 | * sctp_sf_t1_init_timer_expire |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | * |
| 5722 | * Section: 4 Note: 2 |
| 5723 | * Verification Tag: |
| 5724 | * Inputs |
| 5725 | * (endpoint, asoc) |
| 5726 | * |
| 5727 | * RFC 2960 Section 4 Notes |
| 5728 | * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT |
| 5729 | * and re-start the T1-init timer without changing state. This MUST |
| 5730 | * be repeated up to 'Max.Init.Retransmits' times. After that, the |
| 5731 | * endpoint MUST abort the initialization process and report the |
| 5732 | * error to SCTP user. |
| 5733 | * |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5734 | * Outputs |
| 5735 | * (timers, events) |
| 5736 | * |
| 5737 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5738 | enum sctp_disposition sctp_sf_t1_init_timer_expire( |
| 5739 | struct net *net, |
| 5740 | const struct sctp_endpoint *ep, |
| 5741 | const struct sctp_association *asoc, |
| 5742 | const union sctp_subtype type, |
| 5743 | void *arg, |
| 5744 | struct sctp_cmd_seq *commands) |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5745 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5746 | int attempts = asoc->init_err_counter + 1; |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5747 | struct sctp_chunk *repl = NULL; |
| 5748 | struct sctp_bind_addr *bp; |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5749 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5750 | pr_debug("%s: timer T1 expired (INIT)\n", __func__); |
| 5751 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5752 | SCTP_INC_STATS(net, SCTP_MIB_T1_INIT_EXPIREDS); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5753 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 5754 | if (attempts <= asoc->max_init_attempts) { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5755 | bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; |
| 5756 | repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0); |
| 5757 | if (!repl) |
| 5758 | return SCTP_DISPOSITION_NOMEM; |
| 5759 | |
| 5760 | /* Choose transport for INIT. */ |
| 5761 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 5762 | SCTP_CHUNK(repl)); |
| 5763 | |
| 5764 | /* Issue a sideeffect to do the needed accounting. */ |
| 5765 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART, |
| 5766 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 5767 | |
| 5768 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 5769 | } else { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5770 | pr_debug("%s: giving up on INIT, attempts:%d " |
| 5771 | "max_init_attempts:%d\n", __func__, attempts, |
| 5772 | asoc->max_init_attempts); |
| 5773 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5774 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5775 | SCTP_ERROR(ETIMEDOUT)); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5776 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 5777 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5778 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5779 | } |
| 5780 | |
| 5781 | return SCTP_DISPOSITION_CONSUME; |
| 5782 | } |
| 5783 | |
| 5784 | /* |
| 5785 | * sctp_sf_t1_cookie_timer_expire |
| 5786 | * |
| 5787 | * Section: 4 Note: 2 |
| 5788 | * Verification Tag: |
| 5789 | * Inputs |
| 5790 | * (endpoint, asoc) |
| 5791 | * |
| 5792 | * RFC 2960 Section 4 Notes |
| 5793 | * 3) If the T1-cookie timer expires, the endpoint MUST retransmit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | * COOKIE ECHO and re-start the T1-cookie timer without changing |
| 5795 | * state. This MUST be repeated up to 'Max.Init.Retransmits' times. |
| 5796 | * After that, the endpoint MUST abort the initialization process and |
| 5797 | * report the error to SCTP user. |
| 5798 | * |
| 5799 | * Outputs |
| 5800 | * (timers, events) |
| 5801 | * |
| 5802 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5803 | enum sctp_disposition sctp_sf_t1_cookie_timer_expire( |
| 5804 | struct net *net, |
| 5805 | const struct sctp_endpoint *ep, |
| 5806 | const struct sctp_association *asoc, |
| 5807 | const union sctp_subtype type, |
| 5808 | void *arg, |
| 5809 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5810 | { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5811 | int attempts = asoc->init_err_counter + 1; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5812 | struct sctp_chunk *repl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5813 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5814 | pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__); |
| 5815 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5816 | SCTP_INC_STATS(net, SCTP_MIB_T1_COOKIE_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5817 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 5818 | if (attempts <= asoc->max_init_attempts) { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5819 | repl = sctp_make_cookie_echo(asoc, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | if (!repl) |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5821 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | |
Vlad Yasevich | 96cd0d3 | 2008-09-08 14:00:26 -0400 | [diff] [blame] | 5823 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 5824 | SCTP_CHUNK(repl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | /* Issue a sideeffect to do the needed accounting. */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5826 | sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART, |
| 5827 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 5828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 5830 | } else { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5831 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5832 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 5834 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5835 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5836 | } |
| 5837 | |
| 5838 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN |
| 5842 | * with the updated last sequential TSN received from its peer. |
| 5843 | * |
| 5844 | * An endpoint should limit the number of retransmissions of the |
| 5845 | * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'. |
| 5846 | * If this threshold is exceeded the endpoint should destroy the TCB and |
| 5847 | * MUST report the peer endpoint unreachable to the upper layer (and |
| 5848 | * thus the association enters the CLOSED state). The reception of any |
| 5849 | * packet from its peer (i.e. as the peer sends all of its queued DATA |
| 5850 | * chunks) should clear the endpoint's retransmission count and restart |
| 5851 | * the T2-Shutdown timer, giving its peer ample opportunity to transmit |
| 5852 | * all of its queued DATA chunks that have not yet been sent. |
| 5853 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5854 | enum sctp_disposition sctp_sf_t2_timer_expire( |
| 5855 | struct net *net, |
| 5856 | const struct sctp_endpoint *ep, |
| 5857 | const struct sctp_association *asoc, |
| 5858 | const union sctp_subtype type, |
| 5859 | void *arg, |
| 5860 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5861 | { |
| 5862 | struct sctp_chunk *reply = NULL; |
| 5863 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5864 | pr_debug("%s: timer T2 expired\n", __func__); |
| 5865 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5866 | SCTP_INC_STATS(net, SCTP_MIB_T2_SHUTDOWN_EXPIREDS); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5867 | |
Neil Horman | 58fbbed | 2008-02-29 11:40:56 -0800 | [diff] [blame] | 5868 | ((struct sctp_association *)asoc)->shutdown_retries++; |
| 5869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5870 | if (asoc->overall_error_count >= asoc->max_retrans) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5871 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5872 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5873 | /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 5874 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5875 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5876 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 5877 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5878 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5879 | } |
| 5880 | |
| 5881 | switch (asoc->state) { |
| 5882 | case SCTP_STATE_SHUTDOWN_SENT: |
| 5883 | reply = sctp_make_shutdown(asoc, NULL); |
| 5884 | break; |
| 5885 | |
| 5886 | case SCTP_STATE_SHUTDOWN_ACK_SENT: |
| 5887 | reply = sctp_make_shutdown_ack(asoc, NULL); |
| 5888 | break; |
| 5889 | |
| 5890 | default: |
| 5891 | BUG(); |
| 5892 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 5893 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5894 | |
| 5895 | if (!reply) |
| 5896 | goto nomem; |
| 5897 | |
Wei Yongjun | 6345b19 | 2009-04-26 23:13:35 +0800 | [diff] [blame] | 5898 | /* Do some failure management (Section 8.2). |
| 5899 | * If we remove the transport an SHUTDOWN was last sent to, don't |
| 5900 | * do failure management. |
| 5901 | */ |
| 5902 | if (asoc->shutdown_last_sent_to) |
| 5903 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, |
| 5904 | SCTP_TRANSPORT(asoc->shutdown_last_sent_to)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5905 | |
| 5906 | /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for |
| 5907 | * the T2-shutdown timer. |
| 5908 | */ |
| 5909 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5910 | |
| 5911 | /* Restart the T2-shutdown timer. */ |
| 5912 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5913 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5914 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5915 | return SCTP_DISPOSITION_CONSUME; |
| 5916 | |
| 5917 | nomem: |
| 5918 | return SCTP_DISPOSITION_NOMEM; |
| 5919 | } |
| 5920 | |
| 5921 | /* |
| 5922 | * ADDIP Section 4.1 ASCONF CHunk Procedures |
| 5923 | * If the T4 RTO timer expires the endpoint should do B1 to B5 |
| 5924 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5925 | enum sctp_disposition sctp_sf_t4_timer_expire( |
| 5926 | struct net *net, |
| 5927 | const struct sctp_endpoint *ep, |
| 5928 | const struct sctp_association *asoc, |
| 5929 | const union sctp_subtype type, |
| 5930 | void *arg, |
| 5931 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5932 | { |
| 5933 | struct sctp_chunk *chunk = asoc->addip_last_asconf; |
| 5934 | struct sctp_transport *transport = chunk->transport; |
| 5935 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5936 | SCTP_INC_STATS(net, SCTP_MIB_T4_RTO_EXPIREDS); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5938 | /* ADDIP 4.1 B1) Increment the error counters and perform path failure |
| 5939 | * detection on the appropriate destination address as defined in |
| 5940 | * RFC2960 [5] section 8.1 and 8.2. |
| 5941 | */ |
Wei Yongjun | 10a43ce | 2009-04-26 23:14:42 +0800 | [diff] [blame] | 5942 | if (transport) |
| 5943 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, |
| 5944 | SCTP_TRANSPORT(transport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5945 | |
| 5946 | /* Reconfig T4 timer and transport. */ |
| 5947 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); |
| 5948 | |
| 5949 | /* ADDIP 4.1 B2) Increment the association error counters and perform |
| 5950 | * endpoint failure detection on the association as defined in |
| 5951 | * RFC2960 [5] section 8.1 and 8.2. |
| 5952 | * association error counter is incremented in SCTP_CMD_STRIKE. |
| 5953 | */ |
| 5954 | if (asoc->overall_error_count >= asoc->max_retrans) { |
| 5955 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5956 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5957 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5958 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5959 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5960 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5961 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 5962 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5963 | return SCTP_DISPOSITION_ABORT; |
| 5964 | } |
| 5965 | |
| 5966 | /* ADDIP 4.1 B3) Back-off the destination address RTO value to which |
| 5967 | * the ASCONF chunk was sent by doubling the RTO timer value. |
| 5968 | * This is done in SCTP_CMD_STRIKE. |
| 5969 | */ |
| 5970 | |
| 5971 | /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible |
| 5972 | * choose an alternate destination address (please refer to RFC2960 |
| 5973 | * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5974 | * chunk, it MUST be the same (including its serial number) as the last |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5975 | * ASCONF sent. |
| 5976 | */ |
| 5977 | sctp_chunk_hold(asoc->addip_last_asconf); |
| 5978 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 5979 | SCTP_CHUNK(asoc->addip_last_asconf)); |
| 5980 | |
| 5981 | /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different |
| 5982 | * destination is selected, then the RTO used will be that of the new |
| 5983 | * destination address. |
| 5984 | */ |
| 5985 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5986 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 5987 | |
| 5988 | return SCTP_DISPOSITION_CONSUME; |
| 5989 | } |
| 5990 | |
| 5991 | /* sctpimpguide-05 Section 2.12.2 |
| 5992 | * The sender of the SHUTDOWN MAY also start an overall guard timer |
| 5993 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. |
| 5994 | * At the expiration of this timer the sender SHOULD abort the association |
| 5995 | * by sending an ABORT chunk. |
| 5996 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 5997 | enum sctp_disposition sctp_sf_t5_timer_expire( |
| 5998 | struct net *net, |
| 5999 | const struct sctp_endpoint *ep, |
| 6000 | const struct sctp_association *asoc, |
| 6001 | const union sctp_subtype type, |
| 6002 | void *arg, |
| 6003 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6004 | { |
| 6005 | struct sctp_chunk *reply = NULL; |
| 6006 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6007 | pr_debug("%s: timer T5 expired\n", __func__); |
| 6008 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6009 | SCTP_INC_STATS(net, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | |
| 6011 | reply = sctp_make_abort(asoc, NULL, 0); |
| 6012 | if (!reply) |
| 6013 | goto nomem; |
| 6014 | |
| 6015 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 6016 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 6017 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6018 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 6019 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6021 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 6022 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Vlad Yasevich | a1080a8 | 2008-10-09 14:33:26 -0700 | [diff] [blame] | 6023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6024 | return SCTP_DISPOSITION_DELETE_TCB; |
| 6025 | nomem: |
| 6026 | return SCTP_DISPOSITION_NOMEM; |
| 6027 | } |
| 6028 | |
| 6029 | /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires, |
| 6030 | * the association is automatically closed by starting the shutdown process. |
| 6031 | * The work that needs to be done is same as when SHUTDOWN is initiated by |
| 6032 | * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown(). |
| 6033 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6034 | enum sctp_disposition sctp_sf_autoclose_timer_expire( |
| 6035 | struct net *net, |
| 6036 | const struct sctp_endpoint *ep, |
| 6037 | const struct sctp_association *asoc, |
| 6038 | const union sctp_subtype type, |
| 6039 | void *arg, |
| 6040 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6041 | { |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6042 | enum sctp_disposition disposition; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6043 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6044 | SCTP_INC_STATS(net, SCTP_MIB_AUTOCLOSE_EXPIREDS); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 6045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6046 | /* From 9.2 Shutdown of an Association |
| 6047 | * Upon receipt of the SHUTDOWN primitive from its upper |
| 6048 | * layer, the endpoint enters SHUTDOWN-PENDING state and |
| 6049 | * remains there until all outstanding data has been |
| 6050 | * acknowledged by its peer. The endpoint accepts no new data |
| 6051 | * from its upper layer, but retransmits data to the far end |
| 6052 | * if necessary to fill gaps. |
| 6053 | */ |
| 6054 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 6055 | SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); |
| 6056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6057 | disposition = SCTP_DISPOSITION_CONSUME; |
| 6058 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 6059 | disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6060 | arg, commands); |
| 6061 | } |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | return disposition; |
| 6064 | } |
| 6065 | |
| 6066 | /***************************************************************************** |
| 6067 | * These are sa state functions which could apply to all types of events. |
| 6068 | ****************************************************************************/ |
| 6069 | |
| 6070 | /* |
| 6071 | * This table entry is not implemented. |
| 6072 | * |
| 6073 | * Inputs |
| 6074 | * (endpoint, asoc, chunk) |
| 6075 | * |
| 6076 | * The return value is the disposition of the chunk. |
| 6077 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6078 | enum sctp_disposition sctp_sf_not_impl(struct net *net, |
| 6079 | const struct sctp_endpoint *ep, |
| 6080 | const struct sctp_association *asoc, |
| 6081 | const union sctp_subtype type, |
| 6082 | void *arg, struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6083 | { |
| 6084 | return SCTP_DISPOSITION_NOT_IMPL; |
| 6085 | } |
| 6086 | |
| 6087 | /* |
| 6088 | * This table entry represents a bug. |
| 6089 | * |
| 6090 | * Inputs |
| 6091 | * (endpoint, asoc, chunk) |
| 6092 | * |
| 6093 | * The return value is the disposition of the chunk. |
| 6094 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6095 | enum sctp_disposition sctp_sf_bug(struct net *net, |
| 6096 | const struct sctp_endpoint *ep, |
| 6097 | const struct sctp_association *asoc, |
| 6098 | const union sctp_subtype type, |
| 6099 | void *arg, struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6100 | { |
| 6101 | return SCTP_DISPOSITION_BUG; |
| 6102 | } |
| 6103 | |
| 6104 | /* |
| 6105 | * This table entry represents the firing of a timer in the wrong state. |
| 6106 | * Since timer deletion cannot be guaranteed a timer 'may' end up firing |
| 6107 | * when the association is in the wrong state. This event should |
| 6108 | * be ignored, so as to prevent any rearming of the timer. |
| 6109 | * |
| 6110 | * Inputs |
| 6111 | * (endpoint, asoc, chunk) |
| 6112 | * |
| 6113 | * The return value is the disposition of the chunk. |
| 6114 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6115 | enum sctp_disposition sctp_sf_timer_ignore(struct net *net, |
| 6116 | const struct sctp_endpoint *ep, |
| 6117 | const struct sctp_association *asoc, |
| 6118 | const union sctp_subtype type, |
| 6119 | void *arg, |
| 6120 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6122 | pr_debug("%s: timer %d ignored\n", __func__, type.chunk); |
| 6123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6124 | return SCTP_DISPOSITION_CONSUME; |
| 6125 | } |
| 6126 | |
| 6127 | /******************************************************************** |
| 6128 | * 2nd Level Abstractions |
| 6129 | ********************************************************************/ |
| 6130 | |
| 6131 | /* Pull the SACK chunk based on the SACK header. */ |
| 6132 | static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk) |
| 6133 | { |
| 6134 | struct sctp_sackhdr *sack; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6135 | __u16 num_dup_tsns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6136 | unsigned int len; |
| 6137 | __u16 num_blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6138 | |
| 6139 | /* Protect ourselves from reading too far into |
| 6140 | * the skb from a bogus sender. |
| 6141 | */ |
| 6142 | sack = (struct sctp_sackhdr *) chunk->skb->data; |
| 6143 | |
| 6144 | num_blocks = ntohs(sack->num_gap_ack_blocks); |
| 6145 | num_dup_tsns = ntohs(sack->num_dup_tsns); |
| 6146 | len = sizeof(struct sctp_sackhdr); |
| 6147 | len += (num_blocks + num_dup_tsns) * sizeof(__u32); |
| 6148 | if (len > chunk->skb->len) |
| 6149 | return NULL; |
| 6150 | |
| 6151 | skb_pull(chunk->skb, len); |
| 6152 | |
| 6153 | return sack; |
| 6154 | } |
| 6155 | |
| 6156 | /* Create an ABORT packet to be sent as a response, with the specified |
| 6157 | * error causes. |
| 6158 | */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6159 | static struct sctp_packet *sctp_abort_pkt_new( |
| 6160 | struct net *net, |
| 6161 | const struct sctp_endpoint *ep, |
| 6162 | const struct sctp_association *asoc, |
| 6163 | struct sctp_chunk *chunk, |
| 6164 | const void *payload, size_t paylen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | { |
| 6166 | struct sctp_packet *packet; |
| 6167 | struct sctp_chunk *abort; |
| 6168 | |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 6169 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | |
| 6171 | if (packet) { |
| 6172 | /* Make an ABORT. |
| 6173 | * The T bit will be set if the asoc is NULL. |
| 6174 | */ |
| 6175 | abort = sctp_make_abort(asoc, chunk, paylen); |
| 6176 | if (!abort) { |
| 6177 | sctp_ootb_pkt_free(packet); |
| 6178 | return NULL; |
| 6179 | } |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 6180 | |
| 6181 | /* Reflect vtag if T-Bit is set */ |
| 6182 | if (sctp_test_T_bit(abort)) |
| 6183 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 6184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6185 | /* Add specified error causes, i.e., payload, to the |
| 6186 | * end of the chunk. |
| 6187 | */ |
| 6188 | sctp_addto_chunk(abort, paylen, payload); |
| 6189 | |
| 6190 | /* Set the skb to the belonging sock for accounting. */ |
| 6191 | abort->skb->sk = ep->base.sk; |
| 6192 | |
| 6193 | sctp_packet_append_chunk(packet, abort); |
| 6194 | |
| 6195 | } |
| 6196 | |
| 6197 | return packet; |
| 6198 | } |
| 6199 | |
| 6200 | /* Allocate a packet for responding in the OOTB conditions. */ |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6201 | static struct sctp_packet *sctp_ootb_pkt_new( |
| 6202 | struct net *net, |
| 6203 | const struct sctp_association *asoc, |
| 6204 | const struct sctp_chunk *chunk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6206 | struct sctp_transport *transport; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6207 | struct sctp_packet *packet; |
| 6208 | __u16 sport, dport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6209 | __u32 vtag; |
| 6210 | |
| 6211 | /* Get the source and destination port from the inbound packet. */ |
| 6212 | sport = ntohs(chunk->sctp_hdr->dest); |
| 6213 | dport = ntohs(chunk->sctp_hdr->source); |
| 6214 | |
| 6215 | /* The V-tag is going to be the same as the inbound packet if no |
| 6216 | * association exists, otherwise, use the peer's vtag. |
| 6217 | */ |
| 6218 | if (asoc) { |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 6219 | /* Special case the INIT-ACK as there is no peer's vtag |
| 6220 | * yet. |
| 6221 | */ |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 6222 | switch (chunk->chunk_hdr->type) { |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 6223 | case SCTP_CID_INIT_ACK: |
| 6224 | { |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 6225 | struct sctp_initack_chunk *initack; |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 6226 | |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 6227 | initack = (struct sctp_initack_chunk *)chunk->chunk_hdr; |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 6228 | vtag = ntohl(initack->init_hdr.init_tag); |
| 6229 | break; |
| 6230 | } |
| 6231 | default: |
| 6232 | vtag = asoc->peer.i.init_tag; |
| 6233 | break; |
| 6234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6235 | } else { |
| 6236 | /* Special case the INIT and stale COOKIE_ECHO as there is no |
| 6237 | * vtag yet. |
| 6238 | */ |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 6239 | switch (chunk->chunk_hdr->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6240 | case SCTP_CID_INIT: |
| 6241 | { |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 6242 | struct sctp_init_chunk *init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 6244 | init = (struct sctp_init_chunk *)chunk->chunk_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6245 | vtag = ntohl(init->init_hdr.init_tag); |
| 6246 | break; |
| 6247 | } |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 6248 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6249 | vtag = ntohl(chunk->sctp_hdr->vtag); |
| 6250 | break; |
| 6251 | } |
| 6252 | } |
| 6253 | |
| 6254 | /* Make a transport for the bucket, Eliza... */ |
Eric W. Biederman | 89bf345 | 2012-08-07 07:26:14 +0000 | [diff] [blame] | 6255 | transport = sctp_transport_new(net, sctp_source(chunk), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6256 | if (!transport) |
| 6257 | goto nomem; |
| 6258 | |
| 6259 | /* Cache a route for the transport with the chunk's destination as |
| 6260 | * the source address. |
| 6261 | */ |
Al Viro | 16b0a03 | 2006-11-20 17:13:38 -0800 | [diff] [blame] | 6262 | sctp_transport_route(transport, (union sctp_addr *)&chunk->dest, |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 6263 | sctp_sk(net->sctp.ctl_sock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6264 | |
Marcelo Ricardo Leitner | 66b91d2 | 2016-12-28 09:26:34 -0200 | [diff] [blame] | 6265 | packet = &transport->packet; |
| 6266 | sctp_packet_init(packet, transport, sport, dport); |
| 6267 | sctp_packet_config(packet, vtag, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6268 | |
| 6269 | return packet; |
| 6270 | |
| 6271 | nomem: |
| 6272 | return NULL; |
| 6273 | } |
| 6274 | |
| 6275 | /* Free the packet allocated earlier for responding in the OOTB condition. */ |
| 6276 | void sctp_ootb_pkt_free(struct sctp_packet *packet) |
| 6277 | { |
| 6278 | sctp_transport_free(packet->transport); |
| 6279 | } |
| 6280 | |
| 6281 | /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 6282 | static void sctp_send_stale_cookie_err(struct net *net, |
| 6283 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | const struct sctp_association *asoc, |
| 6285 | const struct sctp_chunk *chunk, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 6286 | struct sctp_cmd_seq *commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6287 | struct sctp_chunk *err_chunk) |
| 6288 | { |
| 6289 | struct sctp_packet *packet; |
| 6290 | |
| 6291 | if (err_chunk) { |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 6292 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6293 | if (packet) { |
| 6294 | struct sctp_signed_cookie *cookie; |
| 6295 | |
| 6296 | /* Override the OOTB vtag from the cookie. */ |
| 6297 | cookie = chunk->subh.cookie_hdr; |
| 6298 | packet->vtag = cookie->c.peer_vtag; |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 6299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | /* Set the skb to the belonging sock for accounting. */ |
| 6301 | err_chunk->skb->sk = ep->base.sk; |
| 6302 | sctp_packet_append_chunk(packet, err_chunk); |
| 6303 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 6304 | SCTP_PACKET(packet)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6305 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6306 | } else |
| 6307 | sctp_chunk_free (err_chunk); |
| 6308 | } |
| 6309 | } |
| 6310 | |
| 6311 | |
| 6312 | /* Process a data chunk */ |
| 6313 | static int sctp_eat_data(const struct sctp_association *asoc, |
| 6314 | struct sctp_chunk *chunk, |
Xin Long | a85bbeb | 2017-08-11 10:23:52 +0800 | [diff] [blame] | 6315 | struct sctp_cmd_seq *commands) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6316 | { |
Neil Horman | 7c3ceb4f | 2006-05-05 17:02:09 -0700 | [diff] [blame] | 6317 | struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map; |
Neil Horman | 049b3ff | 2005-11-11 16:08:24 -0800 | [diff] [blame] | 6318 | struct sock *sk = asoc->base.sk; |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 6319 | struct net *net = sock_net(sk); |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6320 | struct sctp_datahdr *data_hdr; |
| 6321 | struct sctp_chunk *err; |
| 6322 | enum sctp_verb deliver; |
| 6323 | size_t datalen; |
Xin Long | 172a159 | 2017-08-11 10:23:57 +0800 | [diff] [blame] | 6324 | __u32 tsn; |
| 6325 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6326 | |
Xin Long | 3583df1 | 2017-06-30 11:52:19 +0800 | [diff] [blame] | 6327 | data_hdr = (struct sctp_datahdr *)chunk->skb->data; |
| 6328 | chunk->subh.data_hdr = data_hdr; |
Xin Long | 9d4ceaf | 2017-12-08 21:04:03 +0800 | [diff] [blame] | 6329 | skb_pull(chunk->skb, sctp_datahdr_len(&asoc->stream)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6330 | |
| 6331 | tsn = ntohl(data_hdr->tsn); |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6332 | pr_debug("%s: TSN 0x%x\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6333 | |
| 6334 | /* ASSERT: Now skb->data is really the user data. */ |
| 6335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | /* Process ECN based congestion. |
| 6337 | * |
| 6338 | * Since the chunk structure is reused for all chunks within |
| 6339 | * a packet, we use ecn_ce_done to track if we've already |
| 6340 | * done CE processing for this packet. |
| 6341 | * |
| 6342 | * We need to do ECN processing even if we plan to discard the |
| 6343 | * chunk later. |
| 6344 | */ |
| 6345 | |
Marcelo Ricardo Leitner | 2d47fd1 | 2016-07-13 15:09:00 -0300 | [diff] [blame] | 6346 | if (asoc->peer.ecn_capable && !chunk->ecn_ce_done) { |
Marcelo Ricardo Leitner | e7487c8 | 2016-07-13 15:08:58 -0300 | [diff] [blame] | 6347 | struct sctp_af *af = SCTP_INPUT_CB(chunk->skb)->af; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6348 | chunk->ecn_ce_done = 1; |
| 6349 | |
Marcelo Ricardo Leitner | 2d47fd1 | 2016-07-13 15:09:00 -0300 | [diff] [blame] | 6350 | if (af->is_ce(sctp_gso_headskb(chunk->skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | /* Do real work as sideffect. */ |
| 6352 | sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE, |
| 6353 | SCTP_U32(tsn)); |
| 6354 | } |
| 6355 | } |
| 6356 | |
| 6357 | tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn); |
| 6358 | if (tmp < 0) { |
| 6359 | /* The TSN is too high--silently discard the chunk and |
| 6360 | * count on it getting retransmitted later. |
| 6361 | */ |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 6362 | if (chunk->asoc) |
| 6363 | chunk->asoc->stats.outofseqtsns++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6364 | return SCTP_IERROR_HIGH_TSN; |
| 6365 | } else if (tmp > 0) { |
| 6366 | /* This is a duplicate. Record it. */ |
| 6367 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn)); |
| 6368 | return SCTP_IERROR_DUP_TSN; |
| 6369 | } |
| 6370 | |
| 6371 | /* This is a new TSN. */ |
| 6372 | |
| 6373 | /* Discard if there is no room in the receive window. |
| 6374 | * Actually, allow a little bit of overflow (up to a MTU). |
| 6375 | */ |
| 6376 | datalen = ntohs(chunk->chunk_hdr->length); |
Xin Long | 9d4ceaf | 2017-12-08 21:04:03 +0800 | [diff] [blame] | 6377 | datalen -= sctp_datachk_len(&asoc->stream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6378 | |
| 6379 | deliver = SCTP_CMD_CHUNK_ULP; |
| 6380 | |
| 6381 | /* Think about partial delivery. */ |
| 6382 | if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) { |
| 6383 | |
| 6384 | /* Even if we don't accept this chunk there is |
| 6385 | * memory pressure. |
| 6386 | */ |
| 6387 | sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL()); |
| 6388 | } |
| 6389 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 6390 | /* Spill over rwnd a little bit. Note: While allowed, this spill over |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6391 | * seems a bit troublesome in that frag_point varies based on |
| 6392 | * PMTU. In cases, such as loopback, this might be a rather |
| 6393 | * large spill over. |
| 6394 | */ |
Daniel Borkmann | 362d520 | 2014-04-14 21:45:17 +0200 | [diff] [blame] | 6395 | if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over || |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6396 | (datalen > asoc->rwnd + asoc->frag_point))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | |
| 6398 | /* If this is the next TSN, consider reneging to make |
| 6399 | * room. Note: Playing nice with a confused sender. A |
| 6400 | * malicious sender can still eat up all our buffer |
| 6401 | * space and in the future we may want to detect and |
| 6402 | * do more drastic reneging. |
| 6403 | */ |
Neil Horman | 7c3ceb4f | 2006-05-05 17:02:09 -0700 | [diff] [blame] | 6404 | if (sctp_tsnmap_has_gap(map) && |
| 6405 | (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6406 | pr_debug("%s: reneging for tsn:%u\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6407 | deliver = SCTP_CMD_RENEGE; |
| 6408 | } else { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6409 | pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n", |
| 6410 | __func__, tsn, datalen, asoc->rwnd); |
| 6411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6412 | return SCTP_IERROR_IGNORE_TSN; |
| 6413 | } |
| 6414 | } |
| 6415 | |
| 6416 | /* |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6417 | * Also try to renege to limit our memory usage in the event that |
| 6418 | * we are under memory pressure |
Hideo Aoki | 3ab224b | 2007-12-31 00:11:19 -0800 | [diff] [blame] | 6419 | * If we can't renege, don't worry about it, the sk_rmem_schedule |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6420 | * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our |
| 6421 | * memory usage too much |
| 6422 | */ |
Xin Long | 9dde27d | 2019-04-15 17:15:07 +0800 | [diff] [blame] | 6423 | if (sk_under_memory_pressure(sk)) { |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6424 | if (sctp_tsnmap_has_gap(map) && |
wangweidong | f7010e6 | 2013-12-23 12:16:52 +0800 | [diff] [blame] | 6425 | (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6426 | pr_debug("%s: under pressure, reneging for tsn:%u\n", |
| 6427 | __func__, tsn); |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6428 | deliver = SCTP_CMD_RENEGE; |
Xin Long | 9dde27d | 2019-04-15 17:15:07 +0800 | [diff] [blame] | 6429 | } else { |
| 6430 | sk_mem_reclaim(sk); |
| 6431 | } |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
| 6434 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6435 | * Section 3.3.10.9 No User Data (9) |
| 6436 | * |
| 6437 | * Cause of error |
| 6438 | * --------------- |
| 6439 | * No User Data: This error cause is returned to the originator of a |
| 6440 | * DATA chunk if a received DATA chunk has no user data. |
| 6441 | */ |
| 6442 | if (unlikely(0 == datalen)) { |
| 6443 | err = sctp_make_abort_no_data(asoc, chunk, tsn); |
| 6444 | if (err) { |
| 6445 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 6446 | SCTP_CHUNK(err)); |
| 6447 | } |
| 6448 | /* We are going to ABORT, so we might as well stop |
| 6449 | * processing the rest of the chunks in the packet. |
| 6450 | */ |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 6451 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 6452 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 6453 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6454 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 6455 | SCTP_PERR(SCTP_ERROR_NO_DATA)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6456 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 6457 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6458 | return SCTP_IERROR_NO_DATA; |
| 6459 | } |
| 6460 | |
Sridhar Samudrala | 9faa730 | 2006-07-21 14:49:07 -0700 | [diff] [blame] | 6461 | chunk->data_accepted = 1; |
| 6462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6463 | /* Note: Some chunks may get overcounted (if we drop) or overcounted |
| 6464 | * if we renege and the chunk arrives again. |
| 6465 | */ |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 6466 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6467 | SCTP_INC_STATS(net, SCTP_MIB_INUNORDERCHUNKS); |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 6468 | if (chunk->asoc) |
| 6469 | chunk->asoc->stats.iuodchunks++; |
| 6470 | } else { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6471 | SCTP_INC_STATS(net, SCTP_MIB_INORDERCHUNKS); |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 6472 | if (chunk->asoc) |
| 6473 | chunk->asoc->stats.iodchunks++; |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6474 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6475 | |
| 6476 | /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number |
| 6477 | * |
| 6478 | * If an endpoint receive a DATA chunk with an invalid stream |
| 6479 | * identifier, it shall acknowledge the reception of the DATA chunk |
| 6480 | * following the normal procedure, immediately send an ERROR chunk |
| 6481 | * with cause set to "Invalid Stream Identifier" (See Section 3.3.10) |
| 6482 | * and discard the DATA chunk. |
| 6483 | */ |
Xin Long | 9d4ceaf | 2017-12-08 21:04:03 +0800 | [diff] [blame] | 6484 | if (ntohs(data_hdr->stream) >= asoc->stream.incnt) { |
Vlad Yasevich | 3888e9e | 2008-07-08 02:28:39 -0700 | [diff] [blame] | 6485 | /* Mark tsn as received even though we drop it */ |
| 6486 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn)); |
| 6487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6488 | err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM, |
| 6489 | &data_hdr->stream, |
Vlad Yasevich | 6383cfb | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 6490 | sizeof(data_hdr->stream), |
| 6491 | sizeof(u16)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6492 | if (err) |
| 6493 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 6494 | SCTP_CHUNK(err)); |
| 6495 | return SCTP_IERROR_BAD_STREAM; |
| 6496 | } |
| 6497 | |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6498 | /* Check to see if the SSN is possible for this TSN. |
| 6499 | * The biggest gap we can record is 4K wide. Since SSNs wrap |
| 6500 | * at an unsigned short, there is no way that an SSN can |
| 6501 | * wrap and for a valid TSN. We can simply check if the current |
| 6502 | * SSN is smaller then the next expected one. If it is, it wrapped |
| 6503 | * and is invalid. |
| 6504 | */ |
Xin Long | 9d4ceaf | 2017-12-08 21:04:03 +0800 | [diff] [blame] | 6505 | if (!asoc->stream.si->validate_data(chunk)) |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6506 | return SCTP_IERROR_PROTO_VIOLATION; |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6508 | /* Send the data up to the user. Note: Schedule the |
| 6509 | * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK |
| 6510 | * chunk needs the updated rwnd. |
| 6511 | */ |
| 6512 | sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk)); |
| 6513 | |
| 6514 | return SCTP_IERROR_NO_ERROR; |
| 6515 | } |