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.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 897c01c029ca..9bb80ec4c08f 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -972,7 +972,7 @@ static int sctp_setsockopt_bindx(struct sock *sk,
972 return -EFAULT; 972 return -EFAULT;
973 973
974 /* Alloc space for the address array in kernel memory. */ 974 /* Alloc space for the address array in kernel memory. */
975 kaddrs = kmalloc(addrs_size, GFP_KERNEL); 975 kaddrs = kmalloc(addrs_size, GFP_USER | __GFP_NOWARN);
976 if (unlikely(!kaddrs)) 976 if (unlikely(!kaddrs))
977 return -ENOMEM; 977 return -ENOMEM;
978 978
@@ -1228,7 +1228,6 @@ out_free:
1228 * To the hash table, try to unhash it, just in case, its a noop 1228 * To the hash table, try to unhash it, just in case, its a noop
1229 * if it wasn't hashed so we're safe 1229 * if it wasn't hashed so we're safe
1230 */ 1230 */
1231 sctp_unhash_established(asoc);
1232 sctp_association_free(asoc); 1231 sctp_association_free(asoc);
1233 } 1232 }
1234 return err; 1233 return err;
@@ -1301,8 +1300,9 @@ static int __sctp_setsockopt_connectx(struct sock *sk,
1301 int addrs_size, 1300 int addrs_size,
1302 sctp_assoc_t *assoc_id) 1301 sctp_assoc_t *assoc_id)
1303{ 1302{
1304 int err = 0;
1305 struct sockaddr *kaddrs; 1303 struct sockaddr *kaddrs;
1304 gfp_t gfp = GFP_KERNEL;
1305 int err = 0;
1306 1306
1307 pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n", 1307 pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",
1308 __func__, sk, addrs, addrs_size); 1308 __func__, sk, addrs, addrs_size);
@@ -1315,7 +1315,9 @@ static int __sctp_setsockopt_connectx(struct sock *sk,
1315 return -EFAULT; 1315 return -EFAULT;
1316 1316
1317 /* Alloc space for the address array in kernel memory. */ 1317 /* Alloc space for the address array in kernel memory. */
1318 kaddrs = kmalloc(addrs_size, GFP_KERNEL); 1318 if (sk->sk_socket->file)
1319 gfp = GFP_USER | __GFP_NOWARN;
1320 kaddrs = kmalloc(addrs_size, gfp);
1319 if (unlikely(!kaddrs)) 1321 if (unlikely(!kaddrs))
1320 return -ENOMEM; 1322 return -ENOMEM;
1321 1323
@@ -1501,7 +1503,6 @@ static void sctp_close(struct sock *sk, long timeout)
1501 * ABORT or SHUTDOWN based on the linger options. 1503 * ABORT or SHUTDOWN based on the linger options.
1502 */ 1504 */
1503 if (sctp_state(asoc, CLOSED)) { 1505 if (sctp_state(asoc, CLOSED)) {
1504 sctp_unhash_established(asoc);
1505 sctp_association_free(asoc); 1506 sctp_association_free(asoc);
1506 continue; 1507 continue;
1507 } 1508 }
@@ -1513,8 +1514,7 @@ static void sctp_close(struct sock *sk, long timeout)
1513 struct sctp_chunk *chunk; 1514 struct sctp_chunk *chunk;
1514 1515
1515 chunk = sctp_make_abort_user(asoc, NULL, 0); 1516 chunk = sctp_make_abort_user(asoc, NULL, 0);
1516 if (chunk) 1517 sctp_primitive_ABORT(net, asoc, chunk);
1517 sctp_primitive_ABORT(net, asoc, chunk);
1518 } else 1518 } else
1519 sctp_primitive_SHUTDOWN(net, asoc, NULL); 1519 sctp_primitive_SHUTDOWN(net, asoc, NULL);
1520 } 1520 }
@@ -1952,8 +1952,6 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
1952 1952
1953 /* Now send the (possibly) fragmented message. */ 1953 /* Now send the (possibly) fragmented message. */
1954 list_for_each_entry(chunk, &datamsg->chunks, frag_list) { 1954 list_for_each_entry(chunk, &datamsg->chunks, frag_list) {
1955 sctp_chunk_hold(chunk);
1956
1957 /* Do accounting for the write space. */ 1955 /* Do accounting for the write space. */
1958 sctp_set_owner_w(chunk); 1956 sctp_set_owner_w(chunk);
1959 1957
@@ -1966,15 +1964,13 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
1966 * breaks. 1964 * breaks.
1967 */ 1965 */
1968 err = sctp_primitive_SEND(net, asoc, datamsg); 1966 err = sctp_primitive_SEND(net, asoc, datamsg);
1967 sctp_datamsg_put(datamsg);
1969 /* Did the lower layer accept the chunk? */ 1968 /* Did the lower layer accept the chunk? */
1970 if (err) { 1969 if (err)
1971 sctp_datamsg_free(datamsg);
1972 goto out_free; 1970 goto out_free;
1973 }
1974 1971
1975 pr_debug("%s: we sent primitively\n", __func__); 1972 pr_debug("%s: we sent primitively\n", __func__);
1976 1973
1977 sctp_datamsg_put(datamsg);
1978 err = msg_len; 1974 err = msg_len;
1979 1975
1980 if (unlikely(wait_connect)) { 1976 if (unlikely(wait_connect)) {
@@ -1988,10 +1984,8 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
1988 goto out_unlock; 1984 goto out_unlock;
1989 1985
1990out_free: 1986out_free:
1991 if (new_asoc) { 1987 if (new_asoc)
1992 sctp_unhash_established(asoc);
1993 sctp_association_free(asoc); 1988 sctp_association_free(asoc);
1994 }
1995out_unlock: 1989out_unlock:
1996 release_sock(sk); 1990 release_sock(sk);
1997 1991
@@ -4928,7 +4922,7 @@ static int sctp_getsockopt_local_addrs(struct sock *sk, int len,
4928 to = optval + offsetof(struct sctp_getaddrs, addrs); 4922 to = optval + offsetof(struct sctp_getaddrs, addrs);
4929 space_left = len - offsetof(struct sctp_getaddrs, addrs); 4923 space_left = len - offsetof(struct sctp_getaddrs, addrs);
4930 4924
4931 addrs = kmalloc(space_left, GFP_KERNEL); 4925 addrs = kmalloc(space_left, GFP_USER | __GFP_NOWARN);
4932 if (!addrs) 4926 if (!addrs)
4933 return -ENOMEM; 4927 return -ENOMEM;
4934 4928
@@ -5777,7 +5771,7 @@ static int sctp_getsockopt_assoc_ids(struct sock *sk, int len,
5777 5771
5778 len = sizeof(struct sctp_assoc_ids) + sizeof(sctp_assoc_t) * num; 5772 len = sizeof(struct sctp_assoc_ids) + sizeof(sctp_assoc_t) * num;
5779 5773
5780 ids = kmalloc(len, GFP_KERNEL); 5774 ids = kmalloc(len, GFP_USER | __GFP_NOWARN);
5781 if (unlikely(!ids)) 5775 if (unlikely(!ids))
5782 return -ENOMEM; 5776 return -ENOMEM;
5783 5777
@@ -6458,7 +6452,7 @@ unsigned int sctp_poll(struct file *file, struct socket *sock, poll_table *wait)
6458 if (sctp_writeable(sk)) { 6452 if (sctp_writeable(sk)) {
6459 mask |= POLLOUT | POLLWRNORM; 6453 mask |= POLLOUT | POLLWRNORM;
6460 } else { 6454 } else {
6461 set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); 6455 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
6462 /* 6456 /*
6463 * Since the socket is not locked, the buffer 6457 * Since the socket is not locked, the buffer
6464 * might be made available after the writeable check and 6458 * might be made available after the writeable check and
@@ -6801,26 +6795,30 @@ no_packet:
6801static void __sctp_write_space(struct sctp_association *asoc) 6795static void __sctp_write_space(struct sctp_association *asoc)
6802{ 6796{
6803 struct sock *sk = asoc->base.sk; 6797 struct sock *sk = asoc->base.sk;
6804 struct socket *sock = sk->sk_socket;
6805 6798
6806 if ((sctp_wspace(asoc) > 0) && sock) { 6799 if (sctp_wspace(asoc) <= 0)
6807 if (waitqueue_active(&asoc->wait)) 6800 return;
6808 wake_up_interruptible(&asoc->wait);
6809 6801
6810 if (sctp_writeable(sk)) { 6802 if (waitqueue_active(&asoc->wait))
6811 wait_queue_head_t *wq = sk_sleep(sk); 6803 wake_up_interruptible(&asoc->wait);
6812 6804
6813 if (wq && waitqueue_active(wq)) 6805 if (sctp_writeable(sk)) {
6814 wake_up_interruptible(wq); 6806 struct socket_wq *wq;
6807
6808 rcu_read_lock();
6809 wq = rcu_dereference(sk->sk_wq);
6810 if (wq) {
6811 if (waitqueue_active(&wq->wait))
6812 wake_up_interruptible(&wq->wait);
6815 6813
6816 /* Note that we try to include the Async I/O support 6814 /* Note that we try to include the Async I/O support
6817 * here by modeling from the current TCP/UDP code. 6815 * here by modeling from the current TCP/UDP code.
6818 * We have not tested with it yet. 6816 * We have not tested with it yet.
6819 */ 6817 */
6820 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) 6818 if (!(sk->sk_shutdown & SEND_SHUTDOWN))
6821 sock_wake_async(sock, 6819 sock_wake_async(wq, SOCK_WAKE_SPACE, POLL_OUT);
6822 SOCK_WAKE_SPACE, POLL_OUT);
6823 } 6820 }
6821 rcu_read_unlock();
6824 } 6822 }
6825} 6823}
6826 6824
@@ -6978,7 +6976,7 @@ void sctp_data_ready(struct sock *sk)
6978 6976
6979 rcu_read_lock(); 6977 rcu_read_lock();
6980 wq = rcu_dereference(sk->sk_wq); 6978 wq = rcu_dereference(sk->sk_wq);
6981 if (wq_has_sleeper(wq)) 6979 if (skwq_has_sleeper(wq))
6982 wake_up_interruptible_sync_poll(&wq->wait, POLLIN | 6980 wake_up_interruptible_sync_poll(&wq->wait, POLLIN |
6983 POLLRDNORM | POLLRDBAND); 6981 POLLRDNORM | POLLRDBAND);
6984 sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN); 6982 sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
@@ -7163,6 +7161,7 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
7163 newsk->sk_type = sk->sk_type; 7161 newsk->sk_type = sk->sk_type;
7164 newsk->sk_bound_dev_if = sk->sk_bound_dev_if; 7162 newsk->sk_bound_dev_if = sk->sk_bound_dev_if;
7165 newsk->sk_flags = sk->sk_flags; 7163 newsk->sk_flags = sk->sk_flags;
7164 newsk->sk_tsflags = sk->sk_tsflags;
7166 newsk->sk_no_check_tx = sk->sk_no_check_tx; 7165 newsk->sk_no_check_tx = sk->sk_no_check_tx;
7167 newsk->sk_no_check_rx = sk->sk_no_check_rx; 7166 newsk->sk_no_check_rx = sk->sk_no_check_rx;
7168 newsk->sk_reuse = sk->sk_reuse; 7167 newsk->sk_reuse = sk->sk_reuse;
@@ -7195,6 +7194,11 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
7195 newinet->mc_ttl = 1; 7194 newinet->mc_ttl = 1;
7196 newinet->mc_index = 0; 7195 newinet->mc_index = 0;
7197 newinet->mc_list = NULL; 7196 newinet->mc_list = NULL;
7197
7198 if (newsk->sk_flags & SK_FLAGS_TIMESTAMP)
7199 net_enable_timestamp();
7200
7201 security_sk_clone(sk, newsk);
7198} 7202}
7199 7203
7200static inline void sctp_copy_descendant(struct sock *sk_to, 7204static inline void sctp_copy_descendant(struct sock *sk_to,
@@ -7375,6 +7379,13 @@ struct proto sctp_prot = {
7375 7379
7376#if IS_ENABLED(CONFIG_IPV6) 7380#if IS_ENABLED(CONFIG_IPV6)
7377 7381
7382#include <net/transp_v6.h>
7383static void sctp_v6_destroy_sock(struct sock *sk)
7384{
7385 sctp_destroy_sock(sk);
7386 inet6_destroy_sock(sk);
7387}
7388
7378struct proto sctpv6_prot = { 7389struct proto sctpv6_prot = {
7379 .name = "SCTPv6", 7390 .name = "SCTPv6",
7380 .owner = THIS_MODULE, 7391 .owner = THIS_MODULE,
@@ -7384,7 +7395,7 @@ struct proto sctpv6_prot = {
7384 .accept = sctp_accept, 7395 .accept = sctp_accept,
7385 .ioctl = sctp_ioctl, 7396 .ioctl = sctp_ioctl,
7386 .init = sctp_init_sock, 7397 .init = sctp_init_sock,
7387 .destroy = sctp_destroy_sock, 7398 .destroy = sctp_v6_destroy_sock,
7388 .shutdown = sctp_shutdown, 7399 .shutdown = sctp_shutdown,
7389 .setsockopt = sctp_setsockopt, 7400 .setsockopt = sctp_setsockopt,
7390 .getsockopt = sctp_getsockopt, 7401 .getsockopt = sctp_getsockopt,