aboutsummaryrefslogtreecommitdiffstats
path: root/net/sctp/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sctp/socket.c')
-rw-r--r--net/sctp/socket.c144
1 files changed, 92 insertions, 52 deletions
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 5e259817a7f3..59d16ea927f0 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -70,6 +70,7 @@
70#include <linux/init.h> 70#include <linux/init.h>
71#include <linux/crypto.h> 71#include <linux/crypto.h>
72#include <linux/slab.h> 72#include <linux/slab.h>
73#include <linux/file.h>
73 74
74#include <net/ip.h> 75#include <net/ip.h>
75#include <net/icmp.h> 76#include <net/icmp.h>
@@ -427,6 +428,7 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
427static int sctp_send_asconf(struct sctp_association *asoc, 428static int sctp_send_asconf(struct sctp_association *asoc,
428 struct sctp_chunk *chunk) 429 struct sctp_chunk *chunk)
429{ 430{
431 struct net *net = sock_net(asoc->base.sk);
430 int retval = 0; 432 int retval = 0;
431 433
432 /* If there is an outstanding ASCONF chunk, queue it for later 434 /* If there is an outstanding ASCONF chunk, queue it for later
@@ -439,7 +441,7 @@ static int sctp_send_asconf(struct sctp_association *asoc,
439 441
440 /* Hold the chunk until an ASCONF_ACK is received. */ 442 /* Hold the chunk until an ASCONF_ACK is received. */
441 sctp_chunk_hold(chunk); 443 sctp_chunk_hold(chunk);
442 retval = sctp_primitive_ASCONF(asoc, chunk); 444 retval = sctp_primitive_ASCONF(net, asoc, chunk);
443 if (retval) 445 if (retval)
444 sctp_chunk_free(chunk); 446 sctp_chunk_free(chunk);
445 else 447 else
@@ -515,6 +517,7 @@ static int sctp_send_asconf_add_ip(struct sock *sk,
515 struct sockaddr *addrs, 517 struct sockaddr *addrs,
516 int addrcnt) 518 int addrcnt)
517{ 519{
520 struct net *net = sock_net(sk);
518 struct sctp_sock *sp; 521 struct sctp_sock *sp;
519 struct sctp_endpoint *ep; 522 struct sctp_endpoint *ep;
520 struct sctp_association *asoc; 523 struct sctp_association *asoc;
@@ -529,7 +532,7 @@ static int sctp_send_asconf_add_ip(struct sock *sk,
529 int i; 532 int i;
530 int retval = 0; 533 int retval = 0;
531 534
532 if (!sctp_addip_enable) 535 if (!net->sctp.addip_enable)
533 return retval; 536 return retval;
534 537
535 sp = sctp_sk(sk); 538 sp = sctp_sk(sk);
@@ -717,6 +720,7 @@ static int sctp_send_asconf_del_ip(struct sock *sk,
717 struct sockaddr *addrs, 720 struct sockaddr *addrs,
718 int addrcnt) 721 int addrcnt)
719{ 722{
723 struct net *net = sock_net(sk);
720 struct sctp_sock *sp; 724 struct sctp_sock *sp;
721 struct sctp_endpoint *ep; 725 struct sctp_endpoint *ep;
722 struct sctp_association *asoc; 726 struct sctp_association *asoc;
@@ -732,7 +736,7 @@ static int sctp_send_asconf_del_ip(struct sock *sk,
732 int stored = 0; 736 int stored = 0;
733 737
734 chunk = NULL; 738 chunk = NULL;
735 if (!sctp_addip_enable) 739 if (!net->sctp.addip_enable)
736 return retval; 740 return retval;
737 741
738 sp = sctp_sk(sk); 742 sp = sctp_sk(sk);
@@ -1050,6 +1054,7 @@ static int __sctp_connect(struct sock* sk,
1050 int addrs_size, 1054 int addrs_size,
1051 sctp_assoc_t *assoc_id) 1055 sctp_assoc_t *assoc_id)
1052{ 1056{
1057 struct net *net = sock_net(sk);
1053 struct sctp_sock *sp; 1058 struct sctp_sock *sp;
1054 struct sctp_endpoint *ep; 1059 struct sctp_endpoint *ep;
1055 struct sctp_association *asoc = NULL; 1060 struct sctp_association *asoc = NULL;
@@ -1200,7 +1205,7 @@ static int __sctp_connect(struct sock* sk,
1200 goto out_free; 1205 goto out_free;
1201 } 1206 }
1202 1207
1203 err = sctp_primitive_ASSOCIATE(asoc, NULL); 1208 err = sctp_primitive_ASSOCIATE(net, asoc, NULL);
1204 if (err < 0) { 1209 if (err < 0) {
1205 goto out_free; 1210 goto out_free;
1206 } 1211 }
@@ -1458,6 +1463,7 @@ SCTP_STATIC int sctp_getsockopt_connectx3(struct sock* sk, int len,
1458 */ 1463 */
1459SCTP_STATIC void sctp_close(struct sock *sk, long timeout) 1464SCTP_STATIC void sctp_close(struct sock *sk, long timeout)
1460{ 1465{
1466 struct net *net = sock_net(sk);
1461 struct sctp_endpoint *ep; 1467 struct sctp_endpoint *ep;
1462 struct sctp_association *asoc; 1468 struct sctp_association *asoc;
1463 struct list_head *pos, *temp; 1469 struct list_head *pos, *temp;
@@ -1499,9 +1505,9 @@ SCTP_STATIC void sctp_close(struct sock *sk, long timeout)
1499 1505
1500 chunk = sctp_make_abort_user(asoc, NULL, 0); 1506 chunk = sctp_make_abort_user(asoc, NULL, 0);
1501 if (chunk) 1507 if (chunk)
1502 sctp_primitive_ABORT(asoc, chunk); 1508 sctp_primitive_ABORT(net, asoc, chunk);
1503 } else 1509 } else
1504 sctp_primitive_SHUTDOWN(asoc, NULL); 1510 sctp_primitive_SHUTDOWN(net, asoc, NULL);
1505 } 1511 }
1506 1512
1507 /* On a TCP-style socket, block for at most linger_time if set. */ 1513 /* On a TCP-style socket, block for at most linger_time if set. */
@@ -1569,6 +1575,7 @@ SCTP_STATIC int sctp_msghdr_parse(const struct msghdr *, sctp_cmsgs_t *);
1569SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, 1575SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
1570 struct msghdr *msg, size_t msg_len) 1576 struct msghdr *msg, size_t msg_len)
1571{ 1577{
1578 struct net *net = sock_net(sk);
1572 struct sctp_sock *sp; 1579 struct sctp_sock *sp;
1573 struct sctp_endpoint *ep; 1580 struct sctp_endpoint *ep;
1574 struct sctp_association *new_asoc=NULL, *asoc=NULL; 1581 struct sctp_association *new_asoc=NULL, *asoc=NULL;
@@ -1714,7 +1721,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
1714 if (sinfo_flags & SCTP_EOF) { 1721 if (sinfo_flags & SCTP_EOF) {
1715 SCTP_DEBUG_PRINTK("Shutting down association: %p\n", 1722 SCTP_DEBUG_PRINTK("Shutting down association: %p\n",
1716 asoc); 1723 asoc);
1717 sctp_primitive_SHUTDOWN(asoc, NULL); 1724 sctp_primitive_SHUTDOWN(net, asoc, NULL);
1718 err = 0; 1725 err = 0;
1719 goto out_unlock; 1726 goto out_unlock;
1720 } 1727 }
@@ -1727,7 +1734,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
1727 } 1734 }
1728 1735
1729 SCTP_DEBUG_PRINTK("Aborting association: %p\n", asoc); 1736 SCTP_DEBUG_PRINTK("Aborting association: %p\n", asoc);
1730 sctp_primitive_ABORT(asoc, chunk); 1737 sctp_primitive_ABORT(net, asoc, chunk);
1731 err = 0; 1738 err = 0;
1732 goto out_unlock; 1739 goto out_unlock;
1733 } 1740 }
@@ -1900,7 +1907,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
1900 1907
1901 /* Auto-connect, if we aren't connected already. */ 1908 /* Auto-connect, if we aren't connected already. */
1902 if (sctp_state(asoc, CLOSED)) { 1909 if (sctp_state(asoc, CLOSED)) {
1903 err = sctp_primitive_ASSOCIATE(asoc, NULL); 1910 err = sctp_primitive_ASSOCIATE(net, asoc, NULL);
1904 if (err < 0) 1911 if (err < 0)
1905 goto out_free; 1912 goto out_free;
1906 SCTP_DEBUG_PRINTK("We associated primitively.\n"); 1913 SCTP_DEBUG_PRINTK("We associated primitively.\n");
@@ -1928,7 +1935,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
1928 * works that way today. Keep it that way or this 1935 * works that way today. Keep it that way or this
1929 * breaks. 1936 * breaks.
1930 */ 1937 */
1931 err = sctp_primitive_SEND(asoc, datamsg); 1938 err = sctp_primitive_SEND(net, asoc, datamsg);
1932 /* Did the lower layer accept the chunk? */ 1939 /* Did the lower layer accept the chunk? */
1933 if (err) 1940 if (err)
1934 sctp_datamsg_free(datamsg); 1941 sctp_datamsg_free(datamsg);
@@ -2320,7 +2327,9 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
2320 int error; 2327 int error;
2321 2328
2322 if (params->spp_flags & SPP_HB_DEMAND && trans) { 2329 if (params->spp_flags & SPP_HB_DEMAND && trans) {
2323 error = sctp_primitive_REQUESTHEARTBEAT (trans->asoc, trans); 2330 struct net *net = sock_net(trans->asoc->base.sk);
2331
2332 error = sctp_primitive_REQUESTHEARTBEAT(net, trans->asoc, trans);
2324 if (error) 2333 if (error)
2325 return error; 2334 return error;
2326 } 2335 }
@@ -3033,6 +3042,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
3033static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval, 3042static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval,
3034 unsigned int optlen) 3043 unsigned int optlen)
3035{ 3044{
3045 struct net *net = sock_net(sk);
3036 struct sctp_sock *sp; 3046 struct sctp_sock *sp;
3037 struct sctp_association *asoc = NULL; 3047 struct sctp_association *asoc = NULL;
3038 struct sctp_setpeerprim prim; 3048 struct sctp_setpeerprim prim;
@@ -3042,7 +3052,7 @@ static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optva
3042 3052
3043 sp = sctp_sk(sk); 3053 sp = sctp_sk(sk);
3044 3054
3045 if (!sctp_addip_enable) 3055 if (!net->sctp.addip_enable)
3046 return -EPERM; 3056 return -EPERM;
3047 3057
3048 if (optlen != sizeof(struct sctp_setpeerprim)) 3058 if (optlen != sizeof(struct sctp_setpeerprim))
@@ -3279,9 +3289,10 @@ static int sctp_setsockopt_auth_chunk(struct sock *sk,
3279 char __user *optval, 3289 char __user *optval,
3280 unsigned int optlen) 3290 unsigned int optlen)
3281{ 3291{
3292 struct net *net = sock_net(sk);
3282 struct sctp_authchunk val; 3293 struct sctp_authchunk val;
3283 3294
3284 if (!sctp_auth_enable) 3295 if (!net->sctp.auth_enable)
3285 return -EACCES; 3296 return -EACCES;
3286 3297
3287 if (optlen != sizeof(struct sctp_authchunk)) 3298 if (optlen != sizeof(struct sctp_authchunk))
@@ -3311,11 +3322,12 @@ static int sctp_setsockopt_hmac_ident(struct sock *sk,
3311 char __user *optval, 3322 char __user *optval,
3312 unsigned int optlen) 3323 unsigned int optlen)
3313{ 3324{
3325 struct net *net = sock_net(sk);
3314 struct sctp_hmacalgo *hmacs; 3326 struct sctp_hmacalgo *hmacs;
3315 u32 idents; 3327 u32 idents;
3316 int err; 3328 int err;
3317 3329
3318 if (!sctp_auth_enable) 3330 if (!net->sctp.auth_enable)
3319 return -EACCES; 3331 return -EACCES;
3320 3332
3321 if (optlen < sizeof(struct sctp_hmacalgo)) 3333 if (optlen < sizeof(struct sctp_hmacalgo))
@@ -3348,11 +3360,12 @@ static int sctp_setsockopt_auth_key(struct sock *sk,
3348 char __user *optval, 3360 char __user *optval,
3349 unsigned int optlen) 3361 unsigned int optlen)
3350{ 3362{
3363 struct net *net = sock_net(sk);
3351 struct sctp_authkey *authkey; 3364 struct sctp_authkey *authkey;
3352 struct sctp_association *asoc; 3365 struct sctp_association *asoc;
3353 int ret; 3366 int ret;
3354 3367
3355 if (!sctp_auth_enable) 3368 if (!net->sctp.auth_enable)
3356 return -EACCES; 3369 return -EACCES;
3357 3370
3358 if (optlen <= sizeof(struct sctp_authkey)) 3371 if (optlen <= sizeof(struct sctp_authkey))
@@ -3389,10 +3402,11 @@ static int sctp_setsockopt_active_key(struct sock *sk,
3389 char __user *optval, 3402 char __user *optval,
3390 unsigned int optlen) 3403 unsigned int optlen)
3391{ 3404{
3405 struct net *net = sock_net(sk);
3392 struct sctp_authkeyid val; 3406 struct sctp_authkeyid val;
3393 struct sctp_association *asoc; 3407 struct sctp_association *asoc;
3394 3408
3395 if (!sctp_auth_enable) 3409 if (!net->sctp.auth_enable)
3396 return -EACCES; 3410 return -EACCES;
3397 3411
3398 if (optlen != sizeof(struct sctp_authkeyid)) 3412 if (optlen != sizeof(struct sctp_authkeyid))
@@ -3417,10 +3431,11 @@ static int sctp_setsockopt_del_key(struct sock *sk,
3417 char __user *optval, 3431 char __user *optval,
3418 unsigned int optlen) 3432 unsigned int optlen)
3419{ 3433{
3434 struct net *net = sock_net(sk);
3420 struct sctp_authkeyid val; 3435 struct sctp_authkeyid val;
3421 struct sctp_association *asoc; 3436 struct sctp_association *asoc;
3422 3437
3423 if (!sctp_auth_enable) 3438 if (!net->sctp.auth_enable)
3424 return -EACCES; 3439 return -EACCES;
3425 3440
3426 if (optlen != sizeof(struct sctp_authkeyid)) 3441 if (optlen != sizeof(struct sctp_authkeyid))
@@ -3471,7 +3486,7 @@ static int sctp_setsockopt_auto_asconf(struct sock *sk, char __user *optval,
3471 sp->do_auto_asconf = 0; 3486 sp->do_auto_asconf = 0;
3472 } else if (val && !sp->do_auto_asconf) { 3487 } else if (val && !sp->do_auto_asconf) {
3473 list_add_tail(&sp->auto_asconf_list, 3488 list_add_tail(&sp->auto_asconf_list,
3474 &sctp_auto_asconf_splist); 3489 &sock_net(sk)->sctp.auto_asconf_splist);
3475 sp->do_auto_asconf = 1; 3490 sp->do_auto_asconf = 1;
3476 } 3491 }
3477 return 0; 3492 return 0;
@@ -3843,6 +3858,7 @@ out:
3843 */ 3858 */
3844SCTP_STATIC int sctp_init_sock(struct sock *sk) 3859SCTP_STATIC int sctp_init_sock(struct sock *sk)
3845{ 3860{
3861 struct net *net = sock_net(sk);
3846 struct sctp_endpoint *ep; 3862 struct sctp_endpoint *ep;
3847 struct sctp_sock *sp; 3863 struct sctp_sock *sp;
3848 3864
@@ -3872,7 +3888,7 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3872 sp->default_timetolive = 0; 3888 sp->default_timetolive = 0;
3873 3889
3874 sp->default_rcv_context = 0; 3890 sp->default_rcv_context = 0;
3875 sp->max_burst = sctp_max_burst; 3891 sp->max_burst = net->sctp.max_burst;
3876 3892
3877 /* Initialize default setup parameters. These parameters 3893 /* Initialize default setup parameters. These parameters
3878 * can be modified with the SCTP_INITMSG socket option or 3894 * can be modified with the SCTP_INITMSG socket option or
@@ -3880,24 +3896,24 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3880 */ 3896 */
3881 sp->initmsg.sinit_num_ostreams = sctp_max_outstreams; 3897 sp->initmsg.sinit_num_ostreams = sctp_max_outstreams;
3882 sp->initmsg.sinit_max_instreams = sctp_max_instreams; 3898 sp->initmsg.sinit_max_instreams = sctp_max_instreams;
3883 sp->initmsg.sinit_max_attempts = sctp_max_retrans_init; 3899 sp->initmsg.sinit_max_attempts = net->sctp.max_retrans_init;
3884 sp->initmsg.sinit_max_init_timeo = sctp_rto_max; 3900 sp->initmsg.sinit_max_init_timeo = net->sctp.rto_max;
3885 3901
3886 /* Initialize default RTO related parameters. These parameters can 3902 /* Initialize default RTO related parameters. These parameters can
3887 * be modified for with the SCTP_RTOINFO socket option. 3903 * be modified for with the SCTP_RTOINFO socket option.
3888 */ 3904 */
3889 sp->rtoinfo.srto_initial = sctp_rto_initial; 3905 sp->rtoinfo.srto_initial = net->sctp.rto_initial;
3890 sp->rtoinfo.srto_max = sctp_rto_max; 3906 sp->rtoinfo.srto_max = net->sctp.rto_max;
3891 sp->rtoinfo.srto_min = sctp_rto_min; 3907 sp->rtoinfo.srto_min = net->sctp.rto_min;
3892 3908
3893 /* Initialize default association related parameters. These parameters 3909 /* Initialize default association related parameters. These parameters
3894 * can be modified with the SCTP_ASSOCINFO socket option. 3910 * can be modified with the SCTP_ASSOCINFO socket option.
3895 */ 3911 */
3896 sp->assocparams.sasoc_asocmaxrxt = sctp_max_retrans_association; 3912 sp->assocparams.sasoc_asocmaxrxt = net->sctp.max_retrans_association;
3897 sp->assocparams.sasoc_number_peer_destinations = 0; 3913 sp->assocparams.sasoc_number_peer_destinations = 0;
3898 sp->assocparams.sasoc_peer_rwnd = 0; 3914 sp->assocparams.sasoc_peer_rwnd = 0;
3899 sp->assocparams.sasoc_local_rwnd = 0; 3915 sp->assocparams.sasoc_local_rwnd = 0;
3900 sp->assocparams.sasoc_cookie_life = sctp_valid_cookie_life; 3916 sp->assocparams.sasoc_cookie_life = net->sctp.valid_cookie_life;
3901 3917
3902 /* Initialize default event subscriptions. By default, all the 3918 /* Initialize default event subscriptions. By default, all the
3903 * options are off. 3919 * options are off.
@@ -3907,10 +3923,10 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3907 /* Default Peer Address Parameters. These defaults can 3923 /* Default Peer Address Parameters. These defaults can
3908 * be modified via SCTP_PEER_ADDR_PARAMS 3924 * be modified via SCTP_PEER_ADDR_PARAMS
3909 */ 3925 */
3910 sp->hbinterval = sctp_hb_interval; 3926 sp->hbinterval = net->sctp.hb_interval;
3911 sp->pathmaxrxt = sctp_max_retrans_path; 3927 sp->pathmaxrxt = net->sctp.max_retrans_path;
3912 sp->pathmtu = 0; // allow default discovery 3928 sp->pathmtu = 0; // allow default discovery
3913 sp->sackdelay = sctp_sack_timeout; 3929 sp->sackdelay = net->sctp.sack_timeout;
3914 sp->sackfreq = 2; 3930 sp->sackfreq = 2;
3915 sp->param_flags = SPP_HB_ENABLE | 3931 sp->param_flags = SPP_HB_ENABLE |
3916 SPP_PMTUD_ENABLE | 3932 SPP_PMTUD_ENABLE |
@@ -3961,10 +3977,10 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3961 3977
3962 local_bh_disable(); 3978 local_bh_disable();
3963 percpu_counter_inc(&sctp_sockets_allocated); 3979 percpu_counter_inc(&sctp_sockets_allocated);
3964 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 3980 sock_prot_inuse_add(net, sk->sk_prot, 1);
3965 if (sctp_default_auto_asconf) { 3981 if (net->sctp.default_auto_asconf) {
3966 list_add_tail(&sp->auto_asconf_list, 3982 list_add_tail(&sp->auto_asconf_list,
3967 &sctp_auto_asconf_splist); 3983 &net->sctp.auto_asconf_splist);
3968 sp->do_auto_asconf = 1; 3984 sp->do_auto_asconf = 1;
3969 } else 3985 } else
3970 sp->do_auto_asconf = 0; 3986 sp->do_auto_asconf = 0;
@@ -4011,6 +4027,7 @@ SCTP_STATIC void sctp_destroy_sock(struct sock *sk)
4011 */ 4027 */
4012SCTP_STATIC void sctp_shutdown(struct sock *sk, int how) 4028SCTP_STATIC void sctp_shutdown(struct sock *sk, int how)
4013{ 4029{
4030 struct net *net = sock_net(sk);
4014 struct sctp_endpoint *ep; 4031 struct sctp_endpoint *ep;
4015 struct sctp_association *asoc; 4032 struct sctp_association *asoc;
4016 4033
@@ -4022,7 +4039,7 @@ SCTP_STATIC void sctp_shutdown(struct sock *sk, int how)
4022 if (!list_empty(&ep->asocs)) { 4039 if (!list_empty(&ep->asocs)) {
4023 asoc = list_entry(ep->asocs.next, 4040 asoc = list_entry(ep->asocs.next,
4024 struct sctp_association, asocs); 4041 struct sctp_association, asocs);
4025 sctp_primitive_SHUTDOWN(asoc, NULL); 4042 sctp_primitive_SHUTDOWN(net, asoc, NULL);
4026 } 4043 }
4027 } 4044 }
4028} 4045}
@@ -4276,6 +4293,7 @@ static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval
4276{ 4293{
4277 sctp_peeloff_arg_t peeloff; 4294 sctp_peeloff_arg_t peeloff;
4278 struct socket *newsock; 4295 struct socket *newsock;
4296 struct file *newfile;
4279 int retval = 0; 4297 int retval = 0;
4280 4298
4281 if (len < sizeof(sctp_peeloff_arg_t)) 4299 if (len < sizeof(sctp_peeloff_arg_t))
@@ -4289,22 +4307,35 @@ static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval
4289 goto out; 4307 goto out;
4290 4308
4291 /* Map the socket to an unused fd that can be returned to the user. */ 4309 /* Map the socket to an unused fd that can be returned to the user. */
4292 retval = sock_map_fd(newsock, 0); 4310 retval = get_unused_fd();
4293 if (retval < 0) { 4311 if (retval < 0) {
4294 sock_release(newsock); 4312 sock_release(newsock);
4295 goto out; 4313 goto out;
4296 } 4314 }
4297 4315
4316 newfile = sock_alloc_file(newsock, 0, NULL);
4317 if (unlikely(IS_ERR(newfile))) {
4318 put_unused_fd(retval);
4319 sock_release(newsock);
4320 return PTR_ERR(newfile);
4321 }
4322
4298 SCTP_DEBUG_PRINTK("%s: sk: %p newsk: %p sd: %d\n", 4323 SCTP_DEBUG_PRINTK("%s: sk: %p newsk: %p sd: %d\n",
4299 __func__, sk, newsock->sk, retval); 4324 __func__, sk, newsock->sk, retval);
4300 4325
4301 /* Return the fd mapped to the new socket. */ 4326 /* Return the fd mapped to the new socket. */
4327 if (put_user(len, optlen)) {
4328 fput(newfile);
4329 put_unused_fd(retval);
4330 return -EFAULT;
4331 }
4302 peeloff.sd = retval; 4332 peeloff.sd = retval;
4303 if (put_user(len, optlen)) 4333 if (copy_to_user(optval, &peeloff, len)) {
4334 fput(newfile);
4335 put_unused_fd(retval);
4304 return -EFAULT; 4336 return -EFAULT;
4305 if (copy_to_user(optval, &peeloff, len)) 4337 }
4306 retval = -EFAULT; 4338 fd_install(retval, newfile);
4307
4308out: 4339out:
4309 return retval; 4340 return retval;
4310} 4341}
@@ -4653,9 +4684,10 @@ static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to,
4653 union sctp_addr temp; 4684 union sctp_addr temp;
4654 int cnt = 0; 4685 int cnt = 0;
4655 int addrlen; 4686 int addrlen;
4687 struct net *net = sock_net(sk);
4656 4688
4657 rcu_read_lock(); 4689 rcu_read_lock();
4658 list_for_each_entry_rcu(addr, &sctp_local_addr_list, list) { 4690 list_for_each_entry_rcu(addr, &net->sctp.local_addr_list, list) {
4659 if (!addr->valid) 4691 if (!addr->valid)
4660 continue; 4692 continue;
4661 4693
@@ -5299,12 +5331,13 @@ static int sctp_getsockopt_maxburst(struct sock *sk, int len,
5299static int sctp_getsockopt_hmac_ident(struct sock *sk, int len, 5331static int sctp_getsockopt_hmac_ident(struct sock *sk, int len,
5300 char __user *optval, int __user *optlen) 5332 char __user *optval, int __user *optlen)
5301{ 5333{
5334 struct net *net = sock_net(sk);
5302 struct sctp_hmacalgo __user *p = (void __user *)optval; 5335 struct sctp_hmacalgo __user *p = (void __user *)optval;
5303 struct sctp_hmac_algo_param *hmacs; 5336 struct sctp_hmac_algo_param *hmacs;
5304 __u16 data_len = 0; 5337 __u16 data_len = 0;
5305 u32 num_idents; 5338 u32 num_idents;
5306 5339
5307 if (!sctp_auth_enable) 5340 if (!net->sctp.auth_enable)
5308 return -EACCES; 5341 return -EACCES;
5309 5342
5310 hmacs = sctp_sk(sk)->ep->auth_hmacs_list; 5343 hmacs = sctp_sk(sk)->ep->auth_hmacs_list;
@@ -5328,10 +5361,11 @@ static int sctp_getsockopt_hmac_ident(struct sock *sk, int len,
5328static int sctp_getsockopt_active_key(struct sock *sk, int len, 5361static int sctp_getsockopt_active_key(struct sock *sk, int len,
5329 char __user *optval, int __user *optlen) 5362 char __user *optval, int __user *optlen)
5330{ 5363{
5364 struct net *net = sock_net(sk);
5331 struct sctp_authkeyid val; 5365 struct sctp_authkeyid val;
5332 struct sctp_association *asoc; 5366 struct sctp_association *asoc;
5333 5367
5334 if (!sctp_auth_enable) 5368 if (!net->sctp.auth_enable)
5335 return -EACCES; 5369 return -EACCES;
5336 5370
5337 if (len < sizeof(struct sctp_authkeyid)) 5371 if (len < sizeof(struct sctp_authkeyid))
@@ -5360,6 +5394,7 @@ static int sctp_getsockopt_active_key(struct sock *sk, int len,
5360static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len, 5394static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len,
5361 char __user *optval, int __user *optlen) 5395 char __user *optval, int __user *optlen)
5362{ 5396{
5397 struct net *net = sock_net(sk);
5363 struct sctp_authchunks __user *p = (void __user *)optval; 5398 struct sctp_authchunks __user *p = (void __user *)optval;
5364 struct sctp_authchunks val; 5399 struct sctp_authchunks val;
5365 struct sctp_association *asoc; 5400 struct sctp_association *asoc;
@@ -5367,7 +5402,7 @@ static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len,
5367 u32 num_chunks = 0; 5402 u32 num_chunks = 0;
5368 char __user *to; 5403 char __user *to;
5369 5404
5370 if (!sctp_auth_enable) 5405 if (!net->sctp.auth_enable)
5371 return -EACCES; 5406 return -EACCES;
5372 5407
5373 if (len < sizeof(struct sctp_authchunks)) 5408 if (len < sizeof(struct sctp_authchunks))
@@ -5403,6 +5438,7 @@ num:
5403static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len, 5438static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len,
5404 char __user *optval, int __user *optlen) 5439 char __user *optval, int __user *optlen)
5405{ 5440{
5441 struct net *net = sock_net(sk);
5406 struct sctp_authchunks __user *p = (void __user *)optval; 5442 struct sctp_authchunks __user *p = (void __user *)optval;
5407 struct sctp_authchunks val; 5443 struct sctp_authchunks val;
5408 struct sctp_association *asoc; 5444 struct sctp_association *asoc;
@@ -5410,7 +5446,7 @@ static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len,
5410 u32 num_chunks = 0; 5446 u32 num_chunks = 0;
5411 char __user *to; 5447 char __user *to;
5412 5448
5413 if (!sctp_auth_enable) 5449 if (!net->sctp.auth_enable)
5414 return -EACCES; 5450 return -EACCES;
5415 5451
5416 if (len < sizeof(struct sctp_authchunks)) 5452 if (len < sizeof(struct sctp_authchunks))
@@ -5769,7 +5805,7 @@ static void sctp_unhash(struct sock *sk)
5769 * a fastreuse flag (FIXME: NPI ipg). 5805 * a fastreuse flag (FIXME: NPI ipg).
5770 */ 5806 */
5771static struct sctp_bind_bucket *sctp_bucket_create( 5807static struct sctp_bind_bucket *sctp_bucket_create(
5772 struct sctp_bind_hashbucket *head, unsigned short snum); 5808 struct sctp_bind_hashbucket *head, struct net *, unsigned short snum);
5773 5809
5774static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) 5810static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
5775{ 5811{
@@ -5799,11 +5835,12 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
5799 rover = low; 5835 rover = low;
5800 if (inet_is_reserved_local_port(rover)) 5836 if (inet_is_reserved_local_port(rover))
5801 continue; 5837 continue;
5802 index = sctp_phashfn(rover); 5838 index = sctp_phashfn(sock_net(sk), rover);
5803 head = &sctp_port_hashtable[index]; 5839 head = &sctp_port_hashtable[index];
5804 sctp_spin_lock(&head->lock); 5840 sctp_spin_lock(&head->lock);
5805 sctp_for_each_hentry(pp, node, &head->chain) 5841 sctp_for_each_hentry(pp, node, &head->chain)
5806 if (pp->port == rover) 5842 if ((pp->port == rover) &&
5843 net_eq(sock_net(sk), pp->net))
5807 goto next; 5844 goto next;
5808 break; 5845 break;
5809 next: 5846 next:
@@ -5827,10 +5864,10 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
5827 * to the port number (snum) - we detect that with the 5864 * to the port number (snum) - we detect that with the
5828 * port iterator, pp being NULL. 5865 * port iterator, pp being NULL.
5829 */ 5866 */
5830 head = &sctp_port_hashtable[sctp_phashfn(snum)]; 5867 head = &sctp_port_hashtable[sctp_phashfn(sock_net(sk), snum)];
5831 sctp_spin_lock(&head->lock); 5868 sctp_spin_lock(&head->lock);
5832 sctp_for_each_hentry(pp, node, &head->chain) { 5869 sctp_for_each_hentry(pp, node, &head->chain) {
5833 if (pp->port == snum) 5870 if ((pp->port == snum) && net_eq(pp->net, sock_net(sk)))
5834 goto pp_found; 5871 goto pp_found;
5835 } 5872 }
5836 } 5873 }
@@ -5881,7 +5918,7 @@ pp_found:
5881pp_not_found: 5918pp_not_found:
5882 /* If there was a hash table miss, create a new port. */ 5919 /* If there was a hash table miss, create a new port. */
5883 ret = 1; 5920 ret = 1;
5884 if (!pp && !(pp = sctp_bucket_create(head, snum))) 5921 if (!pp && !(pp = sctp_bucket_create(head, sock_net(sk), snum)))
5885 goto fail_unlock; 5922 goto fail_unlock;
5886 5923
5887 /* In either case (hit or miss), make sure fastreuse is 1 only 5924 /* In either case (hit or miss), make sure fastreuse is 1 only
@@ -6113,7 +6150,7 @@ unsigned int sctp_poll(struct file *file, struct socket *sock, poll_table *wait)
6113 ********************************************************************/ 6150 ********************************************************************/
6114 6151
6115static struct sctp_bind_bucket *sctp_bucket_create( 6152static struct sctp_bind_bucket *sctp_bucket_create(
6116 struct sctp_bind_hashbucket *head, unsigned short snum) 6153 struct sctp_bind_hashbucket *head, struct net *net, unsigned short snum)
6117{ 6154{
6118 struct sctp_bind_bucket *pp; 6155 struct sctp_bind_bucket *pp;
6119 6156
@@ -6123,6 +6160,7 @@ static struct sctp_bind_bucket *sctp_bucket_create(
6123 pp->port = snum; 6160 pp->port = snum;
6124 pp->fastreuse = 0; 6161 pp->fastreuse = 0;
6125 INIT_HLIST_HEAD(&pp->owner); 6162 INIT_HLIST_HEAD(&pp->owner);
6163 pp->net = net;
6126 hlist_add_head(&pp->node, &head->chain); 6164 hlist_add_head(&pp->node, &head->chain);
6127 } 6165 }
6128 return pp; 6166 return pp;
@@ -6142,7 +6180,8 @@ static void sctp_bucket_destroy(struct sctp_bind_bucket *pp)
6142static inline void __sctp_put_port(struct sock *sk) 6180static inline void __sctp_put_port(struct sock *sk)
6143{ 6181{
6144 struct sctp_bind_hashbucket *head = 6182 struct sctp_bind_hashbucket *head =
6145 &sctp_port_hashtable[sctp_phashfn(inet_sk(sk)->inet_num)]; 6183 &sctp_port_hashtable[sctp_phashfn(sock_net(sk),
6184 inet_sk(sk)->inet_num)];
6146 struct sctp_bind_bucket *pp; 6185 struct sctp_bind_bucket *pp;
6147 6186
6148 sctp_spin_lock(&head->lock); 6187 sctp_spin_lock(&head->lock);
@@ -6809,7 +6848,8 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
6809 newsp->hmac = NULL; 6848 newsp->hmac = NULL;
6810 6849
6811 /* Hook this new socket in to the bind_hash list. */ 6850 /* Hook this new socket in to the bind_hash list. */
6812 head = &sctp_port_hashtable[sctp_phashfn(inet_sk(oldsk)->inet_num)]; 6851 head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk),
6852 inet_sk(oldsk)->inet_num)];
6813 sctp_local_bh_disable(); 6853 sctp_local_bh_disable();
6814 sctp_spin_lock(&head->lock); 6854 sctp_spin_lock(&head->lock);
6815 pp = sctp_sk(oldsk)->bind_hash; 6855 pp = sctp_sk(oldsk)->bind_hash;