aboutsummaryrefslogtreecommitdiffstats
path: root/net/sctp
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-03-19 21:05:24 -0400
committerDavid S. Miller <davem@davemloft.net>2016-03-19 21:05:24 -0400
commitc78a85a8430e35aecd53e190a2f6b999062b1037 (patch)
treefbd69827579db437492fb77b5faa53814114bed3 /net/sctp
parent133800d1f0288b9ddfc0d0aded10d9efa82d5b8c (diff)
parentde06dbfa7861c9019eedefc0c356ba86e5098f1b (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux
Diffstat (limited to 'net/sctp')
-rw-r--r--net/sctp/associola.c4
-rw-r--r--net/sctp/auth.c36
-rw-r--r--net/sctp/chunk.c19
-rw-r--r--net/sctp/endpointola.c1
-rw-r--r--net/sctp/input.c6
-rw-r--r--net/sctp/output.c6
-rw-r--r--net/sctp/outqueue.c30
-rw-r--r--net/sctp/probe.c10
-rw-r--r--net/sctp/proc.c2
-rw-r--r--net/sctp/sm_make_chunk.c131
-rw-r--r--net/sctp/sm_sideeffect.c23
-rw-r--r--net/sctp/socket.c17
-rw-r--r--net/sctp/transport.c2
13 files changed, 148 insertions, 139 deletions
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 2bf8ec92dde4..a19b3e607703 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -1263,7 +1263,7 @@ static struct sctp_transport *sctp_trans_elect_best(struct sctp_transport *curr,
1263 if (score_curr > score_best) 1263 if (score_curr > score_best)
1264 return curr; 1264 return curr;
1265 else if (score_curr == score_best) 1265 else if (score_curr == score_best)
1266 return sctp_trans_elect_tie(curr, best); 1266 return sctp_trans_elect_tie(best, curr);
1267 else 1267 else
1268 return best; 1268 return best;
1269} 1269}
@@ -1493,7 +1493,7 @@ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned int len)
1493 1493
1494 asoc->peer.sack_needed = 0; 1494 asoc->peer.sack_needed = 0;
1495 1495
1496 sctp_outq_tail(&asoc->outqueue, sack); 1496 sctp_outq_tail(&asoc->outqueue, sack, GFP_ATOMIC);
1497 1497
1498 /* Stop the SACK timer. */ 1498 /* Stop the SACK timer. */
1499 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK]; 1499 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK];
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index 1543e39f47c3..912eb1685a5d 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -27,9 +27,9 @@
27 * Vlad Yasevich <vladislav.yasevich@hp.com> 27 * Vlad Yasevich <vladislav.yasevich@hp.com>
28 */ 28 */
29 29
30#include <crypto/hash.h>
30#include <linux/slab.h> 31#include <linux/slab.h>
31#include <linux/types.h> 32#include <linux/types.h>
32#include <linux/crypto.h>
33#include <linux/scatterlist.h> 33#include <linux/scatterlist.h>
34#include <net/sctp/sctp.h> 34#include <net/sctp/sctp.h>
35#include <net/sctp/auth.h> 35#include <net/sctp/auth.h>
@@ -448,7 +448,7 @@ struct sctp_shared_key *sctp_auth_get_shkey(
448 */ 448 */
449int sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp) 449int sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp)
450{ 450{
451 struct crypto_hash *tfm = NULL; 451 struct crypto_shash *tfm = NULL;
452 __u16 id; 452 __u16 id;
453 453
454 /* If AUTH extension is disabled, we are done */ 454 /* If AUTH extension is disabled, we are done */
@@ -462,9 +462,8 @@ int sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp)
462 return 0; 462 return 0;
463 463
464 /* Allocated the array of pointers to transorms */ 464 /* Allocated the array of pointers to transorms */
465 ep->auth_hmacs = kzalloc( 465 ep->auth_hmacs = kzalloc(sizeof(struct crypto_shash *) *
466 sizeof(struct crypto_hash *) * SCTP_AUTH_NUM_HMACS, 466 SCTP_AUTH_NUM_HMACS, gfp);
467 gfp);
468 if (!ep->auth_hmacs) 467 if (!ep->auth_hmacs)
469 return -ENOMEM; 468 return -ENOMEM;
470 469
@@ -483,8 +482,7 @@ int sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp)
483 continue; 482 continue;
484 483
485 /* Allocate the ID */ 484 /* Allocate the ID */
486 tfm = crypto_alloc_hash(sctp_hmac_list[id].hmac_name, 0, 485 tfm = crypto_alloc_shash(sctp_hmac_list[id].hmac_name, 0, 0);
487 CRYPTO_ALG_ASYNC);
488 if (IS_ERR(tfm)) 486 if (IS_ERR(tfm))
489 goto out_err; 487 goto out_err;
490 488
@@ -500,7 +498,7 @@ out_err:
500} 498}
501 499
502/* Destroy the hmac tfm array */ 500/* Destroy the hmac tfm array */
503void sctp_auth_destroy_hmacs(struct crypto_hash *auth_hmacs[]) 501void sctp_auth_destroy_hmacs(struct crypto_shash *auth_hmacs[])
504{ 502{
505 int i; 503 int i;
506 504
@@ -508,8 +506,7 @@ void sctp_auth_destroy_hmacs(struct crypto_hash *auth_hmacs[])
508 return; 506 return;
509 507
510 for (i = 0; i < SCTP_AUTH_NUM_HMACS; i++) { 508 for (i = 0; i < SCTP_AUTH_NUM_HMACS; i++) {
511 if (auth_hmacs[i]) 509 crypto_free_shash(auth_hmacs[i]);
512 crypto_free_hash(auth_hmacs[i]);
513 } 510 }
514 kfree(auth_hmacs); 511 kfree(auth_hmacs);
515} 512}
@@ -709,8 +706,7 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
709 struct sctp_auth_chunk *auth, 706 struct sctp_auth_chunk *auth,
710 gfp_t gfp) 707 gfp_t gfp)
711{ 708{
712 struct scatterlist sg; 709 struct crypto_shash *tfm;
713 struct hash_desc desc;
714 struct sctp_auth_bytes *asoc_key; 710 struct sctp_auth_bytes *asoc_key;
715 __u16 key_id, hmac_id; 711 __u16 key_id, hmac_id;
716 __u8 *digest; 712 __u8 *digest;
@@ -742,16 +738,22 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
742 738
743 /* set up scatter list */ 739 /* set up scatter list */
744 end = skb_tail_pointer(skb); 740 end = skb_tail_pointer(skb);
745 sg_init_one(&sg, auth, end - (unsigned char *)auth);
746 741
747 desc.tfm = asoc->ep->auth_hmacs[hmac_id]; 742 tfm = asoc->ep->auth_hmacs[hmac_id];
748 desc.flags = 0;
749 743
750 digest = auth->auth_hdr.hmac; 744 digest = auth->auth_hdr.hmac;
751 if (crypto_hash_setkey(desc.tfm, &asoc_key->data[0], asoc_key->len)) 745 if (crypto_shash_setkey(tfm, &asoc_key->data[0], asoc_key->len))
752 goto free; 746 goto free;
753 747
754 crypto_hash_digest(&desc, &sg, sg.length, digest); 748 {
749 SHASH_DESC_ON_STACK(desc, tfm);
750
751 desc->tfm = tfm;
752 desc->flags = 0;
753 crypto_shash_digest(desc, (u8 *)auth,
754 end - (unsigned char *)auth, digest);
755 shash_desc_zero(desc);
756 }
755 757
756free: 758free:
757 if (free_key) 759 if (free_key)
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index a3380917f197..958ef5f33f4b 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -70,19 +70,6 @@ static struct sctp_datamsg *sctp_datamsg_new(gfp_t gfp)
70 return msg; 70 return msg;
71} 71}
72 72
73void sctp_datamsg_free(struct sctp_datamsg *msg)
74{
75 struct sctp_chunk *chunk;
76
77 /* This doesn't have to be a _safe vairant because
78 * sctp_chunk_free() only drops the refs.
79 */
80 list_for_each_entry(chunk, &msg->chunks, frag_list)
81 sctp_chunk_free(chunk);
82
83 sctp_datamsg_put(msg);
84}
85
86/* Final destructruction of datamsg memory. */ 73/* Final destructruction of datamsg memory. */
87static void sctp_datamsg_destroy(struct sctp_datamsg *msg) 74static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
88{ 75{
@@ -273,7 +260,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
273 frag |= SCTP_DATA_SACK_IMM; 260 frag |= SCTP_DATA_SACK_IMM;
274 } 261 }
275 262
276 chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag, 0); 263 chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag,
264 0, GFP_KERNEL);
277 265
278 if (!chunk) { 266 if (!chunk) {
279 err = -ENOMEM; 267 err = -ENOMEM;
@@ -309,7 +297,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
309 (sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY)) 297 (sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY))
310 frag |= SCTP_DATA_SACK_IMM; 298 frag |= SCTP_DATA_SACK_IMM;
311 299
312 chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag, 0); 300 chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag,
301 0, GFP_KERNEL);
313 302
314 if (!chunk) { 303 if (!chunk) {
315 err = -ENOMEM; 304 err = -ENOMEM;
diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
index 2522a6175291..9d494e35e7f9 100644
--- a/net/sctp/endpointola.c
+++ b/net/sctp/endpointola.c
@@ -42,7 +42,6 @@
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/in.h> 43#include <linux/in.h>
44#include <linux/random.h> /* get_random_bytes() */ 44#include <linux/random.h> /* get_random_bytes() */
45#include <linux/crypto.h>
46#include <net/sock.h> 45#include <net/sock.h>
47#include <net/ipv6.h> 46#include <net/ipv6.h>
48#include <net/sctp/sctp.h> 47#include <net/sctp/sctp.h>
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 49d2cc751386..db76f1ab4ac2 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -221,7 +221,7 @@ int sctp_rcv(struct sk_buff *skb)
221 goto discard_release; 221 goto discard_release;
222 222
223 /* Create an SCTP packet structure. */ 223 /* Create an SCTP packet structure. */
224 chunk = sctp_chunkify(skb, asoc, sk); 224 chunk = sctp_chunkify(skb, asoc, sk, GFP_ATOMIC);
225 if (!chunk) 225 if (!chunk)
226 goto discard_release; 226 goto discard_release;
227 SCTP_INPUT_CB(skb)->chunk = chunk; 227 SCTP_INPUT_CB(skb)->chunk = chunk;
@@ -937,7 +937,6 @@ static struct sctp_association *__sctp_lookup_association(
937 struct sctp_transport *t; 937 struct sctp_transport *t;
938 struct sctp_association *asoc = NULL; 938 struct sctp_association *asoc = NULL;
939 939
940 rcu_read_lock();
941 t = sctp_addrs_lookup_transport(net, local, peer); 940 t = sctp_addrs_lookup_transport(net, local, peer);
942 if (!t || !sctp_transport_hold(t)) 941 if (!t || !sctp_transport_hold(t))
943 goto out; 942 goto out;
@@ -949,7 +948,6 @@ static struct sctp_association *__sctp_lookup_association(
949 sctp_transport_put(t); 948 sctp_transport_put(t);
950 949
951out: 950out:
952 rcu_read_unlock();
953 return asoc; 951 return asoc;
954} 952}
955 953
@@ -962,7 +960,9 @@ struct sctp_association *sctp_lookup_association(struct net *net,
962{ 960{
963 struct sctp_association *asoc; 961 struct sctp_association *asoc;
964 962
963 rcu_read_lock();
965 asoc = __sctp_lookup_association(net, laddr, paddr, transportp); 964 asoc = __sctp_lookup_association(net, laddr, paddr, transportp);
965 rcu_read_unlock();
966 966
967 return asoc; 967 return asoc;
968} 968}
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 9d610eddd19e..736c004abfbc 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -153,7 +153,7 @@ void sctp_packet_free(struct sctp_packet *packet)
153 */ 153 */
154sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet, 154sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet,
155 struct sctp_chunk *chunk, 155 struct sctp_chunk *chunk,
156 int one_packet) 156 int one_packet, gfp_t gfp)
157{ 157{
158 sctp_xmit_t retval; 158 sctp_xmit_t retval;
159 int error = 0; 159 int error = 0;
@@ -163,7 +163,7 @@ sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet,
163 switch ((retval = (sctp_packet_append_chunk(packet, chunk)))) { 163 switch ((retval = (sctp_packet_append_chunk(packet, chunk)))) {
164 case SCTP_XMIT_PMTU_FULL: 164 case SCTP_XMIT_PMTU_FULL:
165 if (!packet->has_cookie_echo) { 165 if (!packet->has_cookie_echo) {
166 error = sctp_packet_transmit(packet); 166 error = sctp_packet_transmit(packet, gfp);
167 if (error < 0) 167 if (error < 0)
168 chunk->skb->sk->sk_err = -error; 168 chunk->skb->sk->sk_err = -error;
169 169
@@ -376,7 +376,7 @@ static void sctp_packet_set_owner_w(struct sk_buff *skb, struct sock *sk)
376 * 376 *
377 * The return value is a normal kernel error return value. 377 * The return value is a normal kernel error return value.
378 */ 378 */
379int sctp_packet_transmit(struct sctp_packet *packet) 379int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
380{ 380{
381 struct sctp_transport *tp = packet->transport; 381 struct sctp_transport *tp = packet->transport;
382 struct sctp_association *asoc = tp->asoc; 382 struct sctp_association *asoc = tp->asoc;
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index c0380cfb16ae..f03541d0f12d 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -68,7 +68,7 @@ static void sctp_mark_missing(struct sctp_outq *q,
68 68
69static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn); 69static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
70 70
71static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout); 71static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp);
72 72
73/* Add data to the front of the queue. */ 73/* Add data to the front of the queue. */
74static inline void sctp_outq_head_data(struct sctp_outq *q, 74static inline void sctp_outq_head_data(struct sctp_outq *q,
@@ -285,7 +285,7 @@ void sctp_outq_free(struct sctp_outq *q)
285} 285}
286 286
287/* Put a new chunk in an sctp_outq. */ 287/* Put a new chunk in an sctp_outq. */
288int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk) 288int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk, gfp_t gfp)
289{ 289{
290 struct net *net = sock_net(q->asoc->base.sk); 290 struct net *net = sock_net(q->asoc->base.sk);
291 int error = 0; 291 int error = 0;
@@ -341,7 +341,7 @@ int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
341 return error; 341 return error;
342 342
343 if (!q->cork) 343 if (!q->cork)
344 error = sctp_outq_flush(q, 0); 344 error = sctp_outq_flush(q, 0, gfp);
345 345
346 return error; 346 return error;
347} 347}
@@ -510,7 +510,7 @@ void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
510 * will be flushed at the end. 510 * will be flushed at the end.
511 */ 511 */
512 if (reason != SCTP_RTXR_FAST_RTX) 512 if (reason != SCTP_RTXR_FAST_RTX)
513 error = sctp_outq_flush(q, /* rtx_timeout */ 1); 513 error = sctp_outq_flush(q, /* rtx_timeout */ 1, GFP_ATOMIC);
514 514
515 if (error) 515 if (error)
516 q->asoc->base.sk->sk_err = -error; 516 q->asoc->base.sk->sk_err = -error;
@@ -601,12 +601,12 @@ redo:
601 * control chunks are already freed so there 601 * control chunks are already freed so there
602 * is nothing we can do. 602 * is nothing we can do.
603 */ 603 */
604 sctp_packet_transmit(pkt); 604 sctp_packet_transmit(pkt, GFP_ATOMIC);
605 goto redo; 605 goto redo;
606 } 606 }
607 607
608 /* Send this packet. */ 608 /* Send this packet. */
609 error = sctp_packet_transmit(pkt); 609 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
610 610
611 /* If we are retransmitting, we should only 611 /* If we are retransmitting, we should only
612 * send a single packet. 612 * send a single packet.
@@ -622,7 +622,7 @@ redo:
622 622
623 case SCTP_XMIT_RWND_FULL: 623 case SCTP_XMIT_RWND_FULL:
624 /* Send this packet. */ 624 /* Send this packet. */
625 error = sctp_packet_transmit(pkt); 625 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
626 626
627 /* Stop sending DATA as there is no more room 627 /* Stop sending DATA as there is no more room
628 * at the receiver. 628 * at the receiver.
@@ -632,7 +632,7 @@ redo:
632 632
633 case SCTP_XMIT_DELAY: 633 case SCTP_XMIT_DELAY:
634 /* Send this packet. */ 634 /* Send this packet. */
635 error = sctp_packet_transmit(pkt); 635 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
636 636
637 /* Stop sending DATA because of nagle delay. */ 637 /* Stop sending DATA because of nagle delay. */
638 done = 1; 638 done = 1;
@@ -685,12 +685,12 @@ redo:
685} 685}
686 686
687/* Cork the outqueue so queued chunks are really queued. */ 687/* Cork the outqueue so queued chunks are really queued. */
688int sctp_outq_uncork(struct sctp_outq *q) 688int sctp_outq_uncork(struct sctp_outq *q, gfp_t gfp)
689{ 689{
690 if (q->cork) 690 if (q->cork)
691 q->cork = 0; 691 q->cork = 0;
692 692
693 return sctp_outq_flush(q, 0); 693 return sctp_outq_flush(q, 0, gfp);
694} 694}
695 695
696 696
@@ -703,7 +703,7 @@ int sctp_outq_uncork(struct sctp_outq *q)
703 * locking concerns must be made. Today we use the sock lock to protect 703 * locking concerns must be made. Today we use the sock lock to protect
704 * this function. 704 * this function.
705 */ 705 */
706static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout) 706static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
707{ 707{
708 struct sctp_packet *packet; 708 struct sctp_packet *packet;
709 struct sctp_packet singleton; 709 struct sctp_packet singleton;
@@ -825,7 +825,7 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
825 sctp_packet_init(&singleton, transport, sport, dport); 825 sctp_packet_init(&singleton, transport, sport, dport);
826 sctp_packet_config(&singleton, vtag, 0); 826 sctp_packet_config(&singleton, vtag, 0);
827 sctp_packet_append_chunk(&singleton, chunk); 827 sctp_packet_append_chunk(&singleton, chunk);
828 error = sctp_packet_transmit(&singleton); 828 error = sctp_packet_transmit(&singleton, gfp);
829 if (error < 0) 829 if (error < 0)
830 return error; 830 return error;
831 break; 831 break;
@@ -856,7 +856,7 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
856 case SCTP_CID_ASCONF: 856 case SCTP_CID_ASCONF:
857 case SCTP_CID_FWD_TSN: 857 case SCTP_CID_FWD_TSN:
858 status = sctp_packet_transmit_chunk(packet, chunk, 858 status = sctp_packet_transmit_chunk(packet, chunk,
859 one_packet); 859 one_packet, gfp);
860 if (status != SCTP_XMIT_OK) { 860 if (status != SCTP_XMIT_OK) {
861 /* put the chunk back */ 861 /* put the chunk back */
862 list_add(&chunk->list, &q->control_chunk_list); 862 list_add(&chunk->list, &q->control_chunk_list);
@@ -1011,7 +1011,7 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
1011 atomic_read(&chunk->skb->users) : -1); 1011 atomic_read(&chunk->skb->users) : -1);
1012 1012
1013 /* Add the chunk to the packet. */ 1013 /* Add the chunk to the packet. */
1014 status = sctp_packet_transmit_chunk(packet, chunk, 0); 1014 status = sctp_packet_transmit_chunk(packet, chunk, 0, gfp);
1015 1015
1016 switch (status) { 1016 switch (status) {
1017 case SCTP_XMIT_PMTU_FULL: 1017 case SCTP_XMIT_PMTU_FULL:
@@ -1088,7 +1088,7 @@ sctp_flush_out:
1088 send_ready); 1088 send_ready);
1089 packet = &t->packet; 1089 packet = &t->packet;
1090 if (!sctp_packet_empty(packet)) 1090 if (!sctp_packet_empty(packet))
1091 error = sctp_packet_transmit(packet); 1091 error = sctp_packet_transmit(packet, gfp);
1092 1092
1093 /* Clear the burst limited state, if any */ 1093 /* Clear the burst limited state, if any */
1094 sctp_transport_burst_reset(t); 1094 sctp_transport_burst_reset(t);
diff --git a/net/sctp/probe.c b/net/sctp/probe.c
index 5e68b94ee640..6cc2152e0740 100644
--- a/net/sctp/probe.c
+++ b/net/sctp/probe.c
@@ -65,7 +65,7 @@ static struct {
65 struct kfifo fifo; 65 struct kfifo fifo;
66 spinlock_t lock; 66 spinlock_t lock;
67 wait_queue_head_t wait; 67 wait_queue_head_t wait;
68 struct timespec tstart; 68 struct timespec64 tstart;
69} sctpw; 69} sctpw;
70 70
71static __printf(1, 2) void printl(const char *fmt, ...) 71static __printf(1, 2) void printl(const char *fmt, ...)
@@ -85,7 +85,7 @@ static __printf(1, 2) void printl(const char *fmt, ...)
85static int sctpprobe_open(struct inode *inode, struct file *file) 85static int sctpprobe_open(struct inode *inode, struct file *file)
86{ 86{
87 kfifo_reset(&sctpw.fifo); 87 kfifo_reset(&sctpw.fifo);
88 getnstimeofday(&sctpw.tstart); 88 ktime_get_ts64(&sctpw.tstart);
89 89
90 return 0; 90 return 0;
91} 91}
@@ -138,7 +138,7 @@ static sctp_disposition_t jsctp_sf_eat_sack(struct net *net,
138 struct sk_buff *skb = chunk->skb; 138 struct sk_buff *skb = chunk->skb;
139 struct sctp_transport *sp; 139 struct sctp_transport *sp;
140 static __u32 lcwnd = 0; 140 static __u32 lcwnd = 0;
141 struct timespec now; 141 struct timespec64 now;
142 142
143 sp = asoc->peer.primary_path; 143 sp = asoc->peer.primary_path;
144 144
@@ -149,8 +149,8 @@ static sctp_disposition_t jsctp_sf_eat_sack(struct net *net,
149 (full || sp->cwnd != lcwnd)) { 149 (full || sp->cwnd != lcwnd)) {
150 lcwnd = sp->cwnd; 150 lcwnd = sp->cwnd;
151 151
152 getnstimeofday(&now); 152 ktime_get_ts64(&now);
153 now = timespec_sub(now, sctpw.tstart); 153 now = timespec64_sub(now, sctpw.tstart);
154 154
155 printl("%lu.%06lu ", (unsigned long) now.tv_sec, 155 printl("%lu.%06lu ", (unsigned long) now.tv_sec,
156 (unsigned long) now.tv_nsec / NSEC_PER_USEC); 156 (unsigned long) now.tv_nsec / NSEC_PER_USEC);
diff --git a/net/sctp/proc.c b/net/sctp/proc.c
index 963dffcc2618..5cfac8d5d3b3 100644
--- a/net/sctp/proc.c
+++ b/net/sctp/proc.c
@@ -161,7 +161,6 @@ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_associa
161 struct sctp_af *af; 161 struct sctp_af *af;
162 162
163 primary = &assoc->peer.primary_addr; 163 primary = &assoc->peer.primary_addr;
164 rcu_read_lock();
165 list_for_each_entry_rcu(transport, &assoc->peer.transport_addr_list, 164 list_for_each_entry_rcu(transport, &assoc->peer.transport_addr_list,
166 transports) { 165 transports) {
167 addr = &transport->ipaddr; 166 addr = &transport->ipaddr;
@@ -172,7 +171,6 @@ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_associa
172 } 171 }
173 af->seq_dump_addr(seq, addr); 172 af->seq_dump_addr(seq, addr);
174 } 173 }
175 rcu_read_unlock();
176} 174}
177 175
178static void *sctp_eps_seq_start(struct seq_file *seq, loff_t *pos) 176static void *sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 7fe971e30ad6..7f0bf798205b 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -45,6 +45,7 @@
45 45
46#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 46#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
47 47
48#include <crypto/hash.h>
48#include <linux/types.h> 49#include <linux/types.h>
49#include <linux/kernel.h> 50#include <linux/kernel.h>
50#include <linux/ip.h> 51#include <linux/ip.h>
@@ -52,7 +53,6 @@
52#include <linux/net.h> 53#include <linux/net.h>
53#include <linux/inet.h> 54#include <linux/inet.h>
54#include <linux/scatterlist.h> 55#include <linux/scatterlist.h>
55#include <linux/crypto.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <net/sock.h> 57#include <net/sock.h>
58 58
@@ -62,11 +62,13 @@
62#include <net/sctp/sm.h> 62#include <net/sctp/sm.h>
63 63
64static struct sctp_chunk *sctp_make_control(const struct sctp_association *asoc, 64static struct sctp_chunk *sctp_make_control(const struct sctp_association *asoc,
65 __u8 type, __u8 flags, int paylen); 65 __u8 type, __u8 flags, int paylen,
66 gfp_t gfp);
66static struct sctp_chunk *sctp_make_data(const struct sctp_association *asoc, 67static struct sctp_chunk *sctp_make_data(const struct sctp_association *asoc,
67 __u8 flags, int paylen); 68 __u8 flags, int paylen, gfp_t gfp);
68static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc, 69static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
69 __u8 type, __u8 flags, int paylen); 70 __u8 type, __u8 flags, int paylen,
71 gfp_t gfp);
70static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep, 72static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
71 const struct sctp_association *asoc, 73 const struct sctp_association *asoc,
72 const struct sctp_chunk *init_chunk, 74 const struct sctp_chunk *init_chunk,
@@ -318,7 +320,7 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
318 * PLEASE DO NOT FIXME [This version does not support Host Name.] 320 * PLEASE DO NOT FIXME [This version does not support Host Name.]
319 */ 321 */
320 322
321 retval = sctp_make_control(asoc, SCTP_CID_INIT, 0, chunksize); 323 retval = sctp_make_control(asoc, SCTP_CID_INIT, 0, chunksize, gfp);
322 if (!retval) 324 if (!retval)
323 goto nodata; 325 goto nodata;
324 326
@@ -465,7 +467,7 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
465 num_ext); 467 num_ext);
466 468
467 /* Now allocate and fill out the chunk. */ 469 /* Now allocate and fill out the chunk. */
468 retval = sctp_make_control(asoc, SCTP_CID_INIT_ACK, 0, chunksize); 470 retval = sctp_make_control(asoc, SCTP_CID_INIT_ACK, 0, chunksize, gfp);
469 if (!retval) 471 if (!retval)
470 goto nomem_chunk; 472 goto nomem_chunk;
471 473
@@ -570,7 +572,8 @@ struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *asoc,
570 cookie_len = asoc->peer.cookie_len; 572 cookie_len = asoc->peer.cookie_len;
571 573
572 /* Build a cookie echo chunk. */ 574 /* Build a cookie echo chunk. */
573 retval = sctp_make_control(asoc, SCTP_CID_COOKIE_ECHO, 0, cookie_len); 575 retval = sctp_make_control(asoc, SCTP_CID_COOKIE_ECHO, 0,
576 cookie_len, GFP_ATOMIC);
574 if (!retval) 577 if (!retval)
575 goto nodata; 578 goto nodata;
576 retval->subh.cookie_hdr = 579 retval->subh.cookie_hdr =
@@ -615,7 +618,7 @@ struct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *asoc,
615{ 618{
616 struct sctp_chunk *retval; 619 struct sctp_chunk *retval;
617 620
618 retval = sctp_make_control(asoc, SCTP_CID_COOKIE_ACK, 0, 0); 621 retval = sctp_make_control(asoc, SCTP_CID_COOKIE_ACK, 0, 0, GFP_ATOMIC);
619 622
620 /* RFC 2960 6.4 Multi-homed SCTP Endpoints 623 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
621 * 624 *
@@ -664,7 +667,7 @@ struct sctp_chunk *sctp_make_cwr(const struct sctp_association *asoc,
664 667
665 cwr.lowest_tsn = htonl(lowest_tsn); 668 cwr.lowest_tsn = htonl(lowest_tsn);
666 retval = sctp_make_control(asoc, SCTP_CID_ECN_CWR, 0, 669 retval = sctp_make_control(asoc, SCTP_CID_ECN_CWR, 0,
667 sizeof(sctp_cwrhdr_t)); 670 sizeof(sctp_cwrhdr_t), GFP_ATOMIC);
668 671
669 if (!retval) 672 if (!retval)
670 goto nodata; 673 goto nodata;
@@ -698,7 +701,7 @@ struct sctp_chunk *sctp_make_ecne(const struct sctp_association *asoc,
698 701
699 ecne.lowest_tsn = htonl(lowest_tsn); 702 ecne.lowest_tsn = htonl(lowest_tsn);
700 retval = sctp_make_control(asoc, SCTP_CID_ECN_ECNE, 0, 703 retval = sctp_make_control(asoc, SCTP_CID_ECN_ECNE, 0,
701 sizeof(sctp_ecnehdr_t)); 704 sizeof(sctp_ecnehdr_t), GFP_ATOMIC);
702 if (!retval) 705 if (!retval)
703 goto nodata; 706 goto nodata;
704 retval->subh.ecne_hdr = 707 retval->subh.ecne_hdr =
@@ -713,7 +716,8 @@ nodata:
713 */ 716 */
714struct sctp_chunk *sctp_make_datafrag_empty(struct sctp_association *asoc, 717struct sctp_chunk *sctp_make_datafrag_empty(struct sctp_association *asoc,
715 const struct sctp_sndrcvinfo *sinfo, 718 const struct sctp_sndrcvinfo *sinfo,
716 int data_len, __u8 flags, __u16 ssn) 719 int data_len, __u8 flags, __u16 ssn,
720 gfp_t gfp)
717{ 721{
718 struct sctp_chunk *retval; 722 struct sctp_chunk *retval;
719 struct sctp_datahdr dp; 723 struct sctp_datahdr dp;
@@ -734,7 +738,7 @@ struct sctp_chunk *sctp_make_datafrag_empty(struct sctp_association *asoc,
734 dp.ssn = htons(ssn); 738 dp.ssn = htons(ssn);
735 739
736 chunk_len = sizeof(dp) + data_len; 740 chunk_len = sizeof(dp) + data_len;
737 retval = sctp_make_data(asoc, flags, chunk_len); 741 retval = sctp_make_data(asoc, flags, chunk_len, gfp);
738 if (!retval) 742 if (!retval)
739 goto nodata; 743 goto nodata;
740 744
@@ -781,7 +785,7 @@ struct sctp_chunk *sctp_make_sack(const struct sctp_association *asoc)
781 + sizeof(__u32) * num_dup_tsns; 785 + sizeof(__u32) * num_dup_tsns;
782 786
783 /* Create the chunk. */ 787 /* Create the chunk. */
784 retval = sctp_make_control(asoc, SCTP_CID_SACK, 0, len); 788 retval = sctp_make_control(asoc, SCTP_CID_SACK, 0, len, GFP_ATOMIC);
785 if (!retval) 789 if (!retval)
786 goto nodata; 790 goto nodata;
787 791
@@ -861,7 +865,7 @@ struct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc,
861 shut.cum_tsn_ack = htonl(ctsn); 865 shut.cum_tsn_ack = htonl(ctsn);
862 866
863 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN, 0, 867 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN, 0,
864 sizeof(sctp_shutdownhdr_t)); 868 sizeof(sctp_shutdownhdr_t), GFP_ATOMIC);
865 if (!retval) 869 if (!retval)
866 goto nodata; 870 goto nodata;
867 871
@@ -879,7 +883,8 @@ struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc,
879{ 883{
880 struct sctp_chunk *retval; 884 struct sctp_chunk *retval;
881 885
882 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN_ACK, 0, 0); 886 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN_ACK, 0, 0,
887 GFP_ATOMIC);
883 888
884 /* RFC 2960 6.4 Multi-homed SCTP Endpoints 889 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
885 * 890 *
@@ -908,7 +913,8 @@ struct sctp_chunk *sctp_make_shutdown_complete(
908 */ 913 */
909 flags |= asoc ? 0 : SCTP_CHUNK_FLAG_T; 914 flags |= asoc ? 0 : SCTP_CHUNK_FLAG_T;
910 915
911 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN_COMPLETE, flags, 0); 916 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN_COMPLETE, flags,
917 0, GFP_ATOMIC);
912 918
913 /* RFC 2960 6.4 Multi-homed SCTP Endpoints 919 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
914 * 920 *
@@ -947,7 +953,8 @@ struct sctp_chunk *sctp_make_abort(const struct sctp_association *asoc,
947 flags = SCTP_CHUNK_FLAG_T; 953 flags = SCTP_CHUNK_FLAG_T;
948 } 954 }
949 955
950 retval = sctp_make_control(asoc, SCTP_CID_ABORT, flags, hint); 956 retval = sctp_make_control(asoc, SCTP_CID_ABORT, flags, hint,
957 GFP_ATOMIC);
951 958
952 /* RFC 2960 6.4 Multi-homed SCTP Endpoints 959 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
953 * 960 *
@@ -1139,7 +1146,8 @@ struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
1139 struct sctp_chunk *retval; 1146 struct sctp_chunk *retval;
1140 sctp_sender_hb_info_t hbinfo; 1147 sctp_sender_hb_info_t hbinfo;
1141 1148
1142 retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT, 0, sizeof(hbinfo)); 1149 retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT, 0,
1150 sizeof(hbinfo), GFP_ATOMIC);
1143 1151
1144 if (!retval) 1152 if (!retval)
1145 goto nodata; 1153 goto nodata;
@@ -1167,7 +1175,8 @@ struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc,
1167{ 1175{
1168 struct sctp_chunk *retval; 1176 struct sctp_chunk *retval;
1169 1177
1170 retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT_ACK, 0, paylen); 1178 retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT_ACK, 0, paylen,
1179 GFP_ATOMIC);
1171 if (!retval) 1180 if (!retval)
1172 goto nodata; 1181 goto nodata;
1173 1182
@@ -1200,7 +1209,7 @@ static struct sctp_chunk *sctp_make_op_error_space(
1200 struct sctp_chunk *retval; 1209 struct sctp_chunk *retval;
1201 1210
1202 retval = sctp_make_control(asoc, SCTP_CID_ERROR, 0, 1211 retval = sctp_make_control(asoc, SCTP_CID_ERROR, 0,
1203 sizeof(sctp_errhdr_t) + size); 1212 sizeof(sctp_errhdr_t) + size, GFP_ATOMIC);
1204 if (!retval) 1213 if (!retval)
1205 goto nodata; 1214 goto nodata;
1206 1215
@@ -1271,7 +1280,8 @@ struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc)
1271 return NULL; 1280 return NULL;
1272 1281
1273 retval = sctp_make_control(asoc, SCTP_CID_AUTH, 0, 1282 retval = sctp_make_control(asoc, SCTP_CID_AUTH, 0,
1274 hmac_desc->hmac_len + sizeof(sctp_authhdr_t)); 1283 hmac_desc->hmac_len + sizeof(sctp_authhdr_t),
1284 GFP_ATOMIC);
1275 if (!retval) 1285 if (!retval)
1276 return NULL; 1286 return NULL;
1277 1287
@@ -1309,11 +1319,11 @@ struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc)
1309 */ 1319 */
1310struct sctp_chunk *sctp_chunkify(struct sk_buff *skb, 1320struct sctp_chunk *sctp_chunkify(struct sk_buff *skb,
1311 const struct sctp_association *asoc, 1321 const struct sctp_association *asoc,
1312 struct sock *sk) 1322 struct sock *sk, gfp_t gfp)
1313{ 1323{
1314 struct sctp_chunk *retval; 1324 struct sctp_chunk *retval;
1315 1325
1316 retval = kmem_cache_zalloc(sctp_chunk_cachep, GFP_ATOMIC); 1326 retval = kmem_cache_zalloc(sctp_chunk_cachep, gfp);
1317 1327
1318 if (!retval) 1328 if (!retval)
1319 goto nodata; 1329 goto nodata;
@@ -1361,7 +1371,8 @@ const union sctp_addr *sctp_source(const struct sctp_chunk *chunk)
1361 * arguments, reserving enough space for a 'paylen' byte payload. 1371 * arguments, reserving enough space for a 'paylen' byte payload.
1362 */ 1372 */
1363static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc, 1373static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
1364 __u8 type, __u8 flags, int paylen) 1374 __u8 type, __u8 flags, int paylen,
1375 gfp_t gfp)
1365{ 1376{
1366 struct sctp_chunk *retval; 1377 struct sctp_chunk *retval;
1367 sctp_chunkhdr_t *chunk_hdr; 1378 sctp_chunkhdr_t *chunk_hdr;
@@ -1369,8 +1380,7 @@ static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
1369 struct sock *sk; 1380 struct sock *sk;
1370 1381
1371 /* No need to allocate LL here, as this is only a chunk. */ 1382 /* No need to allocate LL here, as this is only a chunk. */
1372 skb = alloc_skb(WORD_ROUND(sizeof(sctp_chunkhdr_t) + paylen), 1383 skb = alloc_skb(WORD_ROUND(sizeof(sctp_chunkhdr_t) + paylen), gfp);
1373 GFP_ATOMIC);
1374 if (!skb) 1384 if (!skb)
1375 goto nodata; 1385 goto nodata;
1376 1386
@@ -1381,7 +1391,7 @@ static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
1381 chunk_hdr->length = htons(sizeof(sctp_chunkhdr_t)); 1391 chunk_hdr->length = htons(sizeof(sctp_chunkhdr_t));
1382 1392
1383 sk = asoc ? asoc->base.sk : NULL; 1393 sk = asoc ? asoc->base.sk : NULL;
1384 retval = sctp_chunkify(skb, asoc, sk); 1394 retval = sctp_chunkify(skb, asoc, sk, gfp);
1385 if (!retval) { 1395 if (!retval) {
1386 kfree_skb(skb); 1396 kfree_skb(skb);
1387 goto nodata; 1397 goto nodata;
@@ -1400,16 +1410,18 @@ nodata:
1400} 1410}
1401 1411
1402static struct sctp_chunk *sctp_make_data(const struct sctp_association *asoc, 1412static struct sctp_chunk *sctp_make_data(const struct sctp_association *asoc,
1403 __u8 flags, int paylen) 1413 __u8 flags, int paylen, gfp_t gfp)
1404{ 1414{
1405 return _sctp_make_chunk(asoc, SCTP_CID_DATA, flags, paylen); 1415 return _sctp_make_chunk(asoc, SCTP_CID_DATA, flags, paylen, gfp);
1406} 1416}
1407 1417
1408static struct sctp_chunk *sctp_make_control(const struct sctp_association *asoc, 1418static struct sctp_chunk *sctp_make_control(const struct sctp_association *asoc,
1409 __u8 type, __u8 flags, int paylen) 1419 __u8 type, __u8 flags, int paylen,
1420 gfp_t gfp)
1410{ 1421{
1411 struct sctp_chunk *chunk = _sctp_make_chunk(asoc, type, flags, paylen); 1422 struct sctp_chunk *chunk;
1412 1423
1424 chunk = _sctp_make_chunk(asoc, type, flags, paylen, gfp);
1413 if (chunk) 1425 if (chunk)
1414 sctp_control_set_owner_w(chunk); 1426 sctp_control_set_owner_w(chunk);
1415 1427
@@ -1606,7 +1618,6 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
1606{ 1618{
1607 sctp_cookie_param_t *retval; 1619 sctp_cookie_param_t *retval;
1608 struct sctp_signed_cookie *cookie; 1620 struct sctp_signed_cookie *cookie;
1609 struct scatterlist sg;
1610 int headersize, bodysize; 1621 int headersize, bodysize;
1611 1622
1612 /* Header size is static data prior to the actual cookie, including 1623 /* Header size is static data prior to the actual cookie, including
@@ -1663,16 +1674,19 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
1663 ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len); 1674 ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len);
1664 1675
1665 if (sctp_sk(ep->base.sk)->hmac) { 1676 if (sctp_sk(ep->base.sk)->hmac) {
1666 struct hash_desc desc; 1677 SHASH_DESC_ON_STACK(desc, sctp_sk(ep->base.sk)->hmac);
1678 int err;
1667 1679
1668 /* Sign the message. */ 1680 /* Sign the message. */
1669 sg_init_one(&sg, &cookie->c, bodysize); 1681 desc->tfm = sctp_sk(ep->base.sk)->hmac;
1670 desc.tfm = sctp_sk(ep->base.sk)->hmac; 1682 desc->flags = 0;
1671 desc.flags = 0; 1683
1672 1684 err = crypto_shash_setkey(desc->tfm, ep->secret_key,
1673 if (crypto_hash_setkey(desc.tfm, ep->secret_key, 1685 sizeof(ep->secret_key)) ?:
1674 sizeof(ep->secret_key)) || 1686 crypto_shash_digest(desc, (u8 *)&cookie->c, bodysize,
1675 crypto_hash_digest(&desc, &sg, bodysize, cookie->signature)) 1687 cookie->signature);
1688 shash_desc_zero(desc);
1689 if (err)
1676 goto free_cookie; 1690 goto free_cookie;
1677 } 1691 }
1678 1692
@@ -1697,12 +1711,10 @@ struct sctp_association *sctp_unpack_cookie(
1697 struct sctp_cookie *bear_cookie; 1711 struct sctp_cookie *bear_cookie;
1698 int headersize, bodysize, fixed_size; 1712 int headersize, bodysize, fixed_size;
1699 __u8 *digest = ep->digest; 1713 __u8 *digest = ep->digest;
1700 struct scatterlist sg;
1701 unsigned int len; 1714 unsigned int len;
1702 sctp_scope_t scope; 1715 sctp_scope_t scope;
1703 struct sk_buff *skb = chunk->skb; 1716 struct sk_buff *skb = chunk->skb;
1704 ktime_t kt; 1717 ktime_t kt;
1705 struct hash_desc desc;
1706 1718
1707 /* Header size is static data prior to the actual cookie, including 1719 /* Header size is static data prior to the actual cookie, including
1708 * any padding. 1720 * any padding.
@@ -1733,16 +1745,23 @@ struct sctp_association *sctp_unpack_cookie(
1733 goto no_hmac; 1745 goto no_hmac;
1734 1746
1735 /* Check the signature. */ 1747 /* Check the signature. */
1736 sg_init_one(&sg, bear_cookie, bodysize); 1748 {
1737 desc.tfm = sctp_sk(ep->base.sk)->hmac; 1749 SHASH_DESC_ON_STACK(desc, sctp_sk(ep->base.sk)->hmac);
1738 desc.flags = 0; 1750 int err;
1739 1751
1740 memset(digest, 0x00, SCTP_SIGNATURE_SIZE); 1752 desc->tfm = sctp_sk(ep->base.sk)->hmac;
1741 if (crypto_hash_setkey(desc.tfm, ep->secret_key, 1753 desc->flags = 0;
1742 sizeof(ep->secret_key)) || 1754
1743 crypto_hash_digest(&desc, &sg, bodysize, digest)) { 1755 err = crypto_shash_setkey(desc->tfm, ep->secret_key,
1744 *error = -SCTP_IERROR_NOMEM; 1756 sizeof(ep->secret_key)) ?:
1745 goto fail; 1757 crypto_shash_digest(desc, (u8 *)bear_cookie, bodysize,
1758 digest);
1759 shash_desc_zero(desc);
1760
1761 if (err) {
1762 *error = -SCTP_IERROR_NOMEM;
1763 goto fail;
1764 }
1746 } 1765 }
1747 1766
1748 if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) { 1767 if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) {
@@ -2757,7 +2776,8 @@ static struct sctp_chunk *sctp_make_asconf(struct sctp_association *asoc,
2757 length += addrlen; 2776 length += addrlen;
2758 2777
2759 /* Create the chunk. */ 2778 /* Create the chunk. */
2760 retval = sctp_make_control(asoc, SCTP_CID_ASCONF, 0, length); 2779 retval = sctp_make_control(asoc, SCTP_CID_ASCONF, 0, length,
2780 GFP_ATOMIC);
2761 if (!retval) 2781 if (!retval)
2762 return NULL; 2782 return NULL;
2763 2783
@@ -2941,7 +2961,8 @@ static struct sctp_chunk *sctp_make_asconf_ack(const struct sctp_association *as
2941 int length = sizeof(asconf) + vparam_len; 2961 int length = sizeof(asconf) + vparam_len;
2942 2962
2943 /* Create the chunk. */ 2963 /* Create the chunk. */
2944 retval = sctp_make_control(asoc, SCTP_CID_ASCONF_ACK, 0, length); 2964 retval = sctp_make_control(asoc, SCTP_CID_ASCONF_ACK, 0, length,
2965 GFP_ATOMIC);
2945 if (!retval) 2966 if (!retval)
2946 return NULL; 2967 return NULL;
2947 2968
@@ -3501,7 +3522,7 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
3501 3522
3502 hint = (nstreams + 1) * sizeof(__u32); 3523 hint = (nstreams + 1) * sizeof(__u32);
3503 3524
3504 retval = sctp_make_control(asoc, SCTP_CID_FWD_TSN, 0, hint); 3525 retval = sctp_make_control(asoc, SCTP_CID_FWD_TSN, 0, hint, GFP_ATOMIC);
3505 3526
3506 if (!retval) 3527 if (!retval)
3507 return NULL; 3528 return NULL;
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index b5327bb77458..3c22c41a2bc2 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -1019,13 +1019,13 @@ static void sctp_cmd_t1_timer_update(struct sctp_association *asoc,
1019 * encouraged for small fragments. 1019 * encouraged for small fragments.
1020 */ 1020 */
1021static int sctp_cmd_send_msg(struct sctp_association *asoc, 1021static int sctp_cmd_send_msg(struct sctp_association *asoc,
1022 struct sctp_datamsg *msg) 1022 struct sctp_datamsg *msg, gfp_t gfp)
1023{ 1023{
1024 struct sctp_chunk *chunk; 1024 struct sctp_chunk *chunk;
1025 int error = 0; 1025 int error = 0;
1026 1026
1027 list_for_each_entry(chunk, &msg->chunks, frag_list) { 1027 list_for_each_entry(chunk, &msg->chunks, frag_list) {
1028 error = sctp_outq_tail(&asoc->outqueue, chunk); 1028 error = sctp_outq_tail(&asoc->outqueue, chunk, gfp);
1029 if (error) 1029 if (error)
1030 break; 1030 break;
1031 } 1031 }
@@ -1249,7 +1249,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1249 case SCTP_CMD_NEW_ASOC: 1249 case SCTP_CMD_NEW_ASOC:
1250 /* Register a new association. */ 1250 /* Register a new association. */
1251 if (local_cork) { 1251 if (local_cork) {
1252 sctp_outq_uncork(&asoc->outqueue); 1252 sctp_outq_uncork(&asoc->outqueue, gfp);
1253 local_cork = 0; 1253 local_cork = 0;
1254 } 1254 }
1255 1255
@@ -1269,7 +1269,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1269 1269
1270 case SCTP_CMD_DELETE_TCB: 1270 case SCTP_CMD_DELETE_TCB:
1271 if (local_cork) { 1271 if (local_cork) {
1272 sctp_outq_uncork(&asoc->outqueue); 1272 sctp_outq_uncork(&asoc->outqueue, gfp);
1273 local_cork = 0; 1273 local_cork = 0;
1274 } 1274 }
1275 /* Delete the current association. */ 1275 /* Delete the current association. */
@@ -1423,13 +1423,14 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1423 local_cork = 1; 1423 local_cork = 1;
1424 } 1424 }
1425 /* Send a chunk to our peer. */ 1425 /* Send a chunk to our peer. */
1426 error = sctp_outq_tail(&asoc->outqueue, cmd->obj.chunk); 1426 error = sctp_outq_tail(&asoc->outqueue, cmd->obj.chunk,
1427 gfp);
1427 break; 1428 break;
1428 1429
1429 case SCTP_CMD_SEND_PKT: 1430 case SCTP_CMD_SEND_PKT:
1430 /* Send a full packet to our peer. */ 1431 /* Send a full packet to our peer. */
1431 packet = cmd->obj.packet; 1432 packet = cmd->obj.packet;
1432 sctp_packet_transmit(packet); 1433 sctp_packet_transmit(packet, gfp);
1433 sctp_ootb_pkt_free(packet); 1434 sctp_ootb_pkt_free(packet);
1434 break; 1435 break;
1435 1436
@@ -1639,7 +1640,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1639 */ 1640 */
1640 chunk->pdiscard = 1; 1641 chunk->pdiscard = 1;
1641 if (asoc) { 1642 if (asoc) {
1642 sctp_outq_uncork(&asoc->outqueue); 1643 sctp_outq_uncork(&asoc->outqueue, gfp);
1643 local_cork = 0; 1644 local_cork = 0;
1644 } 1645 }
1645 break; 1646 break;
@@ -1677,7 +1678,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1677 case SCTP_CMD_FORCE_PRIM_RETRAN: 1678 case SCTP_CMD_FORCE_PRIM_RETRAN:
1678 t = asoc->peer.retran_path; 1679 t = asoc->peer.retran_path;
1679 asoc->peer.retran_path = asoc->peer.primary_path; 1680 asoc->peer.retran_path = asoc->peer.primary_path;
1680 error = sctp_outq_uncork(&asoc->outqueue); 1681 error = sctp_outq_uncork(&asoc->outqueue, gfp);
1681 local_cork = 0; 1682 local_cork = 0;
1682 asoc->peer.retran_path = t; 1683 asoc->peer.retran_path = t;
1683 break; 1684 break;
@@ -1704,7 +1705,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1704 sctp_outq_cork(&asoc->outqueue); 1705 sctp_outq_cork(&asoc->outqueue);
1705 local_cork = 1; 1706 local_cork = 1;
1706 } 1707 }
1707 error = sctp_cmd_send_msg(asoc, cmd->obj.msg); 1708 error = sctp_cmd_send_msg(asoc, cmd->obj.msg, gfp);
1708 break; 1709 break;
1709 case SCTP_CMD_SEND_NEXT_ASCONF: 1710 case SCTP_CMD_SEND_NEXT_ASCONF:
1710 sctp_cmd_send_asconf(asoc); 1711 sctp_cmd_send_asconf(asoc);
@@ -1734,9 +1735,9 @@ out:
1734 */ 1735 */
1735 if (asoc && SCTP_EVENT_T_CHUNK == event_type && chunk) { 1736 if (asoc && SCTP_EVENT_T_CHUNK == event_type && chunk) {
1736 if (chunk->end_of_packet || chunk->singleton) 1737 if (chunk->end_of_packet || chunk->singleton)
1737 error = sctp_outq_uncork(&asoc->outqueue); 1738 error = sctp_outq_uncork(&asoc->outqueue, gfp);
1738 } else if (local_cork) 1739 } else if (local_cork)
1739 error = sctp_outq_uncork(&asoc->outqueue); 1740 error = sctp_outq_uncork(&asoc->outqueue, gfp);
1740 return error; 1741 return error;
1741nomem: 1742nomem:
1742 error = -ENOMEM; 1743 error = -ENOMEM;
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 0e3de0c71137..a44a97c93724 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -52,6 +52,7 @@
52 52
53#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 53#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
54 54
55#include <crypto/hash.h>
55#include <linux/types.h> 56#include <linux/types.h>
56#include <linux/kernel.h> 57#include <linux/kernel.h>
57#include <linux/wait.h> 58#include <linux/wait.h>
@@ -61,7 +62,6 @@
61#include <linux/fcntl.h> 62#include <linux/fcntl.h>
62#include <linux/poll.h> 63#include <linux/poll.h>
63#include <linux/init.h> 64#include <linux/init.h>
64#include <linux/crypto.h>
65#include <linux/slab.h> 65#include <linux/slab.h>
66#include <linux/file.h> 66#include <linux/file.h>
67#include <linux/compat.h> 67#include <linux/compat.h>
@@ -4162,7 +4162,7 @@ static void sctp_destruct_sock(struct sock *sk)
4162 struct sctp_sock *sp = sctp_sk(sk); 4162 struct sctp_sock *sp = sctp_sk(sk);
4163 4163
4164 /* Free up the HMAC transform. */ 4164 /* Free up the HMAC transform. */
4165 crypto_free_hash(sp->hmac); 4165 crypto_free_shash(sp->hmac);
4166 4166
4167 inet_sock_destruct(sk); 4167 inet_sock_destruct(sk);
4168} 4168}
@@ -6108,9 +6108,10 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
6108 return retval; 6108 return retval;
6109} 6109}
6110 6110
6111static void sctp_hash(struct sock *sk) 6111static int sctp_hash(struct sock *sk)
6112{ 6112{
6113 /* STUB */ 6113 /* STUB */
6114 return 0;
6114} 6115}
6115 6116
6116static void sctp_unhash(struct sock *sk) 6117static void sctp_unhash(struct sock *sk)
@@ -6306,13 +6307,13 @@ static int sctp_listen_start(struct sock *sk, int backlog)
6306{ 6307{
6307 struct sctp_sock *sp = sctp_sk(sk); 6308 struct sctp_sock *sp = sctp_sk(sk);
6308 struct sctp_endpoint *ep = sp->ep; 6309 struct sctp_endpoint *ep = sp->ep;
6309 struct crypto_hash *tfm = NULL; 6310 struct crypto_shash *tfm = NULL;
6310 char alg[32]; 6311 char alg[32];
6311 6312
6312 /* Allocate HMAC for generating cookie. */ 6313 /* Allocate HMAC for generating cookie. */
6313 if (!sp->hmac && sp->sctp_hmac_alg) { 6314 if (!sp->hmac && sp->sctp_hmac_alg) {
6314 sprintf(alg, "hmac(%s)", sp->sctp_hmac_alg); 6315 sprintf(alg, "hmac(%s)", sp->sctp_hmac_alg);
6315 tfm = crypto_alloc_hash(alg, 0, CRYPTO_ALG_ASYNC); 6316 tfm = crypto_alloc_shash(alg, 0, 0);
6316 if (IS_ERR(tfm)) { 6317 if (IS_ERR(tfm)) {
6317 net_info_ratelimited("failed to load transform for %s: %ld\n", 6318 net_info_ratelimited("failed to load transform for %s: %ld\n",
6318 sp->sctp_hmac_alg, PTR_ERR(tfm)); 6319 sp->sctp_hmac_alg, PTR_ERR(tfm));
@@ -7255,14 +7256,12 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
7255 /* Hook this new socket in to the bind_hash list. */ 7256 /* Hook this new socket in to the bind_hash list. */
7256 head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk), 7257 head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk),
7257 inet_sk(oldsk)->inet_num)]; 7258 inet_sk(oldsk)->inet_num)];
7258 local_bh_disable(); 7259 spin_lock_bh(&head->lock);
7259 spin_lock(&head->lock);
7260 pp = sctp_sk(oldsk)->bind_hash; 7260 pp = sctp_sk(oldsk)->bind_hash;
7261 sk_add_bind_node(newsk, &pp->owner); 7261 sk_add_bind_node(newsk, &pp->owner);
7262 sctp_sk(newsk)->bind_hash = pp; 7262 sctp_sk(newsk)->bind_hash = pp;
7263 inet_sk(newsk)->inet_num = inet_sk(oldsk)->inet_num; 7263 inet_sk(newsk)->inet_num = inet_sk(oldsk)->inet_num;
7264 spin_unlock(&head->lock); 7264 spin_unlock_bh(&head->lock);
7265 local_bh_enable();
7266 7265
7267 /* Copy the bind_addr list from the original endpoint to the new 7266 /* Copy the bind_addr list from the original endpoint to the new
7268 * endpoint so that we can handle restarts properly 7267 * endpoint so that we can handle restarts properly
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index a431c14044a4..d517153891a6 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -72,7 +72,7 @@ static struct sctp_transport *sctp_transport_init(struct net *net,
72 */ 72 */
73 peer->rto = msecs_to_jiffies(net->sctp.rto_initial); 73 peer->rto = msecs_to_jiffies(net->sctp.rto_initial);
74 74
75 peer->last_time_heard = ktime_get(); 75 peer->last_time_heard = ktime_set(0, 0);
76 peer->last_time_ecne_reduced = jiffies; 76 peer->last_time_ecne_reduced = jiffies;
77 77
78 peer->param_flags = SPP_HB_DISABLE | 78 peer->param_flags = SPP_HB_DISABLE |