History

Merge branch 'do-a-single-memdup_user-in-sctp_setsockopt-v2'

Christoph Hellwig says: ==================== do a single memdup_user in sctp_setsockopt v2 here is a resend of my series to lift the copy_from_user out of the individual sctp sockopt handlers into the main sctp_setsockopt routine. Changes since v1: - fixes a few sizeof calls. - use memzero_explicit in sctp_setsockopt_auth_key instead of special casing it for a kzfree in the caller - remove some minor cleanups from sctp_setsockopt_autoclose to keep it closer to the existing version - add another little only vaguely related cleanup patch ====================

David S. Miller committed 6 years ago

Commit bed1ce72 parents 9aa0dfe 6c8983a1 file · +477 −722Browse files

Unified · Split

net/sctp/socket.c+477−722
@@ -979,9 +979,8 @@ int sctp_asconf_mgmt(struct sctp_sock *sp, struct sctp_sockaddr_entry *addrw) · 978 unmodified lines
979 *979 *
980 * Returns 0 if ok, <0 errno code on error.980 * Returns 0 if ok, <0 errno code on error.
981 */981 */
982static int sctp_setsockopt_bindx_kernel(struct sock *sk,982static int sctp_setsockopt_bindx(struct sock *sk, struct sockaddr *addrs,
983 struct sockaddr *addrs, int addrs_size,983 int addrs_size, int op)
984 int op)
985{984{
986 int err;985 int err;
987 int addrcnt = 0;986 int addrcnt = 0;
@@ -991,7 +990,7 @@ static int sctp_setsockopt_bindx_kernel(struct sock *sk, · 3 unmodified lines
991 struct sctp_af *af;990 struct sctp_af *af;
992 991
993 pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n",992 pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n",
994 __func__, sk, addrs, addrs_size, op);993 __func__, sk, addr_buf, addrs_size, op);
995 994
996 if (unlikely(addrs_size <= 0))995 if (unlikely(addrs_size <= 0))
997 return -EINVAL;996 return -EINVAL;
@@ -1037,29 +1036,13 @@ static int sctp_setsockopt_bindx_kernel(struct sock *sk, · 39 unmodified lines
1037 }1036 }
1038}1037}
1039 1038
1040static int sctp_setsockopt_bindx(struct sock *sk,
1041 struct sockaddr __user *addrs,
1042 int addrs_size, int op)
1043{
1044 struct sockaddr *kaddrs;
1045 int err;
1046
1047 kaddrs = memdup_user(addrs, addrs_size);
1048 if (IS_ERR(kaddrs))
1049 return PTR_ERR(kaddrs);
1050 err = sctp_setsockopt_bindx_kernel(sk, kaddrs, addrs_size, op);
1051 kfree(kaddrs);
1052 return err;
1053}
1054
1055static int sctp_bind_add(struct sock *sk, struct sockaddr *addrs,1039static int sctp_bind_add(struct sock *sk, struct sockaddr *addrs,
1056 int addrlen)1040 int addrlen)
1057{1041{
1058 int err;1042 int err;
1059 1043
1060 lock_sock(sk);1044 lock_sock(sk);
1061 err = sctp_setsockopt_bindx_kernel(sk, addrs, addrlen,1045 err = sctp_setsockopt_bindx(sk, addrs, addrlen, SCTP_BINDX_ADD_ADDR);
1062 SCTP_BINDX_ADD_ADDR);
1063 release_sock(sk);1046 release_sock(sk);
1064 return err;1047 return err;
1065}1048}
@@ -1303,36 +1286,29 @@ out_free: · 237 unmodified lines
1303 * it.1286 * it.
1304 *1287 *
1305 * sk The sk of the socket1288 * sk The sk of the socket
1306 * addrs The pointer to the addresses in user land1289 * addrs The pointer to the addresses
1307 * addrssize Size of the addrs buffer1290 * addrssize Size of the addrs buffer
1308 *1291 *
1309 * Returns >=0 if ok, <0 errno code on error.1292 * Returns >=0 if ok, <0 errno code on error.
1310 */1293 */
1311static int __sctp_setsockopt_connectx(struct sock *sk,1294static int __sctp_setsockopt_connectx(struct sock *sk, struct sockaddr *kaddrs,
1312 struct sockaddr __user *addrs,1295 int addrs_size, sctp_assoc_t *assoc_id)
1313 int addrs_size,
1314 sctp_assoc_t *assoc_id)
1315{1296{
1316 struct sockaddr *kaddrs;
1317 int err = 0, flags = 0;1297 int err = 0, flags = 0;
1318 1298
1319 pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",1299 pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",
1320 __func__, sk, addrs, addrs_size);1300 __func__, sk, kaddrs, addrs_size);
1321 1301
1322 /* make sure the 1st addr's sa_family is accessible later */1302 /* make sure the 1st addr's sa_family is accessible later */
1323 if (unlikely(addrs_size < sizeof(sa_family_t)))1303 if (unlikely(addrs_size < sizeof(sa_family_t)))
1324 return -EINVAL;1304 return -EINVAL;
1325 1305
1326 kaddrs = memdup_user(addrs, addrs_size);
1327 if (IS_ERR(kaddrs))
1328 return PTR_ERR(kaddrs);
1329
1330 /* Allow security module to validate connectx addresses. */1306 /* Allow security module to validate connectx addresses. */
1331 err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_CONNECTX,1307 err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_CONNECTX,
1332 (struct sockaddr *)kaddrs,1308 (struct sockaddr *)kaddrs,
1333 addrs_size);1309 addrs_size);
1334 if (err)1310 if (err)
1335 goto out_free;1311 return err;
1336 1312
1337 /* in-kernel sockets don't generally have a file allocated to them1313 /* in-kernel sockets don't generally have a file allocated to them
1338 * if all they do is call sock_create_kern().1314 * if all they do is call sock_create_kern().
@@ -1340,12 +1316,7 @@ static int __sctp_setsockopt_connectx(struct sock *sk, · 1 unmodified line
1340 if (sk->sk_socket->file)1316 if (sk->sk_socket->file)
1341 flags = sk->sk_socket->file->f_flags;1317 flags = sk->sk_socket->file->f_flags;
1342 1318
1343 err = __sctp_connect(sk, kaddrs, addrs_size, flags, assoc_id);1319 return __sctp_connect(sk, kaddrs, addrs_size, flags, assoc_id);
1344
1345out_free:
1346 kfree(kaddrs);
1347
1348 return err;
1349}1320}
1350 1321
1351/*1322/*
@@ -1353,10 +1324,10 @@ out_free: · 1 unmodified line
1353 * to the option that doesn't provide association id.1324 * to the option that doesn't provide association id.
1354 */1325 */
1355static int sctp_setsockopt_connectx_old(struct sock *sk,1326static int sctp_setsockopt_connectx_old(struct sock *sk,
1356 struct sockaddr __user *addrs,1327 struct sockaddr *kaddrs,
1357 int addrs_size)1328 int addrs_size)
1358{1329{
1359 return __sctp_setsockopt_connectx(sk, addrs, addrs_size, NULL);1330 return __sctp_setsockopt_connectx(sk, kaddrs, addrs_size, NULL);
1360}1331}
1361 1332
1362/*1333/*
@@ -1366,13 +1337,13 @@ static int sctp_setsockopt_connectx_old(struct sock *sk, · 3 unmodified lines
1366 * always positive.1337 * always positive.
1367 */1338 */
1368static int sctp_setsockopt_connectx(struct sock *sk,1339static int sctp_setsockopt_connectx(struct sock *sk,
1369 struct sockaddr __user *addrs,1340 struct sockaddr *kaddrs,
1370 int addrs_size)1341 int addrs_size)
1371{1342{
1372 sctp_assoc_t assoc_id = 0;1343 sctp_assoc_t assoc_id = 0;
1373 int err = 0;1344 int err = 0;
1374 1345
1375 err = __sctp_setsockopt_connectx(sk, addrs, addrs_size, &assoc_id);1346 err = __sctp_setsockopt_connectx(sk, kaddrs, addrs_size, &assoc_id);
1376 1347
1377 if (err)1348 if (err)
1378 return err;1349 return err;
@@ -1402,6 +1373,7 @@ static int sctp_getsockopt_connectx3(struct sock *sk, int len, · 23 unmodified lines
1402{1373{
1403 struct sctp_getaddrs_old param;1374 struct sctp_getaddrs_old param;
1404 sctp_assoc_t assoc_id = 0;1375 sctp_assoc_t assoc_id = 0;
1376 struct sockaddr *kaddrs;
1405 int err = 0;1377 int err = 0;
1406 1378
1407#ifdef CONFIG_COMPAT1379#ifdef CONFIG_COMPAT
@@ -1425,9 +1397,12 @@ static int sctp_getsockopt_connectx3(struct sock *sk, int len, · 17 unmodified lines
1425 return -EFAULT;1397 return -EFAULT;
1426 }1398 }
1427 1399
1428 err = __sctp_setsockopt_connectx(sk, (struct sockaddr __user *)1400 kaddrs = memdup_user(param.addrs, param.addr_num);
1429 param.addrs, param.addr_num,1401 if (IS_ERR(kaddrs))
1430 &assoc_id);1402 return PTR_ERR(kaddrs);
1403
1404 err = __sctp_setsockopt_connectx(sk, kaddrs, param.addr_num, &assoc_id);
1405 kfree(kaddrs);
1431 if (err == 0 || err == -EINPROGRESS) {1406 if (err == 0 || err == -EINPROGRESS) {
1432 if (copy_to_user(optval, &assoc_id, sizeof(assoc_id)))1407 if (copy_to_user(optval, &assoc_id, sizeof(assoc_id)))
1433 return -EFAULT;1408 return -EFAULT;
@@ -2209,28 +2184,18 @@ out: · 775 unmodified lines
2209 * exceeds the current PMTU size, the message will NOT be sent and2184 * exceeds the current PMTU size, the message will NOT be sent and
2210 * instead a error will be indicated to the user.2185 * instead a error will be indicated to the user.
2211 */2186 */
2212static int sctp_setsockopt_disable_fragments(struct sock *sk,2187static int sctp_setsockopt_disable_fragments(struct sock *sk, int *val,
2213 char __user *optval,
2214 unsigned int optlen)2188 unsigned int optlen)
2215{2189{
2216 int val;
2217
2218 if (optlen < sizeof(int))2190 if (optlen < sizeof(int))
2219 return -EINVAL;2191 return -EINVAL;
2220 2192 sctp_sk(sk)->disable_fragments = (*val == 0) ? 0 : 1;
2221 if (get_user(val, (int __user *)optval))
2222 return -EFAULT;
2223
2224 sctp_sk(sk)->disable_fragments = (val == 0) ? 0 : 1;
2225
2226 return 0;2193 return 0;
2227}2194}
2228 2195
2229static int sctp_setsockopt_events(struct sock *sk, char __user *optval,2196static int sctp_setsockopt_events(struct sock *sk, __u8 *sn_type,
2230 unsigned int optlen)2197 unsigned int optlen)
2231{2198{
2232 struct sctp_event_subscribe subscribe;
2233 __u8 *sn_type = (__u8 *)&subscribe;
2234 struct sctp_sock *sp = sctp_sk(sk);2199 struct sctp_sock *sp = sctp_sk(sk);
2235 struct sctp_association *asoc;2200 struct sctp_association *asoc;
2236 int i;2201 int i;
@@ -2238,9 +2203,6 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval, · 1 unmodified line
2238 if (optlen > sizeof(struct sctp_event_subscribe))2203 if (optlen > sizeof(struct sctp_event_subscribe))
2239 return -EINVAL;2204 return -EINVAL;
2240 2205
2241 if (copy_from_user(&subscribe, optval, optlen))
2242 return -EFAULT;
2243
2244 for (i = 0; i < optlen; i++)2206 for (i = 0; i < optlen; i++)
2245 sctp_ulpevent_type_set(&sp->subscribe, SCTP_SN_TYPE_BASE + i,2207 sctp_ulpevent_type_set(&sp->subscribe, SCTP_SN_TYPE_BASE + i,
2246 sn_type[i]);2208 sn_type[i]);
@@ -2280,7 +2242,7 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval, · 33 unmodified lines
2280 * integer defining the number of seconds of idle time before an2242 * integer defining the number of seconds of idle time before an
2281 * association is closed.2243 * association is closed.
2282 */2244 */
2283static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval,2245static int sctp_setsockopt_autoclose(struct sock *sk, u32 *optval,
2284 unsigned int optlen)2246 unsigned int optlen)
2285{2247{
2286 struct sctp_sock *sp = sctp_sk(sk);2248 struct sctp_sock *sp = sctp_sk(sk);
@@ -2291,9 +2253,8 @@ static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval, · 4 unmodified lines
2291 return -EOPNOTSUPP;2253 return -EOPNOTSUPP;
2292 if (optlen != sizeof(int))2254 if (optlen != sizeof(int))
2293 return -EINVAL;2255 return -EINVAL;
2294 if (copy_from_user(&sp->autoclose, optval, optlen))
2295 return -EFAULT;
2296 2256
2257 sp->autoclose = *optval;
2297 if (sp->autoclose > net->sctp.max_autoclose)2258 if (sp->autoclose > net->sctp.max_autoclose)
2298 sp->autoclose = net->sctp.max_autoclose;2259 sp->autoclose = net->sctp.max_autoclose;
2299 2260
@@ -2628,48 +2589,42 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params, · 328 unmodified lines
2628}2589}
2629 2590
2630static int sctp_setsockopt_peer_addr_params(struct sock *sk,2591static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2631 char __user *optval,2592 struct sctp_paddrparams *params,
2632 unsigned int optlen)2593 unsigned int optlen)
2633{2594{
2634 struct sctp_paddrparams params;
2635 struct sctp_transport *trans = NULL;2595 struct sctp_transport *trans = NULL;
2636 struct sctp_association *asoc = NULL;2596 struct sctp_association *asoc = NULL;
2637 struct sctp_sock *sp = sctp_sk(sk);2597 struct sctp_sock *sp = sctp_sk(sk);
2638 int error;2598 int error;
2639 int hb_change, pmtud_change, sackdelay_change;2599 int hb_change, pmtud_change, sackdelay_change;
2640 2600
2641 if (optlen == sizeof(params)) {2601 if (optlen == ALIGN(offsetof(struct sctp_paddrparams,
2642 if (copy_from_user(&params, optval, optlen))
2643 return -EFAULT;
2644 } else if (optlen == ALIGN(offsetof(struct sctp_paddrparams,
2645 spp_ipv6_flowlabel), 4)) {2602 spp_ipv6_flowlabel), 4)) {
2646 if (copy_from_user(&params, optval, optlen))2603 if (params->spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL))
2647 return -EFAULT;
2648 if (params.spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL))
2649 return -EINVAL;2604 return -EINVAL;
2650 } else {2605 } else if (optlen != sizeof(*params)) {
2651 return -EINVAL;2606 return -EINVAL;
2652 }2607 }
2653 2608
2654 /* Validate flags and value parameters. */2609 /* Validate flags and value parameters. */
2655 hb_change = params.spp_flags & SPP_HB;2610 hb_change = params->spp_flags & SPP_HB;
2656 pmtud_change = params.spp_flags & SPP_PMTUD;2611 pmtud_change = params->spp_flags & SPP_PMTUD;
2657 sackdelay_change = params.spp_flags & SPP_SACKDELAY;2612 sackdelay_change = params->spp_flags & SPP_SACKDELAY;
2658 2613
2659 if (hb_change == SPP_HB ||2614 if (hb_change == SPP_HB ||
2660 pmtud_change == SPP_PMTUD ||2615 pmtud_change == SPP_PMTUD ||
2661 sackdelay_change == SPP_SACKDELAY ||2616 sackdelay_change == SPP_SACKDELAY ||
2662 params.spp_sackdelay > 500 ||2617 params->spp_sackdelay > 500 ||
2663 (params.spp_pathmtu &&2618 (params->spp_pathmtu &&
2664 params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))2619 params->spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
2665 return -EINVAL;2620 return -EINVAL;
2666 2621
2667 /* If an address other than INADDR_ANY is specified, and2622 /* If an address other than INADDR_ANY is specified, and
2668 * no transport is found, then the request is invalid.2623 * no transport is found, then the request is invalid.
2669 */2624 */
2670 if (!sctp_is_any(sk, (union sctp_addr *)&params.spp_address)) {2625 if (!sctp_is_any(sk, (union sctp_addr *)&params->spp_address)) {
2671 trans = sctp_addr_id2transport(sk, &params.spp_address,2626 trans = sctp_addr_id2transport(sk, &params->spp_address,
2672 params.spp_assoc_id);2627 params->spp_assoc_id);
2673 if (!trans)2628 if (!trans)
2674 return -EINVAL;2629 return -EINVAL;
2675 }2630 }
@@ -2678,19 +2633,19 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk, · 2 unmodified lines
2678 * socket is a one to many style socket, and an association2633 * socket is a one to many style socket, and an association
2679 * was not found, then the id was invalid.2634 * was not found, then the id was invalid.
2680 */2635 */
2681 asoc = sctp_id2assoc(sk, params.spp_assoc_id);2636 asoc = sctp_id2assoc(sk, params->spp_assoc_id);
2682 if (!asoc && params.spp_assoc_id != SCTP_FUTURE_ASSOC &&2637 if (!asoc && params->spp_assoc_id != SCTP_FUTURE_ASSOC &&
2683 sctp_style(sk, UDP))2638 sctp_style(sk, UDP))
2684 return -EINVAL;2639 return -EINVAL;
2685 2640
2686 /* Heartbeat demand can only be sent on a transport or2641 /* Heartbeat demand can only be sent on a transport or
2687 * association, but not a socket.2642 * association, but not a socket.
2688 */2643 */
2689 if (params.spp_flags & SPP_HB_DEMAND && !trans && !asoc)2644 if (params->spp_flags & SPP_HB_DEMAND && !trans && !asoc)
2690 return -EINVAL;2645 return -EINVAL;
2691 2646
2692 /* Process parameters. */2647 /* Process parameters. */
2693 error = sctp_apply_peer_addr_params(&params, trans, asoc, sp,2648 error = sctp_apply_peer_addr_params(params, trans, asoc, sp,
2694 hb_change, pmtud_change,2649 hb_change, pmtud_change,
2695 sackdelay_change);2650 sackdelay_change);
2696 2651
@@ -2703,7 +2658,7 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk, · 6 unmodified lines
2703 if (!trans && asoc) {2658 if (!trans && asoc) {
2704 list_for_each_entry(trans, &asoc->peer.transport_addr_list,2659 list_for_each_entry(trans, &asoc->peer.transport_addr_list,
2705 transports) {2660 transports) {
2706 sctp_apply_peer_addr_params(&params, trans, asoc, sp,2661 sctp_apply_peer_addr_params(params, trans, asoc, sp,
2707 hb_change, pmtud_change,2662 hb_change, pmtud_change,
2708 sackdelay_change);2663 sackdelay_change);
2709 }2664 }
@@ -2796,17 +2751,14 @@ static void sctp_apply_asoc_delayed_ack(struct sctp_sack_info *params, · 86 unmodified lines
2796 */2751 */
2797 2752
2798static int sctp_setsockopt_delayed_ack(struct sock *sk,2753static int sctp_setsockopt_delayed_ack(struct sock *sk,
2799 char __user *optval, unsigned int optlen)2754 struct sctp_sack_info *params,
2755 unsigned int optlen)
2800{2756{
2801 struct sctp_sock *sp = sctp_sk(sk);2757 struct sctp_sock *sp = sctp_sk(sk);
2802 struct sctp_association *asoc;2758 struct sctp_association *asoc;
2803 struct sctp_sack_info params;
2804 2759
2805 if (optlen == sizeof(struct sctp_sack_info)) {2760 if (optlen == sizeof(struct sctp_sack_info)) {
2806 if (copy_from_user(&params, optval, optlen))2761 if (params->sack_delay == 0 && params->sack_freq == 0)
2807 return -EFAULT;
2808
2809 if (params.sack_delay == 0 && params.sack_freq == 0)
2810 return 0;2762 return 0;
2811 } else if (optlen == sizeof(struct sctp_assoc_value)) {2763 } else if (optlen == sizeof(struct sctp_assoc_value)) {
2812 pr_warn_ratelimited(DEPRECATED2764 pr_warn_ratelimited(DEPRECATED
@@ -2814,59 +2766,57 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk, · 1 unmodified line
2814 "Use of struct sctp_assoc_value in delayed_ack socket option.\n"2766 "Use of struct sctp_assoc_value in delayed_ack socket option.\n"
2815 "Use struct sctp_sack_info instead\n",2767 "Use struct sctp_sack_info instead\n",
2816 current->comm, task_pid_nr(current));2768 current->comm, task_pid_nr(current));
2817 if (copy_from_user(&params, optval, optlen))
2818 return -EFAULT;
2819 2769
2820 if (params.sack_delay == 0)2770 if (params->sack_delay == 0)
2821 params.sack_freq = 1;2771 params->sack_freq = 1;
2822 else2772 else
2823 params.sack_freq = 0;2773 params->sack_freq = 0;
2824 } else2774 } else
2825 return -EINVAL;2775 return -EINVAL;
2826 2776
2827 /* Validate value parameter. */2777 /* Validate value parameter. */
2828 if (params.sack_delay > 500)2778 if (params->sack_delay > 500)
2829 return -EINVAL;2779 return -EINVAL;
2830 2780
2831 /* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the2781 /* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the
2832 * socket is a one to many style socket, and an association2782 * socket is a one to many style socket, and an association
2833 * was not found, then the id was invalid.2783 * was not found, then the id was invalid.
2834 */2784 */
2835 asoc = sctp_id2assoc(sk, params.sack_assoc_id);2785 asoc = sctp_id2assoc(sk, params->sack_assoc_id);
2836 if (!asoc && params.sack_assoc_id > SCTP_ALL_ASSOC &&2786 if (!asoc && params->sack_assoc_id > SCTP_ALL_ASSOC &&
2837 sctp_style(sk, UDP))2787 sctp_style(sk, UDP))
2838 return -EINVAL;2788 return -EINVAL;
2839 2789
2840 if (asoc) {2790 if (asoc) {
2841 sctp_apply_asoc_delayed_ack(&params, asoc);2791 sctp_apply_asoc_delayed_ack(params, asoc);
2842 2792
2843 return 0;2793 return 0;
2844 }2794 }
2845 2795
2846 if (sctp_style(sk, TCP))2796 if (sctp_style(sk, TCP))
2847 params.sack_assoc_id = SCTP_FUTURE_ASSOC;2797 params->sack_assoc_id = SCTP_FUTURE_ASSOC;
2848 2798
2849 if (params.sack_assoc_id == SCTP_FUTURE_ASSOC ||2799 if (params->sack_assoc_id == SCTP_FUTURE_ASSOC ||
2850 params.sack_assoc_id == SCTP_ALL_ASSOC) {2800 params->sack_assoc_id == SCTP_ALL_ASSOC) {
2851 if (params.sack_delay) {2801 if (params->sack_delay) {
2852 sp->sackdelay = params.sack_delay;2802 sp->sackdelay = params->sack_delay;
2853 sp->param_flags =2803 sp->param_flags =
2854 sctp_spp_sackdelay_enable(sp->param_flags);2804 sctp_spp_sackdelay_enable(sp->param_flags);
2855 }2805 }
2856 if (params.sack_freq == 1) {2806 if (params->sack_freq == 1) {
2857 sp->param_flags =2807 sp->param_flags =
2858 sctp_spp_sackdelay_disable(sp->param_flags);2808 sctp_spp_sackdelay_disable(sp->param_flags);
2859 } else if (params.sack_freq > 1) {2809 } else if (params->sack_freq > 1) {
2860 sp->sackfreq = params.sack_freq;2810 sp->sackfreq = params->sack_freq;
2861 sp->param_flags =2811 sp->param_flags =
2862 sctp_spp_sackdelay_enable(sp->param_flags);2812 sctp_spp_sackdelay_enable(sp->param_flags);
2863 }2813 }
2864 }2814 }
2865 2815
2866 if (params.sack_assoc_id == SCTP_CURRENT_ASSOC ||2816 if (params->sack_assoc_id == SCTP_CURRENT_ASSOC ||
2867 params.sack_assoc_id == SCTP_ALL_ASSOC)2817 params->sack_assoc_id == SCTP_ALL_ASSOC)
2868 list_for_each_entry(asoc, &sp->ep->asocs, asocs)2818 list_for_each_entry(asoc, &sp->ep->asocs, asocs)
2869 sctp_apply_asoc_delayed_ack(&params, asoc);2819 sctp_apply_asoc_delayed_ack(params, asoc);
2870 2820
2871 return 0;2821 return 0;
2872}2822}
@@ -2882,24 +2832,22 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk, · 9 unmodified lines
2882 * by the change). With TCP-style sockets, this option is inherited by2832 * by the change). With TCP-style sockets, this option is inherited by
2883 * sockets derived from a listener socket.2833 * sockets derived from a listener socket.
2884 */2834 */
2885static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, unsigned int optlen)2835static int sctp_setsockopt_initmsg(struct sock *sk, struct sctp_initmsg *sinit,
2836 unsigned int optlen)
2886{2837{
2887 struct sctp_initmsg sinit;
2888 struct sctp_sock *sp = sctp_sk(sk);2838 struct sctp_sock *sp = sctp_sk(sk);
2889 2839
2890 if (optlen != sizeof(struct sctp_initmsg))2840 if (optlen != sizeof(struct sctp_initmsg))
2891 return -EINVAL;2841 return -EINVAL;
2892 if (copy_from_user(&sinit, optval, optlen))
2893 return -EFAULT;
2894 2842
2895 if (sinit.sinit_num_ostreams)2843 if (sinit->sinit_num_ostreams)
2896 sp->initmsg.sinit_num_ostreams = sinit.sinit_num_ostreams;2844 sp->initmsg.sinit_num_ostreams = sinit->sinit_num_ostreams;
2897 if (sinit.sinit_max_instreams)2845 if (sinit->sinit_max_instreams)
2898 sp->initmsg.sinit_max_instreams = sinit.sinit_max_instreams;2846 sp->initmsg.sinit_max_instreams = sinit->sinit_max_instreams;
2899 if (sinit.sinit_max_attempts)2847 if (sinit->sinit_max_attempts)
2900 sp->initmsg.sinit_max_attempts = sinit.sinit_max_attempts;2848 sp->initmsg.sinit_max_attempts = sinit->sinit_max_attempts;
2901 if (sinit.sinit_max_init_timeo)2849 if (sinit->sinit_max_init_timeo)
2902 sp->initmsg.sinit_max_init_timeo = sinit.sinit_max_init_timeo;2850 sp->initmsg.sinit_max_init_timeo = sinit->sinit_max_init_timeo;
2903 2851
2904 return 0;2852 return 0;
2905}2853}
@@ -2919,57 +2867,54 @@ static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, unsigne · 13 unmodified lines
2919 * to this call if the caller is using the UDP model.2867 * to this call if the caller is using the UDP model.
2920 */2868 */
2921static int sctp_setsockopt_default_send_param(struct sock *sk,2869static int sctp_setsockopt_default_send_param(struct sock *sk,
2922 char __user *optval,2870 struct sctp_sndrcvinfo *info,
2923 unsigned int optlen)2871 unsigned int optlen)
2924{2872{
2925 struct sctp_sock *sp = sctp_sk(sk);2873 struct sctp_sock *sp = sctp_sk(sk);
2926 struct sctp_association *asoc;2874 struct sctp_association *asoc;
2927 struct sctp_sndrcvinfo info;
2928 2875
2929 if (optlen != sizeof(info))2876 if (optlen != sizeof(*info))
2930 return -EINVAL;2877 return -EINVAL;
2931 if (copy_from_user(&info, optval, optlen))2878 if (info->sinfo_flags &
2932 return -EFAULT;
2933 if (info.sinfo_flags &
2934 ~(SCTP_UNORDERED | SCTP_ADDR_OVER |2879 ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
2935 SCTP_ABORT | SCTP_EOF))2880 SCTP_ABORT | SCTP_EOF))
2936 return -EINVAL;2881 return -EINVAL;
2937 2882
2938 asoc = sctp_id2assoc(sk, info.sinfo_assoc_id);2883 asoc = sctp_id2assoc(sk, info->sinfo_assoc_id);
2939 if (!asoc && info.sinfo_assoc_id > SCTP_ALL_ASSOC &&2884 if (!asoc && info->sinfo_assoc_id > SCTP_ALL_ASSOC &&
2940 sctp_style(sk, UDP))2885 sctp_style(sk, UDP))
2941 return -EINVAL;2886 return -EINVAL;
2942 2887
2943 if (asoc) {2888 if (asoc) {
2944 asoc->default_stream = info.sinfo_stream;2889 asoc->default_stream = info->sinfo_stream;
2945 asoc->default_flags = info.sinfo_flags;2890 asoc->default_flags = info->sinfo_flags;
2946 asoc->default_ppid = info.sinfo_ppid;2891 asoc->default_ppid = info->sinfo_ppid;
2947 asoc->default_context = info.sinfo_context;2892 asoc->default_context = info->sinfo_context;
2948 asoc->default_timetolive = info.sinfo_timetolive;2893 asoc->default_timetolive = info->sinfo_timetolive;
2949 2894
2950 return 0;2895 return 0;
2951 }2896 }
2952 2897
2953 if (sctp_style(sk, TCP))2898 if (sctp_style(sk, TCP))
2954 info.sinfo_assoc_id = SCTP_FUTURE_ASSOC;2899 info->sinfo_assoc_id = SCTP_FUTURE_ASSOC;
2955 2900
2956 if (info.sinfo_assoc_id == SCTP_FUTURE_ASSOC ||2901 if (info->sinfo_assoc_id == SCTP_FUTURE_ASSOC ||
2957 info.sinfo_assoc_id == SCTP_ALL_ASSOC) {2902 info->sinfo_assoc_id == SCTP_ALL_ASSOC) {
2958 sp->default_stream = info.sinfo_stream;2903 sp->default_stream = info->sinfo_stream;
2959 sp->default_flags = info.sinfo_flags;2904 sp->default_flags = info->sinfo_flags;
2960 sp->default_ppid = info.sinfo_ppid;2905 sp->default_ppid = info->sinfo_ppid;
2961 sp->default_context = info.sinfo_context;2906 sp->default_context = info->sinfo_context;
2962 sp->default_timetolive = info.sinfo_timetolive;2907 sp->default_timetolive = info->sinfo_timetolive;
2963 }2908 }
2964 2909
2965 if (info.sinfo_assoc_id == SCTP_CURRENT_ASSOC ||2910 if (info->sinfo_assoc_id == SCTP_CURRENT_ASSOC ||
2966 info.sinfo_assoc_id == SCTP_ALL_ASSOC) {2911 info->sinfo_assoc_id == SCTP_ALL_ASSOC) {
2967 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {2912 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
2968 asoc->default_stream = info.sinfo_stream;2913 asoc->default_stream = info->sinfo_stream;
2969 asoc->default_flags = info.sinfo_flags;2914 asoc->default_flags = info->sinfo_flags;
2970 asoc->default_ppid = info.sinfo_ppid;2915 asoc->default_ppid = info->sinfo_ppid;
2971 asoc->default_context = info.sinfo_context;2916 asoc->default_context = info->sinfo_context;
2972 asoc->default_timetolive = info.sinfo_timetolive;2917 asoc->default_timetolive = info->sinfo_timetolive;
2973 }2918 }
2974 }2919 }
2975 2920
@@ -2980,54 +2925,51 @@ static int sctp_setsockopt_default_send_param(struct sock *sk, · 4 unmodified lines
2980 * (SCTP_DEFAULT_SNDINFO)2925 * (SCTP_DEFAULT_SNDINFO)
2981 */2926 */
2982static int sctp_setsockopt_default_sndinfo(struct sock *sk,2927static int sctp_setsockopt_default_sndinfo(struct sock *sk,
2983 char __user *optval,2928 struct sctp_sndinfo *info,
2984 unsigned int optlen)2929 unsigned int optlen)
2985{2930{
2986 struct sctp_sock *sp = sctp_sk(sk);2931 struct sctp_sock *sp = sctp_sk(sk);
2987 struct sctp_association *asoc;2932 struct sctp_association *asoc;
2988 struct sctp_sndinfo info;
2989 2933
2990 if (optlen != sizeof(info))2934 if (optlen != sizeof(*info))
2991 return -EINVAL;2935 return -EINVAL;
2992 if (copy_from_user(&info, optval, optlen))2936 if (info->snd_flags &
2993 return -EFAULT;
2994 if (info.snd_flags &
2995 ~(SCTP_UNORDERED | SCTP_ADDR_OVER |2937 ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
2996 SCTP_ABORT | SCTP_EOF))2938 SCTP_ABORT | SCTP_EOF))
2997 return -EINVAL;2939 return -EINVAL;
2998 2940
2999 asoc = sctp_id2assoc(sk, info.snd_assoc_id);2941 asoc = sctp_id2assoc(sk, info->snd_assoc_id);
3000 if (!asoc && info.snd_assoc_id > SCTP_ALL_ASSOC &&2942 if (!asoc && info->snd_assoc_id > SCTP_ALL_ASSOC &&
3001 sctp_style(sk, UDP))2943 sctp_style(sk, UDP))
3002 return -EINVAL;2944 return -EINVAL;
3003 2945
3004 if (asoc) {2946 if (asoc) {
3005 asoc->default_stream = info.snd_sid;2947 asoc->default_stream = info->snd_sid;
3006 asoc->default_flags = info.snd_flags;2948 asoc->default_flags = info->snd_flags;
3007 asoc->default_ppid = info.snd_ppid;2949 asoc->default_ppid = info->snd_ppid;
3008 asoc->default_context = info.snd_context;2950 asoc->default_context = info->snd_context;
3009 2951
3010 return 0;2952 return 0;
3011 }2953 }
3012 2954
3013 if (sctp_style(sk, TCP))2955 if (sctp_style(sk, TCP))
3014 info.snd_assoc_id = SCTP_FUTURE_ASSOC;2956 info->snd_assoc_id = SCTP_FUTURE_ASSOC;
3015 2957
3016 if (info.snd_assoc_id == SCTP_FUTURE_ASSOC ||2958 if (info->snd_assoc_id == SCTP_FUTURE_ASSOC ||
3017 info.snd_assoc_id == SCTP_ALL_ASSOC) {2959 info->snd_assoc_id == SCTP_ALL_ASSOC) {
3018 sp->default_stream = info.snd_sid;2960 sp->default_stream = info->snd_sid;
3019 sp->default_flags = info.snd_flags;2961 sp->default_flags = info->snd_flags;
3020 sp->default_ppid = info.snd_ppid;2962 sp->default_ppid = info->snd_ppid;
3021 sp->default_context = info.snd_context;2963 sp->default_context = info->snd_context;
3022 }2964 }
3023 2965
3024 if (info.snd_assoc_id == SCTP_CURRENT_ASSOC ||2966 if (info->snd_assoc_id == SCTP_CURRENT_ASSOC ||
3025 info.snd_assoc_id == SCTP_ALL_ASSOC) {2967 info->snd_assoc_id == SCTP_ALL_ASSOC) {
3026 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {2968 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
3027 asoc->default_stream = info.snd_sid;2969 asoc->default_stream = info->snd_sid;
3028 asoc->default_flags = info.snd_flags;2970 asoc->default_flags = info->snd_flags;
3029 asoc->default_ppid = info.snd_ppid;2971 asoc->default_ppid = info->snd_ppid;
3030 asoc->default_context = info.snd_context;2972 asoc->default_context = info->snd_context;
3031 }2973 }
3032 }2974 }
3033 2975
@@ -3040,10 +2982,9 @@ static int sctp_setsockopt_default_sndinfo(struct sock *sk, · 6 unmodified lines
3040 * the association primary. The enclosed address must be one of the2982 * the association primary. The enclosed address must be one of the
3041 * association peer's addresses.2983 * association peer's addresses.
3042 */2984 */
3043static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval,2985static int sctp_setsockopt_primary_addr(struct sock *sk, struct sctp_prim *prim,
3044 unsigned int optlen)2986 unsigned int optlen)
3045{2987{
3046 struct sctp_prim prim;
3047 struct sctp_transport *trans;2988 struct sctp_transport *trans;
3048 struct sctp_af *af;2989 struct sctp_af *af;
3049 int err;2990 int err;
@@ -3051,21 +2992,18 @@ static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval, · 1 unmodified line
3051 if (optlen != sizeof(struct sctp_prim))2992 if (optlen != sizeof(struct sctp_prim))
3052 return -EINVAL;2993 return -EINVAL;
3053 2994
3054 if (copy_from_user(&prim, optval, sizeof(struct sctp_prim)))
3055 return -EFAULT;
3056
3057 /* Allow security module to validate address but need address len. */2995 /* Allow security module to validate address but need address len. */
3058 af = sctp_get_af_specific(prim.ssp_addr.ss_family);2996 af = sctp_get_af_specific(prim->ssp_addr.ss_family);
3059 if (!af)2997 if (!af)
3060 return -EINVAL;2998 return -EINVAL;
3061 2999
3062 err = security_sctp_bind_connect(sk, SCTP_PRIMARY_ADDR,3000 err = security_sctp_bind_connect(sk, SCTP_PRIMARY_ADDR,
3063 (struct sockaddr *)&prim.ssp_addr,3001 (struct sockaddr *)&prim->ssp_addr,
3064 af->sockaddr_len);3002 af->sockaddr_len);
3065 if (err)3003 if (err)
3066 return err;3004 return err;
3067 3005
3068 trans = sctp_addr_id2transport(sk, &prim.ssp_addr, prim.ssp_assoc_id);3006 trans = sctp_addr_id2transport(sk, &prim->ssp_addr, prim->ssp_assoc_id);
3069 if (!trans)3007 if (!trans)
3070 return -EINVAL;3008 return -EINVAL;
3071 3009
@@ -3082,17 +3020,12 @@ static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval, · 10 unmodified lines
3082 * introduced, at the cost of more packets in the network. Expects an3020 * introduced, at the cost of more packets in the network. Expects an
3083 * integer boolean flag.3021 * integer boolean flag.
3084 */3022 */
3085static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval,3023static int sctp_setsockopt_nodelay(struct sock *sk, int *val,
3086 unsigned int optlen)3024 unsigned int optlen)
3087{3025{
3088 int val;
3089
3090 if (optlen < sizeof(int))3026 if (optlen < sizeof(int))
3091 return -EINVAL;3027 return -EINVAL;
3092 if (get_user(val, (int __user *)optval))3028 sctp_sk(sk)->nodelay = (*val == 0) ? 0 : 1;
3093 return -EFAULT;
3094
3095 sctp_sk(sk)->nodelay = (val == 0) ? 0 : 1;
3096 return 0;3029 return 0;
3097}3030}
3098 3031
@@ -3108,9 +3041,10 @@ static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval, · 9 unmodified lines
3108 * be changed.3041 * be changed.
3109 *3042 *
3110 */3043 */
3111static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigned int optlen)3044static int sctp_setsockopt_rtoinfo(struct sock *sk,
3045 struct sctp_rtoinfo *rtoinfo,
3046 unsigned int optlen)
3112{3047{
3113 struct sctp_rtoinfo rtoinfo;
3114 struct sctp_association *asoc;3048 struct sctp_association *asoc;
3115 unsigned long rto_min, rto_max;3049 unsigned long rto_min, rto_max;
3116 struct sctp_sock *sp = sctp_sk(sk);3050 struct sctp_sock *sp = sctp_sk(sk);
@@ -3118,18 +3052,15 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigne · 1 unmodified line
3118 if (optlen != sizeof (struct sctp_rtoinfo))3052 if (optlen != sizeof (struct sctp_rtoinfo))
3119 return -EINVAL;3053 return -EINVAL;
3120 3054
3121 if (copy_from_user(&rtoinfo, optval, optlen))3055 asoc = sctp_id2assoc(sk, rtoinfo->srto_assoc_id);
3122 return -EFAULT;
3123
3124 asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id);
3125 3056
3126 /* Set the values to the specific association */3057 /* Set the values to the specific association */
3127 if (!asoc && rtoinfo.srto_assoc_id != SCTP_FUTURE_ASSOC &&3058 if (!asoc && rtoinfo->srto_assoc_id != SCTP_FUTURE_ASSOC &&
3128 sctp_style(sk, UDP))3059 sctp_style(sk, UDP))
3129 return -EINVAL;3060 return -EINVAL;
3130 3061
3131 rto_max = rtoinfo.srto_max;3062 rto_max = rtoinfo->srto_max;
3132 rto_min = rtoinfo.srto_min;3063 rto_min = rtoinfo->srto_min;
3133 3064
3134 if (rto_max)3065 if (rto_max)
3135 rto_max = asoc ? msecs_to_jiffies(rto_max) : rto_max;3066 rto_max = asoc ? msecs_to_jiffies(rto_max) : rto_max;
@@ -3145,17 +3076,17 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigne · 9 unmodified lines
3145 return -EINVAL;3076 return -EINVAL;
3146 3077
3147 if (asoc) {3078 if (asoc) {
3148 if (rtoinfo.srto_initial != 0)3079 if (rtoinfo->srto_initial != 0)
3149 asoc->rto_initial =3080 asoc->rto_initial =
3150 msecs_to_jiffies(rtoinfo.srto_initial);3081 msecs_to_jiffies(rtoinfo->srto_initial);
3151 asoc->rto_max = rto_max;3082 asoc->rto_max = rto_max;
3152 asoc->rto_min = rto_min;3083 asoc->rto_min = rto_min;
3153 } else {3084 } else {
3154 /* If there is no association or the association-id = 03085 /* If there is no association or the association-id = 0
3155 * set the values to the endpoint.3086 * set the values to the endpoint.
3156 */3087 */
3157 if (rtoinfo.srto_initial != 0)3088 if (rtoinfo->srto_initial != 0)
3158 sp->rtoinfo.srto_initial = rtoinfo.srto_initial;3089 sp->rtoinfo.srto_initial = rtoinfo->srto_initial;
3159 sp->rtoinfo.srto_max = rto_max;3090 sp->rtoinfo.srto_max = rto_max;
3160 sp->rtoinfo.srto_min = rto_min;3091 sp->rtoinfo.srto_min = rto_min;
3161 }3092 }
@@ -3174,26 +3105,25 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigne · 12 unmodified lines
3174 * See [SCTP] for more information.3105 * See [SCTP] for more information.
3175 *3106 *
3176 */3107 */
3177static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, unsigned int optlen)3108static int sctp_setsockopt_associnfo(struct sock *sk,
3109 struct sctp_assocparams *assocparams,
3110 unsigned int optlen)
3178{3111{
3179 3112
3180 struct sctp_assocparams assocparams;
3181 struct sctp_association *asoc;3113 struct sctp_association *asoc;
3182 3114
3183 if (optlen != sizeof(struct sctp_assocparams))3115 if (optlen != sizeof(struct sctp_assocparams))
3184 return -EINVAL;3116 return -EINVAL;
3185 if (copy_from_user(&assocparams, optval, optlen))
3186 return -EFAULT;
3187 3117
3188 asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id);3118 asoc = sctp_id2assoc(sk, assocparams->sasoc_assoc_id);
3189 3119
3190 if (!asoc && assocparams.sasoc_assoc_id != SCTP_FUTURE_ASSOC &&3120 if (!asoc && assocparams->sasoc_assoc_id != SCTP_FUTURE_ASSOC &&
3191 sctp_style(sk, UDP))3121 sctp_style(sk, UDP))
3192 return -EINVAL;3122 return -EINVAL;
3193 3123
3194 /* Set the values to the specific association */3124 /* Set the values to the specific association */
3195 if (asoc) {3125 if (asoc) {
3196 if (assocparams.sasoc_asocmaxrxt != 0) {3126 if (assocparams->sasoc_asocmaxrxt != 0) {
3197 __u32 path_sum = 0;3127 __u32 path_sum = 0;
3198 int paths = 0;3128 int paths = 0;
3199 struct sctp_transport *peer_addr;3129 struct sctp_transport *peer_addr;
@@ -3210,24 +3140,25 @@ static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, unsig · 10 unmodified lines
3210 * then one path.3140 * then one path.
3211 */3141 */
3212 if (paths > 1 &&3142 if (paths > 1 &&
3213 assocparams.sasoc_asocmaxrxt > path_sum)3143 assocparams->sasoc_asocmaxrxt > path_sum)
3214 return -EINVAL;3144 return -EINVAL;
3215 3145
3216 asoc->max_retrans = assocparams.sasoc_asocmaxrxt;3146 asoc->max_retrans = assocparams->sasoc_asocmaxrxt;
3217 }3147 }
3218 3148
3219 if (assocparams.sasoc_cookie_life != 0)3149 if (assocparams->sasoc_cookie_life != 0)
3220 asoc->cookie_life = ms_to_ktime(assocparams.sasoc_cookie_life);3150 asoc->cookie_life =
3151 ms_to_ktime(assocparams->sasoc_cookie_life);
3221 } else {3152 } else {
3222 /* Set the values to the endpoint */3153 /* Set the values to the endpoint */
3223 struct sctp_sock *sp = sctp_sk(sk);3154 struct sctp_sock *sp = sctp_sk(sk);
3224 3155
3225 if (assocparams.sasoc_asocmaxrxt != 0)3156 if (assocparams->sasoc_asocmaxrxt != 0)
3226 sp->assocparams.sasoc_asocmaxrxt =3157 sp->assocparams.sasoc_asocmaxrxt =
3227 assocparams.sasoc_asocmaxrxt;3158 assocparams->sasoc_asocmaxrxt;
3228 if (assocparams.sasoc_cookie_life != 0)3159 if (assocparams->sasoc_cookie_life != 0)
3229 sp->assocparams.sasoc_cookie_life =3160 sp->assocparams.sasoc_cookie_life =
3230 assocparams.sasoc_cookie_life;3161 assocparams->sasoc_cookie_life;
3231 }3162 }
3232 return 0;3163 return 0;
3233}3164}
@@ -3242,16 +3173,14 @@ static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, unsig · 8 unmodified lines
3242 * addresses and a user will receive both PF_INET6 and PF_INET type3173 * addresses and a user will receive both PF_INET6 and PF_INET type
3243 * addresses on the socket.3174 * addresses on the socket.
3244 */3175 */
3245static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, unsigned int optlen)3176static int sctp_setsockopt_mappedv4(struct sock *sk, int *val,
3177 unsigned int optlen)
3246{3178{
3247 int val;
3248 struct sctp_sock *sp = sctp_sk(sk);3179 struct sctp_sock *sp = sctp_sk(sk);
3249 3180
3250 if (optlen < sizeof(int))3181 if (optlen < sizeof(int))
3251 return -EINVAL;3182 return -EINVAL;
3252 if (get_user(val, (int __user *)optval))3183 if (*val)
3253 return -EFAULT;
3254 if (val)
3255 sp->v4mapped = 1;3184 sp->v4mapped = 1;
3256 else3185 else
3257 sp->v4mapped = 0;3186 sp->v4mapped = 0;
@@ -3286,11 +3215,13 @@ static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, unsign · 28 unmodified lines
3286 * changed (effecting future associations only).3215 * changed (effecting future associations only).
3287 * assoc_value: This parameter specifies the maximum size in bytes.3216 * assoc_value: This parameter specifies the maximum size in bytes.
3288 */3217 */
3289static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned int optlen)3218static int sctp_setsockopt_maxseg(struct sock *sk,
3219 struct sctp_assoc_value *params,
3220 unsigned int optlen)
3290{3221{
3291 struct sctp_sock *sp = sctp_sk(sk);3222 struct sctp_sock *sp = sctp_sk(sk);
3292 struct sctp_assoc_value params;
3293 struct sctp_association *asoc;3223 struct sctp_association *asoc;
3224 sctp_assoc_t assoc_id;
3294 int val;3225 int val;
3295 3226
3296 if (optlen == sizeof(int)) {3227 if (optlen == sizeof(int)) {
@@ -3299,19 +3230,17 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned · 2 unmodified lines
3299 "Use of int in maxseg socket option.\n"3230 "Use of int in maxseg socket option.\n"
3300 "Use struct sctp_assoc_value instead\n",3231 "Use struct sctp_assoc_value instead\n",
3301 current->comm, task_pid_nr(current));3232 current->comm, task_pid_nr(current));
3302 if (copy_from_user(&val, optval, optlen))3233 assoc_id = SCTP_FUTURE_ASSOC;
3303 return -EFAULT;3234 val = *(int *)params;
3304 params.assoc_id = SCTP_FUTURE_ASSOC;
3305 } else if (optlen == sizeof(struct sctp_assoc_value)) {3235 } else if (optlen == sizeof(struct sctp_assoc_value)) {
3306 if (copy_from_user(&params, optval, optlen))3236 assoc_id = params->assoc_id;
3307 return -EFAULT;3237 val = params->assoc_value;
3308 val = params.assoc_value;
3309 } else {3238 } else {
3310 return -EINVAL;3239 return -EINVAL;
3311 }3240 }
3312 3241
3313 asoc = sctp_id2assoc(sk, params.assoc_id);3242 asoc = sctp_id2assoc(sk, assoc_id);
3314 if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&3243 if (!asoc && assoc_id != SCTP_FUTURE_ASSOC &&
3315 sctp_style(sk, UDP))3244 sctp_style(sk, UDP))
3316 return -EINVAL;3245 return -EINVAL;
3317 3246
@@ -3346,12 +3275,12 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned · 28 unmodified lines
3346 * locally bound addresses. The following structure is used to make a3275 * locally bound addresses. The following structure is used to make a
3347 * set primary request:3276 * set primary request:
3348 */3277 */
3349static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval,3278static int sctp_setsockopt_peer_primary_addr(struct sock *sk,
3279 struct sctp_setpeerprim *prim,
3350 unsigned int optlen)3280 unsigned int optlen)
3351{3281{
3352 struct sctp_sock *sp;3282 struct sctp_sock *sp;
3353 struct sctp_association *asoc = NULL;3283 struct sctp_association *asoc = NULL;
3354 struct sctp_setpeerprim prim;
3355 struct sctp_chunk *chunk;3284 struct sctp_chunk *chunk;
3356 struct sctp_af *af;3285 struct sctp_af *af;
3357 int err;3286 int err;
@@ -3364,10 +3293,7 @@ static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optva · 6 unmodified lines
3364 if (optlen != sizeof(struct sctp_setpeerprim))3293 if (optlen != sizeof(struct sctp_setpeerprim))
3365 return -EINVAL;3294 return -EINVAL;
3366 3295
3367 if (copy_from_user(&prim, optval, optlen))3296 asoc = sctp_id2assoc(sk, prim->sspp_assoc_id);
3368 return -EFAULT;
3369
3370 asoc = sctp_id2assoc(sk, prim.sspp_assoc_id);
3371 if (!asoc)3297 if (!asoc)
3372 return -EINVAL;3298 return -EINVAL;
3373 3299
@@ -3380,26 +3306,26 @@ static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optva · 6 unmodified lines
3380 if (!sctp_state(asoc, ESTABLISHED))3306 if (!sctp_state(asoc, ESTABLISHED))
3381 return -ENOTCONN;3307 return -ENOTCONN;
3382 3308
3383 af = sctp_get_af_specific(prim.sspp_addr.ss_family);3309 af = sctp_get_af_specific(prim->sspp_addr.ss_family);
3384 if (!af)3310 if (!af)
3385 return -EINVAL;3311 return -EINVAL;
3386 3312
3387 if (!af->addr_valid((union sctp_addr *)&prim.sspp_addr, sp, NULL))3313 if (!af->addr_valid((union sctp_addr *)&prim->sspp_addr, sp, NULL))
3388 return -EADDRNOTAVAIL;3314 return -EADDRNOTAVAIL;
3389 3315
3390 if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim.sspp_addr))3316 if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim->sspp_addr))
3391 return -EADDRNOTAVAIL;3317 return -EADDRNOTAVAIL;
3392 3318
3393 /* Allow security module to validate address. */3319 /* Allow security module to validate address. */
3394 err = security_sctp_bind_connect(sk, SCTP_SET_PEER_PRIMARY_ADDR,3320 err = security_sctp_bind_connect(sk, SCTP_SET_PEER_PRIMARY_ADDR,
3395 (struct sockaddr *)&prim.sspp_addr,3321 (struct sockaddr *)&prim->sspp_addr,
3396 af->sockaddr_len);3322 af->sockaddr_len);
3397 if (err)3323 if (err)
3398 return err;3324 return err;
3399 3325
3400 /* Create an ASCONF chunk with SET_PRIMARY parameter */3326 /* Create an ASCONF chunk with SET_PRIMARY parameter */
3401 chunk = sctp_make_asconf_set_prim(asoc,3327 chunk = sctp_make_asconf_set_prim(asoc,
3402 (union sctp_addr *)&prim.sspp_addr);3328 (union sctp_addr *)&prim->sspp_addr);
3403 if (!chunk)3329 if (!chunk)
3404 return -ENOMEM;3330 return -ENOMEM;
3405 3331
@@ -3410,17 +3336,14 @@ static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optva · 4 unmodified lines
3410 return err;3336 return err;
3411}3337}
3412 3338
3413static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval,3339static int sctp_setsockopt_adaptation_layer(struct sock *sk,
3340 struct sctp_setadaptation *adapt,
3414 unsigned int optlen)3341 unsigned int optlen)
3415{3342{
3416 struct sctp_setadaptation adaptation;
3417
3418 if (optlen != sizeof(struct sctp_setadaptation))3343 if (optlen != sizeof(struct sctp_setadaptation))
3419 return -EINVAL;3344 return -EINVAL;
3420 if (copy_from_user(&adaptation, optval, optlen))
3421 return -EFAULT;
3422 3345
3423 sctp_sk(sk)->adaptation_ind = adaptation.ssb_adaptation_ind;3346 sctp_sk(sk)->adaptation_ind = adapt->ssb_adaptation_ind;
3424 3347
3425 return 0;3348 return 0;
3426}3349}
@@ -3439,40 +3362,38 @@ static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval · 12 unmodified lines
3439 * received messages from the peer and does not effect the value that is3362 * received messages from the peer and does not effect the value that is
3440 * saved with outbound messages.3363 * saved with outbound messages.
3441 */3364 */
3442static int sctp_setsockopt_context(struct sock *sk, char __user *optval,3365static int sctp_setsockopt_context(struct sock *sk,
3366 struct sctp_assoc_value *params,
3443 unsigned int optlen)3367 unsigned int optlen)
3444{3368{
3445 struct sctp_sock *sp = sctp_sk(sk);3369 struct sctp_sock *sp = sctp_sk(sk);
3446 struct sctp_assoc_value params;
3447 struct sctp_association *asoc;3370 struct sctp_association *asoc;
3448 3371
3449 if (optlen != sizeof(struct sctp_assoc_value))3372 if (optlen != sizeof(struct sctp_assoc_value))
3450 return -EINVAL;3373 return -EINVAL;
3451 if (copy_from_user(&params, optval, optlen))
3452 return -EFAULT;
3453 3374
3454 asoc = sctp_id2assoc(sk, params.assoc_id);3375 asoc = sctp_id2assoc(sk, params->assoc_id);
3455 if (!asoc && params.assoc_id > SCTP_ALL_ASSOC &&3376 if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
3456 sctp_style(sk, UDP))3377 sctp_style(sk, UDP))
3457 return -EINVAL;3378 return -EINVAL;
3458 3379
3459 if (asoc) {3380 if (asoc) {
3460 asoc->default_rcv_context = params.assoc_value;3381 asoc->default_rcv_context = params->assoc_value;
3461 3382
3462 return 0;3383 return 0;
3463 }3384 }
3464 3385
3465 if (sctp_style(sk, TCP))3386 if (sctp_style(sk, TCP))
3466 params.assoc_id = SCTP_FUTURE_ASSOC;3387 params->assoc_id = SCTP_FUTURE_ASSOC;
3467 3388
3468 if (params.assoc_id == SCTP_FUTURE_ASSOC ||3389 if (params->assoc_id == SCTP_FUTURE_ASSOC ||
3469 params.assoc_id == SCTP_ALL_ASSOC)3390 params->assoc_id == SCTP_ALL_ASSOC)
3470 sp->default_rcv_context = params.assoc_value;3391 sp->default_rcv_context = params->assoc_value;
3471 3392
3472 if (params.assoc_id == SCTP_CURRENT_ASSOC ||3393 if (params->assoc_id == SCTP_CURRENT_ASSOC ||
3473 params.assoc_id == SCTP_ALL_ASSOC)3394 params->assoc_id == SCTP_ALL_ASSOC)
3474 list_for_each_entry(asoc, &sp->ep->asocs, asocs)3395 list_for_each_entry(asoc, &sp->ep->asocs, asocs)
3475 asoc->default_rcv_context = params.assoc_value;3396 asoc->default_rcv_context = params->assoc_value;
3476 3397
3477 return 0;3398 return 0;
3478}3399}
@@ -3501,18 +3422,13 @@ static int sctp_setsockopt_context(struct sock *sk, char __user *optval, · 22 unmodified lines
3501 * application using the one to many model may become confused and act3422 * application using the one to many model may become confused and act
3502 * incorrectly.3423 * incorrectly.
3503 */3424 */
3504static int sctp_setsockopt_fragment_interleave(struct sock *sk,3425static int sctp_setsockopt_fragment_interleave(struct sock *sk, int *val,
3505 char __user *optval,
3506 unsigned int optlen)3426 unsigned int optlen)
3507{3427{
3508 int val;
3509
3510 if (optlen != sizeof(int))3428 if (optlen != sizeof(int))
3511 return -EINVAL;3429 return -EINVAL;
3512 if (get_user(val, (int __user *)optval))
3513 return -EFAULT;
3514 3430
3515 sctp_sk(sk)->frag_interleave = !!val;3431 sctp_sk(sk)->frag_interleave = !!*val;
3516 3432
3517 if (!sctp_sk(sk)->frag_interleave)3433 if (!sctp_sk(sk)->frag_interleave)
3518 sctp_sk(sk)->ep->intl_enable = 0;3434 sctp_sk(sk)->ep->intl_enable = 0;
@@ -3537,24 +3453,19 @@ static int sctp_setsockopt_fragment_interleave(struct sock *sk, · 18 unmodified lines
3537 * call as long as the user provided buffer is large enough to hold the3453 * call as long as the user provided buffer is large enough to hold the
3538 * message.3454 * message.
3539 */3455 */
3540static int sctp_setsockopt_partial_delivery_point(struct sock *sk,3456static int sctp_setsockopt_partial_delivery_point(struct sock *sk, u32 *val,
3541 char __user *optval,
3542 unsigned int optlen)3457 unsigned int optlen)
3543{3458{
3544 u32 val;
3545
3546 if (optlen != sizeof(u32))3459 if (optlen != sizeof(u32))
3547 return -EINVAL;3460 return -EINVAL;
3548 if (get_user(val, (int __user *)optval))
3549 return -EFAULT;
3550 3461
3551 /* Note: We double the receive buffer from what the user sets3462 /* Note: We double the receive buffer from what the user sets
3552 * it to be, also initial rwnd is based on rcvbuf/2.3463 * it to be, also initial rwnd is based on rcvbuf/2.
3553 */3464 */
3554 if (val > (sk->sk_rcvbuf >> 1))3465 if (*val > (sk->sk_rcvbuf >> 1))
3555 return -EINVAL;3466 return -EINVAL;
3556 3467
3557 sctp_sk(sk)->pd_point = val;3468 sctp_sk(sk)->pd_point = *val;
3558 3469
3559 return 0; /* is this the right error code? */3470 return 0; /* is this the right error code? */
3560}3471}
@@ -3571,12 +3482,13 @@ static int sctp_setsockopt_partial_delivery_point(struct sock *sk, · 10 unmodified lines
3571 * future associations inheriting the socket value.3482 * future associations inheriting the socket value.
3572 */3483 */
3573static int sctp_setsockopt_maxburst(struct sock *sk,3484static int sctp_setsockopt_maxburst(struct sock *sk,
3574 char __user *optval,3485 struct sctp_assoc_value *params,
3575 unsigned int optlen)3486 unsigned int optlen)
3576{3487{
3577 struct sctp_sock *sp = sctp_sk(sk);3488 struct sctp_sock *sp = sctp_sk(sk);
3578 struct sctp_assoc_value params;
3579 struct sctp_association *asoc;3489 struct sctp_association *asoc;
3490 sctp_assoc_t assoc_id;
3491 u32 assoc_value;
3580 3492
3581 if (optlen == sizeof(int)) {3493 if (optlen == sizeof(int)) {
3582 pr_warn_ratelimited(DEPRECATED3494 pr_warn_ratelimited(DEPRECATED
@@ -3584,37 +3496,33 @@ static int sctp_setsockopt_maxburst(struct sock *sk, · 1 unmodified line
3584 "Use of int in max_burst socket option deprecated.\n"3496 "Use of int in max_burst socket option deprecated.\n"
3585 "Use struct sctp_assoc_value instead\n",3497 "Use struct sctp_assoc_value instead\n",
3586 current->comm, task_pid_nr(current));3498 current->comm, task_pid_nr(current));
3587 if (copy_from_user(&params.assoc_value, optval, optlen))3499 assoc_id = SCTP_FUTURE_ASSOC;
3588 return -EFAULT;3500 assoc_value = *((int *)params);
3589 params.assoc_id = SCTP_FUTURE_ASSOC;
3590 } else if (optlen == sizeof(struct sctp_assoc_value)) {3501 } else if (optlen == sizeof(struct sctp_assoc_value)) {
3591 if (copy_from_user(&params, optval, optlen))3502 assoc_id = params->assoc_id;
3592 return -EFAULT;3503 assoc_value = params->assoc_value;
3593 } else3504 } else
3594 return -EINVAL;3505 return -EINVAL;
3595 3506
3596 asoc = sctp_id2assoc(sk, params.assoc_id);3507 asoc = sctp_id2assoc(sk, assoc_id);
3597 if (!asoc && params.assoc_id > SCTP_ALL_ASSOC &&3508 if (!asoc && assoc_id > SCTP_ALL_ASSOC && sctp_style(sk, UDP))
3598 sctp_style(sk, UDP))
3599 return -EINVAL;3509 return -EINVAL;
3600 3510
3601 if (asoc) {3511 if (asoc) {
3602 asoc->max_burst = params.assoc_value;3512 asoc->max_burst = assoc_value;
3603 3513
3604 return 0;3514 return 0;
3605 }3515 }
3606 3516
3607 if (sctp_style(sk, TCP))3517 if (sctp_style(sk, TCP))
3608 params.assoc_id = SCTP_FUTURE_ASSOC;3518 assoc_id = SCTP_FUTURE_ASSOC;
3609 3519
3610 if (params.assoc_id == SCTP_FUTURE_ASSOC ||3520 if (assoc_id == SCTP_FUTURE_ASSOC || assoc_id == SCTP_ALL_ASSOC)
3611 params.assoc_id == SCTP_ALL_ASSOC)3521 sp->max_burst = assoc_value;
3612 sp->max_burst = params.assoc_value;
3613 3522
3614 if (params.assoc_id == SCTP_CURRENT_ASSOC ||3523 if (assoc_id == SCTP_CURRENT_ASSOC || assoc_id == SCTP_ALL_ASSOC)
3615 params.assoc_id == SCTP_ALL_ASSOC)
3616 list_for_each_entry(asoc, &sp->ep->asocs, asocs)3524 list_for_each_entry(asoc, &sp->ep->asocs, asocs)
3617 asoc->max_burst = params.assoc_value;3525 asoc->max_burst = assoc_value;
3618 3526
3619 return 0;3527 return 0;
3620}3528}
@@ -3627,21 +3535,18 @@ static int sctp_setsockopt_maxburst(struct sock *sk, · 6 unmodified lines
3627 * will only effect future associations on the socket.3535 * will only effect future associations on the socket.
3628 */3536 */
3629static int sctp_setsockopt_auth_chunk(struct sock *sk,3537static int sctp_setsockopt_auth_chunk(struct sock *sk,
3630 char __user *optval,3538 struct sctp_authchunk *val,
3631 unsigned int optlen)3539 unsigned int optlen)
3632{3540{
3633 struct sctp_endpoint *ep = sctp_sk(sk)->ep;3541 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3634 struct sctp_authchunk val;
3635 3542
3636 if (!ep->auth_enable)3543 if (!ep->auth_enable)
3637 return -EACCES;3544 return -EACCES;
3638 3545
3639 if (optlen != sizeof(struct sctp_authchunk))3546 if (optlen != sizeof(struct sctp_authchunk))
3640 return -EINVAL;3547 return -EINVAL;
3641 if (copy_from_user(&val, optval, optlen))
3642 return -EFAULT;
3643 3548
3644 switch (val.sauth_chunk) {3549 switch (val->sauth_chunk) {
3645 case SCTP_CID_INIT:3550 case SCTP_CID_INIT:
3646 case SCTP_CID_INIT_ACK:3551 case SCTP_CID_INIT_ACK:
3647 case SCTP_CID_SHUTDOWN_COMPLETE:3552 case SCTP_CID_SHUTDOWN_COMPLETE:
@@ -3650,7 +3555,7 @@ static int sctp_setsockopt_auth_chunk(struct sock *sk, · 2 unmodified lines
3650 }3555 }
3651 3556
3652 /* add this chunk id to the endpoint */3557 /* add this chunk id to the endpoint */
3653 return sctp_auth_ep_add_chunkid(ep, val.sauth_chunk);3558 return sctp_auth_ep_add_chunkid(ep, val->sauth_chunk);
3654}3559}
3655 3560
3656/*3561/*
@@ -3660,13 +3565,11 @@ static int sctp_setsockopt_auth_chunk(struct sock *sk, · 3 unmodified lines
3660 * endpoint requires the peer to use.3565 * endpoint requires the peer to use.
3661 */3566 */
3662static int sctp_setsockopt_hmac_ident(struct sock *sk,3567static int sctp_setsockopt_hmac_ident(struct sock *sk,
3663 char __user *optval,3568 struct sctp_hmacalgo *hmacs,
3664 unsigned int optlen)3569 unsigned int optlen)
3665{3570{
3666 struct sctp_endpoint *ep = sctp_sk(sk)->ep;3571 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3667 struct sctp_hmacalgo *hmacs;
3668 u32 idents;3572 u32 idents;
3669 int err;
3670 3573
3671 if (!ep->auth_enable)3574 if (!ep->auth_enable)
3672 return -EACCES;3575 return -EACCES;
@@ -3676,21 +3579,12 @@ static int sctp_setsockopt_hmac_ident(struct sock *sk, · 3 unmodified lines
3676 optlen = min_t(unsigned int, optlen, sizeof(struct sctp_hmacalgo) +3579 optlen = min_t(unsigned int, optlen, sizeof(struct sctp_hmacalgo) +
3677 SCTP_AUTH_NUM_HMACS * sizeof(u16));3580 SCTP_AUTH_NUM_HMACS * sizeof(u16));
3678 3581
3679 hmacs = memdup_user(optval, optlen);
3680 if (IS_ERR(hmacs))
3681 return PTR_ERR(hmacs);
3682
3683 idents = hmacs->shmac_num_idents;3582 idents = hmacs->shmac_num_idents;
3684 if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS ||3583 if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS ||
3685 (idents * sizeof(u16)) > (optlen - sizeof(struct sctp_hmacalgo))) {3584 (idents * sizeof(u16)) > (optlen - sizeof(struct sctp_hmacalgo)))
3686 err = -EINVAL;3585 return -EINVAL;
3687 goto out;
3688 }
3689 3586
3690 err = sctp_auth_ep_set_hmacs(ep, hmacs);3587 return sctp_auth_ep_set_hmacs(ep, hmacs);
3691out:
3692 kfree(hmacs);
3693 return err;
3694}3588}
3695 3589
3696/*3590/*
@@ -3700,11 +3594,10 @@ out: · 3 unmodified lines
3700 * association shared key.3594 * association shared key.
3701 */3595 */
3702static int sctp_setsockopt_auth_key(struct sock *sk,3596static int sctp_setsockopt_auth_key(struct sock *sk,
3703 char __user *optval,3597 struct sctp_authkey *authkey,
3704 unsigned int optlen)3598 unsigned int optlen)
3705{3599{
3706 struct sctp_endpoint *ep = sctp_sk(sk)->ep;3600 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3707 struct sctp_authkey *authkey;
3708 struct sctp_association *asoc;3601 struct sctp_association *asoc;
3709 int ret = -EINVAL;3602 int ret = -EINVAL;
3710 3603
@@ -3715,10 +3608,6 @@ static int sctp_setsockopt_auth_key(struct sock *sk, · 4 unmodified lines
3715 */3608 */
3716 optlen = min_t(unsigned int, optlen, USHRT_MAX + sizeof(*authkey));3609 optlen = min_t(unsigned int, optlen, USHRT_MAX + sizeof(*authkey));
3717 3610
3718 authkey = memdup_user(optval, optlen);
3719 if (IS_ERR(authkey))
3720 return PTR_ERR(authkey);
3721
3722 if (authkey->sca_keylength > optlen - sizeof(*authkey))3611 if (authkey->sca_keylength > optlen - sizeof(*authkey))
3723 goto out;3612 goto out;
3724 3613
@@ -3755,7 +3644,7 @@ static int sctp_setsockopt_auth_key(struct sock *sk, · 30 unmodified lines
3755 }3644 }
3756 3645
3757out:3646out:
3758 kzfree(authkey);3647 memzero_explicit(authkey, optlen);
3759 return ret;3648 return ret;
3760}3649}
3761 3650
@@ -3766,42 +3655,39 @@ out: · 4 unmodified lines
3766 * the association shared key.3655 * the association shared key.
3767 */3656 */
3768static int sctp_setsockopt_active_key(struct sock *sk,3657static int sctp_setsockopt_active_key(struct sock *sk,
3769 char __user *optval,3658 struct sctp_authkeyid *val,
3770 unsigned int optlen)3659 unsigned int optlen)
3771{3660{
3772 struct sctp_endpoint *ep = sctp_sk(sk)->ep;3661 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3773 struct sctp_association *asoc;3662 struct sctp_association *asoc;
3774 struct sctp_authkeyid val;
3775 int ret = 0;3663 int ret = 0;
3776 3664
3777 if (optlen != sizeof(struct sctp_authkeyid))3665 if (optlen != sizeof(struct sctp_authkeyid))
3778 return -EINVAL;3666 return -EINVAL;
3779 if (copy_from_user(&val, optval, optlen))
3780 return -EFAULT;
3781 3667
3782 asoc = sctp_id2assoc(sk, val.scact_assoc_id);3668 asoc = sctp_id2assoc(sk, val->scact_assoc_id);
3783 if (!asoc && val.scact_assoc_id > SCTP_ALL_ASSOC &&3669 if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
3784 sctp_style(sk, UDP))3670 sctp_style(sk, UDP))
3785 return -EINVAL;3671 return -EINVAL;
3786 3672
3787 if (asoc)3673 if (asoc)
3788 return sctp_auth_set_active_key(ep, asoc, val.scact_keynumber);3674 return sctp_auth_set_active_key(ep, asoc, val->scact_keynumber);
3789 3675
3790 if (sctp_style(sk, TCP))3676 if (sctp_style(sk, TCP))
3791 val.scact_assoc_id = SCTP_FUTURE_ASSOC;3677 val->scact_assoc_id = SCTP_FUTURE_ASSOC;
3792 3678
3793 if (val.scact_assoc_id == SCTP_FUTURE_ASSOC ||3679 if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
3794 val.scact_assoc_id == SCTP_ALL_ASSOC) {3680 val->scact_assoc_id == SCTP_ALL_ASSOC) {
3795 ret = sctp_auth_set_active_key(ep, asoc, val.scact_keynumber);3681 ret = sctp_auth_set_active_key(ep, asoc, val->scact_keynumber);
3796 if (ret)3682 if (ret)
3797 return ret;3683 return ret;
3798 }3684 }
3799 3685
3800 if (val.scact_assoc_id == SCTP_CURRENT_ASSOC ||3686 if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
3801 val.scact_assoc_id == SCTP_ALL_ASSOC) {3687 val->scact_assoc_id == SCTP_ALL_ASSOC) {
3802 list_for_each_entry(asoc, &ep->asocs, asocs) {3688 list_for_each_entry(asoc, &ep->asocs, asocs) {
3803 int res = sctp_auth_set_active_key(ep, asoc,3689 int res = sctp_auth_set_active_key(ep, asoc,
3804 val.scact_keynumber);3690 val->scact_keynumber);
3805 3691
3806 if (res && !ret)3692 if (res && !ret)
3807 ret = res;3693 ret = res;
@@ -3817,42 +3703,39 @@ static int sctp_setsockopt_active_key(struct sock *sk, · 9 unmodified lines
3817 * This set option will delete a shared secret key from use.3703 * This set option will delete a shared secret key from use.
3818 */3704 */
3819static int sctp_setsockopt_del_key(struct sock *sk,3705static int sctp_setsockopt_del_key(struct sock *sk,
3820 char __user *optval,3706 struct sctp_authkeyid *val,
3821 unsigned int optlen)3707 unsigned int optlen)
3822{3708{
3823 struct sctp_endpoint *ep = sctp_sk(sk)->ep;3709 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3824 struct sctp_association *asoc;3710 struct sctp_association *asoc;
3825 struct sctp_authkeyid val;
3826 int ret = 0;3711 int ret = 0;
3827 3712
3828 if (optlen != sizeof(struct sctp_authkeyid))3713 if (optlen != sizeof(struct sctp_authkeyid))
3829 return -EINVAL;3714 return -EINVAL;
3830 if (copy_from_user(&val, optval, optlen))
3831 return -EFAULT;
3832 3715
3833 asoc = sctp_id2assoc(sk, val.scact_assoc_id);3716 asoc = sctp_id2assoc(sk, val->scact_assoc_id);
3834 if (!asoc && val.scact_assoc_id > SCTP_ALL_ASSOC &&3717 if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
3835 sctp_style(sk, UDP))3718 sctp_style(sk, UDP))
3836 return -EINVAL;3719 return -EINVAL;
3837 3720
3838 if (asoc)3721 if (asoc)
3839 return sctp_auth_del_key_id(ep, asoc, val.scact_keynumber);3722 return sctp_auth_del_key_id(ep, asoc, val->scact_keynumber);
3840 3723
3841 if (sctp_style(sk, TCP))3724 if (sctp_style(sk, TCP))
3842 val.scact_assoc_id = SCTP_FUTURE_ASSOC;3725 val->scact_assoc_id = SCTP_FUTURE_ASSOC;
3843 3726
3844 if (val.scact_assoc_id == SCTP_FUTURE_ASSOC ||3727 if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
3845 val.scact_assoc_id == SCTP_ALL_ASSOC) {3728 val->scact_assoc_id == SCTP_ALL_ASSOC) {
3846 ret = sctp_auth_del_key_id(ep, asoc, val.scact_keynumber);3729 ret = sctp_auth_del_key_id(ep, asoc, val->scact_keynumber);
3847 if (ret)3730 if (ret)
3848 return ret;3731 return ret;
3849 }3732 }
3850 3733
3851 if (val.scact_assoc_id == SCTP_CURRENT_ASSOC ||3734 if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
3852 val.scact_assoc_id == SCTP_ALL_ASSOC) {3735 val->scact_assoc_id == SCTP_ALL_ASSOC) {
3853 list_for_each_entry(asoc, &ep->asocs, asocs) {3736 list_for_each_entry(asoc, &ep->asocs, asocs) {
3854 int res = sctp_auth_del_key_id(ep, asoc,3737 int res = sctp_auth_del_key_id(ep, asoc,
3855 val.scact_keynumber);3738 val->scact_keynumber);
3856 3739
3857 if (res && !ret)3740 if (res && !ret)
3858 ret = res;3741 ret = res;
@@ -3867,42 +3750,40 @@ static int sctp_setsockopt_del_key(struct sock *sk, · 8 unmodified lines
3867 *3750 *
3868 * This set option will deactivate a shared secret key.3751 * This set option will deactivate a shared secret key.
3869 */3752 */
3870static int sctp_setsockopt_deactivate_key(struct sock *sk, char __user *optval,3753static int sctp_setsockopt_deactivate_key(struct sock *sk,
3754 struct sctp_authkeyid *val,
3871 unsigned int optlen)3755 unsigned int optlen)
3872{3756{
3873 struct sctp_endpoint *ep = sctp_sk(sk)->ep;3757 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3874 struct sctp_association *asoc;3758 struct sctp_association *asoc;
3875 struct sctp_authkeyid val;
3876 int ret = 0;3759 int ret = 0;
3877 3760
3878 if (optlen != sizeof(struct sctp_authkeyid))3761 if (optlen != sizeof(struct sctp_authkeyid))
3879 return -EINVAL;3762 return -EINVAL;
3880 if (copy_from_user(&val, optval, optlen))
3881 return -EFAULT;
3882 3763
3883 asoc = sctp_id2assoc(sk, val.scact_assoc_id);3764 asoc = sctp_id2assoc(sk, val->scact_assoc_id);
3884 if (!asoc && val.scact_assoc_id > SCTP_ALL_ASSOC &&3765 if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
3885 sctp_style(sk, UDP))3766 sctp_style(sk, UDP))
3886 return -EINVAL;3767 return -EINVAL;
3887 3768
3888 if (asoc)3769 if (asoc)
3889 return sctp_auth_deact_key_id(ep, asoc, val.scact_keynumber);3770 return sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber);
3890 3771
3891 if (sctp_style(sk, TCP))3772 if (sctp_style(sk, TCP))
3892 val.scact_assoc_id = SCTP_FUTURE_ASSOC;3773 val->scact_assoc_id = SCTP_FUTURE_ASSOC;
3893 3774
3894 if (val.scact_assoc_id == SCTP_FUTURE_ASSOC ||3775 if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
3895 val.scact_assoc_id == SCTP_ALL_ASSOC) {3776 val->scact_assoc_id == SCTP_ALL_ASSOC) {
3896 ret = sctp_auth_deact_key_id(ep, asoc, val.scact_keynumber);3777 ret = sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber);
3897 if (ret)3778 if (ret)
3898 return ret;3779 return ret;
3899 }3780 }
3900 3781
3901 if (val.scact_assoc_id == SCTP_CURRENT_ASSOC ||3782 if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
3902 val.scact_assoc_id == SCTP_ALL_ASSOC) {3783 val->scact_assoc_id == SCTP_ALL_ASSOC) {
3903 list_for_each_entry(asoc, &ep->asocs, asocs) {3784 list_for_each_entry(asoc, &ep->asocs, asocs) {
3904 int res = sctp_auth_deact_key_id(ep, asoc,3785 int res = sctp_auth_deact_key_id(ep, asoc,
3905 val.scact_keynumber);3786 val->scact_keynumber);
3906 3787
3907 if (res && !ret)3788 if (res && !ret)
3908 ret = res;3789 ret = res;
@@ -3926,26 +3807,23 @@ static int sctp_setsockopt_deactivate_key(struct sock *sk, char __user *optval, · 17 unmodified lines
3926 * Note. In this implementation, socket operation overrides default parameter3807 * Note. In this implementation, socket operation overrides default parameter
3927 * being set by sysctl as well as FreeBSD implementation3808 * being set by sysctl as well as FreeBSD implementation
3928 */3809 */
3929static int sctp_setsockopt_auto_asconf(struct sock *sk, char __user *optval,3810static int sctp_setsockopt_auto_asconf(struct sock *sk, int *val,
3930 unsigned int optlen)3811 unsigned int optlen)
3931{3812{
3932 int val;
3933 struct sctp_sock *sp = sctp_sk(sk);3813 struct sctp_sock *sp = sctp_sk(sk);
3934 3814
3935 if (optlen < sizeof(int))3815 if (optlen < sizeof(int))
3936 return -EINVAL;3816 return -EINVAL;
3937 if (get_user(val, (int __user *)optval))3817 if (!sctp_is_ep_boundall(sk) && *val)
3938 return -EFAULT;
3939 if (!sctp_is_ep_boundall(sk) && val)
3940 return -EINVAL;3818 return -EINVAL;
3941 if ((val && sp->do_auto_asconf) || (!val && !sp->do_auto_asconf))3819 if ((*val && sp->do_auto_asconf) || (!*val && !sp->do_auto_asconf))
3942 return 0;3820 return 0;
3943 3821
3944 spin_lock_bh(&sock_net(sk)->sctp.addr_wq_lock);3822 spin_lock_bh(&sock_net(sk)->sctp.addr_wq_lock);
3945 if (val == 0 && sp->do_auto_asconf) {3823 if (*val == 0 && sp->do_auto_asconf) {
3946 list_del(&sp->auto_asconf_list);3824 list_del(&sp->auto_asconf_list);
3947 sp->do_auto_asconf = 0;3825 sp->do_auto_asconf = 0;
3948 } else if (val && !sp->do_auto_asconf) {3826 } else if (*val && !sp->do_auto_asconf) {
3949 list_add_tail(&sp->auto_asconf_list,3827 list_add_tail(&sp->auto_asconf_list,
3950 &sock_net(sk)->sctp.auto_asconf_splist);3828 &sock_net(sk)->sctp.auto_asconf_splist);
3951 sp->do_auto_asconf = 1;3829 sp->do_auto_asconf = 1;
@@ -3962,176 +3840,154 @@ static int sctp_setsockopt_auto_asconf(struct sock *sk, char __user *optval, · 10 unmodified lines
3962 * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt3840 * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
3963 */3841 */
3964static int sctp_setsockopt_paddr_thresholds(struct sock *sk,3842static int sctp_setsockopt_paddr_thresholds(struct sock *sk,
3965 char __user *optval,3843 struct sctp_paddrthlds_v2 *val,
3966 unsigned int optlen, bool v2)3844 unsigned int optlen, bool v2)
3967{3845{
3968 struct sctp_paddrthlds_v2 val;
3969 struct sctp_transport *trans;3846 struct sctp_transport *trans;
3970 struct sctp_association *asoc;3847 struct sctp_association *asoc;
3971 int len;3848 int len;
3972 3849
3973 len = v2 ? sizeof(val) : sizeof(struct sctp_paddrthlds);3850 len = v2 ? sizeof(*val) : sizeof(struct sctp_paddrthlds);
3974 if (optlen < len)3851 if (optlen < len)
3975 return -EINVAL;3852 return -EINVAL;
3976 if (copy_from_user(&val, optval, len))
3977 return -EFAULT;
3978 3853
3979 if (v2 && val.spt_pathpfthld > val.spt_pathcpthld)3854 if (v2 && val->spt_pathpfthld > val->spt_pathcpthld)
3980 return -EINVAL;3855 return -EINVAL;
3981 3856
3982 if (!sctp_is_any(sk, (const union sctp_addr *)&val.spt_address)) {3857 if (!sctp_is_any(sk, (const union sctp_addr *)&val->spt_address)) {
3983 trans = sctp_addr_id2transport(sk, &val.spt_address,3858 trans = sctp_addr_id2transport(sk, &val->spt_address,
3984 val.spt_assoc_id);3859 val->spt_assoc_id);
3985 if (!trans)3860 if (!trans)
3986 return -ENOENT;3861 return -ENOENT;
3987 3862
3988 if (val.spt_pathmaxrxt)3863 if (val->spt_pathmaxrxt)
3989 trans->pathmaxrxt = val.spt_pathmaxrxt;3864 trans->pathmaxrxt = val->spt_pathmaxrxt;
3990 if (v2)3865 if (v2)
3991 trans->ps_retrans = val.spt_pathcpthld;3866 trans->ps_retrans = val->spt_pathcpthld;
3992 trans->pf_retrans = val.spt_pathpfthld;3867 trans->pf_retrans = val->spt_pathpfthld;
3993 3868
3994 return 0;3869 return 0;
3995 }3870 }
3996 3871
3997 asoc = sctp_id2assoc(sk, val.spt_assoc_id);3872 asoc = sctp_id2assoc(sk, val->spt_assoc_id);
3998 if (!asoc && val.spt_assoc_id != SCTP_FUTURE_ASSOC &&3873 if (!asoc && val->spt_assoc_id != SCTP_FUTURE_ASSOC &&
3999 sctp_style(sk, UDP))3874 sctp_style(sk, UDP))
4000 return -EINVAL;3875 return -EINVAL;
4001 3876
4002 if (asoc) {3877 if (asoc) {
4003 list_for_each_entry(trans, &asoc->peer.transport_addr_list,3878 list_for_each_entry(trans, &asoc->peer.transport_addr_list,
4004 transports) {3879 transports) {
4005 if (val.spt_pathmaxrxt)3880 if (val->spt_pathmaxrxt)
4006 trans->pathmaxrxt = val.spt_pathmaxrxt;3881 trans->pathmaxrxt = val->spt_pathmaxrxt;
4007 if (v2)3882 if (v2)
4008 trans->ps_retrans = val.spt_pathcpthld;3883 trans->ps_retrans = val->spt_pathcpthld;
4009 trans->pf_retrans = val.spt_pathpfthld;3884 trans->pf_retrans = val->spt_pathpfthld;
4010 }3885 }
4011 3886
4012 if (val.spt_pathmaxrxt)3887 if (val->spt_pathmaxrxt)
4013 asoc->pathmaxrxt = val.spt_pathmaxrxt;3888 asoc->pathmaxrxt = val->spt_pathmaxrxt;
4014 if (v2)3889 if (v2)
4015 asoc->ps_retrans = val.spt_pathcpthld;3890 asoc->ps_retrans = val->spt_pathcpthld;
4016 asoc->pf_retrans = val.spt_pathpfthld;3891 asoc->pf_retrans = val->spt_pathpfthld;
4017 } else {3892 } else {
4018 struct sctp_sock *sp = sctp_sk(sk);3893 struct sctp_sock *sp = sctp_sk(sk);
4019 3894
4020 if (val.spt_pathmaxrxt)3895 if (val->spt_pathmaxrxt)
4021 sp->pathmaxrxt = val.spt_pathmaxrxt;3896 sp->pathmaxrxt = val->spt_pathmaxrxt;
4022 if (v2)3897 if (v2)
4023 sp->ps_retrans = val.spt_pathcpthld;3898 sp->ps_retrans = val->spt_pathcpthld;
4024 sp->pf_retrans = val.spt_pathpfthld;3899 sp->pf_retrans = val->spt_pathpfthld;
4025 }3900 }
4026 3901
4027 return 0;3902 return 0;
4028}3903}
4029 3904
4030static int sctp_setsockopt_recvrcvinfo(struct sock *sk,3905static int sctp_setsockopt_recvrcvinfo(struct sock *sk, int *val,
4031 char __user *optval,
4032 unsigned int optlen)3906 unsigned int optlen)
4033{3907{
4034 int val;
4035
4036 if (optlen < sizeof(int))3908 if (optlen < sizeof(int))
4037 return -EINVAL;3909 return -EINVAL;
4038 if (get_user(val, (int __user *) optval))
4039 return -EFAULT;
4040 3910
4041 sctp_sk(sk)->recvrcvinfo = (val == 0) ? 0 : 1;3911 sctp_sk(sk)->recvrcvinfo = (*val == 0) ? 0 : 1;
4042 3912
4043 return 0;3913 return 0;
4044}3914}
4045 3915
4046static int sctp_setsockopt_recvnxtinfo(struct sock *sk,3916static int sctp_setsockopt_recvnxtinfo(struct sock *sk, int *val,
4047 char __user *optval,
4048 unsigned int optlen)3917 unsigned int optlen)
4049{3918{
4050 int val;
4051
4052 if (optlen < sizeof(int))3919 if (optlen < sizeof(int))
4053 return -EINVAL;3920 return -EINVAL;
4054 if (get_user(val, (int __user *) optval))
4055 return -EFAULT;
4056 3921
4057 sctp_sk(sk)->recvnxtinfo = (val == 0) ? 0 : 1;3922 sctp_sk(sk)->recvnxtinfo = (*val == 0) ? 0 : 1;
4058 3923
4059 return 0;3924 return 0;
4060}3925}
4061 3926
4062static int sctp_setsockopt_pr_supported(struct sock *sk,3927static int sctp_setsockopt_pr_supported(struct sock *sk,
4063 char __user *optval,3928 struct sctp_assoc_value *params,
4064 unsigned int optlen)3929 unsigned int optlen)
4065{3930{
4066 struct sctp_assoc_value params;
4067 struct sctp_association *asoc;3931 struct sctp_association *asoc;
4068 3932
4069 if (optlen != sizeof(params))3933 if (optlen != sizeof(*params))
4070 return -EINVAL;3934 return -EINVAL;
4071 3935
4072 if (copy_from_user(&params, optval, optlen))3936 asoc = sctp_id2assoc(sk, params->assoc_id);
4073 return -EFAULT;3937 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4074
4075 asoc = sctp_id2assoc(sk, params.assoc_id);
4076 if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
4077 sctp_style(sk, UDP))3938 sctp_style(sk, UDP))
4078 return -EINVAL;3939 return -EINVAL;
4079 3940
4080 sctp_sk(sk)->ep->prsctp_enable = !!params.assoc_value;3941 sctp_sk(sk)->ep->prsctp_enable = !!params->assoc_value;
4081 3942
4082 return 0;3943 return 0;
4083}3944}
4084 3945
4085static int sctp_setsockopt_default_prinfo(struct sock *sk,3946static int sctp_setsockopt_default_prinfo(struct sock *sk,
4086 char __user *optval,3947 struct sctp_default_prinfo *info,
4087 unsigned int optlen)3948 unsigned int optlen)
4088{3949{
4089 struct sctp_sock *sp = sctp_sk(sk);3950 struct sctp_sock *sp = sctp_sk(sk);
4090 struct sctp_default_prinfo info;
4091 struct sctp_association *asoc;3951 struct sctp_association *asoc;
4092 int retval = -EINVAL;3952 int retval = -EINVAL;
4093 3953
4094 if (optlen != sizeof(info))3954 if (optlen != sizeof(*info))
4095 goto out;
4096
4097 if (copy_from_user(&info, optval, sizeof(info))) {
4098 retval = -EFAULT;
4099 goto out;3955 goto out;
4100 }
4101 3956
4102 if (info.pr_policy & ~SCTP_PR_SCTP_MASK)3957 if (info->pr_policy & ~SCTP_PR_SCTP_MASK)
4103 goto out;3958 goto out;
4104 3959
4105 if (info.pr_policy == SCTP_PR_SCTP_NONE)3960 if (info->pr_policy == SCTP_PR_SCTP_NONE)
4106 info.pr_value = 0;3961 info->pr_value = 0;
4107 3962
4108 asoc = sctp_id2assoc(sk, info.pr_assoc_id);3963 asoc = sctp_id2assoc(sk, info->pr_assoc_id);
4109 if (!asoc && info.pr_assoc_id > SCTP_ALL_ASSOC &&3964 if (!asoc && info->pr_assoc_id > SCTP_ALL_ASSOC &&
4110 sctp_style(sk, UDP))3965 sctp_style(sk, UDP))
4111 goto out;3966 goto out;
4112 3967
4113 retval = 0;3968 retval = 0;
4114 3969
4115 if (asoc) {3970 if (asoc) {
4116 SCTP_PR_SET_POLICY(asoc->default_flags, info.pr_policy);3971 SCTP_PR_SET_POLICY(asoc->default_flags, info->pr_policy);
4117 asoc->default_timetolive = info.pr_value;3972 asoc->default_timetolive = info->pr_value;
4118 goto out;3973 goto out;
4119 }3974 }
4120 3975
4121 if (sctp_style(sk, TCP))3976 if (sctp_style(sk, TCP))
4122 info.pr_assoc_id = SCTP_FUTURE_ASSOC;3977 info->pr_assoc_id = SCTP_FUTURE_ASSOC;
4123 3978
4124 if (info.pr_assoc_id == SCTP_FUTURE_ASSOC ||3979 if (info->pr_assoc_id == SCTP_FUTURE_ASSOC ||
4125 info.pr_assoc_id == SCTP_ALL_ASSOC) {3980 info->pr_assoc_id == SCTP_ALL_ASSOC) {
4126 SCTP_PR_SET_POLICY(sp->default_flags, info.pr_policy);3981 SCTP_PR_SET_POLICY(sp->default_flags, info->pr_policy);
4127 sp->default_timetolive = info.pr_value;3982 sp->default_timetolive = info->pr_value;
4128 }3983 }
4129 3984
4130 if (info.pr_assoc_id == SCTP_CURRENT_ASSOC ||3985 if (info->pr_assoc_id == SCTP_CURRENT_ASSOC ||
4131 info.pr_assoc_id == SCTP_ALL_ASSOC) {3986 info->pr_assoc_id == SCTP_ALL_ASSOC) {
4132 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {3987 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
4133 SCTP_PR_SET_POLICY(asoc->default_flags, info.pr_policy);3988 SCTP_PR_SET_POLICY(asoc->default_flags,
4134 asoc->default_timetolive = info.pr_value;3989 info->pr_policy);
3990 asoc->default_timetolive = info->pr_value;
4135 }3991 }
4136 }3992 }
4137 3993
@@ -4140,27 +3996,21 @@ out: · 2 unmodified lines
4140}3996}
4141 3997
4142static int sctp_setsockopt_reconfig_supported(struct sock *sk,3998static int sctp_setsockopt_reconfig_supported(struct sock *sk,
4143 char __user *optval,3999 struct sctp_assoc_value *params,
4144 unsigned int optlen)4000 unsigned int optlen)
4145{4001{
4146 struct sctp_assoc_value params;
4147 struct sctp_association *asoc;4002 struct sctp_association *asoc;
4148 int retval = -EINVAL;4003 int retval = -EINVAL;
4149 4004
4150 if (optlen != sizeof(params))4005 if (optlen != sizeof(*params))
4151 goto out;4006 goto out;
4152 4007
4153 if (copy_from_user(&params, optval, optlen)) {4008 asoc = sctp_id2assoc(sk, params->assoc_id);
4154 retval = -EFAULT;4009 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4155 goto out;
4156 }
4157
4158 asoc = sctp_id2assoc(sk, params.assoc_id);
4159 if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
4160 sctp_style(sk, UDP))4010 sctp_style(sk, UDP))
4161 goto out;4011 goto out;
4162 4012
4163 sctp_sk(sk)->ep->reconf_enable = !!params.assoc_value;4013 sctp_sk(sk)->ep->reconf_enable = !!params->assoc_value;
4164 4014
4165 retval = 0;4015 retval = 0;
4166 4016
@@ -4169,60 +4019,52 @@ out: · 2 unmodified lines
4169}4019}
4170 4020
4171static int sctp_setsockopt_enable_strreset(struct sock *sk,4021static int sctp_setsockopt_enable_strreset(struct sock *sk,
4172 char __user *optval,4022 struct sctp_assoc_value *params,
4173 unsigned int optlen)4023 unsigned int optlen)
4174{4024{
4175 struct sctp_endpoint *ep = sctp_sk(sk)->ep;4025 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
4176 struct sctp_assoc_value params;
4177 struct sctp_association *asoc;4026 struct sctp_association *asoc;
4178 int retval = -EINVAL;4027 int retval = -EINVAL;
4179 4028
4180 if (optlen != sizeof(params))4029 if (optlen != sizeof(*params))
4181 goto out;
4182
4183 if (copy_from_user(&params, optval, optlen)) {
4184 retval = -EFAULT;
4185 goto out;4030 goto out;
4186 }
4187 4031
4188 if (params.assoc_value & (~SCTP_ENABLE_STRRESET_MASK))4032 if (params->assoc_value & (~SCTP_ENABLE_STRRESET_MASK))
4189 goto out;4033 goto out;
4190 4034
4191 asoc = sctp_id2assoc(sk, params.assoc_id);4035 asoc = sctp_id2assoc(sk, params->assoc_id);
4192 if (!asoc && params.assoc_id > SCTP_ALL_ASSOC &&4036 if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
4193 sctp_style(sk, UDP))4037 sctp_style(sk, UDP))
4194 goto out;4038 goto out;
4195 4039
4196 retval = 0;4040 retval = 0;
4197 4041
4198 if (asoc) {4042 if (asoc) {
4199 asoc->strreset_enable = params.assoc_value;4043 asoc->strreset_enable = params->assoc_value;
4200 goto out;4044 goto out;
4201 }4045 }
4202 4046
4203 if (sctp_style(sk, TCP))4047 if (sctp_style(sk, TCP))
4204 params.assoc_id = SCTP_FUTURE_ASSOC;4048 params->assoc_id = SCTP_FUTURE_ASSOC;
4205 4049
4206 if (params.assoc_id == SCTP_FUTURE_ASSOC ||4050 if (params->assoc_id == SCTP_FUTURE_ASSOC ||
4207 params.assoc_id == SCTP_ALL_ASSOC)4051 params->assoc_id == SCTP_ALL_ASSOC)
4208 ep->strreset_enable = params.assoc_value;4052 ep->strreset_enable = params->assoc_value;
4209 4053
4210 if (params.assoc_id == SCTP_CURRENT_ASSOC ||4054 if (params->assoc_id == SCTP_CURRENT_ASSOC ||
4211 params.assoc_id == SCTP_ALL_ASSOC)4055 params->assoc_id == SCTP_ALL_ASSOC)
4212 list_for_each_entry(asoc, &ep->asocs, asocs)4056 list_for_each_entry(asoc, &ep->asocs, asocs)
4213 asoc->strreset_enable = params.assoc_value;4057 asoc->strreset_enable = params->assoc_value;
4214 4058
4215out:4059out:
4216 return retval;4060 return retval;
4217}4061}
4218 4062
4219static int sctp_setsockopt_reset_streams(struct sock *sk,4063static int sctp_setsockopt_reset_streams(struct sock *sk,
4220 char __user *optval,4064 struct sctp_reset_streams *params,
4221 unsigned int optlen)4065 unsigned int optlen)
4222{4066{
4223 struct sctp_reset_streams *params;
4224 struct sctp_association *asoc;4067 struct sctp_association *asoc;
4225 int retval = -EINVAL;
4226 4068
4227 if (optlen < sizeof(*params))4069 if (optlen < sizeof(*params))
4228 return -EINVAL;4070 return -EINVAL;
@@ -4230,116 +4072,82 @@ static int sctp_setsockopt_reset_streams(struct sock *sk, · 1 unmodified line
4230 optlen = min_t(unsigned int, optlen, USHRT_MAX +4072 optlen = min_t(unsigned int, optlen, USHRT_MAX +
4231 sizeof(__u16) * sizeof(*params));4073 sizeof(__u16) * sizeof(*params));
4232 4074
4233 params = memdup_user(optval, optlen);
4234 if (IS_ERR(params))
4235 return PTR_ERR(params);
4236
4237 if (params->srs_number_streams * sizeof(__u16) >4075 if (params->srs_number_streams * sizeof(__u16) >
4238 optlen - sizeof(*params))4076 optlen - sizeof(*params))
4239 goto out;4077 return -EINVAL;
4240 4078
4241 asoc = sctp_id2assoc(sk, params->srs_assoc_id);4079 asoc = sctp_id2assoc(sk, params->srs_assoc_id);
4242 if (!asoc)4080 if (!asoc)
4243 goto out;4081 return -EINVAL;
4244
4245 retval = sctp_send_reset_streams(asoc, params);
4246 4082
4247out:4083 return sctp_send_reset_streams(asoc, params);
4248 kfree(params);
4249 return retval;
4250}4084}
4251 4085
4252static int sctp_setsockopt_reset_assoc(struct sock *sk,4086static int sctp_setsockopt_reset_assoc(struct sock *sk, sctp_assoc_t *associd,
4253 char __user *optval,
4254 unsigned int optlen)4087 unsigned int optlen)
4255{4088{
4256 struct sctp_association *asoc;4089 struct sctp_association *asoc;
4257 sctp_assoc_t associd;
4258 int retval = -EINVAL;
4259
4260 if (optlen != sizeof(associd))
4261 goto out;
4262 4090
4263 if (copy_from_user(&associd, optval, optlen)) {4091 if (optlen != sizeof(*associd))
4264 retval = -EFAULT;4092 return -EINVAL;
4265 goto out;
4266 }
4267 4093
4268 asoc = sctp_id2assoc(sk, associd);4094 asoc = sctp_id2assoc(sk, *associd);
4269 if (!asoc)4095 if (!asoc)
4270 goto out;4096 return -EINVAL;
4271
4272 retval = sctp_send_reset_assoc(asoc);
4273 4097
4274out:4098 return sctp_send_reset_assoc(asoc);
4275 return retval;
4276}4099}
4277 4100
4278static int sctp_setsockopt_add_streams(struct sock *sk,4101static int sctp_setsockopt_add_streams(struct sock *sk,
4279 char __user *optval,4102 struct sctp_add_streams *params,
4280 unsigned int optlen)4103 unsigned int optlen)
4281{4104{
4282 struct sctp_association *asoc;4105 struct sctp_association *asoc;
4283 struct sctp_add_streams params;
4284 int retval = -EINVAL;
4285 4106
4286 if (optlen != sizeof(params))4107 if (optlen != sizeof(*params))
4287 goto out;4108 return -EINVAL;
4288
4289 if (copy_from_user(&params, optval, optlen)) {
4290 retval = -EFAULT;
4291 goto out;
4292 }
4293 4109
4294 asoc = sctp_id2assoc(sk, params.sas_assoc_id);4110 asoc = sctp_id2assoc(sk, params->sas_assoc_id);
4295 if (!asoc)4111 if (!asoc)
4296 goto out;4112 return -EINVAL;
4297
4298 retval = sctp_send_add_streams(asoc, &params);
4299 4113
4300out:4114 return sctp_send_add_streams(asoc, params);
4301 return retval;
4302}4115}
4303 4116
4304static int sctp_setsockopt_scheduler(struct sock *sk,4117static int sctp_setsockopt_scheduler(struct sock *sk,
4305 char __user *optval,4118 struct sctp_assoc_value *params,
4306 unsigned int optlen)4119 unsigned int optlen)
4307{4120{
4308 struct sctp_sock *sp = sctp_sk(sk);4121 struct sctp_sock *sp = sctp_sk(sk);
4309 struct sctp_association *asoc;4122 struct sctp_association *asoc;
4310 struct sctp_assoc_value params;
4311 int retval = 0;4123 int retval = 0;
4312 4124
4313 if (optlen < sizeof(params))4125 if (optlen < sizeof(*params))
4314 return -EINVAL;4126 return -EINVAL;
4315 4127
4316 optlen = sizeof(params);4128 if (params->assoc_value > SCTP_SS_MAX)
4317 if (copy_from_user(&params, optval, optlen))
4318 return -EFAULT;
4319
4320 if (params.assoc_value > SCTP_SS_MAX)
4321 return -EINVAL;4129 return -EINVAL;
4322 4130
4323 asoc = sctp_id2assoc(sk, params.assoc_id);4131 asoc = sctp_id2assoc(sk, params->assoc_id);
4324 if (!asoc && params.assoc_id > SCTP_ALL_ASSOC &&4132 if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
4325 sctp_style(sk, UDP))4133 sctp_style(sk, UDP))
4326 return -EINVAL;4134 return -EINVAL;
4327 4135
4328 if (asoc)4136 if (asoc)
4329 return sctp_sched_set_sched(asoc, params.assoc_value);4137 return sctp_sched_set_sched(asoc, params->assoc_value);
4330 4138
4331 if (sctp_style(sk, TCP))4139 if (sctp_style(sk, TCP))
4332 params.assoc_id = SCTP_FUTURE_ASSOC;4140 params->assoc_id = SCTP_FUTURE_ASSOC;
4333 4141
4334 if (params.assoc_id == SCTP_FUTURE_ASSOC ||4142 if (params->assoc_id == SCTP_FUTURE_ASSOC ||
4335 params.assoc_id == SCTP_ALL_ASSOC)4143 params->assoc_id == SCTP_ALL_ASSOC)
4336 sp->default_ss = params.assoc_value;4144 sp->default_ss = params->assoc_value;
4337 4145
4338 if (params.assoc_id == SCTP_CURRENT_ASSOC ||4146 if (params->assoc_id == SCTP_CURRENT_ASSOC ||
4339 params.assoc_id == SCTP_ALL_ASSOC) {4147 params->assoc_id == SCTP_ALL_ASSOC) {
4340 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {4148 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
4341 int ret = sctp_sched_set_sched(asoc,4149 int ret = sctp_sched_set_sched(asoc,
4342 params.assoc_value);4150 params->assoc_value);
4343 4151
4344 if (ret && !retval)4152 if (ret && !retval)
4345 retval = ret;4153 retval = ret;
@@ -4350,38 +4158,32 @@ static int sctp_setsockopt_scheduler(struct sock *sk, · 4 unmodified lines
4350}4158}
4351 4159
4352static int sctp_setsockopt_scheduler_value(struct sock *sk,4160static int sctp_setsockopt_scheduler_value(struct sock *sk,
4353 char __user *optval,4161 struct sctp_stream_value *params,
4354 unsigned int optlen)4162 unsigned int optlen)
4355{4163{
4356 struct sctp_stream_value params;
4357 struct sctp_association *asoc;4164 struct sctp_association *asoc;
4358 int retval = -EINVAL;4165 int retval = -EINVAL;
4359 4166
4360 if (optlen < sizeof(params))4167 if (optlen < sizeof(*params))
4361 goto out;
4362
4363 optlen = sizeof(params);
4364 if (copy_from_user(&params, optval, optlen)) {
4365 retval = -EFAULT;
4366 goto out;4168 goto out;
4367 }
4368 4169
4369 asoc = sctp_id2assoc(sk, params.assoc_id);4170 asoc = sctp_id2assoc(sk, params->assoc_id);
4370 if (!asoc && params.assoc_id != SCTP_CURRENT_ASSOC &&4171 if (!asoc && params->assoc_id != SCTP_CURRENT_ASSOC &&
4371 sctp_style(sk, UDP))4172 sctp_style(sk, UDP))
4372 goto out;4173 goto out;
4373 4174
4374 if (asoc) {4175 if (asoc) {
4375 retval = sctp_sched_set_value(asoc, params.stream_id,4176 retval = sctp_sched_set_value(asoc, params->stream_id,
4376 params.stream_value, GFP_KERNEL);4177 params->stream_value, GFP_KERNEL);
4377 goto out;4178 goto out;
4378 }4179 }
4379 4180
4380 retval = 0;4181 retval = 0;
4381 4182
4382 list_for_each_entry(asoc, &sctp_sk(sk)->ep->asocs, asocs) {4183 list_for_each_entry(asoc, &sctp_sk(sk)->ep->asocs, asocs) {
4383 int ret = sctp_sched_set_value(asoc, params.stream_id,4184 int ret = sctp_sched_set_value(asoc, params->stream_id,
4384 params.stream_value, GFP_KERNEL);4185 params->stream_value,
4186 GFP_KERNEL);
4385 if (ret && !retval) /* try to return the 1st error. */4187 if (ret && !retval) /* try to return the 1st error. */
4386 retval = ret;4188 retval = ret;
4387 }4189 }
@@ -4391,46 +4193,30 @@ out: · 3 unmodified lines
4391}4193}
4392 4194
4393static int sctp_setsockopt_interleaving_supported(struct sock *sk,4195static int sctp_setsockopt_interleaving_supported(struct sock *sk,
4394 char __user *optval,4196 struct sctp_assoc_value *p,
4395 unsigned int optlen)4197 unsigned int optlen)
4396{4198{
4397 struct sctp_sock *sp = sctp_sk(sk);4199 struct sctp_sock *sp = sctp_sk(sk);
4398 struct sctp_assoc_value params;
4399 struct sctp_association *asoc;4200 struct sctp_association *asoc;
4400 int retval = -EINVAL;
4401 4201
4402 if (optlen < sizeof(params))4202 if (optlen < sizeof(*p))
4403 goto out;4203 return -EINVAL;
4404
4405 optlen = sizeof(params);
4406 if (copy_from_user(&params, optval, optlen)) {
4407 retval = -EFAULT;
4408 goto out;
4409 }
4410 4204
4411 asoc = sctp_id2assoc(sk, params.assoc_id);4205 asoc = sctp_id2assoc(sk, p->assoc_id);
4412 if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&4206 if (!asoc && p->assoc_id != SCTP_FUTURE_ASSOC && sctp_style(sk, UDP))
4413 sctp_style(sk, UDP))4207 return -EINVAL;
4414 goto out;
4415 4208
4416 if (!sock_net(sk)->sctp.intl_enable || !sp->frag_interleave) {4209 if (!sock_net(sk)->sctp.intl_enable || !sp->frag_interleave) {
4417 retval = -EPERM;4210 return -EPERM;
4418 goto out;
4419 }4211 }
4420 4212
4421 sp->ep->intl_enable = !!params.assoc_value;4213 sp->ep->intl_enable = !!p->assoc_value;
4422 4214 return 0;
4423 retval = 0;
4424
4425out:
4426 return retval;
4427}4215}
4428 4216
4429static int sctp_setsockopt_reuse_port(struct sock *sk, char __user *optval,4217static int sctp_setsockopt_reuse_port(struct sock *sk, int *val,
4430 unsigned int optlen)4218 unsigned int optlen)
4431{4219{
4432 int val;
4433
4434 if (!sctp_style(sk, TCP))4220 if (!sctp_style(sk, TCP))
4435 return -EOPNOTSUPP;4221 return -EOPNOTSUPP;
4436 4222
@@ -4440,10 +4226,7 @@ static int sctp_setsockopt_reuse_port(struct sock *sk, char __user *optval, · 3 unmodified lines
4440 if (optlen < sizeof(int))4226 if (optlen < sizeof(int))
4441 return -EINVAL;4227 return -EINVAL;
4442 4228
4443 if (get_user(val, (int __user *)optval))4229 sctp_sk(sk)->reuse = !!*val;
4444 return -EFAULT;
4445
4446 sctp_sk(sk)->reuse = !!val;
4447 4230
4448 return 0;4231 return 0;
4449}4232}
@@ -4469,45 +4252,40 @@ static int sctp_assoc_ulpevent_type_set(struct sctp_event *param, · 19 unmodified lines
4469 return 0;4252 return 0;
4470}4253}
4471 4254
4472static int sctp_setsockopt_event(struct sock *sk, char __user *optval,4255static int sctp_setsockopt_event(struct sock *sk, struct sctp_event *param,
4473 unsigned int optlen)4256 unsigned int optlen)
4474{4257{
4475 struct sctp_sock *sp = sctp_sk(sk);4258 struct sctp_sock *sp = sctp_sk(sk);
4476 struct sctp_association *asoc;4259 struct sctp_association *asoc;
4477 struct sctp_event param;
4478 int retval = 0;4260 int retval = 0;
4479 4261
4480 if (optlen < sizeof(param))4262 if (optlen < sizeof(*param))
4481 return -EINVAL;4263 return -EINVAL;
4482 4264
4483 optlen = sizeof(param);4265 if (param->se_type < SCTP_SN_TYPE_BASE ||
4484 if (copy_from_user(&param, optval, optlen))4266 param->se_type > SCTP_SN_TYPE_MAX)
4485 return -EFAULT;
4486
4487 if (param.se_type < SCTP_SN_TYPE_BASE ||
4488 param.se_type > SCTP_SN_TYPE_MAX)
4489 return -EINVAL;4267 return -EINVAL;
4490 4268
4491 asoc = sctp_id2assoc(sk, param.se_assoc_id);4269 asoc = sctp_id2assoc(sk, param->se_assoc_id);
4492 if (!asoc && param.se_assoc_id > SCTP_ALL_ASSOC &&4270 if (!asoc && param->se_assoc_id > SCTP_ALL_ASSOC &&
4493 sctp_style(sk, UDP))4271 sctp_style(sk, UDP))
4494 return -EINVAL;4272 return -EINVAL;
4495 4273
4496 if (asoc)4274 if (asoc)
4497 return sctp_assoc_ulpevent_type_set(&param, asoc);4275 return sctp_assoc_ulpevent_type_set(param, asoc);
4498 4276
4499 if (sctp_style(sk, TCP))4277 if (sctp_style(sk, TCP))
4500 param.se_assoc_id = SCTP_FUTURE_ASSOC;4278 param->se_assoc_id = SCTP_FUTURE_ASSOC;
4501 4279
4502 if (param.se_assoc_id == SCTP_FUTURE_ASSOC ||4280 if (param->se_assoc_id == SCTP_FUTURE_ASSOC ||
4503 param.se_assoc_id == SCTP_ALL_ASSOC)4281 param->se_assoc_id == SCTP_ALL_ASSOC)
4504 sctp_ulpevent_type_set(&sp->subscribe,4282 sctp_ulpevent_type_set(&sp->subscribe,
4505 param.se_type, param.se_on);4283 param->se_type, param->se_on);
4506 4284
4507 if (param.se_assoc_id == SCTP_CURRENT_ASSOC ||4285 if (param->se_assoc_id == SCTP_CURRENT_ASSOC ||
4508 param.se_assoc_id == SCTP_ALL_ASSOC) {4286 param->se_assoc_id == SCTP_ALL_ASSOC) {
4509 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {4287 list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
4510 int ret = sctp_assoc_ulpevent_type_set(&param, asoc);4288 int ret = sctp_assoc_ulpevent_type_set(param, asoc);
4511 4289
4512 if (ret && !retval)4290 if (ret && !retval)
4513 retval = ret;4291 retval = ret;
@@ -4518,29 +4296,23 @@ static int sctp_setsockopt_event(struct sock *sk, char __user *optval, · 4 unmodified lines
4518}4296}
4519 4297
4520static int sctp_setsockopt_asconf_supported(struct sock *sk,4298static int sctp_setsockopt_asconf_supported(struct sock *sk,
4521 char __user *optval,4299 struct sctp_assoc_value *params,
4522 unsigned int optlen)4300 unsigned int optlen)
4523{4301{
4524 struct sctp_assoc_value params;
4525 struct sctp_association *asoc;4302 struct sctp_association *asoc;
4526 struct sctp_endpoint *ep;4303 struct sctp_endpoint *ep;
4527 int retval = -EINVAL;4304 int retval = -EINVAL;
4528 4305
4529 if (optlen != sizeof(params))4306 if (optlen != sizeof(*params))
4530 goto out;
4531
4532 if (copy_from_user(&params, optval, optlen)) {
4533 retval = -EFAULT;
4534 goto out;4307 goto out;
4535 }
4536 4308
4537 asoc = sctp_id2assoc(sk, params.assoc_id);4309 asoc = sctp_id2assoc(sk, params->assoc_id);
4538 if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&4310 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4539 sctp_style(sk, UDP))4311 sctp_style(sk, UDP))
4540 goto out;4312 goto out;
4541 4313
4542 ep = sctp_sk(sk)->ep;4314 ep = sctp_sk(sk)->ep;
4543 ep->asconf_enable = !!params.assoc_value;4315 ep->asconf_enable = !!params->assoc_value;
4544 4316
4545 if (ep->asconf_enable && ep->auth_enable) {4317 if (ep->asconf_enable && ep->auth_enable) {
4546 sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF);4318 sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF);
@@ -4554,29 +4326,23 @@ out: · 7 unmodified lines
4554}4326}
4555 4327
4556static int sctp_setsockopt_auth_supported(struct sock *sk,4328static int sctp_setsockopt_auth_supported(struct sock *sk,
4557 char __user *optval,4329 struct sctp_assoc_value *params,
4558 unsigned int optlen)4330 unsigned int optlen)
4559{4331{
4560 struct sctp_assoc_value params;
4561 struct sctp_association *asoc;4332 struct sctp_association *asoc;
4562 struct sctp_endpoint *ep;4333 struct sctp_endpoint *ep;
4563 int retval = -EINVAL;4334 int retval = -EINVAL;
4564 4335
4565 if (optlen != sizeof(params))4336 if (optlen != sizeof(*params))
4566 goto out;
4567
4568 if (copy_from_user(&params, optval, optlen)) {
4569 retval = -EFAULT;
4570 goto out;4337 goto out;
4571 }
4572 4338
4573 asoc = sctp_id2assoc(sk, params.assoc_id);4339 asoc = sctp_id2assoc(sk, params->assoc_id);
4574 if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&4340 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4575 sctp_style(sk, UDP))4341 sctp_style(sk, UDP))
4576 goto out;4342 goto out;
4577 4343
4578 ep = sctp_sk(sk)->ep;4344 ep = sctp_sk(sk)->ep;
4579 if (params.assoc_value) {4345 if (params->assoc_value) {
4580 retval = sctp_auth_init(ep, GFP_KERNEL);4346 retval = sctp_auth_init(ep, GFP_KERNEL);
4581 if (retval)4347 if (retval)
4582 goto out;4348 goto out;
@@ -4586,7 +4352,7 @@ static int sctp_setsockopt_auth_supported(struct sock *sk, · 3 unmodified lines
4586 }4352 }
4587 }4353 }
4588 4354
4589 ep->auth_enable = !!params.assoc_value;4355 ep->auth_enable = !!params->assoc_value;
4590 retval = 0;4356 retval = 0;
4591 4357
4592out:4358out:
@@ -4594,27 +4360,21 @@ out: · 1 unmodified line
4594}4360}
4595 4361
4596static int sctp_setsockopt_ecn_supported(struct sock *sk,4362static int sctp_setsockopt_ecn_supported(struct sock *sk,
4597 char __user *optval,4363 struct sctp_assoc_value *params,
4598 unsigned int optlen)4364 unsigned int optlen)
4599{4365{
4600 struct sctp_assoc_value params;
4601 struct sctp_association *asoc;4366 struct sctp_association *asoc;
4602 int retval = -EINVAL;4367 int retval = -EINVAL;
4603 4368
4604 if (optlen != sizeof(params))4369 if (optlen != sizeof(*params))
4605 goto out;4370 goto out;
4606 4371
4607 if (copy_from_user(&params, optval, optlen)) {4372 asoc = sctp_id2assoc(sk, params->assoc_id);
4608 retval = -EFAULT;4373 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4609 goto out;
4610 }
4611
4612 asoc = sctp_id2assoc(sk, params.assoc_id);
4613 if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
4614 sctp_style(sk, UDP))4374 sctp_style(sk, UDP))
4615 goto out;4375 goto out;
4616 4376
4617 sctp_sk(sk)->ep->ecn_enable = !!params.assoc_value;4377 sctp_sk(sk)->ep->ecn_enable = !!params->assoc_value;
4618 retval = 0;4378 retval = 0;
4619 4379
4620out:4380out:
@@ -4622,33 +4382,27 @@ out: · 1 unmodified line
4622}4382}
4623 4383
4624static int sctp_setsockopt_pf_expose(struct sock *sk,4384static int sctp_setsockopt_pf_expose(struct sock *sk,
4625 char __user *optval,4385 struct sctp_assoc_value *params,
4626 unsigned int optlen)4386 unsigned int optlen)
4627{4387{
4628 struct sctp_assoc_value params;
4629 struct sctp_association *asoc;4388 struct sctp_association *asoc;
4630 int retval = -EINVAL;4389 int retval = -EINVAL;
4631 4390
4632 if (optlen != sizeof(params))4391 if (optlen != sizeof(*params))
4633 goto out;4392 goto out;
4634 4393
4635 if (copy_from_user(&params, optval, optlen)) {4394 if (params->assoc_value > SCTP_PF_EXPOSE_MAX)
4636 retval = -EFAULT;
4637 goto out;4395 goto out;
4638 }
4639 4396
4640 if (params.assoc_value > SCTP_PF_EXPOSE_MAX)4397 asoc = sctp_id2assoc(sk, params->assoc_id);
4641 goto out;4398 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
4642
4643 asoc = sctp_id2assoc(sk, params.assoc_id);
4644 if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
4645 sctp_style(sk, UDP))4399 sctp_style(sk, UDP))
4646 goto out;4400 goto out;
4647 4401
4648 if (asoc)4402 if (asoc)
4649 asoc->pf_expose = params.assoc_value;4403 asoc->pf_expose = params->assoc_value;
4650 else4404 else
4651 sctp_sk(sk)->pf_expose = params.assoc_value;4405 sctp_sk(sk)->pf_expose = params->assoc_value;
4652 retval = 0;4406 retval = 0;
4653 4407
4654out:4408out:
@@ -4677,6 +4431,7 @@ out: · 22 unmodified lines
4677static int sctp_setsockopt(struct sock *sk, int level, int optname,4431static int sctp_setsockopt(struct sock *sk, int level, int optname,
4678 char __user *optval, unsigned int optlen)4432 char __user *optval, unsigned int optlen)
4679{4433{
4434 void *kopt = NULL;
4680 int retval = 0;4435 int retval = 0;
4681 4436
4682 pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname);4437 pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname);
@@ -4689,8 +4444,14 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, · 6 unmodified lines
4689 */4444 */
4690 if (level != SOL_SCTP) {4445 if (level != SOL_SCTP) {
4691 struct sctp_af *af = sctp_sk(sk)->pf->af;4446 struct sctp_af *af = sctp_sk(sk)->pf->af;
4692 retval = af->setsockopt(sk, level, optname, optval, optlen);4447
4693 goto out_nounlock;4448 return af->setsockopt(sk, level, optname, optval, optlen);
4449 }
4450
4451 if (optlen > 0) {
4452 kopt = memdup_user(optval, optlen);
4453 if (IS_ERR(kopt))
4454 return PTR_ERR(kopt);
4694 }4455 }
4695 4456
4696 lock_sock(sk);4457 lock_sock(sk);
@@ -4698,179 +4459,174 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, · 1 unmodified line
4698 switch (optname) {4459 switch (optname) {
4699 case SCTP_SOCKOPT_BINDX_ADD:4460 case SCTP_SOCKOPT_BINDX_ADD:
4700 /* 'optlen' is the size of the addresses buffer. */4461 /* 'optlen' is the size of the addresses buffer. */
4701 retval = sctp_setsockopt_bindx(sk, (struct sockaddr __user *)optval,4462 retval = sctp_setsockopt_bindx(sk, kopt, optlen,
4702 optlen, SCTP_BINDX_ADD_ADDR);4463 SCTP_BINDX_ADD_ADDR);
4703 break;4464 break;
4704 4465
4705 case SCTP_SOCKOPT_BINDX_REM:4466 case SCTP_SOCKOPT_BINDX_REM:
4706 /* 'optlen' is the size of the addresses buffer. */4467 /* 'optlen' is the size of the addresses buffer. */
4707 retval = sctp_setsockopt_bindx(sk, (struct sockaddr __user *)optval,4468 retval = sctp_setsockopt_bindx(sk, kopt, optlen,
4708 optlen, SCTP_BINDX_REM_ADDR);4469 SCTP_BINDX_REM_ADDR);
4709 break;4470 break;
4710 4471
4711 case SCTP_SOCKOPT_CONNECTX_OLD:4472 case SCTP_SOCKOPT_CONNECTX_OLD:
4712 /* 'optlen' is the size of the addresses buffer. */4473 /* 'optlen' is the size of the addresses buffer. */
4713 retval = sctp_setsockopt_connectx_old(sk,4474 retval = sctp_setsockopt_connectx_old(sk, kopt, optlen);
4714 (struct sockaddr __user *)optval,
4715 optlen);
4716 break;4475 break;
4717 4476
4718 case SCTP_SOCKOPT_CONNECTX:4477 case SCTP_SOCKOPT_CONNECTX:
4719 /* 'optlen' is the size of the addresses buffer. */4478 /* 'optlen' is the size of the addresses buffer. */
4720 retval = sctp_setsockopt_connectx(sk,4479 retval = sctp_setsockopt_connectx(sk, kopt, optlen);
4721 (struct sockaddr __user *)optval,
4722 optlen);
4723 break;4480 break;
4724 4481
4725 case SCTP_DISABLE_FRAGMENTS:4482 case SCTP_DISABLE_FRAGMENTS:
4726 retval = sctp_setsockopt_disable_fragments(sk, optval, optlen);4483 retval = sctp_setsockopt_disable_fragments(sk, kopt, optlen);
4727 break;4484 break;
4728 4485
4729 case SCTP_EVENTS:4486 case SCTP_EVENTS:
4730 retval = sctp_setsockopt_events(sk, optval, optlen);4487 retval = sctp_setsockopt_events(sk, kopt, optlen);
4731 break;4488 break;
4732 4489
4733 case SCTP_AUTOCLOSE:4490 case SCTP_AUTOCLOSE:
4734 retval = sctp_setsockopt_autoclose(sk, optval, optlen);4491 retval = sctp_setsockopt_autoclose(sk, kopt, optlen);
4735 break;4492 break;
4736 4493
4737 case SCTP_PEER_ADDR_PARAMS:4494 case SCTP_PEER_ADDR_PARAMS:
4738 retval = sctp_setsockopt_peer_addr_params(sk, optval, optlen);4495 retval = sctp_setsockopt_peer_addr_params(sk, kopt, optlen);
4739 break;4496 break;
4740 4497
4741 case SCTP_DELAYED_SACK:4498 case SCTP_DELAYED_SACK:
4742 retval = sctp_setsockopt_delayed_ack(sk, optval, optlen);4499 retval = sctp_setsockopt_delayed_ack(sk, kopt, optlen);
4743 break;4500 break;
4744 case SCTP_PARTIAL_DELIVERY_POINT:4501 case SCTP_PARTIAL_DELIVERY_POINT:
4745 retval = sctp_setsockopt_partial_delivery_point(sk, optval, optlen);4502 retval = sctp_setsockopt_partial_delivery_point(sk, kopt, optlen);
4746 break;4503 break;
4747 4504
4748 case SCTP_INITMSG:4505 case SCTP_INITMSG:
4749 retval = sctp_setsockopt_initmsg(sk, optval, optlen);4506 retval = sctp_setsockopt_initmsg(sk, kopt, optlen);
4750 break;4507 break;
4751 case SCTP_DEFAULT_SEND_PARAM:4508 case SCTP_DEFAULT_SEND_PARAM:
4752 retval = sctp_setsockopt_default_send_param(sk, optval,4509 retval = sctp_setsockopt_default_send_param(sk, kopt, optlen);
4753 optlen);
4754 break;4510 break;
4755 case SCTP_DEFAULT_SNDINFO:4511 case SCTP_DEFAULT_SNDINFO:
4756 retval = sctp_setsockopt_default_sndinfo(sk, optval, optlen);4512 retval = sctp_setsockopt_default_sndinfo(sk, kopt, optlen);
4757 break;4513 break;
4758 case SCTP_PRIMARY_ADDR:4514 case SCTP_PRIMARY_ADDR:
4759 retval = sctp_setsockopt_primary_addr(sk, optval, optlen);4515 retval = sctp_setsockopt_primary_addr(sk, kopt, optlen);
4760 break;4516 break;
4761 case SCTP_SET_PEER_PRIMARY_ADDR:4517 case SCTP_SET_PEER_PRIMARY_ADDR:
4762 retval = sctp_setsockopt_peer_primary_addr(sk, optval, optlen);4518 retval = sctp_setsockopt_peer_primary_addr(sk, kopt, optlen);
4763 break;4519 break;
4764 case SCTP_NODELAY:4520 case SCTP_NODELAY:
4765 retval = sctp_setsockopt_nodelay(sk, optval, optlen);4521 retval = sctp_setsockopt_nodelay(sk, kopt, optlen);
4766 break;4522 break;
4767 case SCTP_RTOINFO:4523 case SCTP_RTOINFO:
4768 retval = sctp_setsockopt_rtoinfo(sk, optval, optlen);4524 retval = sctp_setsockopt_rtoinfo(sk, kopt, optlen);
4769 break;4525 break;
4770 case SCTP_ASSOCINFO:4526 case SCTP_ASSOCINFO:
4771 retval = sctp_setsockopt_associnfo(sk, optval, optlen);4527 retval = sctp_setsockopt_associnfo(sk, kopt, optlen);
4772 break;4528 break;
4773 case SCTP_I_WANT_MAPPED_V4_ADDR:4529 case SCTP_I_WANT_MAPPED_V4_ADDR:
4774 retval = sctp_setsockopt_mappedv4(sk, optval, optlen);4530 retval = sctp_setsockopt_mappedv4(sk, kopt, optlen);
4775 break;4531 break;
4776 case SCTP_MAXSEG:4532 case SCTP_MAXSEG:
4777 retval = sctp_setsockopt_maxseg(sk, optval, optlen);4533 retval = sctp_setsockopt_maxseg(sk, kopt, optlen);
4778 break;4534 break;
4779 case SCTP_ADAPTATION_LAYER:4535 case SCTP_ADAPTATION_LAYER:
4780 retval = sctp_setsockopt_adaptation_layer(sk, optval, optlen);4536 retval = sctp_setsockopt_adaptation_layer(sk, kopt, optlen);
4781 break;4537 break;
4782 case SCTP_CONTEXT:4538 case SCTP_CONTEXT:
4783 retval = sctp_setsockopt_context(sk, optval, optlen);4539 retval = sctp_setsockopt_context(sk, kopt, optlen);
4784 break;4540 break;
4785 case SCTP_FRAGMENT_INTERLEAVE:4541 case SCTP_FRAGMENT_INTERLEAVE:
4786 retval = sctp_setsockopt_fragment_interleave(sk, optval, optlen);4542 retval = sctp_setsockopt_fragment_interleave(sk, kopt, optlen);
4787 break;4543 break;
4788 case SCTP_MAX_BURST:4544 case SCTP_MAX_BURST:
4789 retval = sctp_setsockopt_maxburst(sk, optval, optlen);4545 retval = sctp_setsockopt_maxburst(sk, kopt, optlen);
4790 break;4546 break;
4791 case SCTP_AUTH_CHUNK:4547 case SCTP_AUTH_CHUNK:
4792 retval = sctp_setsockopt_auth_chunk(sk, optval, optlen);4548 retval = sctp_setsockopt_auth_chunk(sk, kopt, optlen);
4793 break;4549 break;
4794 case SCTP_HMAC_IDENT:4550 case SCTP_HMAC_IDENT:
4795 retval = sctp_setsockopt_hmac_ident(sk, optval, optlen);4551 retval = sctp_setsockopt_hmac_ident(sk, kopt, optlen);
4796 break;4552 break;
4797 case SCTP_AUTH_KEY:4553 case SCTP_AUTH_KEY:
4798 retval = sctp_setsockopt_auth_key(sk, optval, optlen);4554 retval = sctp_setsockopt_auth_key(sk, kopt, optlen);
4799 break;4555 break;
4800 case SCTP_AUTH_ACTIVE_KEY:4556 case SCTP_AUTH_ACTIVE_KEY:
4801 retval = sctp_setsockopt_active_key(sk, optval, optlen);4557 retval = sctp_setsockopt_active_key(sk, kopt, optlen);
4802 break;4558 break;
4803 case SCTP_AUTH_DELETE_KEY:4559 case SCTP_AUTH_DELETE_KEY:
4804 retval = sctp_setsockopt_del_key(sk, optval, optlen);4560 retval = sctp_setsockopt_del_key(sk, kopt, optlen);
4805 break;4561 break;
4806 case SCTP_AUTH_DEACTIVATE_KEY:4562 case SCTP_AUTH_DEACTIVATE_KEY:
4807 retval = sctp_setsockopt_deactivate_key(sk, optval, optlen);4563 retval = sctp_setsockopt_deactivate_key(sk, kopt, optlen);
4808 break;4564 break;
4809 case SCTP_AUTO_ASCONF:4565 case SCTP_AUTO_ASCONF:
4810 retval = sctp_setsockopt_auto_asconf(sk, optval, optlen);4566 retval = sctp_setsockopt_auto_asconf(sk, kopt, optlen);
4811 break;4567 break;
4812 case SCTP_PEER_ADDR_THLDS:4568 case SCTP_PEER_ADDR_THLDS:
4813 retval = sctp_setsockopt_paddr_thresholds(sk, optval, optlen,4569 retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen,
4814 false);4570 false);
4815 break;4571 break;
4816 case SCTP_PEER_ADDR_THLDS_V2:4572 case SCTP_PEER_ADDR_THLDS_V2:
4817 retval = sctp_setsockopt_paddr_thresholds(sk, optval, optlen,4573 retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen,
4818 true);4574 true);
4819 break;4575 break;
4820 case SCTP_RECVRCVINFO:4576 case SCTP_RECVRCVINFO:
4821 retval = sctp_setsockopt_recvrcvinfo(sk, optval, optlen);4577 retval = sctp_setsockopt_recvrcvinfo(sk, kopt, optlen);
4822 break;4578 break;
4823 case SCTP_RECVNXTINFO:4579 case SCTP_RECVNXTINFO:
4824 retval = sctp_setsockopt_recvnxtinfo(sk, optval, optlen);4580 retval = sctp_setsockopt_recvnxtinfo(sk, kopt, optlen);
4825 break;4581 break;
4826 case SCTP_PR_SUPPORTED:4582 case SCTP_PR_SUPPORTED:
4827 retval = sctp_setsockopt_pr_supported(sk, optval, optlen);4583 retval = sctp_setsockopt_pr_supported(sk, kopt, optlen);
4828 break;4584 break;
4829 case SCTP_DEFAULT_PRINFO:4585 case SCTP_DEFAULT_PRINFO:
4830 retval = sctp_setsockopt_default_prinfo(sk, optval, optlen);4586 retval = sctp_setsockopt_default_prinfo(sk, kopt, optlen);
4831 break;4587 break;
4832 case SCTP_RECONFIG_SUPPORTED:4588 case SCTP_RECONFIG_SUPPORTED:
4833 retval = sctp_setsockopt_reconfig_supported(sk, optval, optlen);4589 retval = sctp_setsockopt_reconfig_supported(sk, kopt, optlen);
4834 break;4590 break;
4835 case SCTP_ENABLE_STREAM_RESET:4591 case SCTP_ENABLE_STREAM_RESET:
4836 retval = sctp_setsockopt_enable_strreset(sk, optval, optlen);4592 retval = sctp_setsockopt_enable_strreset(sk, kopt, optlen);
4837 break;4593 break;
4838 case SCTP_RESET_STREAMS:4594 case SCTP_RESET_STREAMS:
4839 retval = sctp_setsockopt_reset_streams(sk, optval, optlen);4595 retval = sctp_setsockopt_reset_streams(sk, kopt, optlen);
4840 break;4596 break;
4841 case SCTP_RESET_ASSOC:4597 case SCTP_RESET_ASSOC:
4842 retval = sctp_setsockopt_reset_assoc(sk, optval, optlen);4598 retval = sctp_setsockopt_reset_assoc(sk, kopt, optlen);
4843 break;4599 break;
4844 case SCTP_ADD_STREAMS:4600 case SCTP_ADD_STREAMS:
4845 retval = sctp_setsockopt_add_streams(sk, optval, optlen);4601 retval = sctp_setsockopt_add_streams(sk, kopt, optlen);
4846 break;4602 break;
4847 case SCTP_STREAM_SCHEDULER:4603 case SCTP_STREAM_SCHEDULER:
4848 retval = sctp_setsockopt_scheduler(sk, optval, optlen);4604 retval = sctp_setsockopt_scheduler(sk, kopt, optlen);
4849 break;4605 break;
4850 case SCTP_STREAM_SCHEDULER_VALUE:4606 case SCTP_STREAM_SCHEDULER_VALUE:
4851 retval = sctp_setsockopt_scheduler_value(sk, optval, optlen);4607 retval = sctp_setsockopt_scheduler_value(sk, kopt, optlen);
4852 break;4608 break;
4853 case SCTP_INTERLEAVING_SUPPORTED:4609 case SCTP_INTERLEAVING_SUPPORTED:
4854 retval = sctp_setsockopt_interleaving_supported(sk, optval,4610 retval = sctp_setsockopt_interleaving_supported(sk, kopt,
4855 optlen);4611 optlen);
4856 break;4612 break;
4857 case SCTP_REUSE_PORT:4613 case SCTP_REUSE_PORT:
4858 retval = sctp_setsockopt_reuse_port(sk, optval, optlen);4614 retval = sctp_setsockopt_reuse_port(sk, kopt, optlen);
4859 break;4615 break;
4860 case SCTP_EVENT:4616 case SCTP_EVENT:
4861 retval = sctp_setsockopt_event(sk, optval, optlen);4617 retval = sctp_setsockopt_event(sk, kopt, optlen);
4862 break;4618 break;
4863 case SCTP_ASCONF_SUPPORTED:4619 case SCTP_ASCONF_SUPPORTED:
4864 retval = sctp_setsockopt_asconf_supported(sk, optval, optlen);4620 retval = sctp_setsockopt_asconf_supported(sk, kopt, optlen);
4865 break;4621 break;
4866 case SCTP_AUTH_SUPPORTED:4622 case SCTP_AUTH_SUPPORTED:
4867 retval = sctp_setsockopt_auth_supported(sk, optval, optlen);4623 retval = sctp_setsockopt_auth_supported(sk, kopt, optlen);
4868 break;4624 break;
4869 case SCTP_ECN_SUPPORTED:4625 case SCTP_ECN_SUPPORTED:
4870 retval = sctp_setsockopt_ecn_supported(sk, optval, optlen);4626 retval = sctp_setsockopt_ecn_supported(sk, kopt, optlen);
4871 break;4627 break;
4872 case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:4628 case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
4873 retval = sctp_setsockopt_pf_expose(sk, optval, optlen);4629 retval = sctp_setsockopt_pf_expose(sk, kopt, optlen);
4874 break;4630 break;
4875 default:4631 default:
4876 retval = -ENOPROTOOPT;4632 retval = -ENOPROTOOPT;
@@ -4878,8 +4634,7 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, · 1 unmodified line
4878 }4634 }
4879 4635
4880 release_sock(sk);4636 release_sock(sk);
4881 4637 kfree(kopt);
4882out_nounlock:
4883 return retval;4638 return retval;
4884}4639}
4885 4640

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t