]> err.no Git - linux-2.6/blobdiff - net/sctp/sm_make_chunk.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[linux-2.6] / net / sctp / sm_make_chunk.c
index 167d888d1df263f29ee3734ba4ee6864931b70f6..23ae37ec871167d17c37ddbdbb9d4095e26a4575 100644 (file)
@@ -65,8 +65,6 @@
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
-extern struct kmem_cache *sctp_chunk_cachep;
-
 SCTP_STATIC
 struct sctp_chunk *sctp_make_chunk(const struct sctp_association *asoc,
                                   __u8 type, __u8 flags, int paylen);
@@ -86,7 +84,7 @@ int sctp_chunk_iif(const struct sctp_chunk *chunk)
        struct sctp_af *af;
        int iif = 0;
 
-       af = sctp_get_af_specific(ipver2af(chunk->skb->nh.iph->version));
+       af = sctp_get_af_specific(ipver2af(ip_hdr(chunk->skb)->version));
        if (af)
                iif = af->skb_iif(chunk->skb);
 
@@ -112,20 +110,16 @@ static const struct sctp_paramhdr prsctp_param = {
  * abort chunk.
  */
 void  sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code,
-                     const void *payload, size_t paylen)
+                     size_t paylen)
 {
        sctp_errhdr_t err;
-       int padlen;
        __u16 len;
 
-        /* Cause code constants are now defined in network order.  */
+       /* Cause code constants are now defined in network order.  */
        err.cause = cause_code;
        len = sizeof(sctp_errhdr_t) + paylen;
-       padlen = len % 4;
        err.length  = htons(len);
-       len += padlen;
        chunk->subh.err_hdr = sctp_addto_chunk(chunk, sizeof(sctp_errhdr_t), &err);
-       sctp_addto_chunk(chunk, paylen, payload);
 }
 
 /* 3.3.2 Initiation (INIT) (1)
@@ -295,11 +289,11 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
         */
        chunksize = sizeof(initack) + addrs_len + cookie_len + unkparam_len;
 
-        /* Tell peer that we'll do ECN only if peer advertised such cap.  */
+       /* Tell peer that we'll do ECN only if peer advertised such cap.  */
        if (asoc->peer.ecn_capable)
                chunksize += sizeof(ecap_param);
 
-        /* Tell peer that we'll do PR-SCTP only if peer advertised.  */
+       /* Tell peer that we'll do PR-SCTP only if peer advertised.  */
        if (asoc->peer.prsctp_capable)
                chunksize += sizeof(prsctp_param);
 
@@ -728,7 +722,7 @@ struct sctp_chunk *sctp_make_shutdown_complete(
        if (retval && chunk)
                retval->transport = chunk->transport;
 
-        return retval;
+       return retval;
 }
 
 /* Create an ABORT.  Note that we set the T bit if we have no
@@ -785,8 +779,8 @@ struct sctp_chunk *sctp_make_abort_no_data(
 
        /* Put the tsn back into network byte order.  */
        payload = htonl(tsn);
