| .. | .. |
|---|
| 68 | 68 | #include <net/sctp/stream_sched.h> |
|---|
| 69 | 69 | |
|---|
| 70 | 70 | /* Forward declarations for internal helper functions. */ |
|---|
| 71 | | -static bool sctp_writeable(struct sock *sk); |
|---|
| 71 | +static bool sctp_writeable(const struct sock *sk); |
|---|
| 72 | 72 | static void sctp_wfree(struct sk_buff *skb); |
|---|
| 73 | 73 | static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p, |
|---|
| 74 | 74 | size_t msg_len); |
|---|
| .. | .. |
|---|
| 97 | 97 | |
|---|
| 98 | 98 | static void sctp_enter_memory_pressure(struct sock *sk) |
|---|
| 99 | 99 | { |
|---|
| 100 | | - sctp_memory_pressure = 1; |
|---|
| 100 | + WRITE_ONCE(sctp_memory_pressure, 1); |
|---|
| 101 | 101 | } |
|---|
| 102 | 102 | |
|---|
| 103 | 103 | |
|---|
| .. | .. |
|---|
| 138 | 138 | |
|---|
| 139 | 139 | refcount_add(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc); |
|---|
| 140 | 140 | asoc->sndbuf_used += chunk->skb->truesize + sizeof(struct sctp_chunk); |
|---|
| 141 | | - sk->sk_wmem_queued += chunk->skb->truesize + sizeof(struct sctp_chunk); |
|---|
| 141 | + sk_wmem_queued_add(sk, chunk->skb->truesize + sizeof(struct sctp_chunk)); |
|---|
| 142 | 142 | sk_mem_charge(sk, chunk->skb->truesize); |
|---|
| 143 | 143 | } |
|---|
| 144 | 144 | |
|---|
| .. | .. |
|---|
| 362 | 362 | struct net *net = sock_net(&sp->inet.sk); |
|---|
| 363 | 363 | |
|---|
| 364 | 364 | if (net->sctp.default_auto_asconf) { |
|---|
| 365 | | - spin_lock(&net->sctp.addr_wq_lock); |
|---|
| 365 | + spin_lock_bh(&net->sctp.addr_wq_lock); |
|---|
| 366 | 366 | list_add_tail(&sp->auto_asconf_list, &net->sctp.auto_asconf_splist); |
|---|
| 367 | | - spin_unlock(&net->sctp.addr_wq_lock); |
|---|
| 367 | + spin_unlock_bh(&net->sctp.addr_wq_lock); |
|---|
| 368 | 368 | sp->do_auto_asconf = 1; |
|---|
| 369 | 369 | } |
|---|
| 370 | 370 | } |
|---|
| .. | .. |
|---|
| 1836 | 1836 | err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len); |
|---|
| 1837 | 1837 | if (err) |
|---|
| 1838 | 1838 | goto err; |
|---|
| 1839 | + if (unlikely(sinfo->sinfo_stream >= asoc->stream.outcnt)) { |
|---|
| 1840 | + err = -EINVAL; |
|---|
| 1841 | + goto err; |
|---|
| 1842 | + } |
|---|
| 1839 | 1843 | } |
|---|
| 1840 | 1844 | |
|---|
| 1841 | 1845 | if (sctp_state(asoc, CLOSED)) { |
|---|
| .. | .. |
|---|
| 2453 | 2457 | if (trans) { |
|---|
| 2454 | 2458 | trans->hbinterval = |
|---|
| 2455 | 2459 | msecs_to_jiffies(params->spp_hbinterval); |
|---|
| 2460 | + sctp_transport_reset_hb_timer(trans); |
|---|
| 2456 | 2461 | } else if (asoc) { |
|---|
| 2457 | 2462 | asoc->hbinterval = |
|---|
| 2458 | 2463 | msecs_to_jiffies(params->spp_hbinterval); |
|---|
| .. | .. |
|---|
| 4996 | 5001 | } |
|---|
| 4997 | 5002 | |
|---|
| 4998 | 5003 | /* Triggered when there are no references on the socket anymore */ |
|---|
| 4999 | | -static void sctp_destruct_sock(struct sock *sk) |
|---|
| 5004 | +static void sctp_destruct_common(struct sock *sk) |
|---|
| 5000 | 5005 | { |
|---|
| 5001 | 5006 | struct sctp_sock *sp = sctp_sk(sk); |
|---|
| 5002 | 5007 | |
|---|
| 5003 | 5008 | /* Free up the HMAC transform. */ |
|---|
| 5004 | 5009 | crypto_free_shash(sp->hmac); |
|---|
| 5010 | +} |
|---|
| 5005 | 5011 | |
|---|
| 5012 | +static void sctp_destruct_sock(struct sock *sk) |
|---|
| 5013 | +{ |
|---|
| 5014 | + sctp_destruct_common(sk); |
|---|
| 5006 | 5015 | inet_sock_destruct(sk); |
|---|
| 5007 | 5016 | } |
|---|
| 5008 | 5017 | |
|---|
| .. | .. |
|---|
| 8881 | 8890 | struct sock *sk = asoc->base.sk; |
|---|
| 8882 | 8891 | |
|---|
| 8883 | 8892 | sk_mem_uncharge(sk, skb->truesize); |
|---|
| 8884 | | - sk->sk_wmem_queued -= skb->truesize + sizeof(struct sctp_chunk); |
|---|
| 8893 | + sk_wmem_queued_add(sk, -(skb->truesize + sizeof(struct sctp_chunk))); |
|---|
| 8885 | 8894 | asoc->sndbuf_used -= skb->truesize + sizeof(struct sctp_chunk); |
|---|
| 8886 | 8895 | WARN_ON(refcount_sub_and_test(sizeof(struct sctp_chunk), |
|---|
| 8887 | 8896 | &sk->sk_wmem_alloc)); |
|---|
| .. | .. |
|---|
| 9036 | 9045 | * UDP-style sockets or TCP-style sockets, this code should work. |
|---|
| 9037 | 9046 | * - Daisy |
|---|
| 9038 | 9047 | */ |
|---|
| 9039 | | -static bool sctp_writeable(struct sock *sk) |
|---|
| 9048 | +static bool sctp_writeable(const struct sock *sk) |
|---|
| 9040 | 9049 | { |
|---|
| 9041 | | - return sk->sk_sndbuf > sk->sk_wmem_queued; |
|---|
| 9050 | + return READ_ONCE(sk->sk_sndbuf) > READ_ONCE(sk->sk_wmem_queued); |
|---|
| 9042 | 9051 | } |
|---|
| 9043 | 9052 | |
|---|
| 9044 | 9053 | /* Wait for an association to go into ESTABLISHED state. If timeout is 0, |
|---|
| .. | .. |
|---|
| 9196 | 9205 | sctp_sk(newsk)->reuse = sp->reuse; |
|---|
| 9197 | 9206 | |
|---|
| 9198 | 9207 | newsk->sk_shutdown = sk->sk_shutdown; |
|---|
| 9199 | | - newsk->sk_destruct = sctp_destruct_sock; |
|---|
| 9208 | + newsk->sk_destruct = sk->sk_destruct; |
|---|
| 9200 | 9209 | newsk->sk_family = sk->sk_family; |
|---|
| 9201 | 9210 | newsk->sk_protocol = IPPROTO_SCTP; |
|---|
| 9202 | 9211 | newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv; |
|---|
| .. | .. |
|---|
| 9428 | 9437 | |
|---|
| 9429 | 9438 | #if IS_ENABLED(CONFIG_IPV6) |
|---|
| 9430 | 9439 | |
|---|
| 9431 | | -#include <net/transp_v6.h> |
|---|
| 9432 | | -static void sctp_v6_destroy_sock(struct sock *sk) |
|---|
| 9440 | +static void sctp_v6_destruct_sock(struct sock *sk) |
|---|
| 9433 | 9441 | { |
|---|
| 9434 | | - sctp_destroy_sock(sk); |
|---|
| 9435 | | - inet6_destroy_sock(sk); |
|---|
| 9442 | + sctp_destruct_common(sk); |
|---|
| 9443 | + inet6_sock_destruct(sk); |
|---|
| 9444 | +} |
|---|
| 9445 | + |
|---|
| 9446 | +static int sctp_v6_init_sock(struct sock *sk) |
|---|
| 9447 | +{ |
|---|
| 9448 | + int ret = sctp_init_sock(sk); |
|---|
| 9449 | + |
|---|
| 9450 | + if (!ret) |
|---|
| 9451 | + sk->sk_destruct = sctp_v6_destruct_sock; |
|---|
| 9452 | + |
|---|
| 9453 | + return ret; |
|---|
| 9436 | 9454 | } |
|---|
| 9437 | 9455 | |
|---|
| 9438 | 9456 | struct proto sctpv6_prot = { |
|---|
| .. | .. |
|---|
| 9442 | 9460 | .disconnect = sctp_disconnect, |
|---|
| 9443 | 9461 | .accept = sctp_accept, |
|---|
| 9444 | 9462 | .ioctl = sctp_ioctl, |
|---|
| 9445 | | - .init = sctp_init_sock, |
|---|
| 9446 | | - .destroy = sctp_v6_destroy_sock, |
|---|
| 9463 | + .init = sctp_v6_init_sock, |
|---|
| 9464 | + .destroy = sctp_destroy_sock, |
|---|
| 9447 | 9465 | .shutdown = sctp_shutdown, |
|---|
| 9448 | 9466 | .setsockopt = sctp_setsockopt, |
|---|
| 9449 | 9467 | .getsockopt = sctp_getsockopt, |
|---|