.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* SCTP kernel implementation |
---|
2 | 3 | * (C) Copyright IBM Corp. 2001, 2004 |
---|
3 | 4 | * Copyright (c) 1999-2000 Cisco, Inc. |
---|
.. | .. |
---|
9 | 10 | * These functions work with the state functions in sctp_sm_statefuns.c |
---|
10 | 11 | * to implement the state operations. These functions implement the |
---|
11 | 12 | * steps which require modifying existing data structures. |
---|
12 | | - * |
---|
13 | | - * This SCTP implementation is free software; |
---|
14 | | - * you can redistribute it and/or modify it under the terms of |
---|
15 | | - * the GNU General Public License as published by |
---|
16 | | - * the Free Software Foundation; either version 2, or (at your option) |
---|
17 | | - * any later version. |
---|
18 | | - * |
---|
19 | | - * This SCTP implementation is distributed in the hope that it |
---|
20 | | - * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
---|
21 | | - * ************************ |
---|
22 | | - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
23 | | - * See the GNU General Public License for more details. |
---|
24 | | - * |
---|
25 | | - * You should have received a copy of the GNU General Public License |
---|
26 | | - * along with GNU CC; see the file COPYING. If not, see |
---|
27 | | - * <http://www.gnu.org/licenses/>. |
---|
28 | 13 | * |
---|
29 | 14 | * Please send any bug reports or fixes you make to the |
---|
30 | 15 | * email address(es): |
---|
.. | .. |
---|
222 | 207 | const struct sctp_bind_addr *bp, |
---|
223 | 208 | gfp_t gfp, int vparam_len) |
---|
224 | 209 | { |
---|
225 | | - struct net *net = sock_net(asoc->base.sk); |
---|
226 | 210 | struct sctp_supported_ext_param ext_param; |
---|
227 | 211 | struct sctp_adaptation_ind_param aiparam; |
---|
228 | 212 | struct sctp_paramhdr *auth_chunks = NULL; |
---|
.. | .. |
---|
260 | 244 | |
---|
261 | 245 | chunksize = sizeof(init) + addrs_len; |
---|
262 | 246 | chunksize += SCTP_PAD4(SCTP_SAT_LEN(num_types)); |
---|
263 | | - chunksize += sizeof(ecap_param); |
---|
264 | 247 | |
---|
265 | | - if (asoc->prsctp_enable) |
---|
| 248 | + if (asoc->ep->ecn_enable) |
---|
| 249 | + chunksize += sizeof(ecap_param); |
---|
| 250 | + |
---|
| 251 | + if (asoc->ep->prsctp_enable) |
---|
266 | 252 | chunksize += sizeof(prsctp_param); |
---|
267 | 253 | |
---|
268 | 254 | /* ADDIP: Section 4.2.7: |
---|
.. | .. |
---|
270 | 256 | * the ASCONF,the ASCONF-ACK, and the AUTH chunks in its INIT and |
---|
271 | 257 | * INIT-ACK parameters. |
---|
272 | 258 | */ |
---|
273 | | - if (net->sctp.addip_enable) { |
---|
| 259 | + if (asoc->ep->asconf_enable) { |
---|
274 | 260 | extensions[num_ext] = SCTP_CID_ASCONF; |
---|
275 | 261 | extensions[num_ext+1] = SCTP_CID_ASCONF_ACK; |
---|
276 | 262 | num_ext += 2; |
---|
277 | 263 | } |
---|
278 | 264 | |
---|
279 | | - if (asoc->reconf_enable) { |
---|
| 265 | + if (asoc->ep->reconf_enable) { |
---|
280 | 266 | extensions[num_ext] = SCTP_CID_RECONF; |
---|
281 | 267 | num_ext += 1; |
---|
282 | 268 | } |
---|
.. | .. |
---|
284 | 270 | if (sp->adaptation_ind) |
---|
285 | 271 | chunksize += sizeof(aiparam); |
---|
286 | 272 | |
---|
287 | | - if (sp->strm_interleave) { |
---|
| 273 | + if (asoc->ep->intl_enable) { |
---|
288 | 274 | extensions[num_ext] = SCTP_CID_I_DATA; |
---|
289 | 275 | num_ext += 1; |
---|
290 | 276 | } |
---|
.. | .. |
---|
351 | 337 | sctp_addto_chunk(retval, sizeof(sat), &sat); |
---|
352 | 338 | sctp_addto_chunk(retval, num_types * sizeof(__u16), &types); |
---|
353 | 339 | |
---|
354 | | - sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param); |
---|
| 340 | + if (asoc->ep->ecn_enable) |
---|
| 341 | + sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param); |
---|
355 | 342 | |
---|
356 | 343 | /* Add the supported extensions parameter. Be nice and add this |
---|
357 | 344 | * fist before addiding the parameters for the extensions themselves |
---|
.. | .. |
---|
363 | 350 | sctp_addto_param(retval, num_ext, extensions); |
---|
364 | 351 | } |
---|
365 | 352 | |
---|
366 | | - if (asoc->prsctp_enable) |
---|
| 353 | + if (asoc->ep->prsctp_enable) |
---|
367 | 354 | sctp_addto_chunk(retval, sizeof(prsctp_param), &prsctp_param); |
---|
368 | 355 | |
---|
369 | 356 | if (sp->adaptation_ind) { |
---|
.. | .. |
---|
453 | 440 | if (sp->adaptation_ind) |
---|
454 | 441 | chunksize += sizeof(aiparam); |
---|
455 | 442 | |
---|
456 | | - if (asoc->intl_enable) { |
---|
| 443 | + if (asoc->peer.intl_capable) { |
---|
457 | 444 | extensions[num_ext] = SCTP_CID_I_DATA; |
---|
458 | 445 | num_ext += 1; |
---|
459 | 446 | } |
---|
.. | .. |
---|
1248 | 1235 | |
---|
1249 | 1236 | /* Create an Operation Error chunk of a fixed size, specifically, |
---|
1250 | 1237 | * min(asoc->pathmtu, SCTP_DEFAULT_MAXSEGMENT) - overheads. |
---|
1251 | | - * This is a helper function to allocate an error chunk for for those |
---|
| 1238 | + * This is a helper function to allocate an error chunk for those |
---|
1252 | 1239 | * invalid parameter codes in which we may not want to report all the |
---|
1253 | 1240 | * errors, if the incoming chunk is large. If it can't fit in a single |
---|
1254 | 1241 | * packet, we ignore it. |
---|
.. | .. |
---|
1683 | 1670 | ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len); |
---|
1684 | 1671 | |
---|
1685 | 1672 | if (sctp_sk(ep->base.sk)->hmac) { |
---|
1686 | | - SHASH_DESC_ON_STACK(desc, sctp_sk(ep->base.sk)->hmac); |
---|
| 1673 | + struct crypto_shash *tfm = sctp_sk(ep->base.sk)->hmac; |
---|
1687 | 1674 | int err; |
---|
1688 | 1675 | |
---|
1689 | 1676 | /* Sign the message. */ |
---|
1690 | | - desc->tfm = sctp_sk(ep->base.sk)->hmac; |
---|
1691 | | - desc->flags = 0; |
---|
1692 | | - |
---|
1693 | | - err = crypto_shash_setkey(desc->tfm, ep->secret_key, |
---|
| 1677 | + err = crypto_shash_setkey(tfm, ep->secret_key, |
---|
1694 | 1678 | sizeof(ep->secret_key)) ?: |
---|
1695 | | - crypto_shash_digest(desc, (u8 *)&cookie->c, bodysize, |
---|
1696 | | - cookie->signature); |
---|
1697 | | - shash_desc_zero(desc); |
---|
| 1679 | + crypto_shash_tfm_digest(tfm, (u8 *)&cookie->c, bodysize, |
---|
| 1680 | + cookie->signature); |
---|
1698 | 1681 | if (err) |
---|
1699 | 1682 | goto free_cookie; |
---|
1700 | 1683 | } |
---|
.. | .. |
---|
1755 | 1738 | |
---|
1756 | 1739 | /* Check the signature. */ |
---|
1757 | 1740 | { |
---|
1758 | | - SHASH_DESC_ON_STACK(desc, sctp_sk(ep->base.sk)->hmac); |
---|
| 1741 | + struct crypto_shash *tfm = sctp_sk(ep->base.sk)->hmac; |
---|
1759 | 1742 | int err; |
---|
1760 | 1743 | |
---|
1761 | | - desc->tfm = sctp_sk(ep->base.sk)->hmac; |
---|
1762 | | - desc->flags = 0; |
---|
1763 | | - |
---|
1764 | | - err = crypto_shash_setkey(desc->tfm, ep->secret_key, |
---|
| 1744 | + err = crypto_shash_setkey(tfm, ep->secret_key, |
---|
1765 | 1745 | sizeof(ep->secret_key)) ?: |
---|
1766 | | - crypto_shash_digest(desc, (u8 *)bear_cookie, bodysize, |
---|
1767 | | - digest); |
---|
1768 | | - shash_desc_zero(desc); |
---|
1769 | | - |
---|
| 1746 | + crypto_shash_tfm_digest(tfm, (u8 *)bear_cookie, bodysize, |
---|
| 1747 | + digest); |
---|
1770 | 1748 | if (err) { |
---|
1771 | 1749 | *error = -SCTP_IERROR_NOMEM; |
---|
1772 | 1750 | goto fail; |
---|
.. | .. |
---|
1802 | 1780 | * for init collision case of lost COOKIE ACK. |
---|
1803 | 1781 | * If skb has been timestamped, then use the stamp, otherwise |
---|
1804 | 1782 | * use current time. This introduces a small possibility that |
---|
1805 | | - * that a cookie may be considered expired, but his would only slow |
---|
| 1783 | + * a cookie may be considered expired, but this would only slow |
---|
1806 | 1784 | * down the new association establishment instead of every packet. |
---|
1807 | 1785 | */ |
---|
1808 | 1786 | if (sock_flag(ep->base.sk, SOCK_TIMESTAMP)) |
---|
.. | .. |
---|
1985 | 1963 | return 0; |
---|
1986 | 1964 | } |
---|
1987 | 1965 | |
---|
1988 | | -static int sctp_verify_ext_param(struct net *net, union sctp_params param) |
---|
| 1966 | +static int sctp_verify_ext_param(struct net *net, |
---|
| 1967 | + const struct sctp_endpoint *ep, |
---|
| 1968 | + union sctp_params param) |
---|
1989 | 1969 | { |
---|
1990 | 1970 | __u16 num_ext = ntohs(param.p->length) - sizeof(struct sctp_paramhdr); |
---|
1991 | 1971 | int have_asconf = 0; |
---|
.. | .. |
---|
2012 | 1992 | if (net->sctp.addip_noauth) |
---|
2013 | 1993 | return 1; |
---|
2014 | 1994 | |
---|
2015 | | - if (net->sctp.addip_enable && !have_auth && have_asconf) |
---|
| 1995 | + if (ep->asconf_enable && !have_auth && have_asconf) |
---|
2016 | 1996 | return 0; |
---|
2017 | 1997 | |
---|
2018 | 1998 | return 1; |
---|
.. | .. |
---|
2022 | 2002 | union sctp_params param) |
---|
2023 | 2003 | { |
---|
2024 | 2004 | __u16 num_ext = ntohs(param.p->length) - sizeof(struct sctp_paramhdr); |
---|
2025 | | - struct net *net = sock_net(asoc->base.sk); |
---|
2026 | 2005 | int i; |
---|
2027 | 2006 | |
---|
2028 | 2007 | for (i = 0; i < num_ext; i++) { |
---|
2029 | 2008 | switch (param.ext->chunks[i]) { |
---|
2030 | 2009 | case SCTP_CID_RECONF: |
---|
2031 | | - if (asoc->reconf_enable && |
---|
2032 | | - !asoc->peer.reconf_capable) |
---|
| 2010 | + if (asoc->ep->reconf_enable) |
---|
2033 | 2011 | asoc->peer.reconf_capable = 1; |
---|
2034 | 2012 | break; |
---|
2035 | 2013 | case SCTP_CID_FWD_TSN: |
---|
2036 | | - if (asoc->prsctp_enable && !asoc->peer.prsctp_capable) |
---|
| 2014 | + if (asoc->ep->prsctp_enable) |
---|
2037 | 2015 | asoc->peer.prsctp_capable = 1; |
---|
2038 | 2016 | break; |
---|
2039 | 2017 | case SCTP_CID_AUTH: |
---|
.. | .. |
---|
2045 | 2023 | break; |
---|
2046 | 2024 | case SCTP_CID_ASCONF: |
---|
2047 | 2025 | case SCTP_CID_ASCONF_ACK: |
---|
2048 | | - if (net->sctp.addip_enable) |
---|
| 2026 | + if (asoc->ep->asconf_enable) |
---|
2049 | 2027 | asoc->peer.asconf_capable = 1; |
---|
2050 | 2028 | break; |
---|
2051 | 2029 | case SCTP_CID_I_DATA: |
---|
2052 | | - if (sctp_sk(asoc->base.sk)->strm_interleave) |
---|
2053 | | - asoc->intl_enable = 1; |
---|
| 2030 | + if (asoc->ep->intl_enable) |
---|
| 2031 | + asoc->peer.intl_capable = 1; |
---|
2054 | 2032 | break; |
---|
2055 | 2033 | default: |
---|
2056 | 2034 | break; |
---|
.. | .. |
---|
2099 | 2077 | break; |
---|
2100 | 2078 | case SCTP_PARAM_ACTION_DISCARD_ERR: |
---|
2101 | 2079 | retval = SCTP_IERROR_ERROR; |
---|
2102 | | - /* Fall through */ |
---|
| 2080 | + fallthrough; |
---|
2103 | 2081 | case SCTP_PARAM_ACTION_SKIP_ERR: |
---|
2104 | 2082 | /* Make an ERROR chunk, preparing enough room for |
---|
2105 | 2083 | * returning multiple unknown parameters. |
---|
.. | .. |
---|
2167 | 2145 | break; |
---|
2168 | 2146 | |
---|
2169 | 2147 | case SCTP_PARAM_SUPPORTED_EXT: |
---|
2170 | | - if (!sctp_verify_ext_param(net, param)) |
---|
| 2148 | + if (!sctp_verify_ext_param(net, ep, param)) |
---|
2171 | 2149 | return SCTP_IERROR_ABORT; |
---|
2172 | 2150 | break; |
---|
2173 | 2151 | |
---|
2174 | 2152 | case SCTP_PARAM_SET_PRIMARY: |
---|
2175 | | - if (!net->sctp.addip_enable) |
---|
2176 | | - goto fallthrough; |
---|
| 2153 | + if (!ep->asconf_enable) |
---|
| 2154 | + goto unhandled; |
---|
2177 | 2155 | |
---|
2178 | 2156 | if (ntohs(param.p->length) < sizeof(struct sctp_addip_param) + |
---|
2179 | 2157 | sizeof(struct sctp_paramhdr)) { |
---|
.. | .. |
---|
2192 | 2170 | case SCTP_PARAM_FWD_TSN_SUPPORT: |
---|
2193 | 2171 | if (ep->prsctp_enable) |
---|
2194 | 2172 | break; |
---|
2195 | | - goto fallthrough; |
---|
| 2173 | + goto unhandled; |
---|
2196 | 2174 | |
---|
2197 | 2175 | case SCTP_PARAM_RANDOM: |
---|
2198 | 2176 | if (!ep->auth_enable) |
---|
2199 | | - goto fallthrough; |
---|
| 2177 | + goto unhandled; |
---|
2200 | 2178 | |
---|
2201 | 2179 | /* SCTP-AUTH: Secion 6.1 |
---|
2202 | 2180 | * If the random number is not 32 byte long the association |
---|
.. | .. |
---|
2213 | 2191 | |
---|
2214 | 2192 | case SCTP_PARAM_CHUNKS: |
---|
2215 | 2193 | if (!ep->auth_enable) |
---|
2216 | | - goto fallthrough; |
---|
| 2194 | + goto unhandled; |
---|
2217 | 2195 | |
---|
2218 | 2196 | /* SCTP-AUTH: Section 3.2 |
---|
2219 | 2197 | * The CHUNKS parameter MUST be included once in the INIT or |
---|
.. | .. |
---|
2229 | 2207 | |
---|
2230 | 2208 | case SCTP_PARAM_HMAC_ALGO: |
---|
2231 | 2209 | if (!ep->auth_enable) |
---|
2232 | | - goto fallthrough; |
---|
| 2210 | + goto unhandled; |
---|
2233 | 2211 | |
---|
2234 | 2212 | hmacs = (struct sctp_hmac_algo_param *)param.p; |
---|
2235 | 2213 | n_elt = (ntohs(param.p->length) - |
---|
.. | .. |
---|
2252 | 2230 | retval = SCTP_IERROR_ABORT; |
---|
2253 | 2231 | } |
---|
2254 | 2232 | break; |
---|
2255 | | -fallthrough: |
---|
| 2233 | +unhandled: |
---|
2256 | 2234 | default: |
---|
2257 | 2235 | pr_debug("%s: unrecognized param:%d for chunk:%d\n", |
---|
2258 | 2236 | __func__, ntohs(param.p->type), cid); |
---|
.. | .. |
---|
2333 | 2311 | const union sctp_addr *peer_addr, |
---|
2334 | 2312 | struct sctp_init_chunk *peer_init, gfp_t gfp) |
---|
2335 | 2313 | { |
---|
2336 | | - struct net *net = sock_net(asoc->base.sk); |
---|
2337 | 2314 | struct sctp_transport *transport; |
---|
2338 | 2315 | struct list_head *pos, *temp; |
---|
2339 | 2316 | union sctp_params param; |
---|
.. | .. |
---|
2349 | 2326 | |
---|
2350 | 2327 | /* This implementation defaults to making the first transport |
---|
2351 | 2328 | * added as the primary transport. The source address seems to |
---|
2352 | | - * be a a better choice than any of the embedded addresses. |
---|
| 2329 | + * be a better choice than any of the embedded addresses. |
---|
2353 | 2330 | */ |
---|
2354 | 2331 | if (!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE)) |
---|
2355 | 2332 | goto nomem; |
---|
.. | .. |
---|
2391 | 2368 | * also give us an option to silently ignore the packet, which |
---|
2392 | 2369 | * is what we'll do here. |
---|
2393 | 2370 | */ |
---|
2394 | | - if (!net->sctp.addip_noauth && |
---|
2395 | | - (asoc->peer.asconf_capable && !asoc->peer.auth_capable)) { |
---|
| 2371 | + if (!asoc->base.net->sctp.addip_noauth && |
---|
| 2372 | + (asoc->peer.asconf_capable && !asoc->peer.auth_capable)) { |
---|
2396 | 2373 | asoc->peer.addip_disabled_mask |= (SCTP_PARAM_ADD_IP | |
---|
2397 | 2374 | SCTP_PARAM_DEL_IP | |
---|
2398 | 2375 | SCTP_PARAM_SET_PRIMARY); |
---|
.. | .. |
---|
2519 | 2496 | const union sctp_addr *peer_addr, |
---|
2520 | 2497 | gfp_t gfp) |
---|
2521 | 2498 | { |
---|
2522 | | - struct net *net = sock_net(asoc->base.sk); |
---|
2523 | 2499 | struct sctp_endpoint *ep = asoc->ep; |
---|
2524 | 2500 | union sctp_addr_param *addr_param; |
---|
| 2501 | + struct net *net = asoc->base.net; |
---|
2525 | 2502 | struct sctp_transport *t; |
---|
2526 | 2503 | enum sctp_scope scope; |
---|
2527 | 2504 | union sctp_addr addr; |
---|
.. | .. |
---|
2614 | 2591 | case SCTP_PARAM_STATE_COOKIE: |
---|
2615 | 2592 | asoc->peer.cookie_len = |
---|
2616 | 2593 | ntohs(param.p->length) - sizeof(struct sctp_paramhdr); |
---|
2617 | | - if (asoc->peer.cookie) |
---|
2618 | | - kfree(asoc->peer.cookie); |
---|
| 2594 | + kfree(asoc->peer.cookie); |
---|
2619 | 2595 | asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp); |
---|
2620 | 2596 | if (!asoc->peer.cookie) |
---|
2621 | 2597 | retval = 0; |
---|
.. | .. |
---|
2630 | 2606 | break; |
---|
2631 | 2607 | |
---|
2632 | 2608 | case SCTP_PARAM_ECN_CAPABLE: |
---|
2633 | | - asoc->peer.ecn_capable = 1; |
---|
2634 | | - break; |
---|
| 2609 | + if (asoc->ep->ecn_enable) { |
---|
| 2610 | + asoc->peer.ecn_capable = 1; |
---|
| 2611 | + break; |
---|
| 2612 | + } |
---|
| 2613 | + /* Fall Through */ |
---|
| 2614 | + goto fall_through; |
---|
| 2615 | + |
---|
2635 | 2616 | |
---|
2636 | 2617 | case SCTP_PARAM_ADAPTATION_LAYER_IND: |
---|
2637 | 2618 | asoc->peer.adaptation_ind = ntohl(param.aind->adaptation_ind); |
---|
2638 | 2619 | break; |
---|
2639 | 2620 | |
---|
2640 | 2621 | case SCTP_PARAM_SET_PRIMARY: |
---|
2641 | | - if (!net->sctp.addip_enable) |
---|
| 2622 | + if (!ep->asconf_enable) |
---|
2642 | 2623 | goto fall_through; |
---|
2643 | 2624 | |
---|
2644 | 2625 | addr_param = param.v + sizeof(struct sctp_addip_param); |
---|
.. | .. |
---|
2666 | 2647 | break; |
---|
2667 | 2648 | |
---|
2668 | 2649 | case SCTP_PARAM_FWD_TSN_SUPPORT: |
---|
2669 | | - if (asoc->prsctp_enable) { |
---|
| 2650 | + if (asoc->ep->prsctp_enable) { |
---|
2670 | 2651 | asoc->peer.prsctp_capable = 1; |
---|
2671 | 2652 | break; |
---|
2672 | 2653 | } |
---|
.. | .. |
---|
2678 | 2659 | goto fall_through; |
---|
2679 | 2660 | |
---|
2680 | 2661 | /* Save peer's random parameter */ |
---|
2681 | | - if (asoc->peer.peer_random) |
---|
2682 | | - kfree(asoc->peer.peer_random); |
---|
| 2662 | + kfree(asoc->peer.peer_random); |
---|
2683 | 2663 | asoc->peer.peer_random = kmemdup(param.p, |
---|
2684 | 2664 | ntohs(param.p->length), gfp); |
---|
2685 | 2665 | if (!asoc->peer.peer_random) { |
---|
.. | .. |
---|
2693 | 2673 | goto fall_through; |
---|
2694 | 2674 | |
---|
2695 | 2675 | /* Save peer's HMAC list */ |
---|
2696 | | - if (asoc->peer.peer_hmacs) |
---|
2697 | | - kfree(asoc->peer.peer_hmacs); |
---|
| 2676 | + kfree(asoc->peer.peer_hmacs); |
---|
2698 | 2677 | asoc->peer.peer_hmacs = kmemdup(param.p, |
---|
2699 | 2678 | ntohs(param.p->length), gfp); |
---|
2700 | 2679 | if (!asoc->peer.peer_hmacs) { |
---|
.. | .. |
---|
2710 | 2689 | if (!ep->auth_enable) |
---|
2711 | 2690 | goto fall_through; |
---|
2712 | 2691 | |
---|
2713 | | - if (asoc->peer.peer_chunks) |
---|
2714 | | - kfree(asoc->peer.peer_chunks); |
---|
| 2692 | + kfree(asoc->peer.peer_chunks); |
---|
2715 | 2693 | asoc->peer.peer_chunks = kmemdup(param.p, |
---|
2716 | 2694 | ntohs(param.p->length), gfp); |
---|
2717 | 2695 | if (!asoc->peer.peer_chunks) |
---|