Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[platform/kernel/linux-starfive.git] / net / sctp / sm_make_chunk.c
index b0eaa93..6c08e50 100644 (file)
@@ -2195,9 +2195,16 @@ static enum sctp_ierror sctp_verify_param(struct net *net,
                break;
 
        case SCTP_PARAM_SET_PRIMARY:
-               if (ep->asconf_enable)
-                       break;
-               goto unhandled;
+               if (!ep->asconf_enable)
+                       goto unhandled;
+
+               if (ntohs(param.p->length) < sizeof(struct sctp_addip_param) +
+                                            sizeof(struct sctp_paramhdr)) {
+                       sctp_process_inv_paramlength(asoc, param.p,
+                                                    chunk, err_chunk);
+                       retval = SCTP_IERROR_ABORT;
+               }
+               break;
 
        case SCTP_PARAM_HOST_NAME_ADDRESS:
                /* Tell the peer, we won't support this param.  */
@@ -2375,11 +2382,13 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
 
        /* Process the initialization parameters.  */
        sctp_walk_params(param, peer_init, init_hdr.params) {
-               if (!src_match && (param.p->type == SCTP_PARAM_IPV4_ADDRESS ||
-                   param.p->type == SCTP_PARAM_IPV6_ADDRESS)) {
+               if (!src_match &&
+                   (param.p->type == SCTP_PARAM_IPV4_ADDRESS ||
+                    param.p->type == SCTP_PARAM_IPV6_ADDRESS)) {
                        af = sctp_get_af_specific(param_type2af(param.p->type));
-                       af->from_addr_param(&addr, param.addr,
-                                           chunk->sctp_hdr->source, 0);
+                       if (!af->from_addr_param(&addr, param.addr,
+                                                chunk->sctp_hdr->source, 0))
+                               continue;
                        if (sctp_cmp_addr_exact(sctp_source(chunk), &addr))
                                src_match = 1;
                }
@@ -2560,7 +2569,8 @@ static int sctp_process_param(struct sctp_association *asoc,
                        break;
 do_addr_param:
                af = sctp_get_af_specific(param_type2af(param.p->type));
-               af->from_addr_param(&addr, param.addr, htons(asoc->peer.port), 0);
+               if (!af->from_addr_param(&addr, param.addr, htons(asoc->peer.port), 0))
+                       break;
                scope = sctp_scope(peer_addr);
                if (sctp_in_scope(net, &addr, scope))
                        if (!sctp_assoc_add_peer(asoc, &addr, gfp, SCTP_UNCONFIRMED))
@@ -2661,15 +2671,13 @@ do_addr_param:
                addr_param = param.v + sizeof(struct sctp_addip_param);
 
                af = sctp_get_af_specific(param_type2af(addr_param->p.type));
-               if (af == NULL)
+               if (!af)
                        break;
 
-               af->from_addr_param(&addr, addr_param,
-                                   htons(asoc->peer.port), 0);
+               if (!af->from_addr_param(&addr, addr_param,
+                                        htons(asoc->peer.port), 0))
+                       break;
 
-               /* if the address is invalid, we can't process it.
-                * XXX: see spec for what to do.
-                */
                if (!af->addr_valid(&addr, NULL, NULL))
                        break;
 
@@ -3083,7 +3091,8 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
        if (unlikely(!af))
                return SCTP_ERROR_DNS_FAILED;
 
-       af->from_addr_param(&addr, addr_param, htons(asoc->peer.port), 0);
+       if (!af->from_addr_param(&addr, addr_param, htons(asoc->peer.port), 0))
+               return SCTP_ERROR_DNS_FAILED;
 
        /* ADDIP 4.2.1  This parameter MUST NOT contain a broadcast
         * or multicast address.
@@ -3360,7 +3369,8 @@ static void sctp_asconf_param_success(struct sctp_association *asoc,
 
        /* We have checked the packet before, so we do not check again. */
        af = sctp_get_af_specific(param_type2af(addr_param->p.type));
-       af->from_addr_param(&addr, addr_param, htons(bp->port), 0);
+       if (!af->from_addr_param(&addr, addr_param, htons(bp->port), 0))
+               return;
 
        switch (asconf_param->param_hdr.type) {
        case SCTP_PARAM_ADD_IP: