Merge tag 'selinux-pr-20180403' of git://git.kernel.org/pub/scm/linux/kernel/git...
[muen/linux.git] / net / sctp / chunk.c
index d726d21..be296d6 100644 (file)
@@ -168,6 +168,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
 {
        size_t len, first_len, max_data, remaining;
        size_t msg_len = iov_iter_count(from);
+       struct sctp_shared_key *shkey = NULL;
        struct list_head *pos, *temp;
        struct sctp_chunk *chunk;
        struct sctp_datamsg *msg;
@@ -208,6 +209,17 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
                if (hmac_desc)
                        max_data -= SCTP_PAD4(sizeof(struct sctp_auth_chunk) +
                                              hmac_desc->hmac_len);
+
+               if (sinfo->sinfo_tsn &&
+                   sinfo->sinfo_ssn != asoc->active_key_id) {
+                       shkey = sctp_auth_get_shkey(asoc, sinfo->sinfo_ssn);
+                       if (!shkey) {
+                               err = -EINVAL;
+                               goto errout;
+                       }
+               } else {
+                       shkey = asoc->shkey;
+               }
        }
 
        /* Check what's our max considering the above */
@@ -279,6 +291,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
                if (err < 0)
                        goto errout_chunk_free;
 
+               chunk->shkey = shkey;
+
                /* Put the chunk->skb back into the form expected by send.  */
                __skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr -
                                       chunk->skb->data);