hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/sctp/socket.c
....@@ -68,7 +68,7 @@
6868 #include <net/sctp/stream_sched.h>
6969
7070 /* Forward declarations for internal helper functions. */
71
-static bool sctp_writeable(struct sock *sk);
71
+static bool sctp_writeable(const struct sock *sk);
7272 static void sctp_wfree(struct sk_buff *skb);
7373 static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
7474 size_t msg_len);
....@@ -97,7 +97,7 @@
9797
9898 static void sctp_enter_memory_pressure(struct sock *sk)
9999 {
100
- sctp_memory_pressure = 1;
100
+ WRITE_ONCE(sctp_memory_pressure, 1);
101101 }
102102
103103
....@@ -138,7 +138,7 @@
138138
139139 refcount_add(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc);
140140 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));
142142 sk_mem_charge(sk, chunk->skb->truesize);
143143 }
144144
....@@ -362,9 +362,9 @@
362362 struct net *net = sock_net(&sp->inet.sk);
363363
364364 if (net->sctp.default_auto_asconf) {
365
- spin_lock(&net->sctp.addr_wq_lock);
365
+ spin_lock_bh(&net->sctp.addr_wq_lock);
366366 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);
368368 sp->do_auto_asconf = 1;
369369 }
370370 }
....@@ -1836,6 +1836,10 @@
18361836 err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
18371837 if (err)
18381838 goto err;
1839
+ if (unlikely(sinfo->sinfo_stream >= asoc->stream.outcnt)) {
1840
+ err = -EINVAL;
1841
+ goto err;
1842
+ }
18391843 }
18401844
18411845 if (sctp_state(asoc, CLOSED)) {
....@@ -2453,6 +2457,7 @@
24532457 if (trans) {
24542458 trans->hbinterval =
24552459 msecs_to_jiffies(params->spp_hbinterval);
2460
+ sctp_transport_reset_hb_timer(trans);
24562461 } else if (asoc) {
24572462 asoc->hbinterval =
24582463 msecs_to_jiffies(params->spp_hbinterval);
....@@ -4996,13 +5001,17 @@
49965001 }
49975002
49985003 /* 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)
50005005 {
50015006 struct sctp_sock *sp = sctp_sk(sk);
50025007
50035008 /* Free up the HMAC transform. */
50045009 crypto_free_shash(sp->hmac);
5010
+}
50055011
5012
+static void sctp_destruct_sock(struct sock *sk)
5013
+{
5014
+ sctp_destruct_common(sk);
50065015 inet_sock_destruct(sk);
50075016 }
50085017
....@@ -8881,7 +8890,7 @@
88818890 struct sock *sk = asoc->base.sk;
88828891
88838892 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)));
88858894 asoc->sndbuf_used -= skb->truesize + sizeof(struct sctp_chunk);
88868895 WARN_ON(refcount_sub_and_test(sizeof(struct sctp_chunk),
88878896 &sk->sk_wmem_alloc));
....@@ -9036,9 +9045,9 @@
90369045 * UDP-style sockets or TCP-style sockets, this code should work.
90379046 * - Daisy
90389047 */
9039
-static bool sctp_writeable(struct sock *sk)
9048
+static bool sctp_writeable(const struct sock *sk)
90409049 {
9041
- return sk->sk_sndbuf > sk->sk_wmem_queued;
9050
+ return READ_ONCE(sk->sk_sndbuf) > READ_ONCE(sk->sk_wmem_queued);
90429051 }
90439052
90449053 /* Wait for an association to go into ESTABLISHED state. If timeout is 0,
....@@ -9196,7 +9205,7 @@
91969205 sctp_sk(newsk)->reuse = sp->reuse;
91979206
91989207 newsk->sk_shutdown = sk->sk_shutdown;
9199
- newsk->sk_destruct = sctp_destruct_sock;
9208
+ newsk->sk_destruct = sk->sk_destruct;
92009209 newsk->sk_family = sk->sk_family;
92019210 newsk->sk_protocol = IPPROTO_SCTP;
92029211 newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
....@@ -9428,11 +9437,20 @@
94289437
94299438 #if IS_ENABLED(CONFIG_IPV6)
94309439
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)
94339441 {
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;
94369454 }
94379455
94389456 struct proto sctpv6_prot = {
....@@ -9442,8 +9460,8 @@
94429460 .disconnect = sctp_disconnect,
94439461 .accept = sctp_accept,
94449462 .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,
94479465 .shutdown = sctp_shutdown,
94489466 .setsockopt = sctp_setsockopt,
94499467 .getsockopt = sctp_getsockopt,