sctp: delete the nested flexible array params
authorXin Long <lucien.xin@gmail.com>
Wed, 19 Apr 2023 15:16:28 +0000 (11:16 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 21 Apr 2023 07:19:29 +0000 (08:19 +0100)
This patch deletes the flexible-array params[] from the structure
sctp_inithdr, sctp_addiphdr and sctp_reconf_chunk to avoid some
sparse warnings:

  # make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
  net/sctp/input.c: note: in included file (through include/net/sctp/structs.h, include/net/sctp/sctp.h):
  ./include/linux/sctp.h:278:29: warning: nested flexible array
  ./include/linux/sctp.h:675:30: warning: nested flexible array

This warning is reported if a structure having a flexible array
member is included by other structures.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/sctp.h
include/net/sctp/sctp.h
net/sctp/input.c
net/sctp/sm_make_chunk.c
net/sctp/sm_statefuns.c
net/sctp/stream.c

index 358dc08..0ff36a2 100644 (file)
@@ -270,7 +270,7 @@ struct sctp_inithdr {
        __be16 num_outbound_streams;
        __be16 num_inbound_streams;
        __be32 initial_tsn;
-       __u8  params[];
+       /* __u8  params[]; */
 };
 
 struct sctp_init_chunk {
@@ -667,7 +667,7 @@ struct sctp_addip_param {
 
 struct sctp_addiphdr {
        __be32  serial;
-       __u8    params[];
+       /* __u8 params[]; */
 };
 
 struct sctp_addip_chunk {
@@ -742,7 +742,7 @@ struct sctp_infox {
 
 struct sctp_reconf_chunk {
        struct sctp_chunkhdr chunk_hdr;
-       __u8 params[];
+       /* __u8 params[]; */
 };
 
 struct sctp_strreset_outreq {
index c335dd0..74fae53 100644 (file)
@@ -425,11 +425,11 @@ static inline bool sctp_chunk_pending(const struct sctp_chunk *chunk)
  * the chunk length to indicate when to stop.  Make sure
  * there is room for a param header too.
  */
-#define sctp_walk_params(pos, chunk, member)\
-_sctp_walk_params((pos), (chunk), ntohs((chunk)->chunk_hdr.length), member)
+#define sctp_walk_params(pos, chunk)\
+_sctp_walk_params((pos), (chunk), ntohs((chunk)->chunk_hdr.length))
 
-#define _sctp_walk_params(pos, chunk, end, member)\
-for (pos.v = chunk->member;\
+#define _sctp_walk_params(pos, chunk, end)\
+for (pos.v = (u8 *)(chunk + 1);\
      (pos.v + offsetof(struct sctp_paramhdr, length) + sizeof(pos.p->length) <=\
       (void *)chunk + end) &&\
      pos.v <= (void *)chunk + end - ntohs(pos.p->length) &&\
index 127bf28..2613c4d 100644 (file)
@@ -1150,7 +1150,7 @@ static struct sctp_association *__sctp_rcv_init_lookup(struct net *net,
        init = (struct sctp_init_chunk *)skb->data;
 
        /* Walk the parameters looking for embedded addresses. */
-       sctp_walk_params(params, init, init_hdr.params) {
+       sctp_walk_params(params, init) {
 
                /* Note: Ignoring hostname addresses. */
                af = sctp_get_af_specific(param_type2af(params.p->type));
index c8f4ec5..4dbbbc2 100644 (file)
@@ -2306,7 +2306,7 @@ int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep,
            ntohl(peer_init->init_hdr.a_rwnd) < SCTP_DEFAULT_MINWINDOW)
                return sctp_process_inv_mandatory(asoc, chunk, errp);
 
-       sctp_walk_params(param, peer_init, init_hdr.params) {
+       sctp_walk_params(param, peer_init) {
                if (param.p->type == SCTP_PARAM_STATE_COOKIE)
                        has_cookie = true;
        }
@@ -2329,7 +2329,7 @@ int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep,
                                                  chunk, errp);
 
        /* Verify all the variable length parameters */
-       sctp_walk_params(param, peer_init, init_hdr.params) {
+       sctp_walk_params(param, peer_init) {
                result = sctp_verify_param(net, ep, asoc, param, cid,
                                           chunk, errp);
                switch (result) {
@@ -2381,7 +2381,7 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
                src_match = 1;
 
        /* Process the initialization parameters.  */
-       sctp_walk_params(param, peer_init, init_hdr.params) {
+       sctp_walk_params(param, peer_init) {
                if (!src_match &&
                    (param.p->type == SCTP_PARAM_IPV4_ADDRESS ||
                     param.p->type == SCTP_PARAM_IPV6_ADDRESS)) {
@@ -3202,7 +3202,7 @@ bool sctp_verify_asconf(const struct sctp_association *asoc,
        union sctp_params param;
 
        addip = (struct sctp_addip_chunk *)chunk->chunk_hdr;
-       sctp_walk_params(param, addip, addip_hdr.params) {
+       sctp_walk_params(param, addip) {
                size_t length = ntohs(param.p->length);
 
                *errp = param.p;
@@ -3215,14 +3215,14 @@ bool sctp_verify_asconf(const struct sctp_association *asoc,
                        /* ensure there is only one addr param and it's in the
                         * beginning of addip_hdr params, or we reject it.
                         */
-                       if (param.v != addip->addip_hdr.params)
+                       if (param.v != (addip + 1))
                                return false;
                        addr_param_seen = true;
                        break;
                case SCTP_PARAM_IPV6_ADDRESS:
                        if (length != sizeof(struct sctp_ipv6addr_param))
                                return false;
-                       if (param.v != addip->addip_hdr.params)
+                       if (param.v != (addip + 1))
                                return false;
                        addr_param_seen = true;
                        break;
@@ -3302,7 +3302,7 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
                goto done;
 
        /* Process the TLVs contained within the ASCONF chunk. */
-       sctp_walk_params(param, addip, addip_hdr.params) {
+       sctp_walk_params(param, addip) {
                /* Skip preceeding address parameters. */
                if (param.p->type == SCTP_PARAM_IPV4_ADDRESS ||
                    param.p->type == SCTP_PARAM_IPV6_ADDRESS)
@@ -3636,7 +3636,7 @@ static struct sctp_chunk *sctp_make_reconf(const struct sctp_association *asoc,
                return NULL;
 
        reconf = (struct sctp_reconf_chunk *)retval->chunk_hdr;
-       retval->param_hdr.v = reconf->params;
+       retval->param_hdr.v = (u8 *)(reconf + 1);
 
        return retval;
 }
@@ -3878,7 +3878,7 @@ bool sctp_verify_reconf(const struct sctp_association *asoc,
        __u16 cnt = 0;
 
        hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
-       sctp_walk_params(param, hdr, params) {
+       sctp_walk_params(param, hdr) {
                __u16 length = ntohs(param.p->length);
 
                *errp = param.p;
index ce54261..39d416e 100644 (file)
@@ -4142,7 +4142,7 @@ enum sctp_disposition sctp_sf_do_reconf(struct net *net,
                                                  (void *)err_param, commands);
 
        hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
-       sctp_walk_params(param, hdr, params) {
+       sctp_walk_params(param, hdr) {
                struct sctp_chunk *reply = NULL;
                struct sctp_ulpevent *ev = NULL;
 
index ee6514a..c241cc5 100644 (file)
@@ -491,7 +491,7 @@ static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param(
                return NULL;
 
        hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
-       sctp_walk_params(param, hdr, params) {
+       sctp_walk_params(param, hdr) {
                /* sctp_strreset_tsnreq is actually the basic structure
                 * of all stream reconf params, so it's safe to use it
                 * to access request_seq.