-       sctp_init_cause(retval, SCTP_ERROR_NO_DATA, (const void *)&payload,
-                       sizeof(payload));
+       sctp_init_cause(retval, SCTP_ERROR_NO_DATA, sizeof(payload));
+       sctp_addto_chunk(retval, sizeof(payload), (const void *)&payload);
 
        /* RFC 2960 6.4 Multi-homed SCTP Endpoints
         *
@@ -828,7 +822,8 @@ struct sctp_chunk *sctp_make_abort_user(const struct sctp_association *asoc,
                        goto err_copy;
        }
 
-       sctp_init_cause(retval, SCTP_ERROR_USER_ABORT, payload, paylen);
+       sctp_init_cause(retval, SCTP_ERROR_USER_ABORT, paylen);
+       sctp_addto_chunk(retval, paylen, payload);
 
        if (paylen)
                kfree(payload);
@@ -844,7 +839,7 @@ err_chunk:
        return retval;
 }
 
-/* Make an ABORT chunk with a PROTOCOL VIOLATION cause code. */ 
+/* Make an ABORT chunk with a PROTOCOL VIOLATION cause code. */
 struct sctp_chunk *sctp_make_abort_violation(
        const struct sctp_association *asoc,
        const struct sctp_chunk *chunk,
@@ -855,15 +850,17 @@ struct sctp_chunk *sctp_make_abort_violation(
        struct sctp_paramhdr phdr;
 
        retval = sctp_make_abort(asoc, chunk, sizeof(sctp_errhdr_t) + paylen
-                                       + sizeof(sctp_chunkhdr_t));
+                                       + sizeof(sctp_paramhdr_t));
        if (!retval)
                goto end;
 
-       sctp_init_cause(retval, SCTP_ERROR_PROTO_VIOLATION, payload, paylen);
+       sctp_init_cause(retval, SCTP_ERROR_PROTO_VIOLATION, paylen
+                                       + sizeof(sctp_paramhdr_t));
 
        phdr.type = htons(chunk->chunk_hdr->type);
        phdr.length = chunk->chunk_hdr->length;
-       sctp_addto_chunk(retval, sizeof(sctp_paramhdr_t), &phdr);
+       sctp_addto_chunk(retval, paylen, payload);
+       sctp_addto_param(retval, sizeof(sctp_paramhdr_t), &phdr);
 
 end:
        return retval;
@@ -960,7 +957,8 @@ struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,
        if (!retval)
                goto nodata;
 
-       sctp_init_cause(retval, cause_code, payload, paylen);
+       sctp_init_cause(retval, cause_code, paylen);
+       sctp_addto_chunk(retval, paylen, payload);
 
 nodata:
        return retval;
@@ -979,11 +977,10 @@ struct sctp_chunk *sctp_chunkify(struct sk_buff *skb,
 {
        struct sctp_chunk *retval;
 
-       retval = kmem_cache_alloc(sctp_chunk_cachep, GFP_ATOMIC);
+       retval = kmem_cache_zalloc(sctp_chunk_cachep, GFP_ATOMIC);
 
        if (!retval)
                goto nodata;
-       memset(retval, 0, sizeof(struct sctp_chunk));
 
        if (!sk) {
                SCTP_DEBUG_PRINTK("chunkifying skb %p w/o an sk\n", skb);
@@ -1134,7 +1131,7 @@ void *sctp_addto_chunk(struct sctp_chunk *chunk, int len, const void *data)
        void *target;
        void *padding;
        int chunklen = ntohs(chunk->chunk_hdr->length);
-       int padlen = chunklen % 4;
+       int padlen = WORD_ROUND(chunklen) - chunklen;
 
        padding = skb_put(chunk->skb, padlen);
        target = skb_put(chunk->skb, len);
@@ -1144,7 +1141,26 @@ void *sctp_addto_chunk(struct sctp_chunk *chunk, int len, const void *data)
 
        /* Adjust the chunk length field.  */
        chunk->chunk_hdr->length = htons(chunklen + padlen + len);
-       chunk->chunk_end = chunk->skb->tail;
+       chunk->chunk_end = skb_tail_pointer(chunk->skb);
+
+       return target;
+}
+
+/* Append bytes to the end of a parameter.  Will panic if chunk is not big
+ * enough.
+ */
+void *sctp_addto_param(struct sctp_chunk *chunk, int len, const void *data)
+{
+       void *target;
+       int chunklen = ntohs(chunk->chunk_hdr->length);
+
+       target = skb_put(chunk->skb, len);
+
+       memcpy(target, data, len);
+
+       /* Adjust the chunk length field.  */
+       chunk->chunk_hdr->length = htons(chunklen + len);
+       chunk->chunk_end = skb_tail_pointer(chunk->skb);
 
        return target;
 }
@@ -1169,7 +1185,7 @@ int sctp_user_addto_chunk(struct sctp_chunk *chunk, int off, int len,
        /* Adjust the chunk length field.  */
        chunk->chunk_hdr->length =
                htons(ntohs(chunk->chunk_hdr->length) + len);
-       chunk->chunk_end = chunk->skb->tail;
+       chunk->chunk_end = skb_tail_pointer(chunk->skb);
 
 out:
        return err;
@@ -1180,25 +1196,36 @@ out:
  */
 void sctp_chunk_assign_ssn(struct sctp_chunk *chunk)
 {
+       struct sctp_datamsg *msg;
+       struct sctp_chunk *lchunk;
+       struct sctp_stream *stream;
        __u16 ssn;
        __u16 sid;
 
        if (chunk->has_ssn)
                return;
 
-       /* This is the last possible instant to assign a SSN. */
-       if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
-               ssn = 0;
-       } else {
-               sid = ntohs(chunk->subh.data_hdr->stream);
-               if (chunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG)
-                       ssn = sctp_ssn_next(&chunk->asoc->ssnmap->out, sid);
-               else
-                       ssn = sctp_ssn_peek(&chunk->asoc->ssnmap->out, sid);
-       }
+       /* All fragments will be on the same stream */
+       sid = ntohs(chunk->subh.data_hdr->stream);
+       stream = &chunk->asoc->ssnmap->out;
+
+       /* Now assign the sequence number to the entire message.
+        * All fragments must have the same stream sequence number.
+        */
+       msg = chunk->msg;
+       list_for_each_entry(lchunk, &msg->chunks, frag_list) {
+               if (lchunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
+                       ssn = 0;
+               } else {
+                       if (lchunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG)
+                               ssn = sctp_ssn_next(stream, sid);
+                       else
+                               ssn = sctp_ssn_peek(stream, sid);
+               }
 
-       chunk->subh.data_hdr->ssn = htons(ssn);
-       chunk->has_ssn = 1;
+               lchunk->subh.data_hdr->ssn = htons(ssn);
+               lchunk->has_ssn = 1;
+       }
 }
 
 /* Helper function to assign a TSN if needed.  This assumes that both
@@ -1234,7 +1261,7 @@ struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *ep,
        asoc->temp = 1;
        skb = chunk->skb;
        /* Create an entry for the source address of the packet.  */
-       af = sctp_get_af_specific(ipver2af(skb->nh.iph->version));
+       af = sctp_get_af_specific(ipver2af(ip_hdr(skb)->version));
        if (unlikely(!af))
                goto fail;
        af->from_skb(&asoc->c.peer_addr, skb, 1);
@@ -1265,8 +1292,8 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
        /* Header size is static data prior to the actual cookie, including
         * any padding.
         */
-       headersize = sizeof(sctp_paramhdr_t) + 
-                    (sizeof(struct sctp_signed_cookie) - 
+       headersize = sizeof(sctp_paramhdr_t) +
+                    (sizeof(struct sctp_signed_cookie) -
                      sizeof(struct sctp_cookie));
        bodysize = sizeof(struct sctp_cookie)
                + ntohs(init_chunk->chunk_hdr->length) + addrs_len;
@@ -1315,7 +1342,7 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
        memcpy((__u8 *)&cookie->c.peer_init[0] +
               ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len);
 
-       if (sctp_sk(ep->base.sk)->hmac) {
+       if (sctp_sk(ep->base.sk)->hmac) {
                struct hash_desc desc;
 
                /* Sign the message.  */
@@ -1324,8 +1351,8 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
                sg.length = bodysize;
                keylen = SCTP_SECRET_SIZE;
                key = (char *)ep->secret_key[ep->current_key];
-               desc.tfm = sctp_sk(ep->base.sk)->hmac;
-               desc.flags = 0;
+               desc.tfm = sctp_sk(ep->base.sk)->hmac;
+               desc.flags = 0;
 
                if (crypto_hash_setkey(desc.tfm, key, keylen) ||
                    crypto_hash_digest(&desc, &sg, bodysize, cookie->signature))
@@ -1365,7 +1392,7 @@ struct sctp_association *sctp_unpack_cookie(
         * any padding.
         */
        headersize = sizeof(sctp_chunkhdr_t) +
-                    (sizeof(struct sctp_signed_cookie) - 
+                    (sizeof(struct sctp_signed_cookie) -
                      sizeof(struct sctp_cookie));
        bodysize = ntohs(chunk->chunk_hdr->length) - headersize;
        fixed_size = headersize + sizeof(struct sctp_cookie);
@@ -1455,7 +1482,6 @@ no_hmac:
                do_gettimeofday(&tv);
 
        if (!asoc && tv_lt(bear_cookie->expiration, tv)) {
-               __u16 len;
                /*
                 * Section 3.3.10.3 Stale Cookie Error (3)
                 *
@@ -1473,7 +1499,8 @@ no_hmac:
                        __be32 n = htonl(usecs);
 
                        sctp_init_cause(*errp, SCTP_ERROR_STALE_COOKIE,
-                                       &n, sizeof(n));
+                                       sizeof(n));
+                       sctp_addto_chunk(*errp, sizeof(n), &n);
                        *error = -SCTP_IERROR_STALE_COOKIE;
                } else
                        *error = -SCTP_IERROR_NOMEM;
@@ -1504,7 +1531,7 @@ no_hmac:
        /* Also, add the destination address. */
        if (list_empty(&retval->base.bind_addr.address_list)) {
                sctp_add_bind_addr(&retval->base.bind_addr, &chunk->dest, 1,
-                                  GFP_ATOMIC);
+                               GFP_ATOMIC);
        }
 
        retval->next_tsn = retval->c.initial_tsn;
@@ -1562,8 +1589,9 @@ static int sctp_process_missing_param(const struct sctp_association *asoc,
        if (*errp) {
                report.num_missing = htonl(1);
                report.type = paramtype;
-               sctp_init_cause(*errp, SCTP_ERROR_INV_PARAM,
-                               &report, sizeof(report));
+               sctp_init_cause(*errp, SCTP_ERROR_MISS_PARAM,
+                               sizeof(report));
+               sctp_addto_chunk(*errp, sizeof(report), &report);
        }
 
        /* Stop processing this chunk. */
@@ -1581,7 +1609,7 @@ static int sctp_process_inv_mandatory(const struct sctp_association *asoc,
                *errp = sctp_make_op_error_space(asoc, chunk, 0);
 
        if (*errp)
-               sctp_init_cause(*errp, SCTP_ERROR_INV_PARAM, NULL, 0);
+               sctp_init_cause(*errp, SCTP_ERROR_INV_PARAM, 0);
 
        /* Stop processing this chunk. */
        return 0;
@@ -1593,7 +1621,7 @@ static int sctp_process_inv_paramlength(const struct sctp_association *asoc,
                                        struct sctp_chunk **errp)
 {
        char            error[] = "The following parameter had invalid length:";
-       size_t          payload_len = WORD_ROUND(sizeof(error)) + 
+       size_t          payload_len = WORD_ROUND(sizeof(error)) +
                                                sizeof(sctp_paramhdr_t);
 
 
@@ -1602,9 +1630,10 @@ static int sctp_process_inv_paramlength(const struct sctp_association *asoc,
                *errp = sctp_make_op_error_space(asoc, chunk, payload_len);
 
        if (*errp) {
-               sctp_init_cause(*errp, SCTP_ERROR_PROTO_VIOLATION, error,
-                               sizeof(error));
-               sctp_addto_chunk(*errp, sizeof(sctp_paramhdr_t), param);
+               sctp_init_cause(*errp, SCTP_ERROR_PROTO_VIOLATION,
+                               sizeof(error) + sizeof(sctp_paramhdr_t));
+               sctp_addto_chunk(*errp, sizeof(error), error);
+               sctp_addto_param(*errp, sizeof(sctp_paramhdr_t), param);
        }
 
        return 0;
@@ -1625,9 +1654,10 @@ static int sctp_process_hn_param(const struct sctp_association *asoc,
        if (!*errp)
                *errp = sctp_make_op_error_space(asoc, chunk, len);
 
-       if (*errp)
-               sctp_init_cause(*errp, SCTP_ERROR_DNS_FAILED,
-                               param.v, len);
+       if (*errp) {
+               sctp_init_cause(*errp, SCTP_ERROR_DNS_FAILED, len);
+               sctp_addto_chunk(*errp, len, param.v);
+       }
 
        /* Stop processing this chunk. */
        return 0;
@@ -1679,10 +1709,13 @@ static int sctp_process_unk_param(const struct sctp_association *asoc,
                        *errp = sctp_make_op_error_space(asoc, chunk,
                                        ntohs(chunk->chunk_hdr->length));
 
-               if (*errp)
+               if (*errp) {
                        sctp_init_cause(*errp, SCTP_ERROR_UNKNOWN_PARAM,
-                                       param.v,
                                        WORD_ROUND(ntohs(param.p->length)));
+                       sctp_addto_chunk(*errp,
+                                       WORD_ROUND(ntohs(param.p->length)),
+                                       param.v);
+               }
 
                break;
        case SCTP_PARAM_ACTION_SKIP:
@@ -1697,8 +1730,10 @@ static int sctp_process_unk_param(const struct sctp_association *asoc,
 
                if (*errp) {
                        sctp_init_cause(*errp, SCTP_ERROR_UNKNOWN_PARAM,
-                                       param.v,
                                        WORD_ROUND(ntohs(param.p->length)));
+                       sctp_addto_chunk(*errp,
+                                       WORD_ROUND(ntohs(param.p->length)),
+                                       param.v);
                } else {
                        /* If there is no memory for generating the ERROR
                         * report as specified, an ABORT will be triggered
@@ -1752,7 +1787,7 @@ static int sctp_verify_param(const struct sctp_association *asoc,
        case SCTP_PARAM_FWD_TSN_SUPPORT:
                if (sctp_prsctp_enable)
                        break;
-               /* Fall Through */ 
+               /* Fall Through */
        default:
                SCTP_DEBUG_PRINTK("Unrecognized param: %d for chunk %d.\n",
                                ntohs(param.p->type), cid);
@@ -1775,7 +1810,9 @@ int sctp_verify_init(const struct sctp_association *asoc,
 
        /* Verify stream values are non-zero. */
        if ((0 == peer_init->init_hdr.num_outbound_streams) ||
-           (0 == peer_init->init_hdr.num_inbound_streams)) {
+           (0 == peer_init->init_hdr.num_inbound_streams) ||
+           (0 == peer_init->init_hdr.init_tag) ||
+           (SCTP_DEFAULT_MINWINDOW > ntohl(peer_init->init_hdr.a_rwnd))) {
 
                sctp_process_inv_mandatory(asoc, chunk, errp);
                return 0;
@@ -1796,7 +1833,7 @@ int sctp_verify_init(const struct sctp_association *asoc,
         * VIOLATION error.  We build the ERROR chunk here and let the normal
         * error handling code build and send the packet.
         */
-       if (param.v < (void*)chunk->chunk_end - sizeof(sctp_paramhdr_t)) {
+       if (param.v != (void*)chunk->chunk_end) {
                sctp_process_inv_paramlength(asoc, param.p, chunk, errp);
                return 0;
        }
@@ -1859,7 +1896,7 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
        sctp_walk_params(param, peer_init, init_hdr.params) {
 
                if (!sctp_process_param(asoc, param, peer_addr, gfp))
-                        goto clean_up;
+                       goto clean_up;
        }
 
        /* Walk list of transports, removing transports in the UNKNOWN state. */
@@ -1935,10 +1972,9 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
         */
 
        /* Allocate storage for the negotiated streams if it is not a temporary
-        * association.
+        * association.
         */
        if (!asoc->temp) {
-               int assoc_id;
                int error;
 
                asoc->ssnmap = sctp_ssnmap_new(asoc->c.sinit_max_instreams,
@@ -1946,19 +1982,9 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
                if (!asoc->ssnmap)
                        goto clean_up;
 
-       retry:
-               if (unlikely(!idr_pre_get(&sctp_assocs_id, gfp)))
+               error = sctp_assoc_set_id(asoc, gfp);
+               if (error)
                        goto clean_up;
-               spin_lock_bh(&sctp_assocs_id_lock);
-               error = idr_get_new_above(&sctp_assocs_id, (void *)asoc, 1,
-                                         &assoc_id);
-               spin_unlock_bh(&sctp_assocs_id_lock);
-               if (error == -EAGAIN)
-                       goto retry;
-               else if (error)
-                       goto clean_up;
-
-               asoc->assoc_id = (sctp_assoc_t) assoc_id;
        }
 
        /* ADDIP Section 4.1 ASCONF Chunk Procedures
@@ -2076,7 +2102,7 @@ static int sctp_process_param(struct sctp_association *asoc,
 
                        default: /* Just ignore anything else.  */
                                break;
-                       };
+                       }
                }
                break;
 
@@ -2107,7 +2133,7 @@ static int sctp_process_param(struct sctp_association *asoc,
                        asoc->peer.prsctp_capable = 1;
                        break;
                }
-               /* Fall Through */ 
+               /* Fall Through */
        default:
                /* Any unrecognized parameters should have been caught
                 * and handled by sctp_verify_param() which should be
@@ -2117,7 +2143,7 @@ static int sctp_process_param(struct sctp_association *asoc,
                SCTP_DEBUG_PRINTK("Ignoring param: %d for association %p.\n",
                                  ntohs(param.p->type), asoc);
                break;
-       };
+       }
 
        return retval;
 }
@@ -2166,7 +2192,7 @@ __u32 sctp_generate_tsn(const struct sctp_endpoint *ep)
  *     |                     ASCONF Parameter #N                       |
  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
- * Address Parameter and other parameter will not be wrapped in this function 
+ * Address Parameter and other parameter will not be wrapped in this function
  */
 static struct sctp_chunk *sctp_make_asconf(struct sctp_association *asoc,
                                           union sctp_addr *addr,
@@ -2288,7 +2314,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
  *     |                       Address Parameter                       |
  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
- * Create an ASCONF chunk with Set Primary IP address parameter. 
+ * Create an ASCONF chunk with Set Primary IP address parameter.
  */
 struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
                                             union sctp_addr *addr)
@@ -2337,7 +2363,7 @@ struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
  *     |                 ASCONF Parameter Response#N                   |
  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
- * Create an ASCONF_ACK chunk with enough space for the parameter responses. 
+ * Create an ASCONF_ACK chunk with enough space for the parameter responses.
  */
 static struct sctp_chunk *sctp_make_asconf_ack(const struct sctp_association *asoc,
                                               __u32 serial, int vparam_len)
@@ -2379,7 +2405,7 @@ static void sctp_add_asconf_response(struct sctp_chunk *chunk, __be32 crr_id,
                                 ntohs(asconf_param->param_hdr.length);
        }
 
-       /* Add Success Indication or Error Cause Indication parameter. */ 
+       /* Add Success Indication or Error Cause Indication parameter. */
        ack_param.param_hdr.type = response_type;
        ack_param.param_hdr.length = htons(sizeof(ack_param) +
                                           err_param_len +
@@ -2422,11 +2448,11 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
        switch (asconf_param->param_hdr.type) {
        case SCTP_PARAM_ADD_IP:
                /* ADDIP 4.3 D9) If an endpoint receives an ADD IP address
-                * request and does not have the local resources to add this
-                * new address to the association, it MUST return an Error
-                * Cause TLV set to the new error code 'Operation Refused
-                * Due to Resource Shortage'.
-                */
+                * request and does not have the local resources to add this
+                * new address to the association, it MUST return an Error
+                * Cause TLV set to the new error code 'Operation Refused
+                * Due to Resource Shortage'.
+                */
 
                peer = sctp_assoc_add_peer(asoc, &addr, GFP_ATOMIC, SCTP_UNCONFIRMED);
                if (!peer)
@@ -2438,10 +2464,10 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
                break;
        case SCTP_PARAM_DEL_IP:
                /* ADDIP 4.3 D7) If a request is received to delete the
-                * last remaining IP address of a peer endpoint, the receiver
-                * MUST send an Error Cause TLV with the error cause set to the
-                * new error code 'Request to Delete Last Remaining IP Address'.
-                */
+                * last remaining IP address of a peer endpoint, the receiver
+                * MUST send an Error Cause TLV with the error cause set to the
+                * new error code 'Request to Delete Last Remaining IP Address'.
+                */
                pos = asoc->peer.transport_addr_list.next;
                if (pos->next == &asoc->peer.transport_addr_list)
                        return SCTP_ERROR_DEL_LAST_IP;
@@ -2473,7 +2499,53 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
        return SCTP_ERROR_NO_ERROR;
 }
 
-/* Process an incoming ASCONF chunk with the next expected serial no. and 
+/* Verify the ASCONF packet before we process it.  */
+int sctp_verify_asconf(const struct sctp_association *asoc,
+                      struct sctp_paramhdr *param_hdr, void *chunk_end,
+                      struct sctp_paramhdr **errp) {
+       sctp_addip_param_t *asconf_param;
+       union sctp_params param;
+       int length, plen;
+
+       param.v = (sctp_paramhdr_t *) param_hdr;
+       while (param.v <= chunk_end - sizeof(sctp_paramhdr_t)) {
+               length = ntohs(param.p->length);
+               *errp = param.p;
+
+               if (param.v > chunk_end - length ||
+                   length < sizeof(sctp_paramhdr_t))
+                       return 0;
+
+               switch (param.p->type) {
+               case SCTP_PARAM_ADD_IP:
+               case SCTP_PARAM_DEL_IP:
+               case SCTP_PARAM_SET_PRIMARY:
+                       asconf_param = (sctp_addip_param_t *)param.v;
+                       plen = ntohs(asconf_param->param_hdr.length);
+                       if (plen < sizeof(sctp_addip_param_t) +
+                           sizeof(sctp_paramhdr_t))
+                               return 0;
+                       break;
+               case SCTP_PARAM_SUCCESS_REPORT:
+               case SCTP_PARAM_ADAPTATION_LAYER_IND:
+                       if (length != sizeof(sctp_addip_param_t))
+                               return 0;
+
+                       break;
+               default:
+                       break;
+               }
+
+               param.v += WORD_ROUND(length);
+       }
+
+       if (param.v != chunk_end)
+               return 0;
+
+       return 1;
+}
+
+/* Process an incoming ASCONF chunk with the next expected serial no. and
  * return an ASCONF_ACK chunk to be sent in response.
  */
 struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
@@ -2493,19 +2565,19 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
        hdr = (sctp_addiphdr_t *)asconf->skb->data;
        serial = ntohl(hdr->serial);
 
-       /* Skip the addiphdr and store a pointer to address parameter.  */ 
+       /* Skip the addiphdr and store a pointer to address parameter.  */
        length = sizeof(sctp_addiphdr_t);
        addr_param = (union sctp_addr_param *)(asconf->skb->data + length);
        chunk_len -= length;
 
        /* Skip the address parameter and store a pointer to the first
         * asconf paramter.
-        */ 
+        */
        length = ntohs(addr_param->v4.param_hdr.length);
        asconf_param = (sctp_addip_param_t *)((void *)addr_param + length);
        chunk_len -= length;
 
-       /* create an ASCONF_ACK chunk. 
+       /* create an ASCONF_ACK chunk.
         * Based on the definitions of parameters, we know that the size of
         * ASCONF_ACK parameters are less than or equal to the twice of ASCONF
         * paramters.
@@ -2536,7 +2608,7 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
                /* ADDIP 4.3 D11) When an endpoint receiving an ASCONF to add
                 * an IP address sends an 'Out of Resource' in its response, it
                 * MUST also fail any subsequent add or delete requests bundled
-                * in the ASCONF. 
+                * in the ASCONF.
                 */
                if (SCTP_ERROR_RSRC_LOW == err_code)
                        goto done;
@@ -2547,12 +2619,12 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
                                                      length);
                chunk_len -= length;
        }
-       
+
 done:
        asoc->peer.addip_serial++;
 
        /* If we are sending a new ASCONF_ACK hold a reference to it in assoc
-        * after freeing the reference to old asconf ack if any. 
+        * after freeing the reference to old asconf ack if any.
         */
        if (asconf_ack) {
                if (asoc->addip_last_asconf_ack)
@@ -2587,22 +2659,16 @@ static int sctp_asconf_param_success(struct sctp_association *asoc,
 
        switch (asconf_param->param_hdr.type) {
        case SCTP_PARAM_ADD_IP:
-               sctp_local_bh_disable();
-               sctp_write_lock(&asoc->base.addr_lock);
-               list_for_each(pos, &bp->address_list) {
-                       saddr = list_entry(pos, struct sctp_sockaddr_entry, list);
+               /* This is always done in BH context with a socket lock
+                * held, so the list can not change.
+                */
+               list_for_each_entry(saddr, &bp->address_list, list) {
                        if (sctp_cmp_addr_exact(&saddr->a, &addr))
                                saddr->use_as_src = 1;
                }
-               sctp_write_unlock(&asoc->base.addr_lock);
-               sctp_local_bh_enable();
                break;
        case SCTP_PARAM_DEL_IP:
-               sctp_local_bh_disable();
-               sctp_write_lock(&asoc->base.addr_lock);
-               retval = sctp_del_bind_addr(bp, &addr);
-               sctp_write_unlock(&asoc->base.addr_lock);
-               sctp_local_bh_enable();
+               retval = sctp_del_bind_addr(bp, &addr, call_rcu_bh);
                list_for_each(pos, &asoc->peer.transport_addr_list) {
                        transport = list_entry(pos, struct sctp_transport,
                                                 transports);
@@ -2620,7 +2686,7 @@ static int sctp_asconf_param_success(struct sctp_association *asoc,
 
 /* Get the corresponding ASCONF response error code from the ASCONF_ACK chunk
  * for the given asconf parameter.  If there is no response for this parameter,
- * return the error code based on the third argument 'no_err'. 
+ * return the error code based on the third argument 'no_err'.
  * ADDIP 4.1
  * A7) If an error response is received for a TLV parameter, all TLVs with no
  * response before the failed TLV are considered successful if not reported.
@@ -2644,7 +2710,7 @@ static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
 
        /* Skip the addiphdr from the asconf_ack chunk and store a pointer to
         * the first asconf_ack parameter.
-        */ 
+        */
        length = sizeof(sctp_addiphdr_t);
        asconf_ack_param = (sctp_addip_param_t *)(asconf_ack->skb->data +
                                                  length);
@@ -2695,14 +2761,14 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
 
        /* Skip the chunkhdr and addiphdr from the last asconf sent and store
         * a pointer to address parameter.
-        */ 
+        */
        length = sizeof(sctp_addip_chunk_t);
        addr_param = (union sctp_addr_param *)(asconf->skb->data + length);
        asconf_len -= length;
 
        /* Skip the address parameter in the last asconf sent and store a
         * pointer to the first asconf paramter.
-        */ 
+        */
        length = ntohs(addr_param->v4.param_hdr.length);
        asconf_param = (sctp_addip_param_t *)((void *)addr_param + length);
        asconf_len -= length;
@@ -2739,7 +2805,7 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
                case SCTP_ERROR_INV_PARAM:
                        /* Disable sending this type of asconf parameter in
                         * future.
-                        */     
+                        */
                        asoc->peer.addip_disabled_mask |=
                                asconf_param->param_hdr.type;
                        break;
@@ -2753,7 +2819,7 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
 
                /* Skip the processed asconf parameter and move to the next
                 * one.
-                */ 
+                */
                length = ntohs(asconf_param->param_hdr.length);
                asconf_param = (sctp_addip_param_t *)((void *)asconf_param +
                                                      length);
@@ -2782,14 +2848,14 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
        return retval;
 }
 
-/* Make a FWD TSN chunk. */ 
+/* Make a FWD TSN chunk. */
 struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
                                    __u32 new_cum_tsn, size_t nstreams,
                                    struct sctp_fwdtsn_skip *skiplist)
 {
        struct sctp_chunk *retval = NULL;
        struct sctp_fwdtsn_chunk *ftsn_chunk;
-       struct sctp_fwdtsn_hdr ftsn_hdr; 
+       struct sctp_fwdtsn_hdr ftsn_hdr;
        struct sctp_fwdtsn_skip skip;
        size_t hint;
        int i;