hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/sctp/socket.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.
....@@ -14,22 +15,6 @@
1415 * Note that the descriptions from the specification are USER level
1516 * functions--this file is the functions which populate the struct proto
1617 * for SCTP which is the BOTTOM of the sockets interface.
17
- *
18
- * This SCTP implementation is free software;
19
- * you can redistribute it and/or modify it under the terms of
20
- * the GNU General Public License as published by
21
- * the Free Software Foundation; either version 2, or (at your option)
22
- * any later version.
23
- *
24
- * This SCTP implementation is distributed in the hope that it
25
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied
26
- * ************************
27
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
- * See the GNU General Public License for more details.
29
- *
30
- * You should have received a copy of the GNU General Public License
31
- * along with GNU CC; see the file COPYING. If not, see
32
- * <http://www.gnu.org/licenses/>.
3318 *
3419 * Please send any bug reports or fixes you make to the
3520 * email address(es):
....@@ -83,7 +68,7 @@
8368 #include <net/sctp/stream_sched.h>
8469
8570 /* Forward declarations for internal helper functions. */
86
-static bool sctp_writeable(struct sock *sk);
71
+static bool sctp_writeable(const struct sock *sk);
8772 static void sctp_wfree(struct sk_buff *skb);
8873 static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
8974 size_t msg_len);
....@@ -102,9 +87,9 @@
10287 struct sctp_chunk *chunk);
10388 static int sctp_do_bind(struct sock *, union sctp_addr *, int);
10489 static int sctp_autobind(struct sock *sk);
105
-static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
106
- struct sctp_association *assoc,
107
- enum sctp_socket_type type);
90
+static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
91
+ struct sctp_association *assoc,
92
+ enum sctp_socket_type type);
10893
10994 static unsigned long sctp_memory_pressure;
11095 static atomic_long_t sctp_memory_allocated;
....@@ -112,7 +97,7 @@
11297
11398 static void sctp_enter_memory_pressure(struct sock *sk)
11499 {
115
- sctp_memory_pressure = 1;
100
+ WRITE_ONCE(sctp_memory_pressure, 1);
116101 }
117102
118103
....@@ -151,12 +136,9 @@
151136 /* Save the chunk pointer in skb for sctp_wfree to use later. */
152137 skb_shinfo(chunk->skb)->destructor_arg = chunk;
153138
154
- asoc->sndbuf_used += SCTP_DATA_SNDSIZE(chunk) +
155
- sizeof(struct sk_buff) +
156
- sizeof(struct sctp_chunk);
157
-
158139 refcount_add(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc);
159
- sk->sk_wmem_queued += chunk->skb->truesize;
140
+ asoc->sndbuf_used += chunk->skb->truesize + sizeof(struct sctp_chunk);
141
+ sk_wmem_queued_add(sk, chunk->skb->truesize + sizeof(struct sctp_chunk));
160142 sk_mem_charge(sk, chunk->skb->truesize);
161143 }
162144
....@@ -266,7 +248,7 @@
266248 }
267249
268250 /* Otherwise this is a UDP-style socket. */
269
- if (!id || (id == (sctp_assoc_t)-1))
251
+ if (id <= SCTP_ALL_ASSOC)
270252 return NULL;
271253
272254 spin_lock_bh(&sctp_assocs_id_lock);
....@@ -342,7 +324,7 @@
342324 return retval;
343325 }
344326
345
-static long sctp_get_port_local(struct sock *, union sctp_addr *);
327
+static int sctp_get_port_local(struct sock *, union sctp_addr *);
346328
347329 /* Verify this is a valid sockaddr. */
348330 static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt,
....@@ -380,9 +362,9 @@
380362 struct net *net = sock_net(&sp->inet.sk);
381363
382364 if (net->sctp.default_auto_asconf) {
383
- spin_lock(&net->sctp.addr_wq_lock);
365
+ spin_lock_bh(&net->sctp.addr_wq_lock);
384366 list_add_tail(&sp->auto_asconf_list, &net->sctp.auto_asconf_splist);
385
- spin_unlock(&net->sctp.addr_wq_lock);
367
+ spin_unlock_bh(&net->sctp.addr_wq_lock);
386368 sp->do_auto_asconf = 1;
387369 }
388370 }
....@@ -429,7 +411,10 @@
429411 }
430412 }
431413
432
- if (snum && snum < inet_prot_sock(net) &&
414
+ if (snum && inet_is_local_unbindable_port(net, snum))
415
+ return -EPERM;
416
+
417
+ if (snum && inet_port_requires_bind_service(net, snum) &&
433418 !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
434419 return -EACCES;
435420
....@@ -444,9 +429,8 @@
444429 * detection.
445430 */
446431 addr->v4.sin_port = htons(snum);
447
- if ((ret = sctp_get_port_local(sk, addr))) {
432
+ if (sctp_get_port_local(sk, addr))
448433 return -EADDRINUSE;
449
- }
450434
451435 /* Refresh ephemeral port. */
452436 if (!bp->port) {
....@@ -460,11 +444,13 @@
460444 ret = sctp_add_bind_addr(bp, addr, af->sockaddr_len,
461445 SCTP_ADDR_SRC, GFP_ATOMIC);
462446
463
- /* Copy back into socket for getsockname() use. */
464
- if (!ret) {
465
- inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num);
466
- sp->pf->to_sk_saddr(addr, sk);
447
+ if (ret) {
448
+ sctp_put_port(sk);
449
+ return ret;
467450 }
451
+ /* Copy back into socket for getsockname() use. */
452
+ inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num);
453
+ sp->pf->to_sk_saddr(addr, sk);
468454
469455 return ret;
470456 }
....@@ -482,8 +468,7 @@
482468 static int sctp_send_asconf(struct sctp_association *asoc,
483469 struct sctp_chunk *chunk)
484470 {
485
- struct net *net = sock_net(asoc->base.sk);
486
- int retval = 0;
471
+ int retval = 0;
487472
488473 /* If there is an outstanding ASCONF chunk, queue it for later
489474 * transmission.
....@@ -495,7 +480,7 @@
495480
496481 /* Hold the chunk until an ASCONF_ACK is received. */
497482 sctp_chunk_hold(chunk);
498
- retval = sctp_primitive_ASCONF(net, asoc, chunk);
483
+ retval = sctp_primitive_ASCONF(asoc->base.net, asoc, chunk);
499484 if (retval)
500485 sctp_chunk_free(chunk);
501486 else
....@@ -571,7 +556,6 @@
571556 struct sockaddr *addrs,
572557 int addrcnt)
573558 {
574
- struct net *net = sock_net(sk);
575559 struct sctp_sock *sp;
576560 struct sctp_endpoint *ep;
577561 struct sctp_association *asoc;
....@@ -586,11 +570,11 @@
586570 int i;
587571 int retval = 0;
588572
589
- if (!net->sctp.addip_enable)
590
- return retval;
591
-
592573 sp = sctp_sk(sk);
593574 ep = sp->ep;
575
+
576
+ if (!ep->asconf_enable)
577
+ return retval;
594578
595579 pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n",
596580 __func__, sk, addrs, addrcnt);
....@@ -774,7 +758,6 @@
774758 struct sockaddr *addrs,
775759 int addrcnt)
776760 {
777
- struct net *net = sock_net(sk);
778761 struct sctp_sock *sp;
779762 struct sctp_endpoint *ep;
780763 struct sctp_association *asoc;
....@@ -790,11 +773,11 @@
790773 int stored = 0;
791774
792775 chunk = NULL;
793
- if (!net->sctp.addip_enable)
794
- return retval;
795
-
796776 sp = sctp_sk(sk);
797777 ep = sp->ep;
778
+
779
+ if (!ep->asconf_enable)
780
+ return retval;
798781
799782 pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n",
800783 __func__, sk, addrs, addrcnt);
....@@ -1006,42 +989,33 @@
1006989 * it.
1007990 *
1008991 * sk The sk of the socket
1009
- * addrs The pointer to the addresses in user land
992
+ * addrs The pointer to the addresses
1010993 * addrssize Size of the addrs buffer
1011994 * op Operation to perform (add or remove, see the flags of
1012995 * sctp_bindx)
1013996 *
1014997 * Returns 0 if ok, <0 errno code on error.
1015998 */
1016
-static int sctp_setsockopt_bindx(struct sock *sk,
1017
- struct sockaddr __user *addrs,
999
+static int sctp_setsockopt_bindx(struct sock *sk, struct sockaddr *addrs,
10181000 int addrs_size, int op)
10191001 {
1020
- struct sockaddr *kaddrs;
10211002 int err;
10221003 int addrcnt = 0;
10231004 int walk_size = 0;
10241005 struct sockaddr *sa_addr;
1025
- void *addr_buf;
1006
+ void *addr_buf = addrs;
10261007 struct sctp_af *af;
10271008
10281009 pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n",
1029
- __func__, sk, addrs, addrs_size, op);
1010
+ __func__, sk, addr_buf, addrs_size, op);
10301011
10311012 if (unlikely(addrs_size <= 0))
10321013 return -EINVAL;
10331014
1034
- kaddrs = memdup_user(addrs, addrs_size);
1035
- if (unlikely(IS_ERR(kaddrs)))
1036
- return PTR_ERR(kaddrs);
1037
-
10381015 /* Walk through the addrs buffer and count the number of addresses. */
1039
- addr_buf = kaddrs;
10401016 while (walk_size < addrs_size) {
1041
- if (walk_size + sizeof(sa_family_t) > addrs_size) {
1042
- kfree(kaddrs);
1017
+ if (walk_size + sizeof(sa_family_t) > addrs_size)
10431018 return -EINVAL;
1044
- }
10451019
10461020 sa_addr = addr_buf;
10471021 af = sctp_get_af_specific(sa_addr->sa_family);
....@@ -1049,10 +1023,8 @@
10491023 /* If the address family is not supported or if this address
10501024 * causes the address buffer to overflow return EINVAL.
10511025 */
1052
- if (!af || (walk_size + af->sockaddr_len) > addrs_size) {
1053
- kfree(kaddrs);
1026
+ if (!af || (walk_size + af->sockaddr_len) > addrs_size)
10541027 return -EINVAL;
1055
- }
10561028 addrcnt++;
10571029 addr_buf += af->sockaddr_len;
10581030 walk_size += af->sockaddr_len;
....@@ -1063,32 +1035,129 @@
10631035 case SCTP_BINDX_ADD_ADDR:
10641036 /* Allow security module to validate bindx addresses. */
10651037 err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_BINDX_ADD,
1066
- (struct sockaddr *)kaddrs,
1067
- addrs_size);
1038
+ addrs, addrs_size);
10681039 if (err)
1069
- goto out;
1070
- err = sctp_bindx_add(sk, kaddrs, addrcnt);
1040
+ return err;
1041
+ err = sctp_bindx_add(sk, addrs, addrcnt);
10711042 if (err)
1072
- goto out;
1073
- err = sctp_send_asconf_add_ip(sk, kaddrs, addrcnt);
1074
- break;
1075
-
1043
+ return err;
1044
+ return sctp_send_asconf_add_ip(sk, addrs, addrcnt);
10761045 case SCTP_BINDX_REM_ADDR:
1077
- err = sctp_bindx_rem(sk, kaddrs, addrcnt);
1046
+ err = sctp_bindx_rem(sk, addrs, addrcnt);
10781047 if (err)
1079
- goto out;
1080
- err = sctp_send_asconf_del_ip(sk, kaddrs, addrcnt);
1081
- break;
1048
+ return err;
1049
+ return sctp_send_asconf_del_ip(sk, addrs, addrcnt);
10821050
10831051 default:
1084
- err = -EINVAL;
1085
- break;
1052
+ return -EINVAL;
1053
+ }
1054
+}
1055
+
1056
+static int sctp_bind_add(struct sock *sk, struct sockaddr *addrs,
1057
+ int addrlen)
1058
+{
1059
+ int err;
1060
+
1061
+ lock_sock(sk);
1062
+ err = sctp_setsockopt_bindx(sk, addrs, addrlen, SCTP_BINDX_ADD_ADDR);
1063
+ release_sock(sk);
1064
+ return err;
1065
+}
1066
+
1067
+static int sctp_connect_new_asoc(struct sctp_endpoint *ep,
1068
+ const union sctp_addr *daddr,
1069
+ const struct sctp_initmsg *init,
1070
+ struct sctp_transport **tp)
1071
+{
1072
+ struct sctp_association *asoc;
1073
+ struct sock *sk = ep->base.sk;
1074
+ struct net *net = sock_net(sk);
1075
+ enum sctp_scope scope;
1076
+ int err;
1077
+
1078
+ if (sctp_endpoint_is_peeled_off(ep, daddr))
1079
+ return -EADDRNOTAVAIL;
1080
+
1081
+ if (!ep->base.bind_addr.port) {
1082
+ if (sctp_autobind(sk))
1083
+ return -EAGAIN;
1084
+ } else {
1085
+ if (inet_is_local_unbindable_port(net, ep->base.bind_addr.port))
1086
+ return -EPERM;
1087
+ if (inet_port_requires_bind_service(net, ep->base.bind_addr.port) &&
1088
+ !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
1089
+ return -EACCES;
10861090 }
10871091
1088
-out:
1089
- kfree(kaddrs);
1092
+ scope = sctp_scope(daddr);
1093
+ asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL);
1094
+ if (!asoc)
1095
+ return -ENOMEM;
10901096
1097
+ err = sctp_assoc_set_bind_addr_from_ep(asoc, scope, GFP_KERNEL);
1098
+ if (err < 0)
1099
+ goto free;
1100
+
1101
+ *tp = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL, SCTP_UNKNOWN);
1102
+ if (!*tp) {
1103
+ err = -ENOMEM;
1104
+ goto free;
1105
+ }
1106
+
1107
+ if (!init)
1108
+ return 0;
1109
+
1110
+ if (init->sinit_num_ostreams) {
1111
+ __u16 outcnt = init->sinit_num_ostreams;
1112
+
1113
+ asoc->c.sinit_num_ostreams = outcnt;
1114
+ /* outcnt has been changed, need to re-init stream */
1115
+ err = sctp_stream_init(&asoc->stream, outcnt, 0, GFP_KERNEL);
1116
+ if (err)
1117
+ goto free;
1118
+ }
1119
+
1120
+ if (init->sinit_max_instreams)
1121
+ asoc->c.sinit_max_instreams = init->sinit_max_instreams;
1122
+
1123
+ if (init->sinit_max_attempts)
1124
+ asoc->max_init_attempts = init->sinit_max_attempts;
1125
+
1126
+ if (init->sinit_max_init_timeo)
1127
+ asoc->max_init_timeo =
1128
+ msecs_to_jiffies(init->sinit_max_init_timeo);
1129
+
1130
+ return 0;
1131
+free:
1132
+ sctp_association_free(asoc);
10911133 return err;
1134
+}
1135
+
1136
+static int sctp_connect_add_peer(struct sctp_association *asoc,
1137
+ union sctp_addr *daddr, int addr_len)
1138
+{
1139
+ struct sctp_endpoint *ep = asoc->ep;
1140
+ struct sctp_association *old;
1141
+ struct sctp_transport *t;
1142
+ int err;
1143
+
1144
+ err = sctp_verify_addr(ep->base.sk, daddr, addr_len);
1145
+ if (err)
1146
+ return err;
1147
+
1148
+ old = sctp_endpoint_lookup_assoc(ep, daddr, &t);
1149
+ if (old && old != asoc)
1150
+ return old->state >= SCTP_STATE_ESTABLISHED ? -EISCONN
1151
+ : -EALREADY;
1152
+
1153
+ if (sctp_endpoint_is_peeled_off(ep, daddr))
1154
+ return -EADDRNOTAVAIL;
1155
+
1156
+ t = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL, SCTP_UNKNOWN);
1157
+ if (!t)
1158
+ return -ENOMEM;
1159
+
1160
+ return 0;
10921161 }
10931162
10941163 /* __sctp_connect(struct sock* sk, struct sockaddr *kaddrs, int addrs_size)
....@@ -1096,153 +1165,62 @@
10961165 * Common routine for handling connect() and sctp_connectx().
10971166 * Connect will come in with just a single address.
10981167 */
1099
-static int __sctp_connect(struct sock *sk,
1100
- struct sockaddr *kaddrs,
1101
- int addrs_size, int flags,
1102
- sctp_assoc_t *assoc_id)
1168
+static int __sctp_connect(struct sock *sk, struct sockaddr *kaddrs,
1169
+ int addrs_size, int flags, sctp_assoc_t *assoc_id)
11031170 {
1104
- struct net *net = sock_net(sk);
1105
- struct sctp_sock *sp;
1106
- struct sctp_endpoint *ep;
1107
- struct sctp_association *asoc = NULL;
1108
- struct sctp_association *asoc2;
1171
+ struct sctp_sock *sp = sctp_sk(sk);
1172
+ struct sctp_endpoint *ep = sp->ep;
11091173 struct sctp_transport *transport;
1110
- union sctp_addr to;
1111
- enum sctp_scope scope;
1174
+ struct sctp_association *asoc;
1175
+ void *addr_buf = kaddrs;
1176
+ union sctp_addr *daddr;
1177
+ struct sctp_af *af;
1178
+ int walk_size, err;
11121179 long timeo;
1113
- int err = 0;
1114
- int addrcnt = 0;
1115
- int walk_size = 0;
1116
- union sctp_addr *sa_addr = NULL;
1117
- void *addr_buf;
1118
- unsigned short port;
11191180
1120
- sp = sctp_sk(sk);
1121
- ep = sp->ep;
1122
-
1123
- /* connect() cannot be done on a socket that is already in ESTABLISHED
1124
- * state - UDP-style peeled off socket or a TCP-style socket that
1125
- * is already connected.
1126
- * It cannot be done even on a TCP-style listening socket.
1127
- */
11281181 if (sctp_sstate(sk, ESTABLISHED) || sctp_sstate(sk, CLOSING) ||
1129
- (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))) {
1130
- err = -EISCONN;
1131
- goto out_free;
1132
- }
1182
+ (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)))
1183
+ return -EISCONN;
11331184
1134
- /* Walk through the addrs buffer and count the number of addresses. */
1135
- addr_buf = kaddrs;
1185
+ daddr = addr_buf;
1186
+ af = sctp_get_af_specific(daddr->sa.sa_family);
1187
+ if (!af || af->sockaddr_len > addrs_size)
1188
+ return -EINVAL;
1189
+
1190
+ err = sctp_verify_addr(sk, daddr, af->sockaddr_len);
1191
+ if (err)
1192
+ return err;
1193
+
1194
+ asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
1195
+ if (asoc)
1196
+ return asoc->state >= SCTP_STATE_ESTABLISHED ? -EISCONN
1197
+ : -EALREADY;
1198
+
1199
+ err = sctp_connect_new_asoc(ep, daddr, NULL, &transport);
1200
+ if (err)
1201
+ return err;
1202
+ asoc = transport->asoc;
1203
+
1204
+ addr_buf += af->sockaddr_len;
1205
+ walk_size = af->sockaddr_len;
11361206 while (walk_size < addrs_size) {
1137
- struct sctp_af *af;
1138
-
1139
- if (walk_size + sizeof(sa_family_t) > addrs_size) {
1140
- err = -EINVAL;
1207
+ err = -EINVAL;
1208
+ if (walk_size + sizeof(sa_family_t) > addrs_size)
11411209 goto out_free;
1142
- }
11431210
1144
- sa_addr = addr_buf;
1145
- af = sctp_get_af_specific(sa_addr->sa.sa_family);
1146
-
1147
- /* If the address family is not supported or if this address
1148
- * causes the address buffer to overflow return EINVAL.
1149
- */
1150
- if (!af || (walk_size + af->sockaddr_len) > addrs_size) {
1151
- err = -EINVAL;
1211
+ daddr = addr_buf;
1212
+ af = sctp_get_af_specific(daddr->sa.sa_family);
1213
+ if (!af || af->sockaddr_len + walk_size > addrs_size)
11521214 goto out_free;
1153
- }
11541215
1155
- port = ntohs(sa_addr->v4.sin_port);
1216
+ if (asoc->peer.port != ntohs(daddr->v4.sin_port))
1217
+ goto out_free;
11561218
1157
- /* Save current address so we can work with it */
1158
- memcpy(&to, sa_addr, af->sockaddr_len);
1159
-
1160
- err = sctp_verify_addr(sk, &to, af->sockaddr_len);
1219
+ err = sctp_connect_add_peer(asoc, daddr, af->sockaddr_len);
11611220 if (err)
11621221 goto out_free;
11631222
1164
- /* Make sure the destination port is correctly set
1165
- * in all addresses.
1166
- */
1167
- if (asoc && asoc->peer.port && asoc->peer.port != port) {
1168
- err = -EINVAL;
1169
- goto out_free;
1170
- }
1171
-
1172
- /* Check if there already is a matching association on the
1173
- * endpoint (other than the one created here).
1174
- */
1175
- asoc2 = sctp_endpoint_lookup_assoc(ep, &to, &transport);
1176
- if (asoc2 && asoc2 != asoc) {
1177
- if (asoc2->state >= SCTP_STATE_ESTABLISHED)
1178
- err = -EISCONN;
1179
- else
1180
- err = -EALREADY;
1181
- goto out_free;
1182
- }
1183
-
1184
- /* If we could not find a matching association on the endpoint,
1185
- * make sure that there is no peeled-off association matching
1186
- * the peer address even on another socket.
1187
- */
1188
- if (sctp_endpoint_is_peeled_off(ep, &to)) {
1189
- err = -EADDRNOTAVAIL;
1190
- goto out_free;
1191
- }
1192
-
1193
- if (!asoc) {
1194
- /* If a bind() or sctp_bindx() is not called prior to
1195
- * an sctp_connectx() call, the system picks an
1196
- * ephemeral port and will choose an address set
1197
- * equivalent to binding with a wildcard address.
1198
- */
1199
- if (!ep->base.bind_addr.port) {
1200
- if (sctp_autobind(sk)) {
1201
- err = -EAGAIN;
1202
- goto out_free;
1203
- }
1204
- } else {
1205
- /*
1206
- * If an unprivileged user inherits a 1-many
1207
- * style socket with open associations on a
1208
- * privileged port, it MAY be permitted to
1209
- * accept new associations, but it SHOULD NOT
1210
- * be permitted to open new associations.
1211
- */
1212
- if (ep->base.bind_addr.port <
1213
- inet_prot_sock(net) &&
1214
- !ns_capable(net->user_ns,
1215
- CAP_NET_BIND_SERVICE)) {
1216
- err = -EACCES;
1217
- goto out_free;
1218
- }
1219
- }
1220
-
1221
- scope = sctp_scope(&to);
1222
- asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL);
1223
- if (!asoc) {
1224
- err = -ENOMEM;
1225
- goto out_free;
1226
- }
1227
-
1228
- err = sctp_assoc_set_bind_addr_from_ep(asoc, scope,
1229
- GFP_KERNEL);
1230
- if (err < 0) {
1231
- goto out_free;
1232
- }
1233
-
1234
- }
1235
-
1236
- /* Prime the peer's transport structures. */
1237
- transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL,
1238
- SCTP_UNKNOWN);
1239
- if (!transport) {
1240
- err = -ENOMEM;
1241
- goto out_free;
1242
- }
1243
-
1244
- addrcnt++;
1245
- addr_buf += af->sockaddr_len;
1223
+ addr_buf += af->sockaddr_len;
12461224 walk_size += af->sockaddr_len;
12471225 }
12481226
....@@ -1255,40 +1233,25 @@
12551233 goto out_free;
12561234 }
12571235
1258
- err = sctp_primitive_ASSOCIATE(net, asoc, NULL);
1259
- if (err < 0) {
1236
+ err = sctp_primitive_ASSOCIATE(sock_net(sk), asoc, NULL);
1237
+ if (err < 0)
12601238 goto out_free;
1261
- }
12621239
12631240 /* Initialize sk's dport and daddr for getpeername() */
12641241 inet_sk(sk)->inet_dport = htons(asoc->peer.port);
1265
- sp->pf->to_sk_daddr(sa_addr, sk);
1242
+ sp->pf->to_sk_daddr(daddr, sk);
12661243 sk->sk_err = 0;
1267
-
1268
- timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
12691244
12701245 if (assoc_id)
12711246 *assoc_id = asoc->assoc_id;
12721247
1273
- err = sctp_wait_for_connect(asoc, &timeo);
1274
- /* Note: the asoc may be freed after the return of
1275
- * sctp_wait_for_connect.
1276
- */
1277
-
1278
- /* Don't free association on exit. */
1279
- asoc = NULL;
1248
+ timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
1249
+ return sctp_wait_for_connect(asoc, &timeo);
12801250
12811251 out_free:
12821252 pr_debug("%s: took out_free path with asoc:%p kaddrs:%p err:%d\n",
12831253 __func__, asoc, kaddrs, err);
1284
-
1285
- if (asoc) {
1286
- /* sctp_primitive_ASSOCIATE may have added this association
1287
- * To the hash table, try to unhash it, just in case, its a noop
1288
- * if it wasn't hashed so we're safe
1289
- */
1290
- sctp_association_free(asoc);
1291
- }
1254
+ sctp_association_free(asoc);
12921255 return err;
12931256 }
12941257
....@@ -1342,35 +1305,29 @@
13421305 * it.
13431306 *
13441307 * sk The sk of the socket
1345
- * addrs The pointer to the addresses in user land
1308
+ * addrs The pointer to the addresses
13461309 * addrssize Size of the addrs buffer
13471310 *
13481311 * Returns >=0 if ok, <0 errno code on error.
13491312 */
1350
-static int __sctp_setsockopt_connectx(struct sock *sk,
1351
- struct sockaddr __user *addrs,
1352
- int addrs_size,
1353
- sctp_assoc_t *assoc_id)
1313
+static int __sctp_setsockopt_connectx(struct sock *sk, struct sockaddr *kaddrs,
1314
+ int addrs_size, sctp_assoc_t *assoc_id)
13541315 {
1355
- struct sockaddr *kaddrs;
13561316 int err = 0, flags = 0;
13571317
13581318 pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",
1359
- __func__, sk, addrs, addrs_size);
1319
+ __func__, sk, kaddrs, addrs_size);
13601320
1361
- if (unlikely(addrs_size <= 0))
1321
+ /* make sure the 1st addr's sa_family is accessible later */
1322
+ if (unlikely(addrs_size < sizeof(sa_family_t)))
13621323 return -EINVAL;
1363
-
1364
- kaddrs = memdup_user(addrs, addrs_size);
1365
- if (unlikely(IS_ERR(kaddrs)))
1366
- return PTR_ERR(kaddrs);
13671324
13681325 /* Allow security module to validate connectx addresses. */
13691326 err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_CONNECTX,
13701327 (struct sockaddr *)kaddrs,
13711328 addrs_size);
13721329 if (err)
1373
- goto out_free;
1330
+ return err;
13741331
13751332 /* in-kernel sockets don't generally have a file allocated to them
13761333 * if all they do is call sock_create_kern().
....@@ -1378,12 +1335,7 @@
13781335 if (sk->sk_socket->file)
13791336 flags = sk->sk_socket->file->f_flags;
13801337
1381
- err = __sctp_connect(sk, kaddrs, addrs_size, flags, assoc_id);
1382
-
1383
-out_free:
1384
- kfree(kaddrs);
1385
-
1386
- return err;
1338
+ return __sctp_connect(sk, kaddrs, addrs_size, flags, assoc_id);
13871339 }
13881340
13891341 /*
....@@ -1391,10 +1343,10 @@
13911343 * to the option that doesn't provide association id.
13921344 */
13931345 static int sctp_setsockopt_connectx_old(struct sock *sk,
1394
- struct sockaddr __user *addrs,
1346
+ struct sockaddr *kaddrs,
13951347 int addrs_size)
13961348 {
1397
- return __sctp_setsockopt_connectx(sk, addrs, addrs_size, NULL);
1349
+ return __sctp_setsockopt_connectx(sk, kaddrs, addrs_size, NULL);
13981350 }
13991351
14001352 /*
....@@ -1404,13 +1356,13 @@
14041356 * always positive.
14051357 */
14061358 static int sctp_setsockopt_connectx(struct sock *sk,
1407
- struct sockaddr __user *addrs,
1359
+ struct sockaddr *kaddrs,
14081360 int addrs_size)
14091361 {
14101362 sctp_assoc_t assoc_id = 0;
14111363 int err = 0;
14121364
1413
- err = __sctp_setsockopt_connectx(sk, addrs, addrs_size, &assoc_id);
1365
+ err = __sctp_setsockopt_connectx(sk, kaddrs, addrs_size, &assoc_id);
14141366
14151367 if (err)
14161368 return err;
....@@ -1440,6 +1392,7 @@
14401392 {
14411393 struct sctp_getaddrs_old param;
14421394 sctp_assoc_t assoc_id = 0;
1395
+ struct sockaddr *kaddrs;
14431396 int err = 0;
14441397
14451398 #ifdef CONFIG_COMPAT
....@@ -1463,9 +1416,12 @@
14631416 return -EFAULT;
14641417 }
14651418
1466
- err = __sctp_setsockopt_connectx(sk, (struct sockaddr __user *)
1467
- param.addrs, param.addr_num,
1468
- &assoc_id);
1419
+ kaddrs = memdup_user(param.addrs, param.addr_num);
1420
+ if (IS_ERR(kaddrs))
1421
+ return PTR_ERR(kaddrs);
1422
+
1423
+ err = __sctp_setsockopt_connectx(sk, kaddrs, param.addr_num, &assoc_id);
1424
+ kfree(kaddrs);
14691425 if (err == 0 || err == -EINPROGRESS) {
14701426 if (copy_to_user(optval, &assoc_id, sizeof(assoc_id)))
14711427 return -EFAULT;
....@@ -1706,9 +1662,7 @@
17061662 struct sctp_transport **tp)
17071663 {
17081664 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
1709
- struct net *net = sock_net(sk);
17101665 struct sctp_association *asoc;
1711
- enum sctp_scope scope;
17121666 struct cmsghdr *cmsg;
17131667 __be32 flowinfo = 0;
17141668 struct sctp_af *af;
....@@ -1722,20 +1676,6 @@
17221676 if (sctp_style(sk, TCP) && (sctp_sstate(sk, ESTABLISHED) ||
17231677 sctp_sstate(sk, CLOSING)))
17241678 return -EADDRNOTAVAIL;
1725
-
1726
- if (sctp_endpoint_is_peeled_off(ep, daddr))
1727
- return -EADDRNOTAVAIL;
1728
-
1729
- if (!ep->base.bind_addr.port) {
1730
- if (sctp_autobind(sk))
1731
- return -EAGAIN;
1732
- } else {
1733
- if (ep->base.bind_addr.port < inet_prot_sock(net) &&
1734
- !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
1735
- return -EACCES;
1736
- }
1737
-
1738
- scope = sctp_scope(daddr);
17391679
17401680 /* Label connection socket for first association 1-to-many
17411681 * style for client sequence socket()->sendmsg(). This
....@@ -1752,45 +1692,10 @@
17521692 if (err < 0)
17531693 return err;
17541694
1755
- asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL);
1756
- if (!asoc)
1757
- return -ENOMEM;
1758
-
1759
- if (sctp_assoc_set_bind_addr_from_ep(asoc, scope, GFP_KERNEL) < 0) {
1760
- err = -ENOMEM;
1761
- goto free;
1762
- }
1763
-
1764
- if (cmsgs->init) {
1765
- struct sctp_initmsg *init = cmsgs->init;
1766
-
1767
- if (init->sinit_num_ostreams) {
1768
- __u16 outcnt = init->sinit_num_ostreams;
1769
-
1770
- asoc->c.sinit_num_ostreams = outcnt;
1771
- /* outcnt has been changed, need to re-init stream */
1772
- err = sctp_stream_init(&asoc->stream, outcnt, 0,
1773
- GFP_KERNEL);
1774
- if (err)
1775
- goto free;
1776
- }
1777
-
1778
- if (init->sinit_max_instreams)
1779
- asoc->c.sinit_max_instreams = init->sinit_max_instreams;
1780
-
1781
- if (init->sinit_max_attempts)
1782
- asoc->max_init_attempts = init->sinit_max_attempts;
1783
-
1784
- if (init->sinit_max_init_timeo)
1785
- asoc->max_init_timeo =
1786
- msecs_to_jiffies(init->sinit_max_init_timeo);
1787
- }
1788
-
1789
- *tp = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL, SCTP_UNKNOWN);
1790
- if (!*tp) {
1791
- err = -ENOMEM;
1792
- goto free;
1793
- }
1695
+ err = sctp_connect_new_asoc(ep, daddr, cmsgs->init, tp);
1696
+ if (err)
1697
+ return err;
1698
+ asoc = (*tp)->asoc;
17941699
17951700 if (!cmsgs->addrs_msg)
17961701 return 0;
....@@ -1800,8 +1705,6 @@
18001705
18011706 /* sendv addr list parse */
18021707 for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
1803
- struct sctp_transport *transport;
1804
- struct sctp_association *old;
18051708 union sctp_addr _daddr;
18061709 int dlen;
18071710
....@@ -1835,30 +1738,10 @@
18351738 daddr->v6.sin6_port = htons(asoc->peer.port);
18361739 memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
18371740 }
1838
- err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
1741
+
1742
+ err = sctp_connect_add_peer(asoc, daddr, sizeof(*daddr));
18391743 if (err)
18401744 goto free;
1841
-
1842
- old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
1843
- if (old && old != asoc) {
1844
- if (old->state >= SCTP_STATE_ESTABLISHED)
1845
- err = -EISCONN;
1846
- else
1847
- err = -EALREADY;
1848
- goto free;
1849
- }
1850
-
1851
- if (sctp_endpoint_is_peeled_off(ep, daddr)) {
1852
- err = -EADDRNOTAVAIL;
1853
- goto free;
1854
- }
1855
-
1856
- transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
1857
- SCTP_UNKNOWN);
1858
- if (!transport) {
1859
- err = -ENOMEM;
1860
- goto free;
1861
- }
18621745 }
18631746
18641747 return 0;
....@@ -1953,6 +1836,10 @@
19531836 err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
19541837 if (err)
19551838 goto err;
1839
+ if (unlikely(sinfo->sinfo_stream >= asoc->stream.outcnt)) {
1840
+ err = -EINVAL;
1841
+ goto err;
1842
+ }
19561843 }
19571844
19581845 if (sctp_state(asoc, CLOSED)) {
....@@ -1960,7 +1847,7 @@
19601847 if (err)
19611848 goto err;
19621849
1963
- if (sp->strm_interleave) {
1850
+ if (asoc->ep->intl_enable) {
19641851 timeo = sock_sndtimeo(sk, 0);
19651852 err = sctp_wait_for_connect(asoc, &timeo);
19661853 if (err) {
....@@ -2266,7 +2153,7 @@
22662153 if (sp->recvrcvinfo)
22672154 sctp_ulpevent_read_rcvinfo(event, msg);
22682155 /* Check if we allow SCTP_SNDRCVINFO. */
2269
- if (sp->subscribe.sctp_data_io_event)
2156
+ if (sctp_ulpevent_type_enabled(sp->subscribe, SCTP_DATA_IO_EVENT))
22702157 sctp_ulpevent_read_sndrcvinfo(event, msg);
22712158
22722159 err = copied;
....@@ -2320,42 +2207,40 @@
23202207 * exceeds the current PMTU size, the message will NOT be sent and
23212208 * instead a error will be indicated to the user.
23222209 */
2323
-static int sctp_setsockopt_disable_fragments(struct sock *sk,
2324
- char __user *optval,
2210
+static int sctp_setsockopt_disable_fragments(struct sock *sk, int *val,
23252211 unsigned int optlen)
23262212 {
2327
- int val;
2328
-
23292213 if (optlen < sizeof(int))
23302214 return -EINVAL;
2331
-
2332
- if (get_user(val, (int __user *)optval))
2333
- return -EFAULT;
2334
-
2335
- sctp_sk(sk)->disable_fragments = (val == 0) ? 0 : 1;
2336
-
2215
+ sctp_sk(sk)->disable_fragments = (*val == 0) ? 0 : 1;
23372216 return 0;
23382217 }
23392218
2340
-static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
2219
+static int sctp_setsockopt_events(struct sock *sk, __u8 *sn_type,
23412220 unsigned int optlen)
23422221 {
2222
+ struct sctp_sock *sp = sctp_sk(sk);
23432223 struct sctp_association *asoc;
2344
- struct sctp_ulpevent *event;
2224
+ int i;
23452225
23462226 if (optlen > sizeof(struct sctp_event_subscribe))
23472227 return -EINVAL;
2348
- if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
2349
- return -EFAULT;
2228
+
2229
+ for (i = 0; i < optlen; i++)
2230
+ sctp_ulpevent_type_set(&sp->subscribe, SCTP_SN_TYPE_BASE + i,
2231
+ sn_type[i]);
2232
+
2233
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs)
2234
+ asoc->subscribe = sctp_sk(sk)->subscribe;
23502235
23512236 /* At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
23522237 * if there is no data to be sent or retransmit, the stack will
23532238 * immediately send up this notification.
23542239 */
2355
- if (sctp_ulpevent_type_enabled(SCTP_SENDER_DRY_EVENT,
2356
- &sctp_sk(sk)->subscribe)) {
2357
- asoc = sctp_id2assoc(sk, 0);
2240
+ if (sctp_ulpevent_type_enabled(sp->subscribe, SCTP_SENDER_DRY_EVENT)) {
2241
+ struct sctp_ulpevent *event;
23582242
2243
+ asoc = sctp_id2assoc(sk, 0);
23592244 if (asoc && sctp_outq_is_empty(&asoc->outqueue)) {
23602245 event = sctp_ulpevent_make_sender_dry_event(asoc,
23612246 GFP_USER | __GFP_NOWARN);
....@@ -2380,7 +2265,7 @@
23802265 * integer defining the number of seconds of idle time before an
23812266 * association is closed.
23822267 */
2383
-static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval,
2268
+static int sctp_setsockopt_autoclose(struct sock *sk, u32 *optval,
23842269 unsigned int optlen)
23852270 {
23862271 struct sctp_sock *sp = sctp_sk(sk);
....@@ -2391,9 +2276,8 @@
23912276 return -EOPNOTSUPP;
23922277 if (optlen != sizeof(int))
23932278 return -EINVAL;
2394
- if (copy_from_user(&sp->autoclose, optval, optlen))
2395
- return -EFAULT;
23962279
2280
+ sp->autoclose = *optval;
23972281 if (sp->autoclose > net->sctp.max_autoclose)
23982282 sp->autoclose = net->sctp.max_autoclose;
23992283
....@@ -2549,9 +2433,8 @@
25492433 int error;
25502434
25512435 if (params->spp_flags & SPP_HB_DEMAND && trans) {
2552
- struct net *net = sock_net(trans->asoc->base.sk);
2553
-
2554
- error = sctp_primitive_REQUESTHEARTBEAT(net, trans->asoc, trans);
2436
+ error = sctp_primitive_REQUESTHEARTBEAT(trans->asoc->base.net,
2437
+ trans->asoc, trans);
25552438 if (error)
25562439 return error;
25572440 }
....@@ -2574,6 +2457,7 @@
25742457 if (trans) {
25752458 trans->hbinterval =
25762459 msecs_to_jiffies(params->spp_hbinterval);
2460
+ sctp_transport_reset_hb_timer(trans);
25772461 } else if (asoc) {
25782462 asoc->hbinterval =
25792463 msecs_to_jiffies(params->spp_hbinterval);
....@@ -2729,68 +2613,63 @@
27292613 }
27302614
27312615 static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2732
- char __user *optval,
2616
+ struct sctp_paddrparams *params,
27332617 unsigned int optlen)
27342618 {
2735
- struct sctp_paddrparams params;
27362619 struct sctp_transport *trans = NULL;
27372620 struct sctp_association *asoc = NULL;
27382621 struct sctp_sock *sp = sctp_sk(sk);
27392622 int error;
27402623 int hb_change, pmtud_change, sackdelay_change;
27412624
2742
- if (optlen == sizeof(params)) {
2743
- if (copy_from_user(&params, optval, optlen))
2744
- return -EFAULT;
2745
- } else if (optlen == ALIGN(offsetof(struct sctp_paddrparams,
2625
+ if (optlen == ALIGN(offsetof(struct sctp_paddrparams,
27462626 spp_ipv6_flowlabel), 4)) {
2747
- if (copy_from_user(&params, optval, optlen))
2748
- return -EFAULT;
2749
- if (params.spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL))
2627
+ if (params->spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL))
27502628 return -EINVAL;
2751
- } else {
2629
+ } else if (optlen != sizeof(*params)) {
27522630 return -EINVAL;
27532631 }
27542632
27552633 /* Validate flags and value parameters. */
2756
- hb_change = params.spp_flags & SPP_HB;
2757
- pmtud_change = params.spp_flags & SPP_PMTUD;
2758
- sackdelay_change = params.spp_flags & SPP_SACKDELAY;
2634
+ hb_change = params->spp_flags & SPP_HB;
2635
+ pmtud_change = params->spp_flags & SPP_PMTUD;
2636
+ sackdelay_change = params->spp_flags & SPP_SACKDELAY;
27592637
27602638 if (hb_change == SPP_HB ||
27612639 pmtud_change == SPP_PMTUD ||
27622640 sackdelay_change == SPP_SACKDELAY ||
2763
- params.spp_sackdelay > 500 ||
2764
- (params.spp_pathmtu &&
2765
- params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
2641
+ params->spp_sackdelay > 500 ||
2642
+ (params->spp_pathmtu &&
2643
+ params->spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
27662644 return -EINVAL;
27672645
27682646 /* If an address other than INADDR_ANY is specified, and
27692647 * no transport is found, then the request is invalid.
27702648 */
2771
- if (!sctp_is_any(sk, (union sctp_addr *)&params.spp_address)) {
2772
- trans = sctp_addr_id2transport(sk, &params.spp_address,
2773
- params.spp_assoc_id);
2649
+ if (!sctp_is_any(sk, (union sctp_addr *)&params->spp_address)) {
2650
+ trans = sctp_addr_id2transport(sk, &params->spp_address,
2651
+ params->spp_assoc_id);
27742652 if (!trans)
27752653 return -EINVAL;
27762654 }
27772655
2778
- /* Get association, if assoc_id != 0 and the socket is a one
2779
- * to many style socket, and an association was not found, then
2780
- * the id was invalid.
2656
+ /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
2657
+ * socket is a one to many style socket, and an association
2658
+ * was not found, then the id was invalid.
27812659 */
2782
- asoc = sctp_id2assoc(sk, params.spp_assoc_id);
2783
- if (!asoc && params.spp_assoc_id && sctp_style(sk, UDP))
2660
+ asoc = sctp_id2assoc(sk, params->spp_assoc_id);
2661
+ if (!asoc && params->spp_assoc_id != SCTP_FUTURE_ASSOC &&
2662
+ sctp_style(sk, UDP))
27842663 return -EINVAL;
27852664
27862665 /* Heartbeat demand can only be sent on a transport or
27872666 * association, but not a socket.
27882667 */
2789
- if (params.spp_flags & SPP_HB_DEMAND && !trans && !asoc)
2668
+ if (params->spp_flags & SPP_HB_DEMAND && !trans && !asoc)
27902669 return -EINVAL;
27912670
27922671 /* Process parameters. */
2793
- error = sctp_apply_peer_addr_params(&params, trans, asoc, sp,
2672
+ error = sctp_apply_peer_addr_params(params, trans, asoc, sp,
27942673 hb_change, pmtud_change,
27952674 sackdelay_change);
27962675
....@@ -2803,7 +2682,7 @@
28032682 if (!trans && asoc) {
28042683 list_for_each_entry(trans, &asoc->peer.transport_addr_list,
28052684 transports) {
2806
- sctp_apply_peer_addr_params(&params, trans, asoc, sp,
2685
+ sctp_apply_peer_addr_params(params, trans, asoc, sp,
28072686 hb_change, pmtud_change,
28082687 sackdelay_change);
28092688 }
....@@ -2820,6 +2699,43 @@
28202699 static inline __u32 sctp_spp_sackdelay_disable(__u32 param_flags)
28212700 {
28222701 return (param_flags & ~SPP_SACKDELAY) | SPP_SACKDELAY_DISABLE;
2702
+}
2703
+
2704
+static void sctp_apply_asoc_delayed_ack(struct sctp_sack_info *params,
2705
+ struct sctp_association *asoc)
2706
+{
2707
+ struct sctp_transport *trans;
2708
+
2709
+ if (params->sack_delay) {
2710
+ asoc->sackdelay = msecs_to_jiffies(params->sack_delay);
2711
+ asoc->param_flags =
2712
+ sctp_spp_sackdelay_enable(asoc->param_flags);
2713
+ }
2714
+ if (params->sack_freq == 1) {
2715
+ asoc->param_flags =
2716
+ sctp_spp_sackdelay_disable(asoc->param_flags);
2717
+ } else if (params->sack_freq > 1) {
2718
+ asoc->sackfreq = params->sack_freq;
2719
+ asoc->param_flags =
2720
+ sctp_spp_sackdelay_enable(asoc->param_flags);
2721
+ }
2722
+
2723
+ list_for_each_entry(trans, &asoc->peer.transport_addr_list,
2724
+ transports) {
2725
+ if (params->sack_delay) {
2726
+ trans->sackdelay = msecs_to_jiffies(params->sack_delay);
2727
+ trans->param_flags =
2728
+ sctp_spp_sackdelay_enable(trans->param_flags);
2729
+ }
2730
+ if (params->sack_freq == 1) {
2731
+ trans->param_flags =
2732
+ sctp_spp_sackdelay_disable(trans->param_flags);
2733
+ } else if (params->sack_freq > 1) {
2734
+ trans->sackfreq = params->sack_freq;
2735
+ trans->param_flags =
2736
+ sctp_spp_sackdelay_enable(trans->param_flags);
2737
+ }
2738
+ }
28232739 }
28242740
28252741 /*
....@@ -2857,104 +2773,84 @@
28572773 * timer to expire. The default value for this is 2, setting this
28582774 * value to 1 will disable the delayed sack algorithm.
28592775 */
2776
+static int __sctp_setsockopt_delayed_ack(struct sock *sk,
2777
+ struct sctp_sack_info *params)
2778
+{
2779
+ struct sctp_sock *sp = sctp_sk(sk);
2780
+ struct sctp_association *asoc;
2781
+
2782
+ /* Validate value parameter. */
2783
+ if (params->sack_delay > 500)
2784
+ return -EINVAL;
2785
+
2786
+ /* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the
2787
+ * socket is a one to many style socket, and an association
2788
+ * was not found, then the id was invalid.
2789
+ */
2790
+ asoc = sctp_id2assoc(sk, params->sack_assoc_id);
2791
+ if (!asoc && params->sack_assoc_id > SCTP_ALL_ASSOC &&
2792
+ sctp_style(sk, UDP))
2793
+ return -EINVAL;
2794
+
2795
+ if (asoc) {
2796
+ sctp_apply_asoc_delayed_ack(params, asoc);
2797
+
2798
+ return 0;
2799
+ }
2800
+
2801
+ if (sctp_style(sk, TCP))
2802
+ params->sack_assoc_id = SCTP_FUTURE_ASSOC;
2803
+
2804
+ if (params->sack_assoc_id == SCTP_FUTURE_ASSOC ||
2805
+ params->sack_assoc_id == SCTP_ALL_ASSOC) {
2806
+ if (params->sack_delay) {
2807
+ sp->sackdelay = params->sack_delay;
2808
+ sp->param_flags =
2809
+ sctp_spp_sackdelay_enable(sp->param_flags);
2810
+ }
2811
+ if (params->sack_freq == 1) {
2812
+ sp->param_flags =
2813
+ sctp_spp_sackdelay_disable(sp->param_flags);
2814
+ } else if (params->sack_freq > 1) {
2815
+ sp->sackfreq = params->sack_freq;
2816
+ sp->param_flags =
2817
+ sctp_spp_sackdelay_enable(sp->param_flags);
2818
+ }
2819
+ }
2820
+
2821
+ if (params->sack_assoc_id == SCTP_CURRENT_ASSOC ||
2822
+ params->sack_assoc_id == SCTP_ALL_ASSOC)
2823
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs)
2824
+ sctp_apply_asoc_delayed_ack(params, asoc);
2825
+
2826
+ return 0;
2827
+}
28602828
28612829 static int sctp_setsockopt_delayed_ack(struct sock *sk,
2862
- char __user *optval, unsigned int optlen)
2830
+ struct sctp_sack_info *params,
2831
+ unsigned int optlen)
28632832 {
2864
- struct sctp_sack_info params;
2865
- struct sctp_transport *trans = NULL;
2866
- struct sctp_association *asoc = NULL;
2867
- struct sctp_sock *sp = sctp_sk(sk);
2833
+ if (optlen == sizeof(struct sctp_assoc_value)) {
2834
+ struct sctp_assoc_value *v = (struct sctp_assoc_value *)params;
2835
+ struct sctp_sack_info p;
28682836
2869
- if (optlen == sizeof(struct sctp_sack_info)) {
2870
- if (copy_from_user(&params, optval, optlen))
2871
- return -EFAULT;
2872
-
2873
- if (params.sack_delay == 0 && params.sack_freq == 0)
2874
- return 0;
2875
- } else if (optlen == sizeof(struct sctp_assoc_value)) {
28762837 pr_warn_ratelimited(DEPRECATED
28772838 "%s (pid %d) "
28782839 "Use of struct sctp_assoc_value in delayed_ack socket option.\n"
28792840 "Use struct sctp_sack_info instead\n",
28802841 current->comm, task_pid_nr(current));
2881
- if (copy_from_user(&params, optval, optlen))
2882
- return -EFAULT;
28832842
2884
- if (params.sack_delay == 0)
2885
- params.sack_freq = 1;
2886
- else
2887
- params.sack_freq = 0;
2888
- } else
2889
- return -EINVAL;
2890
-
2891
- /* Validate value parameter. */
2892
- if (params.sack_delay > 500)
2893
- return -EINVAL;
2894
-
2895
- /* Get association, if sack_assoc_id != 0 and the socket is a one
2896
- * to many style socket, and an association was not found, then
2897
- * the id was invalid.
2898
- */
2899
- asoc = sctp_id2assoc(sk, params.sack_assoc_id);
2900
- if (!asoc && params.sack_assoc_id && sctp_style(sk, UDP))
2901
- return -EINVAL;
2902
-
2903
- if (params.sack_delay) {
2904
- if (asoc) {
2905
- asoc->sackdelay =
2906
- msecs_to_jiffies(params.sack_delay);
2907
- asoc->param_flags =
2908
- sctp_spp_sackdelay_enable(asoc->param_flags);
2909
- } else {
2910
- sp->sackdelay = params.sack_delay;
2911
- sp->param_flags =
2912
- sctp_spp_sackdelay_enable(sp->param_flags);
2913
- }
2843
+ p.sack_assoc_id = v->assoc_id;
2844
+ p.sack_delay = v->assoc_value;
2845
+ p.sack_freq = v->assoc_value ? 0 : 1;
2846
+ return __sctp_setsockopt_delayed_ack(sk, &p);
29142847 }
29152848
2916
- if (params.sack_freq == 1) {
2917
- if (asoc) {
2918
- asoc->param_flags =
2919
- sctp_spp_sackdelay_disable(asoc->param_flags);
2920
- } else {
2921
- sp->param_flags =
2922
- sctp_spp_sackdelay_disable(sp->param_flags);
2923
- }
2924
- } else if (params.sack_freq > 1) {
2925
- if (asoc) {
2926
- asoc->sackfreq = params.sack_freq;
2927
- asoc->param_flags =
2928
- sctp_spp_sackdelay_enable(asoc->param_flags);
2929
- } else {
2930
- sp->sackfreq = params.sack_freq;
2931
- sp->param_flags =
2932
- sctp_spp_sackdelay_enable(sp->param_flags);
2933
- }
2934
- }
2935
-
2936
- /* If change is for association, also apply to each transport. */
2937
- if (asoc) {
2938
- list_for_each_entry(trans, &asoc->peer.transport_addr_list,
2939
- transports) {
2940
- if (params.sack_delay) {
2941
- trans->sackdelay =
2942
- msecs_to_jiffies(params.sack_delay);
2943
- trans->param_flags =
2944
- sctp_spp_sackdelay_enable(trans->param_flags);
2945
- }
2946
- if (params.sack_freq == 1) {
2947
- trans->param_flags =
2948
- sctp_spp_sackdelay_disable(trans->param_flags);
2949
- } else if (params.sack_freq > 1) {
2950
- trans->sackfreq = params.sack_freq;
2951
- trans->param_flags =
2952
- sctp_spp_sackdelay_enable(trans->param_flags);
2953
- }
2954
- }
2955
- }
2956
-
2957
- return 0;
2849
+ if (optlen != sizeof(struct sctp_sack_info))
2850
+ return -EINVAL;
2851
+ if (params->sack_delay == 0 && params->sack_freq == 0)
2852
+ return 0;
2853
+ return __sctp_setsockopt_delayed_ack(sk, params);
29582854 }
29592855
29602856 /* 7.1.3 Initialization Parameters (SCTP_INITMSG)
....@@ -2968,24 +2864,22 @@
29682864 * by the change). With TCP-style sockets, this option is inherited by
29692865 * sockets derived from a listener socket.
29702866 */
2971
-static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, unsigned int optlen)
2867
+static int sctp_setsockopt_initmsg(struct sock *sk, struct sctp_initmsg *sinit,
2868
+ unsigned int optlen)
29722869 {
2973
- struct sctp_initmsg sinit;
29742870 struct sctp_sock *sp = sctp_sk(sk);
29752871
29762872 if (optlen != sizeof(struct sctp_initmsg))
29772873 return -EINVAL;
2978
- if (copy_from_user(&sinit, optval, optlen))
2979
- return -EFAULT;
29802874
2981
- if (sinit.sinit_num_ostreams)
2982
- sp->initmsg.sinit_num_ostreams = sinit.sinit_num_ostreams;
2983
- if (sinit.sinit_max_instreams)
2984
- sp->initmsg.sinit_max_instreams = sinit.sinit_max_instreams;
2985
- if (sinit.sinit_max_attempts)
2986
- sp->initmsg.sinit_max_attempts = sinit.sinit_max_attempts;
2987
- if (sinit.sinit_max_init_timeo)
2988
- sp->initmsg.sinit_max_init_timeo = sinit.sinit_max_init_timeo;
2875
+ if (sinit->sinit_num_ostreams)
2876
+ sp->initmsg.sinit_num_ostreams = sinit->sinit_num_ostreams;
2877
+ if (sinit->sinit_max_instreams)
2878
+ sp->initmsg.sinit_max_instreams = sinit->sinit_max_instreams;
2879
+ if (sinit->sinit_max_attempts)
2880
+ sp->initmsg.sinit_max_attempts = sinit->sinit_max_attempts;
2881
+ if (sinit->sinit_max_init_timeo)
2882
+ sp->initmsg.sinit_max_init_timeo = sinit->sinit_max_init_timeo;
29892883
29902884 return 0;
29912885 }
....@@ -3005,37 +2899,55 @@
30052899 * to this call if the caller is using the UDP model.
30062900 */
30072901 static int sctp_setsockopt_default_send_param(struct sock *sk,
3008
- char __user *optval,
2902
+ struct sctp_sndrcvinfo *info,
30092903 unsigned int optlen)
30102904 {
30112905 struct sctp_sock *sp = sctp_sk(sk);
30122906 struct sctp_association *asoc;
3013
- struct sctp_sndrcvinfo info;
30142907
3015
- if (optlen != sizeof(info))
2908
+ if (optlen != sizeof(*info))
30162909 return -EINVAL;
3017
- if (copy_from_user(&info, optval, optlen))
3018
- return -EFAULT;
3019
- if (info.sinfo_flags &
2910
+ if (info->sinfo_flags &
30202911 ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
30212912 SCTP_ABORT | SCTP_EOF))
30222913 return -EINVAL;
30232914
3024
- asoc = sctp_id2assoc(sk, info.sinfo_assoc_id);
3025
- if (!asoc && info.sinfo_assoc_id && sctp_style(sk, UDP))
2915
+ asoc = sctp_id2assoc(sk, info->sinfo_assoc_id);
2916
+ if (!asoc && info->sinfo_assoc_id > SCTP_ALL_ASSOC &&
2917
+ sctp_style(sk, UDP))
30262918 return -EINVAL;
2919
+
30272920 if (asoc) {
3028
- asoc->default_stream = info.sinfo_stream;
3029
- asoc->default_flags = info.sinfo_flags;
3030
- asoc->default_ppid = info.sinfo_ppid;
3031
- asoc->default_context = info.sinfo_context;
3032
- asoc->default_timetolive = info.sinfo_timetolive;
3033
- } else {
3034
- sp->default_stream = info.sinfo_stream;
3035
- sp->default_flags = info.sinfo_flags;
3036
- sp->default_ppid = info.sinfo_ppid;
3037
- sp->default_context = info.sinfo_context;
3038
- sp->default_timetolive = info.sinfo_timetolive;
2921
+ asoc->default_stream = info->sinfo_stream;
2922
+ asoc->default_flags = info->sinfo_flags;
2923
+ asoc->default_ppid = info->sinfo_ppid;
2924
+ asoc->default_context = info->sinfo_context;
2925
+ asoc->default_timetolive = info->sinfo_timetolive;
2926
+
2927
+ return 0;
2928
+ }
2929
+
2930
+ if (sctp_style(sk, TCP))
2931
+ info->sinfo_assoc_id = SCTP_FUTURE_ASSOC;
2932
+
2933
+ if (info->sinfo_assoc_id == SCTP_FUTURE_ASSOC ||
2934
+ info->sinfo_assoc_id == SCTP_ALL_ASSOC) {
2935
+ sp->default_stream = info->sinfo_stream;
2936
+ sp->default_flags = info->sinfo_flags;
2937
+ sp->default_ppid = info->sinfo_ppid;
2938
+ sp->default_context = info->sinfo_context;
2939
+ sp->default_timetolive = info->sinfo_timetolive;
2940
+ }
2941
+
2942
+ if (info->sinfo_assoc_id == SCTP_CURRENT_ASSOC ||
2943
+ info->sinfo_assoc_id == SCTP_ALL_ASSOC) {
2944
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
2945
+ asoc->default_stream = info->sinfo_stream;
2946
+ asoc->default_flags = info->sinfo_flags;
2947
+ asoc->default_ppid = info->sinfo_ppid;
2948
+ asoc->default_context = info->sinfo_context;
2949
+ asoc->default_timetolive = info->sinfo_timetolive;
2950
+ }
30392951 }
30402952
30412953 return 0;
....@@ -3045,35 +2957,52 @@
30452957 * (SCTP_DEFAULT_SNDINFO)
30462958 */
30472959 static int sctp_setsockopt_default_sndinfo(struct sock *sk,
3048
- char __user *optval,
2960
+ struct sctp_sndinfo *info,
30492961 unsigned int optlen)
30502962 {
30512963 struct sctp_sock *sp = sctp_sk(sk);
30522964 struct sctp_association *asoc;
3053
- struct sctp_sndinfo info;
30542965
3055
- if (optlen != sizeof(info))
2966
+ if (optlen != sizeof(*info))
30562967 return -EINVAL;
3057
- if (copy_from_user(&info, optval, optlen))
3058
- return -EFAULT;
3059
- if (info.snd_flags &
2968
+ if (info->snd_flags &
30602969 ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
30612970 SCTP_ABORT | SCTP_EOF))
30622971 return -EINVAL;
30632972
3064
- asoc = sctp_id2assoc(sk, info.snd_assoc_id);
3065
- if (!asoc && info.snd_assoc_id && sctp_style(sk, UDP))
2973
+ asoc = sctp_id2assoc(sk, info->snd_assoc_id);
2974
+ if (!asoc && info->snd_assoc_id > SCTP_ALL_ASSOC &&
2975
+ sctp_style(sk, UDP))
30662976 return -EINVAL;
2977
+
30672978 if (asoc) {
3068
- asoc->default_stream = info.snd_sid;
3069
- asoc->default_flags = info.snd_flags;
3070
- asoc->default_ppid = info.snd_ppid;
3071
- asoc->default_context = info.snd_context;
3072
- } else {
3073
- sp->default_stream = info.snd_sid;
3074
- sp->default_flags = info.snd_flags;
3075
- sp->default_ppid = info.snd_ppid;
3076
- sp->default_context = info.snd_context;
2979
+ asoc->default_stream = info->snd_sid;
2980
+ asoc->default_flags = info->snd_flags;
2981
+ asoc->default_ppid = info->snd_ppid;
2982
+ asoc->default_context = info->snd_context;
2983
+
2984
+ return 0;
2985
+ }
2986
+
2987
+ if (sctp_style(sk, TCP))
2988
+ info->snd_assoc_id = SCTP_FUTURE_ASSOC;
2989
+
2990
+ if (info->snd_assoc_id == SCTP_FUTURE_ASSOC ||
2991
+ info->snd_assoc_id == SCTP_ALL_ASSOC) {
2992
+ sp->default_stream = info->snd_sid;
2993
+ sp->default_flags = info->snd_flags;
2994
+ sp->default_ppid = info->snd_ppid;
2995
+ sp->default_context = info->snd_context;
2996
+ }
2997
+
2998
+ if (info->snd_assoc_id == SCTP_CURRENT_ASSOC ||
2999
+ info->snd_assoc_id == SCTP_ALL_ASSOC) {
3000
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
3001
+ asoc->default_stream = info->snd_sid;
3002
+ asoc->default_flags = info->snd_flags;
3003
+ asoc->default_ppid = info->snd_ppid;
3004
+ asoc->default_context = info->snd_context;
3005
+ }
30773006 }
30783007
30793008 return 0;
....@@ -3085,10 +3014,9 @@
30853014 * the association primary. The enclosed address must be one of the
30863015 * association peer's addresses.
30873016 */
3088
-static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval,
3017
+static int sctp_setsockopt_primary_addr(struct sock *sk, struct sctp_prim *prim,
30893018 unsigned int optlen)
30903019 {
3091
- struct sctp_prim prim;
30923020 struct sctp_transport *trans;
30933021 struct sctp_af *af;
30943022 int err;
....@@ -3096,21 +3024,18 @@
30963024 if (optlen != sizeof(struct sctp_prim))
30973025 return -EINVAL;
30983026
3099
- if (copy_from_user(&prim, optval, sizeof(struct sctp_prim)))
3100
- return -EFAULT;
3101
-
31023027 /* Allow security module to validate address but need address len. */
3103
- af = sctp_get_af_specific(prim.ssp_addr.ss_family);
3028
+ af = sctp_get_af_specific(prim->ssp_addr.ss_family);
31043029 if (!af)
31053030 return -EINVAL;
31063031
31073032 err = security_sctp_bind_connect(sk, SCTP_PRIMARY_ADDR,
3108
- (struct sockaddr *)&prim.ssp_addr,
3033
+ (struct sockaddr *)&prim->ssp_addr,
31093034 af->sockaddr_len);
31103035 if (err)
31113036 return err;
31123037
3113
- trans = sctp_addr_id2transport(sk, &prim.ssp_addr, prim.ssp_assoc_id);
3038
+ trans = sctp_addr_id2transport(sk, &prim->ssp_addr, prim->ssp_assoc_id);
31143039 if (!trans)
31153040 return -EINVAL;
31163041
....@@ -3127,17 +3052,12 @@
31273052 * introduced, at the cost of more packets in the network. Expects an
31283053 * integer boolean flag.
31293054 */
3130
-static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval,
3055
+static int sctp_setsockopt_nodelay(struct sock *sk, int *val,
31313056 unsigned int optlen)
31323057 {
3133
- int val;
3134
-
31353058 if (optlen < sizeof(int))
31363059 return -EINVAL;
3137
- if (get_user(val, (int __user *)optval))
3138
- return -EFAULT;
3139
-
3140
- sctp_sk(sk)->nodelay = (val == 0) ? 0 : 1;
3060
+ sctp_sk(sk)->nodelay = (*val == 0) ? 0 : 1;
31413061 return 0;
31423062 }
31433063
....@@ -3153,9 +3073,10 @@
31533073 * be changed.
31543074 *
31553075 */
3156
-static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigned int optlen)
3076
+static int sctp_setsockopt_rtoinfo(struct sock *sk,
3077
+ struct sctp_rtoinfo *rtoinfo,
3078
+ unsigned int optlen)
31573079 {
3158
- struct sctp_rtoinfo rtoinfo;
31593080 struct sctp_association *asoc;
31603081 unsigned long rto_min, rto_max;
31613082 struct sctp_sock *sp = sctp_sk(sk);
....@@ -3163,17 +3084,15 @@
31633084 if (optlen != sizeof (struct sctp_rtoinfo))
31643085 return -EINVAL;
31653086
3166
- if (copy_from_user(&rtoinfo, optval, optlen))
3167
- return -EFAULT;
3168
-
3169
- asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id);
3087
+ asoc = sctp_id2assoc(sk, rtoinfo->srto_assoc_id);
31703088
31713089 /* Set the values to the specific association */
3172
- if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP))
3090
+ if (!asoc && rtoinfo->srto_assoc_id != SCTP_FUTURE_ASSOC &&
3091
+ sctp_style(sk, UDP))
31733092 return -EINVAL;
31743093
3175
- rto_max = rtoinfo.srto_max;
3176
- rto_min = rtoinfo.srto_min;
3094
+ rto_max = rtoinfo->srto_max;
3095
+ rto_min = rtoinfo->srto_min;
31773096
31783097 if (rto_max)
31793098 rto_max = asoc ? msecs_to_jiffies(rto_max) : rto_max;
....@@ -3189,17 +3108,17 @@
31893108 return -EINVAL;
31903109
31913110 if (asoc) {
3192
- if (rtoinfo.srto_initial != 0)
3111
+ if (rtoinfo->srto_initial != 0)
31933112 asoc->rto_initial =
3194
- msecs_to_jiffies(rtoinfo.srto_initial);
3113
+ msecs_to_jiffies(rtoinfo->srto_initial);
31953114 asoc->rto_max = rto_max;
31963115 asoc->rto_min = rto_min;
31973116 } else {
31983117 /* If there is no association or the association-id = 0
31993118 * set the values to the endpoint.
32003119 */
3201
- if (rtoinfo.srto_initial != 0)
3202
- sp->rtoinfo.srto_initial = rtoinfo.srto_initial;
3120
+ if (rtoinfo->srto_initial != 0)
3121
+ sp->rtoinfo.srto_initial = rtoinfo->srto_initial;
32033122 sp->rtoinfo.srto_max = rto_max;
32043123 sp->rtoinfo.srto_min = rto_min;
32053124 }
....@@ -3218,25 +3137,25 @@
32183137 * See [SCTP] for more information.
32193138 *
32203139 */
3221
-static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, unsigned int optlen)
3140
+static int sctp_setsockopt_associnfo(struct sock *sk,
3141
+ struct sctp_assocparams *assocparams,
3142
+ unsigned int optlen)
32223143 {
32233144
3224
- struct sctp_assocparams assocparams;
32253145 struct sctp_association *asoc;
32263146
32273147 if (optlen != sizeof(struct sctp_assocparams))
32283148 return -EINVAL;
3229
- if (copy_from_user(&assocparams, optval, optlen))
3230
- return -EFAULT;
32313149
3232
- asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id);
3150
+ asoc = sctp_id2assoc(sk, assocparams->sasoc_assoc_id);
32333151
3234
- if (!asoc && assocparams.sasoc_assoc_id && sctp_style(sk, UDP))
3152
+ if (!asoc && assocparams->sasoc_assoc_id != SCTP_FUTURE_ASSOC &&
3153
+ sctp_style(sk, UDP))
32353154 return -EINVAL;
32363155
32373156 /* Set the values to the specific association */
32383157 if (asoc) {
3239
- if (assocparams.sasoc_asocmaxrxt != 0) {
3158
+ if (assocparams->sasoc_asocmaxrxt != 0) {
32403159 __u32 path_sum = 0;
32413160 int paths = 0;
32423161 struct sctp_transport *peer_addr;
....@@ -3253,24 +3172,25 @@
32533172 * then one path.
32543173 */
32553174 if (paths > 1 &&
3256
- assocparams.sasoc_asocmaxrxt > path_sum)
3175
+ assocparams->sasoc_asocmaxrxt > path_sum)
32573176 return -EINVAL;
32583177
3259
- asoc->max_retrans = assocparams.sasoc_asocmaxrxt;
3178
+ asoc->max_retrans = assocparams->sasoc_asocmaxrxt;
32603179 }
32613180
3262
- if (assocparams.sasoc_cookie_life != 0)
3263
- asoc->cookie_life = ms_to_ktime(assocparams.sasoc_cookie_life);
3181
+ if (assocparams->sasoc_cookie_life != 0)
3182
+ asoc->cookie_life =
3183
+ ms_to_ktime(assocparams->sasoc_cookie_life);
32643184 } else {
32653185 /* Set the values to the endpoint */
32663186 struct sctp_sock *sp = sctp_sk(sk);
32673187
3268
- if (assocparams.sasoc_asocmaxrxt != 0)
3188
+ if (assocparams->sasoc_asocmaxrxt != 0)
32693189 sp->assocparams.sasoc_asocmaxrxt =
3270
- assocparams.sasoc_asocmaxrxt;
3271
- if (assocparams.sasoc_cookie_life != 0)
3190
+ assocparams->sasoc_asocmaxrxt;
3191
+ if (assocparams->sasoc_cookie_life != 0)
32723192 sp->assocparams.sasoc_cookie_life =
3273
- assocparams.sasoc_cookie_life;
3193
+ assocparams->sasoc_cookie_life;
32743194 }
32753195 return 0;
32763196 }
....@@ -3285,16 +3205,14 @@
32853205 * addresses and a user will receive both PF_INET6 and PF_INET type
32863206 * addresses on the socket.
32873207 */
3288
-static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, unsigned int optlen)
3208
+static int sctp_setsockopt_mappedv4(struct sock *sk, int *val,
3209
+ unsigned int optlen)
32893210 {
3290
- int val;
32913211 struct sctp_sock *sp = sctp_sk(sk);
32923212
32933213 if (optlen < sizeof(int))
32943214 return -EINVAL;
3295
- if (get_user(val, (int __user *)optval))
3296
- return -EFAULT;
3297
- if (val)
3215
+ if (*val)
32983216 sp->v4mapped = 1;
32993217 else
33003218 sp->v4mapped = 0;
....@@ -3329,11 +3247,13 @@
33293247 * changed (effecting future associations only).
33303248 * assoc_value: This parameter specifies the maximum size in bytes.
33313249 */
3332
-static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned int optlen)
3250
+static int sctp_setsockopt_maxseg(struct sock *sk,
3251
+ struct sctp_assoc_value *params,
3252
+ unsigned int optlen)
33333253 {
33343254 struct sctp_sock *sp = sctp_sk(sk);
3335
- struct sctp_assoc_value params;
33363255 struct sctp_association *asoc;
3256
+ sctp_assoc_t assoc_id;
33373257 int val;
33383258
33393259 if (optlen == sizeof(int)) {
....@@ -3342,18 +3262,19 @@
33423262 "Use of int in maxseg socket option.\n"
33433263 "Use struct sctp_assoc_value instead\n",
33443264 current->comm, task_pid_nr(current));
3345
- if (copy_from_user(&val, optval, optlen))
3346
- return -EFAULT;
3347
- params.assoc_id = 0;
3265
+ assoc_id = SCTP_FUTURE_ASSOC;
3266
+ val = *(int *)params;
33483267 } else if (optlen == sizeof(struct sctp_assoc_value)) {
3349
- if (copy_from_user(&params, optval, optlen))
3350
- return -EFAULT;
3351
- val = params.assoc_value;
3268
+ assoc_id = params->assoc_id;
3269
+ val = params->assoc_value;
33523270 } else {
33533271 return -EINVAL;
33543272 }
33553273
3356
- asoc = sctp_id2assoc(sk, params.assoc_id);
3274
+ asoc = sctp_id2assoc(sk, assoc_id);
3275
+ if (!asoc && assoc_id != SCTP_FUTURE_ASSOC &&
3276
+ sctp_style(sk, UDP))
3277
+ return -EINVAL;
33573278
33583279 if (val) {
33593280 int min_len, max_len;
....@@ -3371,8 +3292,6 @@
33713292 asoc->user_frag = val;
33723293 sctp_assoc_update_frag_point(asoc);
33733294 } else {
3374
- if (params.assoc_id && sctp_style(sk, UDP))
3375
- return -EINVAL;
33763295 sp->user_frag = val;
33773296 }
33783297
....@@ -3388,29 +3307,25 @@
33883307 * locally bound addresses. The following structure is used to make a
33893308 * set primary request:
33903309 */
3391
-static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval,
3310
+static int sctp_setsockopt_peer_primary_addr(struct sock *sk,
3311
+ struct sctp_setpeerprim *prim,
33923312 unsigned int optlen)
33933313 {
3394
- struct net *net = sock_net(sk);
33953314 struct sctp_sock *sp;
33963315 struct sctp_association *asoc = NULL;
3397
- struct sctp_setpeerprim prim;
33983316 struct sctp_chunk *chunk;
33993317 struct sctp_af *af;
34003318 int err;
34013319
34023320 sp = sctp_sk(sk);
34033321
3404
- if (!net->sctp.addip_enable)
3322
+ if (!sp->ep->asconf_enable)
34053323 return -EPERM;
34063324
34073325 if (optlen != sizeof(struct sctp_setpeerprim))
34083326 return -EINVAL;
34093327
3410
- if (copy_from_user(&prim, optval, optlen))
3411
- return -EFAULT;
3412
-
3413
- asoc = sctp_id2assoc(sk, prim.sspp_assoc_id);
3328
+ asoc = sctp_id2assoc(sk, prim->sspp_assoc_id);
34143329 if (!asoc)
34153330 return -EINVAL;
34163331
....@@ -3423,26 +3338,26 @@
34233338 if (!sctp_state(asoc, ESTABLISHED))
34243339 return -ENOTCONN;
34253340
3426
- af = sctp_get_af_specific(prim.sspp_addr.ss_family);
3341
+ af = sctp_get_af_specific(prim->sspp_addr.ss_family);
34273342 if (!af)
34283343 return -EINVAL;
34293344
3430
- if (!af->addr_valid((union sctp_addr *)&prim.sspp_addr, sp, NULL))
3345
+ if (!af->addr_valid((union sctp_addr *)&prim->sspp_addr, sp, NULL))
34313346 return -EADDRNOTAVAIL;
34323347
3433
- if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim.sspp_addr))
3348
+ if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim->sspp_addr))
34343349 return -EADDRNOTAVAIL;
34353350
34363351 /* Allow security module to validate address. */
34373352 err = security_sctp_bind_connect(sk, SCTP_SET_PEER_PRIMARY_ADDR,
3438
- (struct sockaddr *)&prim.sspp_addr,
3353
+ (struct sockaddr *)&prim->sspp_addr,
34393354 af->sockaddr_len);
34403355 if (err)
34413356 return err;
34423357
34433358 /* Create an ASCONF chunk with SET_PRIMARY parameter */
34443359 chunk = sctp_make_asconf_set_prim(asoc,
3445
- (union sctp_addr *)&prim.sspp_addr);
3360
+ (union sctp_addr *)&prim->sspp_addr);
34463361 if (!chunk)
34473362 return -ENOMEM;
34483363
....@@ -3453,17 +3368,14 @@
34533368 return err;
34543369 }
34553370
3456
-static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval,
3371
+static int sctp_setsockopt_adaptation_layer(struct sock *sk,
3372
+ struct sctp_setadaptation *adapt,
34573373 unsigned int optlen)
34583374 {
3459
- struct sctp_setadaptation adaptation;
3460
-
34613375 if (optlen != sizeof(struct sctp_setadaptation))
34623376 return -EINVAL;
3463
- if (copy_from_user(&adaptation, optval, optlen))
3464
- return -EFAULT;
34653377
3466
- sctp_sk(sk)->adaptation_ind = adaptation.ssb_adaptation_ind;
3378
+ sctp_sk(sk)->adaptation_ind = adapt->ssb_adaptation_ind;
34673379
34683380 return 0;
34693381 }
....@@ -3482,28 +3394,38 @@
34823394 * received messages from the peer and does not effect the value that is
34833395 * saved with outbound messages.
34843396 */
3485
-static int sctp_setsockopt_context(struct sock *sk, char __user *optval,
3397
+static int sctp_setsockopt_context(struct sock *sk,
3398
+ struct sctp_assoc_value *params,
34863399 unsigned int optlen)
34873400 {
3488
- struct sctp_assoc_value params;
3489
- struct sctp_sock *sp;
3401
+ struct sctp_sock *sp = sctp_sk(sk);
34903402 struct sctp_association *asoc;
34913403
34923404 if (optlen != sizeof(struct sctp_assoc_value))
34933405 return -EINVAL;
3494
- if (copy_from_user(&params, optval, optlen))
3495
- return -EFAULT;
34963406
3497
- sp = sctp_sk(sk);
3407
+ asoc = sctp_id2assoc(sk, params->assoc_id);
3408
+ if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
3409
+ sctp_style(sk, UDP))
3410
+ return -EINVAL;
34983411
3499
- if (params.assoc_id != 0) {
3500
- asoc = sctp_id2assoc(sk, params.assoc_id);
3501
- if (!asoc)
3502
- return -EINVAL;
3503
- asoc->default_rcv_context = params.assoc_value;
3504
- } else {
3505
- sp->default_rcv_context = params.assoc_value;
3412
+ if (asoc) {
3413
+ asoc->default_rcv_context = params->assoc_value;
3414
+
3415
+ return 0;
35063416 }
3417
+
3418
+ if (sctp_style(sk, TCP))
3419
+ params->assoc_id = SCTP_FUTURE_ASSOC;
3420
+
3421
+ if (params->assoc_id == SCTP_FUTURE_ASSOC ||
3422
+ params->assoc_id == SCTP_ALL_ASSOC)
3423
+ sp->default_rcv_context = params->assoc_value;
3424
+
3425
+ if (params->assoc_id == SCTP_CURRENT_ASSOC ||
3426
+ params->assoc_id == SCTP_ALL_ASSOC)
3427
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs)
3428
+ asoc->default_rcv_context = params->assoc_value;
35073429
35083430 return 0;
35093431 }
....@@ -3532,21 +3454,16 @@
35323454 * application using the one to many model may become confused and act
35333455 * incorrectly.
35343456 */
3535
-static int sctp_setsockopt_fragment_interleave(struct sock *sk,
3536
- char __user *optval,
3457
+static int sctp_setsockopt_fragment_interleave(struct sock *sk, int *val,
35373458 unsigned int optlen)
35383459 {
3539
- int val;
3540
-
35413460 if (optlen != sizeof(int))
35423461 return -EINVAL;
3543
- if (get_user(val, (int __user *)optval))
3544
- return -EFAULT;
35453462
3546
- sctp_sk(sk)->frag_interleave = !!val;
3463
+ sctp_sk(sk)->frag_interleave = !!*val;
35473464
35483465 if (!sctp_sk(sk)->frag_interleave)
3549
- sctp_sk(sk)->strm_interleave = 0;
3466
+ sctp_sk(sk)->ep->intl_enable = 0;
35503467
35513468 return 0;
35523469 }
....@@ -3568,24 +3485,19 @@
35683485 * call as long as the user provided buffer is large enough to hold the
35693486 * message.
35703487 */
3571
-static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
3572
- char __user *optval,
3488
+static int sctp_setsockopt_partial_delivery_point(struct sock *sk, u32 *val,
35733489 unsigned int optlen)
35743490 {
3575
- u32 val;
3576
-
35773491 if (optlen != sizeof(u32))
35783492 return -EINVAL;
3579
- if (get_user(val, (int __user *)optval))
3580
- return -EFAULT;
35813493
35823494 /* Note: We double the receive buffer from what the user sets
35833495 * it to be, also initial rwnd is based on rcvbuf/2.
35843496 */
3585
- if (val > (sk->sk_rcvbuf >> 1))
3497
+ if (*val > (sk->sk_rcvbuf >> 1))
35863498 return -EINVAL;
35873499
3588
- sctp_sk(sk)->pd_point = val;
3500
+ sctp_sk(sk)->pd_point = *val;
35893501
35903502 return 0; /* is this the right error code? */
35913503 }
....@@ -3602,14 +3514,13 @@
36023514 * future associations inheriting the socket value.
36033515 */
36043516 static int sctp_setsockopt_maxburst(struct sock *sk,
3605
- char __user *optval,
3517
+ struct sctp_assoc_value *params,
36063518 unsigned int optlen)
36073519 {
3608
- struct sctp_assoc_value params;
3609
- struct sctp_sock *sp;
3520
+ struct sctp_sock *sp = sctp_sk(sk);
36103521 struct sctp_association *asoc;
3611
- int val;
3612
- int assoc_id = 0;
3522
+ sctp_assoc_t assoc_id;
3523
+ u32 assoc_value;
36133524
36143525 if (optlen == sizeof(int)) {
36153526 pr_warn_ratelimited(DEPRECATED
....@@ -3617,25 +3528,33 @@
36173528 "Use of int in max_burst socket option deprecated.\n"
36183529 "Use struct sctp_assoc_value instead\n",
36193530 current->comm, task_pid_nr(current));
3620
- if (copy_from_user(&val, optval, optlen))
3621
- return -EFAULT;
3531
+ assoc_id = SCTP_FUTURE_ASSOC;
3532
+ assoc_value = *((int *)params);
36223533 } else if (optlen == sizeof(struct sctp_assoc_value)) {
3623
- if (copy_from_user(&params, optval, optlen))
3624
- return -EFAULT;
3625
- val = params.assoc_value;
3626
- assoc_id = params.assoc_id;
3534
+ assoc_id = params->assoc_id;
3535
+ assoc_value = params->assoc_value;
36273536 } else
36283537 return -EINVAL;
36293538
3630
- sp = sctp_sk(sk);
3539
+ asoc = sctp_id2assoc(sk, assoc_id);
3540
+ if (!asoc && assoc_id > SCTP_ALL_ASSOC && sctp_style(sk, UDP))
3541
+ return -EINVAL;
36313542
3632
- if (assoc_id != 0) {
3633
- asoc = sctp_id2assoc(sk, assoc_id);
3634
- if (!asoc)
3635
- return -EINVAL;
3636
- asoc->max_burst = val;
3637
- } else
3638
- sp->max_burst = val;
3543
+ if (asoc) {
3544
+ asoc->max_burst = assoc_value;
3545
+
3546
+ return 0;
3547
+ }
3548
+
3549
+ if (sctp_style(sk, TCP))
3550
+ assoc_id = SCTP_FUTURE_ASSOC;
3551
+
3552
+ if (assoc_id == SCTP_FUTURE_ASSOC || assoc_id == SCTP_ALL_ASSOC)
3553
+ sp->max_burst = assoc_value;
3554
+
3555
+ if (assoc_id == SCTP_CURRENT_ASSOC || assoc_id == SCTP_ALL_ASSOC)
3556
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs)
3557
+ asoc->max_burst = assoc_value;
36393558
36403559 return 0;
36413560 }
....@@ -3648,21 +3567,18 @@
36483567 * will only effect future associations on the socket.
36493568 */
36503569 static int sctp_setsockopt_auth_chunk(struct sock *sk,
3651
- char __user *optval,
3570
+ struct sctp_authchunk *val,
36523571 unsigned int optlen)
36533572 {
36543573 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3655
- struct sctp_authchunk val;
36563574
36573575 if (!ep->auth_enable)
36583576 return -EACCES;
36593577
36603578 if (optlen != sizeof(struct sctp_authchunk))
36613579 return -EINVAL;
3662
- if (copy_from_user(&val, optval, optlen))
3663
- return -EFAULT;
36643580
3665
- switch (val.sauth_chunk) {
3581
+ switch (val->sauth_chunk) {
36663582 case SCTP_CID_INIT:
36673583 case SCTP_CID_INIT_ACK:
36683584 case SCTP_CID_SHUTDOWN_COMPLETE:
....@@ -3671,7 +3587,7 @@
36713587 }
36723588
36733589 /* add this chunk id to the endpoint */
3674
- return sctp_auth_ep_add_chunkid(ep, val.sauth_chunk);
3590
+ return sctp_auth_ep_add_chunkid(ep, val->sauth_chunk);
36753591 }
36763592
36773593 /*
....@@ -3681,13 +3597,11 @@
36813597 * endpoint requires the peer to use.
36823598 */
36833599 static int sctp_setsockopt_hmac_ident(struct sock *sk,
3684
- char __user *optval,
3600
+ struct sctp_hmacalgo *hmacs,
36853601 unsigned int optlen)
36863602 {
36873603 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3688
- struct sctp_hmacalgo *hmacs;
36893604 u32 idents;
3690
- int err;
36913605
36923606 if (!ep->auth_enable)
36933607 return -EACCES;
....@@ -3697,21 +3611,12 @@
36973611 optlen = min_t(unsigned int, optlen, sizeof(struct sctp_hmacalgo) +
36983612 SCTP_AUTH_NUM_HMACS * sizeof(u16));
36993613
3700
- hmacs = memdup_user(optval, optlen);
3701
- if (IS_ERR(hmacs))
3702
- return PTR_ERR(hmacs);
3703
-
37043614 idents = hmacs->shmac_num_idents;
37053615 if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS ||
3706
- (idents * sizeof(u16)) > (optlen - sizeof(struct sctp_hmacalgo))) {
3707
- err = -EINVAL;
3708
- goto out;
3709
- }
3616
+ (idents * sizeof(u16)) > (optlen - sizeof(struct sctp_hmacalgo)))
3617
+ return -EINVAL;
37103618
3711
- err = sctp_auth_ep_set_hmacs(ep, hmacs);
3712
-out:
3713
- kfree(hmacs);
3714
- return err;
3619
+ return sctp_auth_ep_set_hmacs(ep, hmacs);
37153620 }
37163621
37173622 /*
....@@ -3721,43 +3626,57 @@
37213626 * association shared key.
37223627 */
37233628 static int sctp_setsockopt_auth_key(struct sock *sk,
3724
- char __user *optval,
3629
+ struct sctp_authkey *authkey,
37253630 unsigned int optlen)
37263631 {
37273632 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3728
- struct sctp_authkey *authkey;
37293633 struct sctp_association *asoc;
3730
- int ret;
3731
-
3732
- if (!ep->auth_enable)
3733
- return -EACCES;
3634
+ int ret = -EINVAL;
37343635
37353636 if (optlen <= sizeof(struct sctp_authkey))
37363637 return -EINVAL;
37373638 /* authkey->sca_keylength is u16, so optlen can't be bigger than
37383639 * this.
37393640 */
3740
- optlen = min_t(unsigned int, optlen, USHRT_MAX +
3741
- sizeof(struct sctp_authkey));
3641
+ optlen = min_t(unsigned int, optlen, USHRT_MAX + sizeof(*authkey));
37423642
3743
- authkey = memdup_user(optval, optlen);
3744
- if (IS_ERR(authkey))
3745
- return PTR_ERR(authkey);
3746
-
3747
- if (authkey->sca_keylength > optlen - sizeof(struct sctp_authkey)) {
3748
- ret = -EINVAL;
3643
+ if (authkey->sca_keylength > optlen - sizeof(*authkey))
37493644 goto out;
3750
- }
37513645
37523646 asoc = sctp_id2assoc(sk, authkey->sca_assoc_id);
3753
- if (!asoc && authkey->sca_assoc_id && sctp_style(sk, UDP)) {
3754
- ret = -EINVAL;
3647
+ if (!asoc && authkey->sca_assoc_id > SCTP_ALL_ASSOC &&
3648
+ sctp_style(sk, UDP))
3649
+ goto out;
3650
+
3651
+ if (asoc) {
3652
+ ret = sctp_auth_set_key(ep, asoc, authkey);
37553653 goto out;
37563654 }
37573655
3758
- ret = sctp_auth_set_key(ep, asoc, authkey);
3656
+ if (sctp_style(sk, TCP))
3657
+ authkey->sca_assoc_id = SCTP_FUTURE_ASSOC;
3658
+
3659
+ if (authkey->sca_assoc_id == SCTP_FUTURE_ASSOC ||
3660
+ authkey->sca_assoc_id == SCTP_ALL_ASSOC) {
3661
+ ret = sctp_auth_set_key(ep, asoc, authkey);
3662
+ if (ret)
3663
+ goto out;
3664
+ }
3665
+
3666
+ ret = 0;
3667
+
3668
+ if (authkey->sca_assoc_id == SCTP_CURRENT_ASSOC ||
3669
+ authkey->sca_assoc_id == SCTP_ALL_ASSOC) {
3670
+ list_for_each_entry(asoc, &ep->asocs, asocs) {
3671
+ int res = sctp_auth_set_key(ep, asoc, authkey);
3672
+
3673
+ if (res && !ret)
3674
+ ret = res;
3675
+ }
3676
+ }
3677
+
37593678 out:
3760
- kzfree(authkey);
3679
+ memzero_explicit(authkey, optlen);
37613680 return ret;
37623681 }
37633682
....@@ -3768,26 +3687,46 @@
37683687 * the association shared key.
37693688 */
37703689 static int sctp_setsockopt_active_key(struct sock *sk,
3771
- char __user *optval,
3690
+ struct sctp_authkeyid *val,
37723691 unsigned int optlen)
37733692 {
37743693 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3775
- struct sctp_authkeyid val;
37763694 struct sctp_association *asoc;
3777
-
3778
- if (!ep->auth_enable)
3779
- return -EACCES;
3695
+ int ret = 0;
37803696
37813697 if (optlen != sizeof(struct sctp_authkeyid))
37823698 return -EINVAL;
3783
- if (copy_from_user(&val, optval, optlen))
3784
- return -EFAULT;
37853699
3786
- asoc = sctp_id2assoc(sk, val.scact_assoc_id);
3787
- if (!asoc && val.scact_assoc_id && sctp_style(sk, UDP))
3700
+ asoc = sctp_id2assoc(sk, val->scact_assoc_id);
3701
+ if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
3702
+ sctp_style(sk, UDP))
37883703 return -EINVAL;
37893704
3790
- return sctp_auth_set_active_key(ep, asoc, val.scact_keynumber);
3705
+ if (asoc)
3706
+ return sctp_auth_set_active_key(ep, asoc, val->scact_keynumber);
3707
+
3708
+ if (sctp_style(sk, TCP))
3709
+ val->scact_assoc_id = SCTP_FUTURE_ASSOC;
3710
+
3711
+ if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
3712
+ val->scact_assoc_id == SCTP_ALL_ASSOC) {
3713
+ ret = sctp_auth_set_active_key(ep, asoc, val->scact_keynumber);
3714
+ if (ret)
3715
+ return ret;
3716
+ }
3717
+
3718
+ if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
3719
+ val->scact_assoc_id == SCTP_ALL_ASSOC) {
3720
+ list_for_each_entry(asoc, &ep->asocs, asocs) {
3721
+ int res = sctp_auth_set_active_key(ep, asoc,
3722
+ val->scact_keynumber);
3723
+
3724
+ if (res && !ret)
3725
+ ret = res;
3726
+ }
3727
+ }
3728
+
3729
+ return ret;
37913730 }
37923731
37933732 /*
....@@ -3796,27 +3735,46 @@
37963735 * This set option will delete a shared secret key from use.
37973736 */
37983737 static int sctp_setsockopt_del_key(struct sock *sk,
3799
- char __user *optval,
3738
+ struct sctp_authkeyid *val,
38003739 unsigned int optlen)
38013740 {
38023741 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3803
- struct sctp_authkeyid val;
38043742 struct sctp_association *asoc;
3805
-
3806
- if (!ep->auth_enable)
3807
- return -EACCES;
3743
+ int ret = 0;
38083744
38093745 if (optlen != sizeof(struct sctp_authkeyid))
38103746 return -EINVAL;
3811
- if (copy_from_user(&val, optval, optlen))
3812
- return -EFAULT;
38133747
3814
- asoc = sctp_id2assoc(sk, val.scact_assoc_id);
3815
- if (!asoc && val.scact_assoc_id && sctp_style(sk, UDP))
3748
+ asoc = sctp_id2assoc(sk, val->scact_assoc_id);
3749
+ if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
3750
+ sctp_style(sk, UDP))
38163751 return -EINVAL;
38173752
3818
- return sctp_auth_del_key_id(ep, asoc, val.scact_keynumber);
3753
+ if (asoc)
3754
+ return sctp_auth_del_key_id(ep, asoc, val->scact_keynumber);
38193755
3756
+ if (sctp_style(sk, TCP))
3757
+ val->scact_assoc_id = SCTP_FUTURE_ASSOC;
3758
+
3759
+ if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
3760
+ val->scact_assoc_id == SCTP_ALL_ASSOC) {
3761
+ ret = sctp_auth_del_key_id(ep, asoc, val->scact_keynumber);
3762
+ if (ret)
3763
+ return ret;
3764
+ }
3765
+
3766
+ if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
3767
+ val->scact_assoc_id == SCTP_ALL_ASSOC) {
3768
+ list_for_each_entry(asoc, &ep->asocs, asocs) {
3769
+ int res = sctp_auth_del_key_id(ep, asoc,
3770
+ val->scact_keynumber);
3771
+
3772
+ if (res && !ret)
3773
+ ret = res;
3774
+ }
3775
+ }
3776
+
3777
+ return ret;
38203778 }
38213779
38223780 /*
....@@ -3824,26 +3782,47 @@
38243782 *
38253783 * This set option will deactivate a shared secret key.
38263784 */
3827
-static int sctp_setsockopt_deactivate_key(struct sock *sk, char __user *optval,
3785
+static int sctp_setsockopt_deactivate_key(struct sock *sk,
3786
+ struct sctp_authkeyid *val,
38283787 unsigned int optlen)
38293788 {
38303789 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3831
- struct sctp_authkeyid val;
38323790 struct sctp_association *asoc;
3833
-
3834
- if (!ep->auth_enable)
3835
- return -EACCES;
3791
+ int ret = 0;
38363792
38373793 if (optlen != sizeof(struct sctp_authkeyid))
38383794 return -EINVAL;
3839
- if (copy_from_user(&val, optval, optlen))
3840
- return -EFAULT;
38413795
3842
- asoc = sctp_id2assoc(sk, val.scact_assoc_id);
3843
- if (!asoc && val.scact_assoc_id && sctp_style(sk, UDP))
3796
+ asoc = sctp_id2assoc(sk, val->scact_assoc_id);
3797
+ if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
3798
+ sctp_style(sk, UDP))
38443799 return -EINVAL;
38453800
3846
- return sctp_auth_deact_key_id(ep, asoc, val.scact_keynumber);
3801
+ if (asoc)
3802
+ return sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber);
3803
+
3804
+ if (sctp_style(sk, TCP))
3805
+ val->scact_assoc_id = SCTP_FUTURE_ASSOC;
3806
+
3807
+ if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
3808
+ val->scact_assoc_id == SCTP_ALL_ASSOC) {
3809
+ ret = sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber);
3810
+ if (ret)
3811
+ return ret;
3812
+ }
3813
+
3814
+ if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
3815
+ val->scact_assoc_id == SCTP_ALL_ASSOC) {
3816
+ list_for_each_entry(asoc, &ep->asocs, asocs) {
3817
+ int res = sctp_auth_deact_key_id(ep, asoc,
3818
+ val->scact_keynumber);
3819
+
3820
+ if (res && !ret)
3821
+ ret = res;
3822
+ }
3823
+ }
3824
+
3825
+ return ret;
38473826 }
38483827
38493828 /*
....@@ -3860,26 +3839,23 @@
38603839 * Note. In this implementation, socket operation overrides default parameter
38613840 * being set by sysctl as well as FreeBSD implementation
38623841 */
3863
-static int sctp_setsockopt_auto_asconf(struct sock *sk, char __user *optval,
3842
+static int sctp_setsockopt_auto_asconf(struct sock *sk, int *val,
38643843 unsigned int optlen)
38653844 {
3866
- int val;
38673845 struct sctp_sock *sp = sctp_sk(sk);
38683846
38693847 if (optlen < sizeof(int))
38703848 return -EINVAL;
3871
- if (get_user(val, (int __user *)optval))
3872
- return -EFAULT;
3873
- if (!sctp_is_ep_boundall(sk) && val)
3849
+ if (!sctp_is_ep_boundall(sk) && *val)
38743850 return -EINVAL;
3875
- if ((val && sp->do_auto_asconf) || (!val && !sp->do_auto_asconf))
3851
+ if ((*val && sp->do_auto_asconf) || (!*val && !sp->do_auto_asconf))
38763852 return 0;
38773853
38783854 spin_lock_bh(&sock_net(sk)->sctp.addr_wq_lock);
3879
- if (val == 0 && sp->do_auto_asconf) {
3855
+ if (*val == 0 && sp->do_auto_asconf) {
38803856 list_del(&sp->auto_asconf_list);
38813857 sp->do_auto_asconf = 0;
3882
- } else if (val && !sp->do_auto_asconf) {
3858
+ } else if (*val && !sp->do_auto_asconf) {
38833859 list_add_tail(&sp->auto_asconf_list,
38843860 &sock_net(sk)->sctp.auto_asconf_splist);
38853861 sp->do_auto_asconf = 1;
....@@ -3896,164 +3872,177 @@
38963872 * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
38973873 */
38983874 static int sctp_setsockopt_paddr_thresholds(struct sock *sk,
3899
- char __user *optval,
3900
- unsigned int optlen)
3875
+ struct sctp_paddrthlds_v2 *val,
3876
+ unsigned int optlen, bool v2)
39013877 {
3902
- struct sctp_paddrthlds val;
39033878 struct sctp_transport *trans;
39043879 struct sctp_association *asoc;
3880
+ int len;
39053881
3906
- if (optlen < sizeof(struct sctp_paddrthlds))
3882
+ len = v2 ? sizeof(*val) : sizeof(struct sctp_paddrthlds);
3883
+ if (optlen < len)
39073884 return -EINVAL;
3908
- if (copy_from_user(&val, (struct sctp_paddrthlds __user *)optval,
3909
- sizeof(struct sctp_paddrthlds)))
3910
- return -EFAULT;
39113885
3886
+ if (v2 && val->spt_pathpfthld > val->spt_pathcpthld)
3887
+ return -EINVAL;
39123888
3913
- if (sctp_is_any(sk, (const union sctp_addr *)&val.spt_address)) {
3914
- asoc = sctp_id2assoc(sk, val.spt_assoc_id);
3915
- if (!asoc)
3916
- return -ENOENT;
3917
- list_for_each_entry(trans, &asoc->peer.transport_addr_list,
3918
- transports) {
3919
- if (val.spt_pathmaxrxt)
3920
- trans->pathmaxrxt = val.spt_pathmaxrxt;
3921
- trans->pf_retrans = val.spt_pathpfthld;
3922
- }
3923
-
3924
- if (val.spt_pathmaxrxt)
3925
- asoc->pathmaxrxt = val.spt_pathmaxrxt;
3926
- asoc->pf_retrans = val.spt_pathpfthld;
3927
- } else {
3928
- trans = sctp_addr_id2transport(sk, &val.spt_address,
3929
- val.spt_assoc_id);
3889
+ if (!sctp_is_any(sk, (const union sctp_addr *)&val->spt_address)) {
3890
+ trans = sctp_addr_id2transport(sk, &val->spt_address,
3891
+ val->spt_assoc_id);
39303892 if (!trans)
39313893 return -ENOENT;
39323894
3933
- if (val.spt_pathmaxrxt)
3934
- trans->pathmaxrxt = val.spt_pathmaxrxt;
3935
- trans->pf_retrans = val.spt_pathpfthld;
3895
+ if (val->spt_pathmaxrxt)
3896
+ trans->pathmaxrxt = val->spt_pathmaxrxt;
3897
+ if (v2)
3898
+ trans->ps_retrans = val->spt_pathcpthld;
3899
+ trans->pf_retrans = val->spt_pathpfthld;
3900
+
3901
+ return 0;
3902
+ }
3903
+
3904
+ asoc = sctp_id2assoc(sk, val->spt_assoc_id);
3905
+ if (!asoc && val->spt_assoc_id != SCTP_FUTURE_ASSOC &&
3906
+ sctp_style(sk, UDP))
3907
+ return -EINVAL;
3908
+
3909
+ if (asoc) {
3910
+ list_for_each_entry(trans, &asoc->peer.transport_addr_list,
3911
+ transports) {
3912
+ if (val->spt_pathmaxrxt)
3913
+ trans->pathmaxrxt = val->spt_pathmaxrxt;
3914
+ if (v2)
3915
+ trans->ps_retrans = val->spt_pathcpthld;
3916
+ trans->pf_retrans = val->spt_pathpfthld;
3917
+ }
3918
+
3919
+ if (val->spt_pathmaxrxt)
3920
+ asoc->pathmaxrxt = val->spt_pathmaxrxt;
3921
+ if (v2)
3922
+ asoc->ps_retrans = val->spt_pathcpthld;
3923
+ asoc->pf_retrans = val->spt_pathpfthld;
3924
+ } else {
3925
+ struct sctp_sock *sp = sctp_sk(sk);
3926
+
3927
+ if (val->spt_pathmaxrxt)
3928
+ sp->pathmaxrxt = val->spt_pathmaxrxt;
3929
+ if (v2)
3930
+ sp->ps_retrans = val->spt_pathcpthld;
3931
+ sp->pf_retrans = val->spt_pathpfthld;
39363932 }
39373933
39383934 return 0;
39393935 }
39403936
3941
-static int sctp_setsockopt_recvrcvinfo(struct sock *sk,
3942
- char __user *optval,
3937
+static int sctp_setsockopt_recvrcvinfo(struct sock *sk, int *val,
39433938 unsigned int optlen)
39443939 {
3945
- int val;
3946
-
39473940 if (optlen < sizeof(int))
39483941 return -EINVAL;
3949
- if (get_user(val, (int __user *) optval))
3950
- return -EFAULT;
39513942
3952
- sctp_sk(sk)->recvrcvinfo = (val == 0) ? 0 : 1;
3943
+ sctp_sk(sk)->recvrcvinfo = (*val == 0) ? 0 : 1;
39533944
39543945 return 0;
39553946 }
39563947
3957
-static int sctp_setsockopt_recvnxtinfo(struct sock *sk,
3958
- char __user *optval,
3948
+static int sctp_setsockopt_recvnxtinfo(struct sock *sk, int *val,
39593949 unsigned int optlen)
39603950 {
3961
- int val;
3962
-
39633951 if (optlen < sizeof(int))
39643952 return -EINVAL;
3965
- if (get_user(val, (int __user *) optval))
3966
- return -EFAULT;
39673953
3968
- sctp_sk(sk)->recvnxtinfo = (val == 0) ? 0 : 1;
3954
+ sctp_sk(sk)->recvnxtinfo = (*val == 0) ? 0 : 1;
39693955
39703956 return 0;
39713957 }
39723958
39733959 static int sctp_setsockopt_pr_supported(struct sock *sk,
3974
- char __user *optval,
3960
+ struct sctp_assoc_value *params,
39753961 unsigned int optlen)
39763962 {
3977
- struct sctp_assoc_value params;
3963
+ struct sctp_association *asoc;
39783964
3979
- if (optlen != sizeof(params))
3965
+ if (optlen != sizeof(*params))
39803966 return -EINVAL;
39813967
3982
- if (copy_from_user(&params, optval, optlen))
3983
- return -EFAULT;
3968
+ asoc = sctp_id2assoc(sk, params->assoc_id);
3969
+ if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
3970
+ sctp_style(sk, UDP))
3971
+ return -EINVAL;
39843972
3985
- sctp_sk(sk)->ep->prsctp_enable = !!params.assoc_value;
3973
+ sctp_sk(sk)->ep->prsctp_enable = !!params->assoc_value;
39863974
39873975 return 0;
39883976 }
39893977
39903978 static int sctp_setsockopt_default_prinfo(struct sock *sk,
3991
- char __user *optval,
3979
+ struct sctp_default_prinfo *info,
39923980 unsigned int optlen)
39933981 {
3994
- struct sctp_default_prinfo info;
3982
+ struct sctp_sock *sp = sctp_sk(sk);
39953983 struct sctp_association *asoc;
39963984 int retval = -EINVAL;
39973985
3998
- if (optlen != sizeof(info))
3986
+ if (optlen != sizeof(*info))
39993987 goto out;
40003988
4001
- if (copy_from_user(&info, optval, sizeof(info))) {
4002
- retval = -EFAULT;
4003
- goto out;
4004
- }
4005
-
4006
- if (info.pr_policy & ~SCTP_PR_SCTP_MASK)
3989
+ if (info->pr_policy & ~SCTP_PR_SCTP_MASK)
40073990 goto out;
40083991
4009
- if (info.pr_policy == SCTP_PR_SCTP_NONE)
4010
- info.pr_value = 0;
3992
+ if (info->pr_policy == SCTP_PR_SCTP_NONE)
3993
+ info->pr_value = 0;
40113994
4012
- asoc = sctp_id2assoc(sk, info.pr_assoc_id);
4013
- if (asoc) {
4014
- SCTP_PR_SET_POLICY(asoc->default_flags, info.pr_policy);
4015
- asoc->default_timetolive = info.pr_value;
4016
- } else if (!info.pr_assoc_id) {
4017
- struct sctp_sock *sp = sctp_sk(sk);
4018
-
4019
- SCTP_PR_SET_POLICY(sp->default_flags, info.pr_policy);
4020
- sp->default_timetolive = info.pr_value;
4021
- } else {
3995
+ asoc = sctp_id2assoc(sk, info->pr_assoc_id);
3996
+ if (!asoc && info->pr_assoc_id > SCTP_ALL_ASSOC &&
3997
+ sctp_style(sk, UDP))
40223998 goto out;
4023
- }
40243999
40254000 retval = 0;
4001
+
4002
+ if (asoc) {
4003
+ SCTP_PR_SET_POLICY(asoc->default_flags, info->pr_policy);
4004
+ asoc->default_timetolive = info->pr_value;
4005
+ goto out;
4006
+ }
4007
+
4008
+ if (sctp_style(sk, TCP))
4009
+ info->pr_assoc_id = SCTP_FUTURE_ASSOC;
4010
+
4011
+ if (info->pr_assoc_id == SCTP_FUTURE_ASSOC ||
4012
+ info->pr_assoc_id == SCTP_ALL_ASSOC) {
4013
+ SCTP_PR_SET_POLICY(sp->default_flags, info->pr_policy);
4014
+ sp->default_timetolive = info->pr_value;
4015
+ }
4016
+
4017
+ if (info->pr_assoc_id == SCTP_CURRENT_ASSOC ||
4018
+ info->pr_assoc_id == SCTP_ALL_ASSOC) {
4019
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
4020
+ SCTP_PR_SET_POLICY(asoc->default_flags,
4021
+ info->pr_policy);
4022
+ asoc->default_timetolive = info->pr_value;
4023
+ }
4024
+ }
40264025
40274026 out:
40284027 return retval;
40294028 }
40304029
40314030 static int sctp_setsockopt_reconfig_supported(struct sock *sk,
4032
- char __user *optval,
4031
+ struct sctp_assoc_value *params,
40334032 unsigned int optlen)
40344033 {
4035
- struct sctp_assoc_value params;
40364034 struct sctp_association *asoc;
40374035 int retval = -EINVAL;
40384036
4039
- if (optlen != sizeof(params))
4037
+ if (optlen != sizeof(*params))
40404038 goto out;
40414039
4042
- if (copy_from_user(&params, optval, optlen)) {
4043
- retval = -EFAULT;
4040
+ asoc = sctp_id2assoc(sk, params->assoc_id);
4041
+ if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4042
+ sctp_style(sk, UDP))
40444043 goto out;
4045
- }
40464044
4047
- asoc = sctp_id2assoc(sk, params.assoc_id);
4048
- if (asoc) {
4049
- asoc->reconf_enable = !!params.assoc_value;
4050
- } else if (!params.assoc_id) {
4051
- struct sctp_sock *sp = sctp_sk(sk);
4052
-
4053
- sp->ep->reconf_enable = !!params.assoc_value;
4054
- } else {
4055
- goto out;
4056
- }
4045
+ sctp_sk(sk)->ep->reconf_enable = !!params->assoc_value;
40574046
40584047 retval = 0;
40594048
....@@ -4062,48 +4051,52 @@
40624051 }
40634052
40644053 static int sctp_setsockopt_enable_strreset(struct sock *sk,
4065
- char __user *optval,
4054
+ struct sctp_assoc_value *params,
40664055 unsigned int optlen)
40674056 {
4068
- struct sctp_assoc_value params;
4057
+ struct sctp_endpoint *ep = sctp_sk(sk)->ep;
40694058 struct sctp_association *asoc;
40704059 int retval = -EINVAL;
40714060
4072
- if (optlen != sizeof(params))
4061
+ if (optlen != sizeof(*params))
40734062 goto out;
40744063
4075
- if (copy_from_user(&params, optval, optlen)) {
4076
- retval = -EFAULT;
4077
- goto out;
4078
- }
4079
-
4080
- if (params.assoc_value & (~SCTP_ENABLE_STRRESET_MASK))
4064
+ if (params->assoc_value & (~SCTP_ENABLE_STRRESET_MASK))
40814065 goto out;
40824066
4083
- asoc = sctp_id2assoc(sk, params.assoc_id);
4084
- if (asoc) {
4085
- asoc->strreset_enable = params.assoc_value;
4086
- } else if (!params.assoc_id) {
4087
- struct sctp_sock *sp = sctp_sk(sk);
4088
-
4089
- sp->ep->strreset_enable = params.assoc_value;
4090
- } else {
4067
+ asoc = sctp_id2assoc(sk, params->assoc_id);
4068
+ if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
4069
+ sctp_style(sk, UDP))
40914070 goto out;
4092
- }
40934071
40944072 retval = 0;
4073
+
4074
+ if (asoc) {
4075
+ asoc->strreset_enable = params->assoc_value;
4076
+ goto out;
4077
+ }
4078
+
4079
+ if (sctp_style(sk, TCP))
4080
+ params->assoc_id = SCTP_FUTURE_ASSOC;
4081
+
4082
+ if (params->assoc_id == SCTP_FUTURE_ASSOC ||
4083
+ params->assoc_id == SCTP_ALL_ASSOC)
4084
+ ep->strreset_enable = params->assoc_value;
4085
+
4086
+ if (params->assoc_id == SCTP_CURRENT_ASSOC ||
4087
+ params->assoc_id == SCTP_ALL_ASSOC)
4088
+ list_for_each_entry(asoc, &ep->asocs, asocs)
4089
+ asoc->strreset_enable = params->assoc_value;
40954090
40964091 out:
40974092 return retval;
40984093 }
40994094
41004095 static int sctp_setsockopt_reset_streams(struct sock *sk,
4101
- char __user *optval,
4096
+ struct sctp_reset_streams *params,
41024097 unsigned int optlen)
41034098 {
4104
- struct sctp_reset_streams *params;
41054099 struct sctp_association *asoc;
4106
- int retval = -EINVAL;
41074100
41084101 if (optlen < sizeof(*params))
41094102 return -EINVAL;
....@@ -4111,174 +4104,151 @@
41114104 optlen = min_t(unsigned int, optlen, USHRT_MAX +
41124105 sizeof(__u16) * sizeof(*params));
41134106
4114
- params = memdup_user(optval, optlen);
4115
- if (IS_ERR(params))
4116
- return PTR_ERR(params);
4117
-
41184107 if (params->srs_number_streams * sizeof(__u16) >
41194108 optlen - sizeof(*params))
4120
- goto out;
4109
+ return -EINVAL;
41214110
41224111 asoc = sctp_id2assoc(sk, params->srs_assoc_id);
41234112 if (!asoc)
4124
- goto out;
4113
+ return -EINVAL;
41254114
4126
- retval = sctp_send_reset_streams(asoc, params);
4127
-
4128
-out:
4129
- kfree(params);
4130
- return retval;
4115
+ return sctp_send_reset_streams(asoc, params);
41314116 }
41324117
4133
-static int sctp_setsockopt_reset_assoc(struct sock *sk,
4134
- char __user *optval,
4118
+static int sctp_setsockopt_reset_assoc(struct sock *sk, sctp_assoc_t *associd,
41354119 unsigned int optlen)
41364120 {
41374121 struct sctp_association *asoc;
4138
- sctp_assoc_t associd;
4139
- int retval = -EINVAL;
41404122
4141
- if (optlen != sizeof(associd))
4142
- goto out;
4123
+ if (optlen != sizeof(*associd))
4124
+ return -EINVAL;
41434125
4144
- if (copy_from_user(&associd, optval, optlen)) {
4145
- retval = -EFAULT;
4146
- goto out;
4147
- }
4148
-
4149
- asoc = sctp_id2assoc(sk, associd);
4126
+ asoc = sctp_id2assoc(sk, *associd);
41504127 if (!asoc)
4151
- goto out;
4128
+ return -EINVAL;
41524129
4153
- retval = sctp_send_reset_assoc(asoc);
4154
-
4155
-out:
4156
- return retval;
4130
+ return sctp_send_reset_assoc(asoc);
41574131 }
41584132
41594133 static int sctp_setsockopt_add_streams(struct sock *sk,
4160
- char __user *optval,
4134
+ struct sctp_add_streams *params,
41614135 unsigned int optlen)
41624136 {
41634137 struct sctp_association *asoc;
4164
- struct sctp_add_streams params;
4165
- int retval = -EINVAL;
41664138
4167
- if (optlen != sizeof(params))
4168
- goto out;
4139
+ if (optlen != sizeof(*params))
4140
+ return -EINVAL;
41694141
4170
- if (copy_from_user(&params, optval, optlen)) {
4171
- retval = -EFAULT;
4172
- goto out;
4173
- }
4174
-
4175
- asoc = sctp_id2assoc(sk, params.sas_assoc_id);
4142
+ asoc = sctp_id2assoc(sk, params->sas_assoc_id);
41764143 if (!asoc)
4177
- goto out;
4144
+ return -EINVAL;
41784145
4179
- retval = sctp_send_add_streams(asoc, &params);
4180
-
4181
-out:
4182
- return retval;
4146
+ return sctp_send_add_streams(asoc, params);
41834147 }
41844148
41854149 static int sctp_setsockopt_scheduler(struct sock *sk,
4186
- char __user *optval,
4150
+ struct sctp_assoc_value *params,
41874151 unsigned int optlen)
41884152 {
4153
+ struct sctp_sock *sp = sctp_sk(sk);
41894154 struct sctp_association *asoc;
4190
- struct sctp_assoc_value params;
4191
- int retval = -EINVAL;
4155
+ int retval = 0;
41924156
4193
- if (optlen < sizeof(params))
4194
- goto out;
4157
+ if (optlen < sizeof(*params))
4158
+ return -EINVAL;
41954159
4196
- optlen = sizeof(params);
4197
- if (copy_from_user(&params, optval, optlen)) {
4198
- retval = -EFAULT;
4199
- goto out;
4160
+ if (params->assoc_value > SCTP_SS_MAX)
4161
+ return -EINVAL;
4162
+
4163
+ asoc = sctp_id2assoc(sk, params->assoc_id);
4164
+ if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
4165
+ sctp_style(sk, UDP))
4166
+ return -EINVAL;
4167
+
4168
+ if (asoc)
4169
+ return sctp_sched_set_sched(asoc, params->assoc_value);
4170
+
4171
+ if (sctp_style(sk, TCP))
4172
+ params->assoc_id = SCTP_FUTURE_ASSOC;
4173
+
4174
+ if (params->assoc_id == SCTP_FUTURE_ASSOC ||
4175
+ params->assoc_id == SCTP_ALL_ASSOC)
4176
+ sp->default_ss = params->assoc_value;
4177
+
4178
+ if (params->assoc_id == SCTP_CURRENT_ASSOC ||
4179
+ params->assoc_id == SCTP_ALL_ASSOC) {
4180
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
4181
+ int ret = sctp_sched_set_sched(asoc,
4182
+ params->assoc_value);
4183
+
4184
+ if (ret && !retval)
4185
+ retval = ret;
4186
+ }
42004187 }
42014188
4202
- if (params.assoc_value > SCTP_SS_MAX)
4203
- goto out;
4204
-
4205
- asoc = sctp_id2assoc(sk, params.assoc_id);
4206
- if (!asoc)
4207
- goto out;
4208
-
4209
- retval = sctp_sched_set_sched(asoc, params.assoc_value);
4210
-
4211
-out:
42124189 return retval;
42134190 }
42144191
42154192 static int sctp_setsockopt_scheduler_value(struct sock *sk,
4216
- char __user *optval,
4193
+ struct sctp_stream_value *params,
42174194 unsigned int optlen)
42184195 {
42194196 struct sctp_association *asoc;
4220
- struct sctp_stream_value params;
42214197 int retval = -EINVAL;
42224198
4223
- if (optlen < sizeof(params))
4199
+ if (optlen < sizeof(*params))
42244200 goto out;
42254201
4226
- optlen = sizeof(params);
4227
- if (copy_from_user(&params, optval, optlen)) {
4228
- retval = -EFAULT;
4202
+ asoc = sctp_id2assoc(sk, params->assoc_id);
4203
+ if (!asoc && params->assoc_id != SCTP_CURRENT_ASSOC &&
4204
+ sctp_style(sk, UDP))
4205
+ goto out;
4206
+
4207
+ if (asoc) {
4208
+ retval = sctp_sched_set_value(asoc, params->stream_id,
4209
+ params->stream_value, GFP_KERNEL);
42294210 goto out;
42304211 }
42314212
4232
- asoc = sctp_id2assoc(sk, params.assoc_id);
4233
- if (!asoc)
4234
- goto out;
4213
+ retval = 0;
42354214
4236
- retval = sctp_sched_set_value(asoc, params.stream_id,
4237
- params.stream_value, GFP_KERNEL);
4215
+ list_for_each_entry(asoc, &sctp_sk(sk)->ep->asocs, asocs) {
4216
+ int ret = sctp_sched_set_value(asoc, params->stream_id,
4217
+ params->stream_value,
4218
+ GFP_KERNEL);
4219
+ if (ret && !retval) /* try to return the 1st error. */
4220
+ retval = ret;
4221
+ }
42384222
42394223 out:
42404224 return retval;
42414225 }
42424226
42434227 static int sctp_setsockopt_interleaving_supported(struct sock *sk,
4244
- char __user *optval,
4228
+ struct sctp_assoc_value *p,
42454229 unsigned int optlen)
42464230 {
42474231 struct sctp_sock *sp = sctp_sk(sk);
4248
- struct net *net = sock_net(sk);
4249
- struct sctp_assoc_value params;
4250
- int retval = -EINVAL;
4232
+ struct sctp_association *asoc;
42514233
4252
- if (optlen < sizeof(params))
4253
- goto out;
4234
+ if (optlen < sizeof(*p))
4235
+ return -EINVAL;
42544236
4255
- optlen = sizeof(params);
4256
- if (copy_from_user(&params, optval, optlen)) {
4257
- retval = -EFAULT;
4258
- goto out;
4237
+ asoc = sctp_id2assoc(sk, p->assoc_id);
4238
+ if (!asoc && p->assoc_id != SCTP_FUTURE_ASSOC && sctp_style(sk, UDP))
4239
+ return -EINVAL;
4240
+
4241
+ if (!sock_net(sk)->sctp.intl_enable || !sp->frag_interleave) {
4242
+ return -EPERM;
42594243 }
42604244
4261
- if (params.assoc_id)
4262
- goto out;
4263
-
4264
- if (!net->sctp.intl_enable || !sp->frag_interleave) {
4265
- retval = -EPERM;
4266
- goto out;
4267
- }
4268
-
4269
- sp->strm_interleave = !!params.assoc_value;
4270
-
4271
- retval = 0;
4272
-
4273
-out:
4274
- return retval;
4245
+ sp->ep->intl_enable = !!p->assoc_value;
4246
+ return 0;
42754247 }
42764248
4277
-static int sctp_setsockopt_reuse_port(struct sock *sk, char __user *optval,
4249
+static int sctp_setsockopt_reuse_port(struct sock *sk, int *val,
42784250 unsigned int optlen)
42794251 {
4280
- int val;
4281
-
42824252 if (!sctp_style(sk, TCP))
42834253 return -EOPNOTSUPP;
42844254
....@@ -4288,12 +4258,187 @@
42884258 if (optlen < sizeof(int))
42894259 return -EINVAL;
42904260
4291
- if (get_user(val, (int __user *)optval))
4292
- return -EFAULT;
4293
-
4294
- sctp_sk(sk)->reuse = !!val;
4261
+ sctp_sk(sk)->reuse = !!*val;
42954262
42964263 return 0;
4264
+}
4265
+
4266
+static int sctp_assoc_ulpevent_type_set(struct sctp_event *param,
4267
+ struct sctp_association *asoc)
4268
+{
4269
+ struct sctp_ulpevent *event;
4270
+
4271
+ sctp_ulpevent_type_set(&asoc->subscribe, param->se_type, param->se_on);
4272
+
4273
+ if (param->se_type == SCTP_SENDER_DRY_EVENT && param->se_on) {
4274
+ if (sctp_outq_is_empty(&asoc->outqueue)) {
4275
+ event = sctp_ulpevent_make_sender_dry_event(asoc,
4276
+ GFP_USER | __GFP_NOWARN);
4277
+ if (!event)
4278
+ return -ENOMEM;
4279
+
4280
+ asoc->stream.si->enqueue_event(&asoc->ulpq, event);
4281
+ }
4282
+ }
4283
+
4284
+ return 0;
4285
+}
4286
+
4287
+static int sctp_setsockopt_event(struct sock *sk, struct sctp_event *param,
4288
+ unsigned int optlen)
4289
+{
4290
+ struct sctp_sock *sp = sctp_sk(sk);
4291
+ struct sctp_association *asoc;
4292
+ int retval = 0;
4293
+
4294
+ if (optlen < sizeof(*param))
4295
+ return -EINVAL;
4296
+
4297
+ if (param->se_type < SCTP_SN_TYPE_BASE ||
4298
+ param->se_type > SCTP_SN_TYPE_MAX)
4299
+ return -EINVAL;
4300
+
4301
+ asoc = sctp_id2assoc(sk, param->se_assoc_id);
4302
+ if (!asoc && param->se_assoc_id > SCTP_ALL_ASSOC &&
4303
+ sctp_style(sk, UDP))
4304
+ return -EINVAL;
4305
+
4306
+ if (asoc)
4307
+ return sctp_assoc_ulpevent_type_set(param, asoc);
4308
+
4309
+ if (sctp_style(sk, TCP))
4310
+ param->se_assoc_id = SCTP_FUTURE_ASSOC;
4311
+
4312
+ if (param->se_assoc_id == SCTP_FUTURE_ASSOC ||
4313
+ param->se_assoc_id == SCTP_ALL_ASSOC)
4314
+ sctp_ulpevent_type_set(&sp->subscribe,
4315
+ param->se_type, param->se_on);
4316
+
4317
+ if (param->se_assoc_id == SCTP_CURRENT_ASSOC ||
4318
+ param->se_assoc_id == SCTP_ALL_ASSOC) {
4319
+ list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
4320
+ int ret = sctp_assoc_ulpevent_type_set(param, asoc);
4321
+
4322
+ if (ret && !retval)
4323
+ retval = ret;
4324
+ }
4325
+ }
4326
+
4327
+ return retval;
4328
+}
4329
+
4330
+static int sctp_setsockopt_asconf_supported(struct sock *sk,
4331
+ struct sctp_assoc_value *params,
4332
+ unsigned int optlen)
4333
+{
4334
+ struct sctp_association *asoc;
4335
+ struct sctp_endpoint *ep;
4336
+ int retval = -EINVAL;
4337
+
4338
+ if (optlen != sizeof(*params))
4339
+ goto out;
4340
+
4341
+ asoc = sctp_id2assoc(sk, params->assoc_id);
4342
+ if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4343
+ sctp_style(sk, UDP))
4344
+ goto out;
4345
+
4346
+ ep = sctp_sk(sk)->ep;
4347
+ ep->asconf_enable = !!params->assoc_value;
4348
+
4349
+ if (ep->asconf_enable && ep->auth_enable) {
4350
+ sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF);
4351
+ sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF_ACK);
4352
+ }
4353
+
4354
+ retval = 0;
4355
+
4356
+out:
4357
+ return retval;
4358
+}
4359
+
4360
+static int sctp_setsockopt_auth_supported(struct sock *sk,
4361
+ struct sctp_assoc_value *params,
4362
+ unsigned int optlen)
4363
+{
4364
+ struct sctp_association *asoc;
4365
+ struct sctp_endpoint *ep;
4366
+ int retval = -EINVAL;
4367
+
4368
+ if (optlen != sizeof(*params))
4369
+ goto out;
4370
+
4371
+ asoc = sctp_id2assoc(sk, params->assoc_id);
4372
+ if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4373
+ sctp_style(sk, UDP))
4374
+ goto out;
4375
+
4376
+ ep = sctp_sk(sk)->ep;
4377
+ if (params->assoc_value) {
4378
+ retval = sctp_auth_init(ep, GFP_KERNEL);
4379
+ if (retval)
4380
+ goto out;
4381
+ if (ep->asconf_enable) {
4382
+ sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF);
4383
+ sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF_ACK);
4384
+ }
4385
+ }
4386
+
4387
+ ep->auth_enable = !!params->assoc_value;
4388
+ retval = 0;
4389
+
4390
+out:
4391
+ return retval;
4392
+}
4393
+
4394
+static int sctp_setsockopt_ecn_supported(struct sock *sk,
4395
+ struct sctp_assoc_value *params,
4396
+ unsigned int optlen)
4397
+{
4398
+ struct sctp_association *asoc;
4399
+ int retval = -EINVAL;
4400
+
4401
+ if (optlen != sizeof(*params))
4402
+ goto out;
4403
+
4404
+ asoc = sctp_id2assoc(sk, params->assoc_id);
4405
+ if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4406
+ sctp_style(sk, UDP))
4407
+ goto out;
4408
+
4409
+ sctp_sk(sk)->ep->ecn_enable = !!params->assoc_value;
4410
+ retval = 0;
4411
+
4412
+out:
4413
+ return retval;
4414
+}
4415
+
4416
+static int sctp_setsockopt_pf_expose(struct sock *sk,
4417
+ struct sctp_assoc_value *params,
4418
+ unsigned int optlen)
4419
+{
4420
+ struct sctp_association *asoc;
4421
+ int retval = -EINVAL;
4422
+
4423
+ if (optlen != sizeof(*params))
4424
+ goto out;
4425
+
4426
+ if (params->assoc_value > SCTP_PF_EXPOSE_MAX)
4427
+ goto out;
4428
+
4429
+ asoc = sctp_id2assoc(sk, params->assoc_id);
4430
+ if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4431
+ sctp_style(sk, UDP))
4432
+ goto out;
4433
+
4434
+ if (asoc)
4435
+ asoc->pf_expose = params->assoc_value;
4436
+ else
4437
+ sctp_sk(sk)->pf_expose = params->assoc_value;
4438
+ retval = 0;
4439
+
4440
+out:
4441
+ return retval;
42974442 }
42984443
42994444 /* API 6.2 setsockopt(), getsockopt()
....@@ -4316,8 +4461,9 @@
43164461 * optlen - the size of the buffer.
43174462 */
43184463 static int sctp_setsockopt(struct sock *sk, int level, int optname,
4319
- char __user *optval, unsigned int optlen)
4464
+ sockptr_t optval, unsigned int optlen)
43204465 {
4466
+ void *kopt = NULL;
43214467 int retval = 0;
43224468
43234469 pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname);
....@@ -4330,8 +4476,18 @@
43304476 */
43314477 if (level != SOL_SCTP) {
43324478 struct sctp_af *af = sctp_sk(sk)->pf->af;
4333
- retval = af->setsockopt(sk, level, optname, optval, optlen);
4334
- goto out_nounlock;
4479
+
4480
+ return af->setsockopt(sk, level, optname, optval, optlen);
4481
+ }
4482
+
4483
+ if (optlen > 0) {
4484
+ /* Trim it to the biggest size sctp sockopt may need if necessary */
4485
+ optlen = min_t(unsigned int, optlen,
4486
+ PAGE_ALIGN(USHRT_MAX +
4487
+ sizeof(__u16) * sizeof(struct sctp_reset_streams)));
4488
+ kopt = memdup_sockptr(optval, optlen);
4489
+ if (IS_ERR(kopt))
4490
+ return PTR_ERR(kopt);
43354491 }
43364492
43374493 lock_sock(sk);
....@@ -4339,159 +4495,174 @@
43394495 switch (optname) {
43404496 case SCTP_SOCKOPT_BINDX_ADD:
43414497 /* 'optlen' is the size of the addresses buffer. */
4342
- retval = sctp_setsockopt_bindx(sk, (struct sockaddr __user *)optval,
4343
- optlen, SCTP_BINDX_ADD_ADDR);
4498
+ retval = sctp_setsockopt_bindx(sk, kopt, optlen,
4499
+ SCTP_BINDX_ADD_ADDR);
43444500 break;
43454501
43464502 case SCTP_SOCKOPT_BINDX_REM:
43474503 /* 'optlen' is the size of the addresses buffer. */
4348
- retval = sctp_setsockopt_bindx(sk, (struct sockaddr __user *)optval,
4349
- optlen, SCTP_BINDX_REM_ADDR);
4504
+ retval = sctp_setsockopt_bindx(sk, kopt, optlen,
4505
+ SCTP_BINDX_REM_ADDR);
43504506 break;
43514507
43524508 case SCTP_SOCKOPT_CONNECTX_OLD:
43534509 /* 'optlen' is the size of the addresses buffer. */
4354
- retval = sctp_setsockopt_connectx_old(sk,
4355
- (struct sockaddr __user *)optval,
4356
- optlen);
4510
+ retval = sctp_setsockopt_connectx_old(sk, kopt, optlen);
43574511 break;
43584512
43594513 case SCTP_SOCKOPT_CONNECTX:
43604514 /* 'optlen' is the size of the addresses buffer. */
4361
- retval = sctp_setsockopt_connectx(sk,
4362
- (struct sockaddr __user *)optval,
4363
- optlen);
4515
+ retval = sctp_setsockopt_connectx(sk, kopt, optlen);
43644516 break;
43654517
43664518 case SCTP_DISABLE_FRAGMENTS:
4367
- retval = sctp_setsockopt_disable_fragments(sk, optval, optlen);
4519
+ retval = sctp_setsockopt_disable_fragments(sk, kopt, optlen);
43684520 break;
43694521
43704522 case SCTP_EVENTS:
4371
- retval = sctp_setsockopt_events(sk, optval, optlen);
4523
+ retval = sctp_setsockopt_events(sk, kopt, optlen);
43724524 break;
43734525
43744526 case SCTP_AUTOCLOSE:
4375
- retval = sctp_setsockopt_autoclose(sk, optval, optlen);
4527
+ retval = sctp_setsockopt_autoclose(sk, kopt, optlen);
43764528 break;
43774529
43784530 case SCTP_PEER_ADDR_PARAMS:
4379
- retval = sctp_setsockopt_peer_addr_params(sk, optval, optlen);
4531
+ retval = sctp_setsockopt_peer_addr_params(sk, kopt, optlen);
43804532 break;
43814533
43824534 case SCTP_DELAYED_SACK:
4383
- retval = sctp_setsockopt_delayed_ack(sk, optval, optlen);
4535
+ retval = sctp_setsockopt_delayed_ack(sk, kopt, optlen);
43844536 break;
43854537 case SCTP_PARTIAL_DELIVERY_POINT:
4386
- retval = sctp_setsockopt_partial_delivery_point(sk, optval, optlen);
4538
+ retval = sctp_setsockopt_partial_delivery_point(sk, kopt, optlen);
43874539 break;
43884540
43894541 case SCTP_INITMSG:
4390
- retval = sctp_setsockopt_initmsg(sk, optval, optlen);
4542
+ retval = sctp_setsockopt_initmsg(sk, kopt, optlen);
43914543 break;
43924544 case SCTP_DEFAULT_SEND_PARAM:
4393
- retval = sctp_setsockopt_default_send_param(sk, optval,
4394
- optlen);
4545
+ retval = sctp_setsockopt_default_send_param(sk, kopt, optlen);
43954546 break;
43964547 case SCTP_DEFAULT_SNDINFO:
4397
- retval = sctp_setsockopt_default_sndinfo(sk, optval, optlen);
4548
+ retval = sctp_setsockopt_default_sndinfo(sk, kopt, optlen);
43984549 break;
43994550 case SCTP_PRIMARY_ADDR:
4400
- retval = sctp_setsockopt_primary_addr(sk, optval, optlen);
4551
+ retval = sctp_setsockopt_primary_addr(sk, kopt, optlen);
44014552 break;
44024553 case SCTP_SET_PEER_PRIMARY_ADDR:
4403
- retval = sctp_setsockopt_peer_primary_addr(sk, optval, optlen);
4554
+ retval = sctp_setsockopt_peer_primary_addr(sk, kopt, optlen);
44044555 break;
44054556 case SCTP_NODELAY:
4406
- retval = sctp_setsockopt_nodelay(sk, optval, optlen);
4557
+ retval = sctp_setsockopt_nodelay(sk, kopt, optlen);
44074558 break;
44084559 case SCTP_RTOINFO:
4409
- retval = sctp_setsockopt_rtoinfo(sk, optval, optlen);
4560
+ retval = sctp_setsockopt_rtoinfo(sk, kopt, optlen);
44104561 break;
44114562 case SCTP_ASSOCINFO:
4412
- retval = sctp_setsockopt_associnfo(sk, optval, optlen);
4563
+ retval = sctp_setsockopt_associnfo(sk, kopt, optlen);
44134564 break;
44144565 case SCTP_I_WANT_MAPPED_V4_ADDR:
4415
- retval = sctp_setsockopt_mappedv4(sk, optval, optlen);
4566
+ retval = sctp_setsockopt_mappedv4(sk, kopt, optlen);
44164567 break;
44174568 case SCTP_MAXSEG:
4418
- retval = sctp_setsockopt_maxseg(sk, optval, optlen);
4569
+ retval = sctp_setsockopt_maxseg(sk, kopt, optlen);
44194570 break;
44204571 case SCTP_ADAPTATION_LAYER:
4421
- retval = sctp_setsockopt_adaptation_layer(sk, optval, optlen);
4572
+ retval = sctp_setsockopt_adaptation_layer(sk, kopt, optlen);
44224573 break;
44234574 case SCTP_CONTEXT:
4424
- retval = sctp_setsockopt_context(sk, optval, optlen);
4575
+ retval = sctp_setsockopt_context(sk, kopt, optlen);
44254576 break;
44264577 case SCTP_FRAGMENT_INTERLEAVE:
4427
- retval = sctp_setsockopt_fragment_interleave(sk, optval, optlen);
4578
+ retval = sctp_setsockopt_fragment_interleave(sk, kopt, optlen);
44284579 break;
44294580 case SCTP_MAX_BURST:
4430
- retval = sctp_setsockopt_maxburst(sk, optval, optlen);
4581
+ retval = sctp_setsockopt_maxburst(sk, kopt, optlen);
44314582 break;
44324583 case SCTP_AUTH_CHUNK:
4433
- retval = sctp_setsockopt_auth_chunk(sk, optval, optlen);
4584
+ retval = sctp_setsockopt_auth_chunk(sk, kopt, optlen);
44344585 break;
44354586 case SCTP_HMAC_IDENT:
4436
- retval = sctp_setsockopt_hmac_ident(sk, optval, optlen);
4587
+ retval = sctp_setsockopt_hmac_ident(sk, kopt, optlen);
44374588 break;
44384589 case SCTP_AUTH_KEY:
4439
- retval = sctp_setsockopt_auth_key(sk, optval, optlen);
4590
+ retval = sctp_setsockopt_auth_key(sk, kopt, optlen);
44404591 break;
44414592 case SCTP_AUTH_ACTIVE_KEY:
4442
- retval = sctp_setsockopt_active_key(sk, optval, optlen);
4593
+ retval = sctp_setsockopt_active_key(sk, kopt, optlen);
44434594 break;
44444595 case SCTP_AUTH_DELETE_KEY:
4445
- retval = sctp_setsockopt_del_key(sk, optval, optlen);
4596
+ retval = sctp_setsockopt_del_key(sk, kopt, optlen);
44464597 break;
44474598 case SCTP_AUTH_DEACTIVATE_KEY:
4448
- retval = sctp_setsockopt_deactivate_key(sk, optval, optlen);
4599
+ retval = sctp_setsockopt_deactivate_key(sk, kopt, optlen);
44494600 break;
44504601 case SCTP_AUTO_ASCONF:
4451
- retval = sctp_setsockopt_auto_asconf(sk, optval, optlen);
4602
+ retval = sctp_setsockopt_auto_asconf(sk, kopt, optlen);
44524603 break;
44534604 case SCTP_PEER_ADDR_THLDS:
4454
- retval = sctp_setsockopt_paddr_thresholds(sk, optval, optlen);
4605
+ retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen,
4606
+ false);
4607
+ break;
4608
+ case SCTP_PEER_ADDR_THLDS_V2:
4609
+ retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen,
4610
+ true);
44554611 break;
44564612 case SCTP_RECVRCVINFO:
4457
- retval = sctp_setsockopt_recvrcvinfo(sk, optval, optlen);
4613
+ retval = sctp_setsockopt_recvrcvinfo(sk, kopt, optlen);
44584614 break;
44594615 case SCTP_RECVNXTINFO:
4460
- retval = sctp_setsockopt_recvnxtinfo(sk, optval, optlen);
4616
+ retval = sctp_setsockopt_recvnxtinfo(sk, kopt, optlen);
44614617 break;
44624618 case SCTP_PR_SUPPORTED:
4463
- retval = sctp_setsockopt_pr_supported(sk, optval, optlen);
4619
+ retval = sctp_setsockopt_pr_supported(sk, kopt, optlen);
44644620 break;
44654621 case SCTP_DEFAULT_PRINFO:
4466
- retval = sctp_setsockopt_default_prinfo(sk, optval, optlen);
4622
+ retval = sctp_setsockopt_default_prinfo(sk, kopt, optlen);
44674623 break;
44684624 case SCTP_RECONFIG_SUPPORTED:
4469
- retval = sctp_setsockopt_reconfig_supported(sk, optval, optlen);
4625
+ retval = sctp_setsockopt_reconfig_supported(sk, kopt, optlen);
44704626 break;
44714627 case SCTP_ENABLE_STREAM_RESET:
4472
- retval = sctp_setsockopt_enable_strreset(sk, optval, optlen);
4628
+ retval = sctp_setsockopt_enable_strreset(sk, kopt, optlen);
44734629 break;
44744630 case SCTP_RESET_STREAMS:
4475
- retval = sctp_setsockopt_reset_streams(sk, optval, optlen);
4631
+ retval = sctp_setsockopt_reset_streams(sk, kopt, optlen);
44764632 break;
44774633 case SCTP_RESET_ASSOC:
4478
- retval = sctp_setsockopt_reset_assoc(sk, optval, optlen);
4634
+ retval = sctp_setsockopt_reset_assoc(sk, kopt, optlen);
44794635 break;
44804636 case SCTP_ADD_STREAMS:
4481
- retval = sctp_setsockopt_add_streams(sk, optval, optlen);
4637
+ retval = sctp_setsockopt_add_streams(sk, kopt, optlen);
44824638 break;
44834639 case SCTP_STREAM_SCHEDULER:
4484
- retval = sctp_setsockopt_scheduler(sk, optval, optlen);
4640
+ retval = sctp_setsockopt_scheduler(sk, kopt, optlen);
44854641 break;
44864642 case SCTP_STREAM_SCHEDULER_VALUE:
4487
- retval = sctp_setsockopt_scheduler_value(sk, optval, optlen);
4643
+ retval = sctp_setsockopt_scheduler_value(sk, kopt, optlen);
44884644 break;
44894645 case SCTP_INTERLEAVING_SUPPORTED:
4490
- retval = sctp_setsockopt_interleaving_supported(sk, optval,
4646
+ retval = sctp_setsockopt_interleaving_supported(sk, kopt,
44914647 optlen);
44924648 break;
44934649 case SCTP_REUSE_PORT:
4494
- retval = sctp_setsockopt_reuse_port(sk, optval, optlen);
4650
+ retval = sctp_setsockopt_reuse_port(sk, kopt, optlen);
4651
+ break;
4652
+ case SCTP_EVENT:
4653
+ retval = sctp_setsockopt_event(sk, kopt, optlen);
4654
+ break;
4655
+ case SCTP_ASCONF_SUPPORTED:
4656
+ retval = sctp_setsockopt_asconf_supported(sk, kopt, optlen);
4657
+ break;
4658
+ case SCTP_AUTH_SUPPORTED:
4659
+ retval = sctp_setsockopt_auth_supported(sk, kopt, optlen);
4660
+ break;
4661
+ case SCTP_ECN_SUPPORTED:
4662
+ retval = sctp_setsockopt_ecn_supported(sk, kopt, optlen);
4663
+ break;
4664
+ case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
4665
+ retval = sctp_setsockopt_pf_expose(sk, kopt, optlen);
44954666 break;
44964667 default:
44974668 retval = -ENOPROTOOPT;
....@@ -4499,8 +4670,7 @@
44994670 }
45004671
45014672 release_sock(sk);
4502
-
4503
-out_nounlock:
4673
+ kfree(kopt);
45044674 return retval;
45054675 }
45064676
....@@ -4527,7 +4697,6 @@
45274697 int err = -EINVAL;
45284698
45294699 lock_sock(sk);
4530
-
45314700 pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
45324701 addr, addr_len);
45334702
....@@ -4609,7 +4778,11 @@
46094778 /* Populate the fields of the newsk from the oldsk and migrate the
46104779 * asoc to the newsk.
46114780 */
4612
- sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP);
4781
+ error = sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP);
4782
+ if (error) {
4783
+ sk_common_release(newsk);
4784
+ newsk = NULL;
4785
+ }
46134786
46144787 out:
46154788 release_sock(sk);
....@@ -4725,19 +4898,23 @@
47254898 /* Initialize default event subscriptions. By default, all the
47264899 * options are off.
47274900 */
4728
- memset(&sp->subscribe, 0, sizeof(struct sctp_event_subscribe));
4901
+ sp->subscribe = 0;
47294902
47304903 /* Default Peer Address Parameters. These defaults can
47314904 * be modified via SCTP_PEER_ADDR_PARAMS
47324905 */
47334906 sp->hbinterval = net->sctp.hb_interval;
47344907 sp->pathmaxrxt = net->sctp.max_retrans_path;
4908
+ sp->pf_retrans = net->sctp.pf_retrans;
4909
+ sp->ps_retrans = net->sctp.ps_retrans;
4910
+ sp->pf_expose = net->sctp.pf_expose;
47354911 sp->pathmtu = 0; /* allow default discovery */
47364912 sp->sackdelay = net->sctp.sack_timeout;
47374913 sp->sackfreq = 2;
47384914 sp->param_flags = SPP_HB_ENABLE |
47394915 SPP_PMTUD_ENABLE |
47404916 SPP_SACKDELAY_ENABLE;
4917
+ sp->default_ss = SCTP_SS_DEFAULT;
47414918
47424919 /* If enabled no SCTP message fragmentation will be performed.
47434920 * Configure through SCTP_DISABLE_FRAGMENTS socket option.
....@@ -4824,13 +5001,17 @@
48245001 }
48255002
48265003 /* Triggered when there are no references on the socket anymore */
4827
-static void sctp_destruct_sock(struct sock *sk)
5004
+static void sctp_destruct_common(struct sock *sk)
48285005 {
48295006 struct sctp_sock *sp = sctp_sk(sk);
48305007
48315008 /* Free up the HMAC transform. */
48325009 crypto_free_shash(sp->hmac);
5010
+}
48335011
5012
+static void sctp_destruct_sock(struct sock *sk)
5013
+{
5014
+ sctp_destruct_common(sk);
48345015 inet_sock_destruct(sk);
48355016 }
48365017
....@@ -4956,14 +5137,14 @@
49565137 EXPORT_SYMBOL_GPL(sctp_get_sctp_info);
49575138
49585139 /* use callback to avoid exporting the core structure */
4959
-void sctp_transport_walk_start(struct rhashtable_iter *iter)
5140
+void sctp_transport_walk_start(struct rhashtable_iter *iter) __acquires(RCU)
49605141 {
49615142 rhltable_walk_enter(&sctp_transport_hashtable, iter);
49625143
49635144 rhashtable_walk_start(iter);
49645145 }
49655146
4966
-void sctp_transport_walk_stop(struct rhashtable_iter *iter)
5147
+void sctp_transport_walk_stop(struct rhashtable_iter *iter) __releases(RCU)
49675148 {
49685149 rhashtable_walk_stop(iter);
49695150 rhashtable_walk_exit(iter);
....@@ -4985,7 +5166,7 @@
49855166 if (!sctp_transport_hold(t))
49865167 continue;
49875168
4988
- if (net_eq(sock_net(t->asoc->base.sk), net) &&
5169
+ if (net_eq(t->asoc->base.net, net) &&
49895170 t->asoc->peer.primary_path == t)
49905171 break;
49915172
....@@ -5205,8 +5386,16 @@
52055386
52065387 transport = sctp_addr_id2transport(sk, &pinfo.spinfo_address,
52075388 pinfo.spinfo_assoc_id);
5208
- if (!transport)
5209
- return -EINVAL;
5389
+ if (!transport) {
5390
+ retval = -EINVAL;
5391
+ goto out;
5392
+ }
5393
+
5394
+ if (transport->state == SCTP_PF &&
5395
+ transport->asoc->pf_expose == SCTP_PF_EXPOSE_DISABLE) {
5396
+ retval = -EACCES;
5397
+ goto out;
5398
+ }
52105399
52115400 pinfo.spinfo_assoc_id = sctp_assoc2id(transport->asoc);
52125401 pinfo.spinfo_state = transport->state;
....@@ -5264,14 +5453,24 @@
52645453 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
52655454 int __user *optlen)
52665455 {
5456
+ struct sctp_event_subscribe subscribe;
5457
+ __u8 *sn_type = (__u8 *)&subscribe;
5458
+ int i;
5459
+
52675460 if (len == 0)
52685461 return -EINVAL;
52695462 if (len > sizeof(struct sctp_event_subscribe))
52705463 len = sizeof(struct sctp_event_subscribe);
52715464 if (put_user(len, optlen))
52725465 return -EFAULT;
5273
- if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
5466
+
5467
+ for (i = 0; i < len; i++)
5468
+ sn_type[i] = sctp_ulpevent_type_enabled(sctp_sk(sk)->subscribe,
5469
+ SCTP_SN_TYPE_BASE + i);
5470
+
5471
+ if (copy_to_user(optval, &subscribe, len))
52745472 return -EFAULT;
5473
+
52755474 return 0;
52765475 }
52775476
....@@ -5333,13 +5532,18 @@
53335532 * Set the daddr and initialize id to something more random and also
53345533 * copy over any ip options.
53355534 */
5336
- sp->pf->to_sk_daddr(&asoc->peer.primary_addr, sk);
5535
+ sp->pf->to_sk_daddr(&asoc->peer.primary_addr, sock->sk);
53375536 sp->pf->copy_ip_options(sk, sock->sk);
53385537
53395538 /* Populate the fields of the newsk from the oldsk and migrate the
53405539 * asoc to the newsk.
53415540 */
5342
- sctp_sock_migrate(sk, sock->sk, asoc, SCTP_SOCKET_UDP_HIGH_BANDWIDTH);
5541
+ err = sctp_sock_migrate(sk, sock->sk, asoc,
5542
+ SCTP_SOCKET_UDP_HIGH_BANDWIDTH);
5543
+ if (err) {
5544
+ sock_release(sock);
5545
+ sock = NULL;
5546
+ }
53435547
53445548 *sockp = sock;
53455549
....@@ -5615,12 +5819,13 @@
56155819 }
56165820 }
56175821
5618
- /* Get association, if assoc_id != 0 and the socket is a one
5619
- * to many style socket, and an association was not found, then
5620
- * the id was invalid.
5822
+ /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
5823
+ * socket is a one to many style socket, and an association
5824
+ * was not found, then the id was invalid.
56215825 */
56225826 asoc = sctp_id2assoc(sk, params.spp_assoc_id);
5623
- if (!asoc && params.spp_assoc_id && sctp_style(sk, UDP)) {
5827
+ if (!asoc && params.spp_assoc_id != SCTP_FUTURE_ASSOC &&
5828
+ sctp_style(sk, UDP)) {
56245829 pr_debug("%s: failed no association\n", __func__);
56255830 return -EINVAL;
56265831 }
....@@ -5749,19 +5954,19 @@
57495954 } else
57505955 return -EINVAL;
57515956
5752
- /* Get association, if sack_assoc_id != 0 and the socket is a one
5753
- * to many style socket, and an association was not found, then
5754
- * the id was invalid.
5957
+ /* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the
5958
+ * socket is a one to many style socket, and an association
5959
+ * was not found, then the id was invalid.
57555960 */
57565961 asoc = sctp_id2assoc(sk, params.sack_assoc_id);
5757
- if (!asoc && params.sack_assoc_id && sctp_style(sk, UDP))
5962
+ if (!asoc && params.sack_assoc_id != SCTP_FUTURE_ASSOC &&
5963
+ sctp_style(sk, UDP))
57585964 return -EINVAL;
57595965
57605966 if (asoc) {
57615967 /* Fetch association values. */
57625968 if (asoc->param_flags & SPP_SACKDELAY_ENABLE) {
5763
- params.sack_delay = jiffies_to_msecs(
5764
- asoc->sackdelay);
5969
+ params.sack_delay = jiffies_to_msecs(asoc->sackdelay);
57655970 params.sack_freq = asoc->sackfreq;
57665971
57675972 } else {
....@@ -6114,8 +6319,10 @@
61146319 return -EFAULT;
61156320
61166321 asoc = sctp_id2assoc(sk, info.sinfo_assoc_id);
6117
- if (!asoc && info.sinfo_assoc_id && sctp_style(sk, UDP))
6322
+ if (!asoc && info.sinfo_assoc_id != SCTP_FUTURE_ASSOC &&
6323
+ sctp_style(sk, UDP))
61186324 return -EINVAL;
6325
+
61196326 if (asoc) {
61206327 info.sinfo_stream = asoc->default_stream;
61216328 info.sinfo_flags = asoc->default_flags;
....@@ -6158,8 +6365,10 @@
61586365 return -EFAULT;
61596366
61606367 asoc = sctp_id2assoc(sk, info.snd_assoc_id);
6161
- if (!asoc && info.snd_assoc_id && sctp_style(sk, UDP))
6368
+ if (!asoc && info.snd_assoc_id != SCTP_FUTURE_ASSOC &&
6369
+ sctp_style(sk, UDP))
61626370 return -EINVAL;
6371
+
61636372 if (asoc) {
61646373 info.snd_sid = asoc->default_stream;
61656374 info.snd_flags = asoc->default_flags;
....@@ -6235,7 +6444,8 @@
62356444
62366445 asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id);
62376446
6238
- if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP))
6447
+ if (!asoc && rtoinfo.srto_assoc_id != SCTP_FUTURE_ASSOC &&
6448
+ sctp_style(sk, UDP))
62396449 return -EINVAL;
62406450
62416451 /* Values corresponding to the specific association. */
....@@ -6292,7 +6502,8 @@
62926502
62936503 asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id);
62946504
6295
- if (!asoc && assocparams.sasoc_assoc_id && sctp_style(sk, UDP))
6505
+ if (!asoc && assocparams.sasoc_assoc_id != SCTP_FUTURE_ASSOC &&
6506
+ sctp_style(sk, UDP))
62966507 return -EINVAL;
62976508
62986509 /* Values correspoinding to the specific association */
....@@ -6367,7 +6578,6 @@
63676578 char __user *optval, int __user *optlen)
63686579 {
63696580 struct sctp_assoc_value params;
6370
- struct sctp_sock *sp;
63716581 struct sctp_association *asoc;
63726582
63736583 if (len < sizeof(struct sctp_assoc_value))
....@@ -6378,16 +6588,13 @@
63786588 if (copy_from_user(&params, optval, len))
63796589 return -EFAULT;
63806590
6381
- sp = sctp_sk(sk);
6591
+ asoc = sctp_id2assoc(sk, params.assoc_id);
6592
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
6593
+ sctp_style(sk, UDP))
6594
+ return -EINVAL;
63826595
6383
- if (params.assoc_id != 0) {
6384
- asoc = sctp_id2assoc(sk, params.assoc_id);
6385
- if (!asoc)
6386
- return -EINVAL;
6387
- params.assoc_value = asoc->default_rcv_context;
6388
- } else {
6389
- params.assoc_value = sp->default_rcv_context;
6390
- }
6596
+ params.assoc_value = asoc ? asoc->default_rcv_context
6597
+ : sctp_sk(sk)->default_rcv_context;
63916598
63926599 if (put_user(len, optlen))
63936600 return -EFAULT;
....@@ -6436,7 +6643,7 @@
64366643 "Use of int in maxseg socket option.\n"
64376644 "Use struct sctp_assoc_value instead\n",
64386645 current->comm, task_pid_nr(current));
6439
- params.assoc_id = 0;
6646
+ params.assoc_id = SCTP_FUTURE_ASSOC;
64406647 } else if (len >= sizeof(struct sctp_assoc_value)) {
64416648 len = sizeof(struct sctp_assoc_value);
64426649 if (copy_from_user(&params, optval, len))
....@@ -6445,7 +6652,8 @@
64456652 return -EINVAL;
64466653
64476654 asoc = sctp_id2assoc(sk, params.assoc_id);
6448
- if (!asoc && params.assoc_id && sctp_style(sk, UDP))
6655
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
6656
+ sctp_style(sk, UDP))
64496657 return -EINVAL;
64506658
64516659 if (asoc)
....@@ -6522,7 +6730,6 @@
65226730 int __user *optlen)
65236731 {
65246732 struct sctp_assoc_value params;
6525
- struct sctp_sock *sp;
65266733 struct sctp_association *asoc;
65276734
65286735 if (len == sizeof(int)) {
....@@ -6531,7 +6738,7 @@
65316738 "Use of int in max_burst socket option.\n"
65326739 "Use struct sctp_assoc_value instead\n",
65336740 current->comm, task_pid_nr(current));
6534
- params.assoc_id = 0;
6741
+ params.assoc_id = SCTP_FUTURE_ASSOC;
65356742 } else if (len >= sizeof(struct sctp_assoc_value)) {
65366743 len = sizeof(struct sctp_assoc_value);
65376744 if (copy_from_user(&params, optval, len))
....@@ -6539,15 +6746,12 @@
65396746 } else
65406747 return -EINVAL;
65416748
6542
- sp = sctp_sk(sk);
6749
+ asoc = sctp_id2assoc(sk, params.assoc_id);
6750
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
6751
+ sctp_style(sk, UDP))
6752
+ return -EINVAL;
65436753
6544
- if (params.assoc_id != 0) {
6545
- asoc = sctp_id2assoc(sk, params.assoc_id);
6546
- if (!asoc)
6547
- return -EINVAL;
6548
- params.assoc_value = asoc->max_burst;
6549
- } else
6550
- params.assoc_value = sp->max_burst;
6754
+ params.assoc_value = asoc ? asoc->max_burst : sctp_sk(sk)->max_burst;
65516755
65526756 if (len == sizeof(int)) {
65536757 if (copy_to_user(optval, &params.assoc_value, len))
....@@ -6604,9 +6808,6 @@
66046808 struct sctp_authkeyid val;
66056809 struct sctp_association *asoc;
66066810
6607
- if (!ep->auth_enable)
6608
- return -EACCES;
6609
-
66106811 if (len < sizeof(struct sctp_authkeyid))
66116812 return -EINVAL;
66126813
....@@ -6618,10 +6819,15 @@
66186819 if (!asoc && val.scact_assoc_id && sctp_style(sk, UDP))
66196820 return -EINVAL;
66206821
6621
- if (asoc)
6822
+ if (asoc) {
6823
+ if (!asoc->peer.auth_capable)
6824
+ return -EACCES;
66226825 val.scact_keynumber = asoc->active_key_id;
6623
- else
6826
+ } else {
6827
+ if (!ep->auth_enable)
6828
+ return -EACCES;
66246829 val.scact_keynumber = ep->active_key_id;
6830
+ }
66256831
66266832 if (put_user(len, optlen))
66276833 return -EFAULT;
....@@ -6634,16 +6840,12 @@
66346840 static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len,
66356841 char __user *optval, int __user *optlen)
66366842 {
6637
- struct sctp_endpoint *ep = sctp_sk(sk)->ep;
66386843 struct sctp_authchunks __user *p = (void __user *)optval;
66396844 struct sctp_authchunks val;
66406845 struct sctp_association *asoc;
66416846 struct sctp_chunks_param *ch;
66426847 u32 num_chunks = 0;
66436848 char __user *to;
6644
-
6645
- if (!ep->auth_enable)
6646
- return -EACCES;
66476849
66486850 if (len < sizeof(struct sctp_authchunks))
66496851 return -EINVAL;
....@@ -6655,6 +6857,9 @@
66556857 asoc = sctp_id2assoc(sk, val.gauth_assoc_id);
66566858 if (!asoc)
66576859 return -EINVAL;
6860
+
6861
+ if (!asoc->peer.auth_capable)
6862
+ return -EACCES;
66586863
66596864 ch = asoc->peer.peer_chunks;
66606865 if (!ch)
....@@ -6687,9 +6892,6 @@
66876892 u32 num_chunks = 0;
66886893 char __user *to;
66896894
6690
- if (!ep->auth_enable)
6691
- return -EACCES;
6692
-
66936895 if (len < sizeof(struct sctp_authchunks))
66946896 return -EINVAL;
66956897
....@@ -6698,14 +6900,19 @@
66986900
66996901 to = p->gauth_chunks;
67006902 asoc = sctp_id2assoc(sk, val.gauth_assoc_id);
6701
- if (!asoc && val.gauth_assoc_id && sctp_style(sk, UDP))
6903
+ if (!asoc && val.gauth_assoc_id != SCTP_FUTURE_ASSOC &&
6904
+ sctp_style(sk, UDP))
67026905 return -EINVAL;
67036906
6704
- if (asoc)
6907
+ if (asoc) {
6908
+ if (!asoc->peer.auth_capable)
6909
+ return -EACCES;
67056910 ch = (struct sctp_chunks_param *)asoc->c.auth_chunks;
6706
- else
6911
+ } else {
6912
+ if (!ep->auth_enable)
6913
+ return -EACCES;
67076914 ch = ep->auth_chunk_list;
6708
-
6915
+ }
67096916 if (!ch)
67106917 goto num;
67116918
....@@ -6836,28 +7043,22 @@
68367043 * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
68377044 */
68387045 static int sctp_getsockopt_paddr_thresholds(struct sock *sk,
6839
- char __user *optval,
6840
- int len,
6841
- int __user *optlen)
7046
+ char __user *optval, int len,
7047
+ int __user *optlen, bool v2)
68427048 {
6843
- struct sctp_paddrthlds val;
7049
+ struct sctp_paddrthlds_v2 val;
68447050 struct sctp_transport *trans;
68457051 struct sctp_association *asoc;
7052
+ int min;
68467053
6847
- if (len < sizeof(struct sctp_paddrthlds))
7054
+ min = v2 ? sizeof(val) : sizeof(struct sctp_paddrthlds);
7055
+ if (len < min)
68487056 return -EINVAL;
6849
- len = sizeof(struct sctp_paddrthlds);
6850
- if (copy_from_user(&val, (struct sctp_paddrthlds __user *)optval, len))
7057
+ len = min;
7058
+ if (copy_from_user(&val, optval, len))
68517059 return -EFAULT;
68527060
6853
- if (sctp_is_any(sk, (const union sctp_addr *)&val.spt_address)) {
6854
- asoc = sctp_id2assoc(sk, val.spt_assoc_id);
6855
- if (!asoc)
6856
- return -ENOENT;
6857
-
6858
- val.spt_pathpfthld = asoc->pf_retrans;
6859
- val.spt_pathmaxrxt = asoc->pathmaxrxt;
6860
- } else {
7061
+ if (!sctp_is_any(sk, (const union sctp_addr *)&val.spt_address)) {
68617062 trans = sctp_addr_id2transport(sk, &val.spt_address,
68627063 val.spt_assoc_id);
68637064 if (!trans)
....@@ -6865,8 +7066,29 @@
68657066
68667067 val.spt_pathmaxrxt = trans->pathmaxrxt;
68677068 val.spt_pathpfthld = trans->pf_retrans;
7069
+ val.spt_pathcpthld = trans->ps_retrans;
7070
+
7071
+ goto out;
68687072 }
68697073
7074
+ asoc = sctp_id2assoc(sk, val.spt_assoc_id);
7075
+ if (!asoc && val.spt_assoc_id != SCTP_FUTURE_ASSOC &&
7076
+ sctp_style(sk, UDP))
7077
+ return -EINVAL;
7078
+
7079
+ if (asoc) {
7080
+ val.spt_pathpfthld = asoc->pf_retrans;
7081
+ val.spt_pathmaxrxt = asoc->pathmaxrxt;
7082
+ val.spt_pathcpthld = asoc->ps_retrans;
7083
+ } else {
7084
+ struct sctp_sock *sp = sctp_sk(sk);
7085
+
7086
+ val.spt_pathpfthld = sp->pf_retrans;
7087
+ val.spt_pathmaxrxt = sp->pathmaxrxt;
7088
+ val.spt_pathcpthld = sp->ps_retrans;
7089
+ }
7090
+
7091
+out:
68707092 if (put_user(len, optlen) || copy_to_user(optval, &val, len))
68717093 return -EFAULT;
68727094
....@@ -6995,16 +7217,14 @@
69957217 goto out;
69967218
69977219 asoc = sctp_id2assoc(sk, params.assoc_id);
6998
- if (asoc) {
6999
- params.assoc_value = asoc->prsctp_enable;
7000
- } else if (!params.assoc_id) {
7001
- struct sctp_sock *sp = sctp_sk(sk);
7002
-
7003
- params.assoc_value = sp->ep->prsctp_enable;
7004
- } else {
7220
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7221
+ sctp_style(sk, UDP)) {
70057222 retval = -EINVAL;
70067223 goto out;
70077224 }
7225
+
7226
+ params.assoc_value = asoc ? asoc->peer.prsctp_capable
7227
+ : sctp_sk(sk)->ep->prsctp_enable;
70087228
70097229 if (put_user(len, optlen))
70107230 goto out;
....@@ -7036,17 +7256,20 @@
70367256 goto out;
70377257
70387258 asoc = sctp_id2assoc(sk, info.pr_assoc_id);
7259
+ if (!asoc && info.pr_assoc_id != SCTP_FUTURE_ASSOC &&
7260
+ sctp_style(sk, UDP)) {
7261
+ retval = -EINVAL;
7262
+ goto out;
7263
+ }
7264
+
70397265 if (asoc) {
70407266 info.pr_policy = SCTP_PR_POLICY(asoc->default_flags);
70417267 info.pr_value = asoc->default_timetolive;
7042
- } else if (!info.pr_assoc_id) {
7268
+ } else {
70437269 struct sctp_sock *sp = sctp_sk(sk);
70447270
70457271 info.pr_policy = SCTP_PR_POLICY(sp->default_flags);
70467272 info.pr_value = sp->default_timetolive;
7047
- } else {
7048
- retval = -EINVAL;
7049
- goto out;
70507273 }
70517274
70527275 if (put_user(len, optlen))
....@@ -7202,16 +7425,14 @@
72027425 goto out;
72037426
72047427 asoc = sctp_id2assoc(sk, params.assoc_id);
7205
- if (asoc) {
7206
- params.assoc_value = asoc->reconf_enable;
7207
- } else if (!params.assoc_id) {
7208
- struct sctp_sock *sp = sctp_sk(sk);
7209
-
7210
- params.assoc_value = sp->ep->reconf_enable;
7211
- } else {
7428
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7429
+ sctp_style(sk, UDP)) {
72127430 retval = -EINVAL;
72137431 goto out;
72147432 }
7433
+
7434
+ params.assoc_value = asoc ? asoc->peer.reconf_capable
7435
+ : sctp_sk(sk)->ep->reconf_enable;
72157436
72167437 if (put_user(len, optlen))
72177438 goto out;
....@@ -7243,16 +7464,14 @@
72437464 goto out;
72447465
72457466 asoc = sctp_id2assoc(sk, params.assoc_id);
7246
- if (asoc) {
7247
- params.assoc_value = asoc->strreset_enable;
7248
- } else if (!params.assoc_id) {
7249
- struct sctp_sock *sp = sctp_sk(sk);
7250
-
7251
- params.assoc_value = sp->ep->strreset_enable;
7252
- } else {
7467
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7468
+ sctp_style(sk, UDP)) {
72537469 retval = -EINVAL;
72547470 goto out;
72557471 }
7472
+
7473
+ params.assoc_value = asoc ? asoc->strreset_enable
7474
+ : sctp_sk(sk)->ep->strreset_enable;
72567475
72577476 if (put_user(len, optlen))
72587477 goto out;
....@@ -7284,12 +7503,14 @@
72847503 goto out;
72857504
72867505 asoc = sctp_id2assoc(sk, params.assoc_id);
7287
- if (!asoc) {
7506
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7507
+ sctp_style(sk, UDP)) {
72887508 retval = -EINVAL;
72897509 goto out;
72907510 }
72917511
7292
- params.assoc_value = sctp_sched_get_sched(asoc);
7512
+ params.assoc_value = asoc ? sctp_sched_get_sched(asoc)
7513
+ : sctp_sk(sk)->default_ss;
72937514
72947515 if (put_user(len, optlen))
72957516 goto out;
....@@ -7363,16 +7584,14 @@
73637584 goto out;
73647585
73657586 asoc = sctp_id2assoc(sk, params.assoc_id);
7366
- if (asoc) {
7367
- params.assoc_value = asoc->intl_enable;
7368
- } else if (!params.assoc_id) {
7369
- struct sctp_sock *sp = sctp_sk(sk);
7370
-
7371
- params.assoc_value = sp->strm_interleave;
7372
- } else {
7587
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7588
+ sctp_style(sk, UDP)) {
73737589 retval = -EINVAL;
73747590 goto out;
73757591 }
7592
+
7593
+ params.assoc_value = asoc ? asoc->peer.intl_capable
7594
+ : sctp_sk(sk)->ep->intl_enable;
73767595
73777596 if (put_user(len, optlen))
73787597 goto out;
....@@ -7404,6 +7623,197 @@
74047623 return -EFAULT;
74057624
74067625 return 0;
7626
+}
7627
+
7628
+static int sctp_getsockopt_event(struct sock *sk, int len, char __user *optval,
7629
+ int __user *optlen)
7630
+{
7631
+ struct sctp_association *asoc;
7632
+ struct sctp_event param;
7633
+ __u16 subscribe;
7634
+
7635
+ if (len < sizeof(param))
7636
+ return -EINVAL;
7637
+
7638
+ len = sizeof(param);
7639
+ if (copy_from_user(&param, optval, len))
7640
+ return -EFAULT;
7641
+
7642
+ if (param.se_type < SCTP_SN_TYPE_BASE ||
7643
+ param.se_type > SCTP_SN_TYPE_MAX)
7644
+ return -EINVAL;
7645
+
7646
+ asoc = sctp_id2assoc(sk, param.se_assoc_id);
7647
+ if (!asoc && param.se_assoc_id != SCTP_FUTURE_ASSOC &&
7648
+ sctp_style(sk, UDP))
7649
+ return -EINVAL;
7650
+
7651
+ subscribe = asoc ? asoc->subscribe : sctp_sk(sk)->subscribe;
7652
+ param.se_on = sctp_ulpevent_type_enabled(subscribe, param.se_type);
7653
+
7654
+ if (put_user(len, optlen))
7655
+ return -EFAULT;
7656
+
7657
+ if (copy_to_user(optval, &param, len))
7658
+ return -EFAULT;
7659
+
7660
+ return 0;
7661
+}
7662
+
7663
+static int sctp_getsockopt_asconf_supported(struct sock *sk, int len,
7664
+ char __user *optval,
7665
+ int __user *optlen)
7666
+{
7667
+ struct sctp_assoc_value params;
7668
+ struct sctp_association *asoc;
7669
+ int retval = -EFAULT;
7670
+
7671
+ if (len < sizeof(params)) {
7672
+ retval = -EINVAL;
7673
+ goto out;
7674
+ }
7675
+
7676
+ len = sizeof(params);
7677
+ if (copy_from_user(&params, optval, len))
7678
+ goto out;
7679
+
7680
+ asoc = sctp_id2assoc(sk, params.assoc_id);
7681
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7682
+ sctp_style(sk, UDP)) {
7683
+ retval = -EINVAL;
7684
+ goto out;
7685
+ }
7686
+
7687
+ params.assoc_value = asoc ? asoc->peer.asconf_capable
7688
+ : sctp_sk(sk)->ep->asconf_enable;
7689
+
7690
+ if (put_user(len, optlen))
7691
+ goto out;
7692
+
7693
+ if (copy_to_user(optval, &params, len))
7694
+ goto out;
7695
+
7696
+ retval = 0;
7697
+
7698
+out:
7699
+ return retval;
7700
+}
7701
+
7702
+static int sctp_getsockopt_auth_supported(struct sock *sk, int len,
7703
+ char __user *optval,
7704
+ int __user *optlen)
7705
+{
7706
+ struct sctp_assoc_value params;
7707
+ struct sctp_association *asoc;
7708
+ int retval = -EFAULT;
7709
+
7710
+ if (len < sizeof(params)) {
7711
+ retval = -EINVAL;
7712
+ goto out;
7713
+ }
7714
+
7715
+ len = sizeof(params);
7716
+ if (copy_from_user(&params, optval, len))
7717
+ goto out;
7718
+
7719
+ asoc = sctp_id2assoc(sk, params.assoc_id);
7720
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7721
+ sctp_style(sk, UDP)) {
7722
+ retval = -EINVAL;
7723
+ goto out;
7724
+ }
7725
+
7726
+ params.assoc_value = asoc ? asoc->peer.auth_capable
7727
+ : sctp_sk(sk)->ep->auth_enable;
7728
+
7729
+ if (put_user(len, optlen))
7730
+ goto out;
7731
+
7732
+ if (copy_to_user(optval, &params, len))
7733
+ goto out;
7734
+
7735
+ retval = 0;
7736
+
7737
+out:
7738
+ return retval;
7739
+}
7740
+
7741
+static int sctp_getsockopt_ecn_supported(struct sock *sk, int len,
7742
+ char __user *optval,
7743
+ int __user *optlen)
7744
+{
7745
+ struct sctp_assoc_value params;
7746
+ struct sctp_association *asoc;
7747
+ int retval = -EFAULT;
7748
+
7749
+ if (len < sizeof(params)) {
7750
+ retval = -EINVAL;
7751
+ goto out;
7752
+ }
7753
+
7754
+ len = sizeof(params);
7755
+ if (copy_from_user(&params, optval, len))
7756
+ goto out;
7757
+
7758
+ asoc = sctp_id2assoc(sk, params.assoc_id);
7759
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7760
+ sctp_style(sk, UDP)) {
7761
+ retval = -EINVAL;
7762
+ goto out;
7763
+ }
7764
+
7765
+ params.assoc_value = asoc ? asoc->peer.ecn_capable
7766
+ : sctp_sk(sk)->ep->ecn_enable;
7767
+
7768
+ if (put_user(len, optlen))
7769
+ goto out;
7770
+
7771
+ if (copy_to_user(optval, &params, len))
7772
+ goto out;
7773
+
7774
+ retval = 0;
7775
+
7776
+out:
7777
+ return retval;
7778
+}
7779
+
7780
+static int sctp_getsockopt_pf_expose(struct sock *sk, int len,
7781
+ char __user *optval,
7782
+ int __user *optlen)
7783
+{
7784
+ struct sctp_assoc_value params;
7785
+ struct sctp_association *asoc;
7786
+ int retval = -EFAULT;
7787
+
7788
+ if (len < sizeof(params)) {
7789
+ retval = -EINVAL;
7790
+ goto out;
7791
+ }
7792
+
7793
+ len = sizeof(params);
7794
+ if (copy_from_user(&params, optval, len))
7795
+ goto out;
7796
+
7797
+ asoc = sctp_id2assoc(sk, params.assoc_id);
7798
+ if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
7799
+ sctp_style(sk, UDP)) {
7800
+ retval = -EINVAL;
7801
+ goto out;
7802
+ }
7803
+
7804
+ params.assoc_value = asoc ? asoc->pf_expose
7805
+ : sctp_sk(sk)->pf_expose;
7806
+
7807
+ if (put_user(len, optlen))
7808
+ goto out;
7809
+
7810
+ if (copy_to_user(optval, &params, len))
7811
+ goto out;
7812
+
7813
+ retval = 0;
7814
+
7815
+out:
7816
+ return retval;
74077817 }
74087818
74097819 static int sctp_getsockopt(struct sock *sk, int level, int optname,
....@@ -7555,7 +7965,12 @@
75557965 retval = sctp_getsockopt_auto_asconf(sk, len, optval, optlen);
75567966 break;
75577967 case SCTP_PEER_ADDR_THLDS:
7558
- retval = sctp_getsockopt_paddr_thresholds(sk, optval, len, optlen);
7968
+ retval = sctp_getsockopt_paddr_thresholds(sk, optval, len,
7969
+ optlen, false);
7970
+ break;
7971
+ case SCTP_PEER_ADDR_THLDS_V2:
7972
+ retval = sctp_getsockopt_paddr_thresholds(sk, optval, len,
7973
+ optlen, true);
75597974 break;
75607975 case SCTP_GET_ASSOC_STATS:
75617976 retval = sctp_getsockopt_assoc_stats(sk, len, optval, optlen);
....@@ -7604,6 +8019,23 @@
76048019 case SCTP_REUSE_PORT:
76058020 retval = sctp_getsockopt_reuse_port(sk, len, optval, optlen);
76068021 break;
8022
+ case SCTP_EVENT:
8023
+ retval = sctp_getsockopt_event(sk, len, optval, optlen);
8024
+ break;
8025
+ case SCTP_ASCONF_SUPPORTED:
8026
+ retval = sctp_getsockopt_asconf_supported(sk, len, optval,
8027
+ optlen);
8028
+ break;
8029
+ case SCTP_AUTH_SUPPORTED:
8030
+ retval = sctp_getsockopt_auth_supported(sk, len, optval,
8031
+ optlen);
8032
+ break;
8033
+ case SCTP_ECN_SUPPORTED:
8034
+ retval = sctp_getsockopt_ecn_supported(sk, len, optval, optlen);
8035
+ break;
8036
+ case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
8037
+ retval = sctp_getsockopt_pf_expose(sk, len, optval, optlen);
8038
+ break;
76078039 default:
76088040 retval = -ENOPROTOOPT;
76098041 break;
....@@ -7639,10 +8071,13 @@
76398071 static struct sctp_bind_bucket *sctp_bucket_create(
76408072 struct sctp_bind_hashbucket *head, struct net *, unsigned short snum);
76418073
7642
-static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
8074
+static int sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
76438075 {
7644
- bool reuse = (sk->sk_reuse || sctp_sk(sk)->reuse);
8076
+ struct sctp_sock *sp = sctp_sk(sk);
8077
+ bool reuse = (sk->sk_reuse || sp->reuse);
76458078 struct sctp_bind_hashbucket *head; /* hash list */
8079
+ struct net *net = sock_net(sk);
8080
+ kuid_t uid = sock_i_uid(sk);
76468081 struct sctp_bind_bucket *pp;
76478082 unsigned short snum;
76488083 int ret;
....@@ -7655,7 +8090,6 @@
76558090 /* Search for an available port. */
76568091 int low, high, remaining, index;
76578092 unsigned int rover;
7658
- struct net *net = sock_net(sk);
76598093
76608094 inet_get_local_port_range(net, &low, &high);
76618095 remaining = (high - low) + 1;
....@@ -7667,12 +8101,12 @@
76678101 rover = low;
76688102 if (inet_is_local_reserved_port(net, rover))
76698103 continue;
7670
- index = sctp_phashfn(sock_net(sk), rover);
8104
+ index = sctp_phashfn(net, rover);
76718105 head = &sctp_port_hashtable[index];
76728106 spin_lock_bh(&head->lock);
76738107 sctp_for_each_hentry(pp, &head->chain)
76748108 if ((pp->port == rover) &&
7675
- net_eq(sock_net(sk), pp->net))
8109
+ net_eq(net, pp->net))
76768110 goto next;
76778111 break;
76788112 next:
....@@ -7697,10 +8131,10 @@
76978131 * to the port number (snum) - we detect that with the
76988132 * port iterator, pp being NULL.
76998133 */
7700
- head = &sctp_port_hashtable[sctp_phashfn(sock_net(sk), snum)];
8134
+ head = &sctp_port_hashtable[sctp_phashfn(net, snum)];
77018135 spin_lock_bh(&head->lock);
77028136 sctp_for_each_hentry(pp, &head->chain) {
7703
- if ((pp->port == snum) && net_eq(pp->net, sock_net(sk)))
8137
+ if ((pp->port == snum) && net_eq(pp->net, net))
77048138 goto pp_found;
77058139 }
77068140 }
....@@ -7717,7 +8151,10 @@
77178151
77188152 pr_debug("%s: found a possible match\n", __func__);
77198153
7720
- if (pp->fastreuse && reuse && sk->sk_state != SCTP_SS_LISTENING)
8154
+ if ((pp->fastreuse && reuse &&
8155
+ sk->sk_state != SCTP_SS_LISTENING) ||
8156
+ (pp->fastreuseport && sk->sk_reuseport &&
8157
+ uid_eq(pp->fastuid, uid)))
77218158 goto success;
77228159
77238160 /* Run through the list of sockets bound to the port
....@@ -7731,17 +8168,19 @@
77318168 * in an endpoint.
77328169 */
77338170 sk_for_each_bound(sk2, &pp->owner) {
7734
- struct sctp_endpoint *ep2;
7735
- ep2 = sctp_sk(sk2)->ep;
8171
+ struct sctp_sock *sp2 = sctp_sk(sk2);
8172
+ struct sctp_endpoint *ep2 = sp2->ep;
77368173
77378174 if (sk == sk2 ||
7738
- (reuse && (sk2->sk_reuse || sctp_sk(sk2)->reuse) &&
7739
- sk2->sk_state != SCTP_SS_LISTENING))
8175
+ (reuse && (sk2->sk_reuse || sp2->reuse) &&
8176
+ sk2->sk_state != SCTP_SS_LISTENING) ||
8177
+ (sk->sk_reuseport && sk2->sk_reuseport &&
8178
+ uid_eq(uid, sock_i_uid(sk2))))
77408179 continue;
77418180
7742
- if (sctp_bind_addr_conflict(&ep2->base.bind_addr, addr,
7743
- sctp_sk(sk2), sctp_sk(sk))) {
7744
- ret = (long)sk2;
8181
+ if (sctp_bind_addr_conflict(&ep2->base.bind_addr,
8182
+ addr, sp2, sp)) {
8183
+ ret = 1;
77458184 goto fail_unlock;
77468185 }
77478186 }
....@@ -7751,7 +8190,7 @@
77518190 pp_not_found:
77528191 /* If there was a hash table miss, create a new port. */
77538192 ret = 1;
7754
- if (!pp && !(pp = sctp_bucket_create(head, sock_net(sk), snum)))
8193
+ if (!pp && !(pp = sctp_bucket_create(head, net, snum)))
77558194 goto fail_unlock;
77568195
77578196 /* In either case (hit or miss), make sure fastreuse is 1 only
....@@ -7763,19 +8202,32 @@
77638202 pp->fastreuse = 1;
77648203 else
77658204 pp->fastreuse = 0;
7766
- } else if (pp->fastreuse &&
7767
- (!reuse || sk->sk_state == SCTP_SS_LISTENING))
7768
- pp->fastreuse = 0;
8205
+
8206
+ if (sk->sk_reuseport) {
8207
+ pp->fastreuseport = 1;
8208
+ pp->fastuid = uid;
8209
+ } else {
8210
+ pp->fastreuseport = 0;
8211
+ }
8212
+ } else {
8213
+ if (pp->fastreuse &&
8214
+ (!reuse || sk->sk_state == SCTP_SS_LISTENING))
8215
+ pp->fastreuse = 0;
8216
+
8217
+ if (pp->fastreuseport &&
8218
+ (!sk->sk_reuseport || !uid_eq(pp->fastuid, uid)))
8219
+ pp->fastreuseport = 0;
8220
+ }
77698221
77708222 /* We are set, so fill up all the data in the hash table
77718223 * entry, tie the socket list information with the rest of the
77728224 * sockets FIXME: Blurry, NPI (ipg).
77738225 */
77748226 success:
7775
- if (!sctp_sk(sk)->bind_hash) {
8227
+ if (!sp->bind_hash) {
77768228 inet_sk(sk)->inet_num = snum;
77778229 sk_add_bind_node(sk, &pp->owner);
7778
- sctp_sk(sk)->bind_hash = pp;
8230
+ sp->bind_hash = pp;
77798231 }
77808232 ret = 0;
77818233
....@@ -7797,7 +8249,7 @@
77978249 addr.v4.sin_port = htons(snum);
77988250
77998251 /* Note: sk->sk_num gets filled in if ephemeral port request. */
7800
- return !!sctp_get_port_local(sk, &addr);
8252
+ return sctp_get_port_local(sk, &addr);
78018253 }
78028254
78038255 /*
....@@ -7844,9 +8296,8 @@
78448296 }
78458297 }
78468298
7847
- sk->sk_max_ack_backlog = backlog;
7848
- sctp_hash_endpoint(ep);
7849
- return 0;
8299
+ WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
8300
+ return sctp_hash_endpoint(ep);
78508301 }
78518302
78528303 /*
....@@ -7899,7 +8350,7 @@
78998350
79008351 /* If we are already listening, just update the backlog */
79018352 if (sctp_sstate(sk, LISTENING))
7902
- sk->sk_max_ack_backlog = backlog;
8353
+ WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
79038354 else {
79048355 err = sctp_listen_start(sk, backlog);
79058356 if (err)
....@@ -8438,17 +8889,11 @@
84388889 struct sctp_association *asoc = chunk->asoc;
84398890 struct sock *sk = asoc->base.sk;
84408891
8441
- asoc->sndbuf_used -= SCTP_DATA_SNDSIZE(chunk) +
8442
- sizeof(struct sk_buff) +
8443
- sizeof(struct sctp_chunk);
8444
-
8445
- WARN_ON(refcount_sub_and_test(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc));
8446
-
8447
- /*
8448
- * This undoes what is done via sctp_set_owner_w and sk_mem_charge
8449
- */
8450
- sk->sk_wmem_queued -= skb->truesize;
84518892 sk_mem_uncharge(sk, skb->truesize);
8893
+ sk_wmem_queued_add(sk, -(skb->truesize + sizeof(struct sctp_chunk)));
8894
+ asoc->sndbuf_used -= skb->truesize + sizeof(struct sctp_chunk);
8895
+ WARN_ON(refcount_sub_and_test(sizeof(struct sctp_chunk),
8896
+ &sk->sk_wmem_alloc));
84528897
84538898 if (chunk->shkey) {
84548899 struct sctp_shared_key *shkey = chunk->shkey;
....@@ -8600,9 +9045,9 @@
86009045 * UDP-style sockets or TCP-style sockets, this code should work.
86019046 * - Daisy
86029047 */
8603
-static bool sctp_writeable(struct sock *sk)
9048
+static bool sctp_writeable(const struct sock *sk)
86049049 {
8605
- return sk->sk_sndbuf > sk->sk_wmem_queued;
9050
+ return READ_ONCE(sk->sk_sndbuf) > READ_ONCE(sk->sk_wmem_queued);
86069051 }
86079052
86089053 /* Wait for an association to go into ESTABLISHED state. If timeout is 0,
....@@ -8760,7 +9205,7 @@
87609205 sctp_sk(newsk)->reuse = sp->reuse;
87619206
87629207 newsk->sk_shutdown = sk->sk_shutdown;
8763
- newsk->sk_destruct = sctp_destruct_sock;
9208
+ newsk->sk_destruct = sk->sk_destruct;
87649209 newsk->sk_family = sk->sk_family;
87659210 newsk->sk_protocol = IPPROTO_SCTP;
87669211 newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
....@@ -8801,22 +9246,19 @@
88019246 static inline void sctp_copy_descendant(struct sock *sk_to,
88029247 const struct sock *sk_from)
88039248 {
8804
- int ancestor_size = sizeof(struct inet_sock) +
8805
- sizeof(struct sctp_sock) -
8806
- offsetof(struct sctp_sock, auto_asconf_list);
9249
+ size_t ancestor_size = sizeof(struct inet_sock);
88079250
8808
- if (sk_from->sk_family == PF_INET6)
8809
- ancestor_size += sizeof(struct ipv6_pinfo);
8810
-
9251
+ ancestor_size += sk_from->sk_prot->obj_size;
9252
+ ancestor_size -= offsetof(struct sctp_sock, pd_lobby);
88119253 __inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
88129254 }
88139255
88149256 /* Populate the fields of the newsk from the oldsk and migrate the assoc
88159257 * and its messages to the newsk.
88169258 */
8817
-static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
8818
- struct sctp_association *assoc,
8819
- enum sctp_socket_type type)
9259
+static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
9260
+ struct sctp_association *assoc,
9261
+ enum sctp_socket_type type)
88209262 {
88219263 struct sctp_sock *oldsp = sctp_sk(oldsk);
88229264 struct sctp_sock *newsp = sctp_sk(newsk);
....@@ -8825,6 +9267,7 @@
88259267 struct sk_buff *skb, *tmp;
88269268 struct sctp_ulpevent *event;
88279269 struct sctp_bind_hashbucket *head;
9270
+ int err;
88289271
88299272 /* Migrate socket buffer sizes and all the socket level options to the
88309273 * new socket.
....@@ -8853,8 +9296,20 @@
88539296 /* Copy the bind_addr list from the original endpoint to the new
88549297 * endpoint so that we can handle restarts properly
88559298 */
8856
- sctp_bind_addr_dup(&newsp->ep->base.bind_addr,
8857
- &oldsp->ep->base.bind_addr, GFP_KERNEL);
9299
+ err = sctp_bind_addr_dup(&newsp->ep->base.bind_addr,
9300
+ &oldsp->ep->base.bind_addr, GFP_KERNEL);
9301
+ if (err)
9302
+ return err;
9303
+
9304
+ /* New ep's auth_hmacs should be set if old ep's is set, in case
9305
+ * that net->sctp.auth_enable has been changed to 0 by users and
9306
+ * new ep's auth_hmacs couldn't be set in sctp_endpoint_init().
9307
+ */
9308
+ if (oldsp->ep->auth_hmacs) {
9309
+ err = sctp_auth_init_hmacs(newsp->ep, GFP_KERNEL);
9310
+ if (err)
9311
+ return err;
9312
+ }
88589313
88599314 sctp_auto_asconf_init(newsp);
88609315
....@@ -8876,7 +9331,6 @@
88769331 * 2) Peeling off partial delivery; keep pd_lobby in new pd_lobby.
88779332 * 3) Peeling off non-partial delivery; move pd_lobby to receive_queue.
88789333 */
8879
- skb_queue_head_init(&newsp->pd_lobby);
88809334 atomic_set(&sctp_sk(newsk)->pd_mode, assoc->ulpq.pd_mode);
88819335
88829336 if (atomic_read(&sctp_sk(oldsk)->pd_mode)) {
....@@ -8941,6 +9395,8 @@
89419395 }
89429396
89439397 release_sock(newsk);
9398
+
9399
+ return 0;
89449400 }
89459401
89469402
....@@ -8960,6 +9416,7 @@
89609416 .sendmsg = sctp_sendmsg,
89619417 .recvmsg = sctp_recvmsg,
89629418 .bind = sctp_bind,
9419
+ .bind_add = sctp_bind_add,
89639420 .backlog_rcv = sctp_backlog_rcv,
89649421 .hash = sctp_hash,
89659422 .unhash = sctp_unhash,
....@@ -8980,11 +9437,20 @@
89809437
89819438 #if IS_ENABLED(CONFIG_IPV6)
89829439
8983
-#include <net/transp_v6.h>
8984
-static void sctp_v6_destroy_sock(struct sock *sk)
9440
+static void sctp_v6_destruct_sock(struct sock *sk)
89859441 {
8986
- sctp_destroy_sock(sk);
8987
- inet6_destroy_sock(sk);
9442
+ sctp_destruct_common(sk);
9443
+ inet6_sock_destruct(sk);
9444
+}
9445
+
9446
+static int sctp_v6_init_sock(struct sock *sk)
9447
+{
9448
+ int ret = sctp_init_sock(sk);
9449
+
9450
+ if (!ret)
9451
+ sk->sk_destruct = sctp_v6_destruct_sock;
9452
+
9453
+ return ret;
89889454 }
89899455
89909456 struct proto sctpv6_prot = {
....@@ -8994,14 +9460,15 @@
89949460 .disconnect = sctp_disconnect,
89959461 .accept = sctp_accept,
89969462 .ioctl = sctp_ioctl,
8997
- .init = sctp_init_sock,
8998
- .destroy = sctp_v6_destroy_sock,
9463
+ .init = sctp_v6_init_sock,
9464
+ .destroy = sctp_destroy_sock,
89999465 .shutdown = sctp_shutdown,
90009466 .setsockopt = sctp_setsockopt,
90019467 .getsockopt = sctp_getsockopt,
90029468 .sendmsg = sctp_sendmsg,
90039469 .recvmsg = sctp_recvmsg,
90049470 .bind = sctp_bind,
9471
+ .bind_add = sctp_bind_add,
90059472 .backlog_rcv = sctp_backlog_rcv,
90069473 .hash = sctp_hash,
90079474 .unhash = sctp_unhash,