hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/sctp/sm_make_chunk.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* SCTP kernel implementation
23 * (C) Copyright IBM Corp. 2001, 2004
34 * Copyright (c) 1999-2000 Cisco, Inc.
....@@ -9,22 +10,6 @@
910 * These functions work with the state functions in sctp_sm_statefuns.c
1011 * to implement the state operations. These functions implement the
1112 * 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/>.
2813 *
2914 * Please send any bug reports or fixes you make to the
3015 * email address(es):
....@@ -222,7 +207,6 @@
222207 const struct sctp_bind_addr *bp,
223208 gfp_t gfp, int vparam_len)
224209 {
225
- struct net *net = sock_net(asoc->base.sk);
226210 struct sctp_supported_ext_param ext_param;
227211 struct sctp_adaptation_ind_param aiparam;
228212 struct sctp_paramhdr *auth_chunks = NULL;
....@@ -260,9 +244,11 @@
260244
261245 chunksize = sizeof(init) + addrs_len;
262246 chunksize += SCTP_PAD4(SCTP_SAT_LEN(num_types));
263
- chunksize += sizeof(ecap_param);
264247
265
- if (asoc->prsctp_enable)
248
+ if (asoc->ep->ecn_enable)
249
+ chunksize += sizeof(ecap_param);
250
+
251
+ if (asoc->ep->prsctp_enable)
266252 chunksize += sizeof(prsctp_param);
267253
268254 /* ADDIP: Section 4.2.7:
....@@ -270,13 +256,13 @@
270256 * the ASCONF,the ASCONF-ACK, and the AUTH chunks in its INIT and
271257 * INIT-ACK parameters.
272258 */
273
- if (net->sctp.addip_enable) {
259
+ if (asoc->ep->asconf_enable) {
274260 extensions[num_ext] = SCTP_CID_ASCONF;
275261 extensions[num_ext+1] = SCTP_CID_ASCONF_ACK;
276262 num_ext += 2;
277263 }
278264
279
- if (asoc->reconf_enable) {
265
+ if (asoc->ep->reconf_enable) {
280266 extensions[num_ext] = SCTP_CID_RECONF;
281267 num_ext += 1;
282268 }
....@@ -284,7 +270,7 @@
284270 if (sp->adaptation_ind)
285271 chunksize += sizeof(aiparam);
286272
287
- if (sp->strm_interleave) {
273
+ if (asoc->ep->intl_enable) {
288274 extensions[num_ext] = SCTP_CID_I_DATA;
289275 num_ext += 1;
290276 }
....@@ -351,7 +337,8 @@
351337 sctp_addto_chunk(retval, sizeof(sat), &sat);
352338 sctp_addto_chunk(retval, num_types * sizeof(__u16), &types);
353339
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);
355342
356343 /* Add the supported extensions parameter. Be nice and add this
357344 * fist before addiding the parameters for the extensions themselves
....@@ -363,7 +350,7 @@
363350 sctp_addto_param(retval, num_ext, extensions);
364351 }
365352
366
- if (asoc->prsctp_enable)
353
+ if (asoc->ep->prsctp_enable)
367354 sctp_addto_chunk(retval, sizeof(prsctp_param), &prsctp_param);
368355
369356 if (sp->adaptation_ind) {
....@@ -453,7 +440,7 @@
453440 if (sp->adaptation_ind)
454441 chunksize += sizeof(aiparam);
455442
456
- if (asoc->intl_enable) {
443
+ if (asoc->peer.intl_capable) {
457444 extensions[num_ext] = SCTP_CID_I_DATA;
458445 num_ext += 1;
459446 }
....@@ -1248,7 +1235,7 @@
12481235
12491236 /* Create an Operation Error chunk of a fixed size, specifically,
12501237 * 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
12521239 * invalid parameter codes in which we may not want to report all the
12531240 * errors, if the incoming chunk is large. If it can't fit in a single
12541241 * packet, we ignore it.
....@@ -1683,18 +1670,14 @@
16831670 ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len);
16841671
16851672 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;
16871674 int err;
16881675
16891676 /* 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,
16941678 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);
16981681 if (err)
16991682 goto free_cookie;
17001683 }
....@@ -1755,18 +1738,13 @@
17551738
17561739 /* Check the signature. */
17571740 {
1758
- SHASH_DESC_ON_STACK(desc, sctp_sk(ep->base.sk)->hmac);
1741
+ struct crypto_shash *tfm = sctp_sk(ep->base.sk)->hmac;
17591742 int err;
17601743
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,
17651745 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);
17701748 if (err) {
17711749 *error = -SCTP_IERROR_NOMEM;
17721750 goto fail;
....@@ -1802,7 +1780,7 @@
18021780 * for init collision case of lost COOKIE ACK.
18031781 * If skb has been timestamped, then use the stamp, otherwise
18041782 * 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
18061784 * down the new association establishment instead of every packet.
18071785 */
18081786 if (sock_flag(ep->base.sk, SOCK_TIMESTAMP))
....@@ -1985,7 +1963,9 @@
19851963 return 0;
19861964 }
19871965
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)
19891969 {
19901970 __u16 num_ext = ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
19911971 int have_asconf = 0;
....@@ -2012,7 +1992,7 @@
20121992 if (net->sctp.addip_noauth)
20131993 return 1;
20141994
2015
- if (net->sctp.addip_enable && !have_auth && have_asconf)
1995
+ if (ep->asconf_enable && !have_auth && have_asconf)
20161996 return 0;
20171997
20181998 return 1;
....@@ -2022,18 +2002,16 @@
20222002 union sctp_params param)
20232003 {
20242004 __u16 num_ext = ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
2025
- struct net *net = sock_net(asoc->base.sk);
20262005 int i;
20272006
20282007 for (i = 0; i < num_ext; i++) {
20292008 switch (param.ext->chunks[i]) {
20302009 case SCTP_CID_RECONF:
2031
- if (asoc->reconf_enable &&
2032
- !asoc->peer.reconf_capable)
2010
+ if (asoc->ep->reconf_enable)
20332011 asoc->peer.reconf_capable = 1;
20342012 break;
20352013 case SCTP_CID_FWD_TSN:
2036
- if (asoc->prsctp_enable && !asoc->peer.prsctp_capable)
2014
+ if (asoc->ep->prsctp_enable)
20372015 asoc->peer.prsctp_capable = 1;
20382016 break;
20392017 case SCTP_CID_AUTH:
....@@ -2045,12 +2023,12 @@
20452023 break;
20462024 case SCTP_CID_ASCONF:
20472025 case SCTP_CID_ASCONF_ACK:
2048
- if (net->sctp.addip_enable)
2026
+ if (asoc->ep->asconf_enable)
20492027 asoc->peer.asconf_capable = 1;
20502028 break;
20512029 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;
20542032 break;
20552033 default:
20562034 break;
....@@ -2099,7 +2077,7 @@
20992077 break;
21002078 case SCTP_PARAM_ACTION_DISCARD_ERR:
21012079 retval = SCTP_IERROR_ERROR;
2102
- /* Fall through */
2080
+ fallthrough;
21032081 case SCTP_PARAM_ACTION_SKIP_ERR:
21042082 /* Make an ERROR chunk, preparing enough room for
21052083 * returning multiple unknown parameters.
....@@ -2167,13 +2145,13 @@
21672145 break;
21682146
21692147 case SCTP_PARAM_SUPPORTED_EXT:
2170
- if (!sctp_verify_ext_param(net, param))
2148
+ if (!sctp_verify_ext_param(net, ep, param))
21712149 return SCTP_IERROR_ABORT;
21722150 break;
21732151
21742152 case SCTP_PARAM_SET_PRIMARY:
2175
- if (!net->sctp.addip_enable)
2176
- goto fallthrough;
2153
+ if (!ep->asconf_enable)
2154
+ goto unhandled;
21772155
21782156 if (ntohs(param.p->length) < sizeof(struct sctp_addip_param) +
21792157 sizeof(struct sctp_paramhdr)) {
....@@ -2192,11 +2170,11 @@
21922170 case SCTP_PARAM_FWD_TSN_SUPPORT:
21932171 if (ep->prsctp_enable)
21942172 break;
2195
- goto fallthrough;
2173
+ goto unhandled;
21962174
21972175 case SCTP_PARAM_RANDOM:
21982176 if (!ep->auth_enable)
2199
- goto fallthrough;
2177
+ goto unhandled;
22002178
22012179 /* SCTP-AUTH: Secion 6.1
22022180 * If the random number is not 32 byte long the association
....@@ -2213,7 +2191,7 @@
22132191
22142192 case SCTP_PARAM_CHUNKS:
22152193 if (!ep->auth_enable)
2216
- goto fallthrough;
2194
+ goto unhandled;
22172195
22182196 /* SCTP-AUTH: Section 3.2
22192197 * The CHUNKS parameter MUST be included once in the INIT or
....@@ -2229,7 +2207,7 @@
22292207
22302208 case SCTP_PARAM_HMAC_ALGO:
22312209 if (!ep->auth_enable)
2232
- goto fallthrough;
2210
+ goto unhandled;
22332211
22342212 hmacs = (struct sctp_hmac_algo_param *)param.p;
22352213 n_elt = (ntohs(param.p->length) -
....@@ -2252,7 +2230,7 @@
22522230 retval = SCTP_IERROR_ABORT;
22532231 }
22542232 break;
2255
-fallthrough:
2233
+unhandled:
22562234 default:
22572235 pr_debug("%s: unrecognized param:%d for chunk:%d\n",
22582236 __func__, ntohs(param.p->type), cid);
....@@ -2333,7 +2311,6 @@
23332311 const union sctp_addr *peer_addr,
23342312 struct sctp_init_chunk *peer_init, gfp_t gfp)
23352313 {
2336
- struct net *net = sock_net(asoc->base.sk);
23372314 struct sctp_transport *transport;
23382315 struct list_head *pos, *temp;
23392316 union sctp_params param;
....@@ -2349,7 +2326,7 @@
23492326
23502327 /* This implementation defaults to making the first transport
23512328 * 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.
23532330 */
23542331 if (!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE))
23552332 goto nomem;
....@@ -2391,8 +2368,8 @@
23912368 * also give us an option to silently ignore the packet, which
23922369 * is what we'll do here.
23932370 */
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)) {
23962373 asoc->peer.addip_disabled_mask |= (SCTP_PARAM_ADD_IP |
23972374 SCTP_PARAM_DEL_IP |
23982375 SCTP_PARAM_SET_PRIMARY);
....@@ -2519,9 +2496,9 @@
25192496 const union sctp_addr *peer_addr,
25202497 gfp_t gfp)
25212498 {
2522
- struct net *net = sock_net(asoc->base.sk);
25232499 struct sctp_endpoint *ep = asoc->ep;
25242500 union sctp_addr_param *addr_param;
2501
+ struct net *net = asoc->base.net;
25252502 struct sctp_transport *t;
25262503 enum sctp_scope scope;
25272504 union sctp_addr addr;
....@@ -2614,8 +2591,7 @@
26142591 case SCTP_PARAM_STATE_COOKIE:
26152592 asoc->peer.cookie_len =
26162593 ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
2617
- if (asoc->peer.cookie)
2618
- kfree(asoc->peer.cookie);
2594
+ kfree(asoc->peer.cookie);
26192595 asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
26202596 if (!asoc->peer.cookie)
26212597 retval = 0;
....@@ -2630,15 +2606,20 @@
26302606 break;
26312607
26322608 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
+
26352616
26362617 case SCTP_PARAM_ADAPTATION_LAYER_IND:
26372618 asoc->peer.adaptation_ind = ntohl(param.aind->adaptation_ind);
26382619 break;
26392620
26402621 case SCTP_PARAM_SET_PRIMARY:
2641
- if (!net->sctp.addip_enable)
2622
+ if (!ep->asconf_enable)
26422623 goto fall_through;
26432624
26442625 addr_param = param.v + sizeof(struct sctp_addip_param);
....@@ -2666,7 +2647,7 @@
26662647 break;
26672648
26682649 case SCTP_PARAM_FWD_TSN_SUPPORT:
2669
- if (asoc->prsctp_enable) {
2650
+ if (asoc->ep->prsctp_enable) {
26702651 asoc->peer.prsctp_capable = 1;
26712652 break;
26722653 }
....@@ -2678,8 +2659,7 @@
26782659 goto fall_through;
26792660
26802661 /* Save peer's random parameter */
2681
- if (asoc->peer.peer_random)
2682
- kfree(asoc->peer.peer_random);
2662
+ kfree(asoc->peer.peer_random);
26832663 asoc->peer.peer_random = kmemdup(param.p,
26842664 ntohs(param.p->length), gfp);
26852665 if (!asoc->peer.peer_random) {
....@@ -2693,8 +2673,7 @@
26932673 goto fall_through;
26942674
26952675 /* Save peer's HMAC list */
2696
- if (asoc->peer.peer_hmacs)
2697
- kfree(asoc->peer.peer_hmacs);
2676
+ kfree(asoc->peer.peer_hmacs);
26982677 asoc->peer.peer_hmacs = kmemdup(param.p,
26992678 ntohs(param.p->length), gfp);
27002679 if (!asoc->peer.peer_hmacs) {
....@@ -2710,8 +2689,7 @@
27102689 if (!ep->auth_enable)
27112690 goto fall_through;
27122691
2713
- if (asoc->peer.peer_chunks)
2714
- kfree(asoc->peer.peer_chunks);
2692
+ kfree(asoc->peer.peer_chunks);
27152693 asoc->peer.peer_chunks = kmemdup(param.p,
27162694 ntohs(param.p->length), gfp);
27172695 if (!asoc->peer.peer_chunks)