* [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings
@ 2023-04-19 15:16 Xin Long
2023-04-19 15:16 ` [PATCH net-next 1/6] sctp: delete the nested flexible array params Xin Long
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Xin Long @ 2023-04-19 15:16 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Marcelo Ricardo Leitner
Paolo noticed a compile warning in SCTP,
../net/sctp/stream_sched_fc.c: note: in included file (through ../include/net/sctp/sctp.h):
../include/net/sctp/structs.h:335:41: warning: array of flexible structures
But not only this, there are actually quite a lot of such warnings in
some SCTP structs. This patchset fixes most of warnings by deleting
these nested flexible array members.
After this patchset, there are still some warnings left:
# make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
./include/net/sctp/structs.h:1145:41: warning: nested flexible array
./include/uapi/linux/sctp.h:641:34: warning: nested flexible array
./include/uapi/linux/sctp.h:643:34: warning: nested flexible array
./include/uapi/linux/sctp.h:644:33: warning: nested flexible array
./include/uapi/linux/sctp.h:650:40: warning: nested flexible array
./include/uapi/linux/sctp.h:653:39: warning: nested flexible array
the 1st is caused by __data[] in struct ip_options, not in SCTP;
the others are in uapi, and we should not touch them.
Note that instead of completely deleting it, we just leave it as a
comment in the struct, signalling to the reader that we do expect
such variable parameters over there, as Marcelo suggested.
Xin Long (6):
sctp: delete the nested flexible array params
sctp: delete the nested flexible array skip
sctp: delete the nested flexible array variable
sctp: delete the nested flexible array peer_init
sctp: delete the nested flexible array hmac
sctp: delete the nested flexible array payload
include/linux/sctp.h | 18 +++++++++---------
include/net/sctp/sctp.h | 12 ++++++------
include/net/sctp/structs.h | 2 +-
net/sctp/associola.c | 5 +++--
net/sctp/auth.c | 2 +-
net/sctp/input.c | 2 +-
net/sctp/outqueue.c | 11 +++++++----
net/sctp/sm_make_chunk.c | 22 +++++++++++-----------
net/sctp/sm_sideeffect.c | 3 +--
net/sctp/sm_statefuns.c | 14 ++++++--------
net/sctp/stream.c | 2 +-
net/sctp/stream_interleave.c | 4 ++--
12 files changed, 49 insertions(+), 48 deletions(-)
--
2.39.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 1/6] sctp: delete the nested flexible array params
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
@ 2023-04-19 15:16 ` Xin Long
2023-04-19 15:16 ` [PATCH net-next 2/6] sctp: delete the nested flexible array skip Xin Long
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Xin Long @ 2023-04-19 15:16 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Marcelo Ricardo Leitner
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>
---
include/linux/sctp.h | 6 +++---
include/net/sctp/sctp.h | 8 ++++----
net/sctp/input.c | 2 +-
net/sctp/sm_make_chunk.c | 18 +++++++++---------
net/sctp/sm_statefuns.c | 2 +-
net/sctp/stream.c | 2 +-
6 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 358dc08e0831..0ff36a2737a3 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -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 {
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index c335dd01a597..74fae532b944 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -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) &&\
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 127bf28a6033..2613c4d74b16 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -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));
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index c8f4ec5d5f98..4dbbbc2a7742 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -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;
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index ce5426171206..39d416e7f795 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -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;
diff --git a/net/sctp/stream.c b/net/sctp/stream.c
index ee6514af830f..c241cc552e8d 100644
--- a/net/sctp/stream.c
+++ b/net/sctp/stream.c
@@ -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.
--
2.39.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 2/6] sctp: delete the nested flexible array skip
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
2023-04-19 15:16 ` [PATCH net-next 1/6] sctp: delete the nested flexible array params Xin Long
@ 2023-04-19 15:16 ` Xin Long
2023-04-19 15:31 ` Stephen Hemminger
2023-04-19 15:16 ` [PATCH net-next 3/6] sctp: delete the nested flexible array variable Xin Long
` (5 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Xin Long @ 2023-04-19 15:16 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Marcelo Ricardo Leitner
This patch deletes the flexible-array skip[] from the structure
sctp_ifwdtsn/fwdtsn_hdr to avoid some sparse warnings:
# make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
net/sctp/stream_interleave.c: note: in included file (through include/net/sctp/structs.h, include/net/sctp/sctp.h):
./include/linux/sctp.h:611:32: warning: nested flexible array
./include/linux/sctp.h:628:33: warning: nested flexible array
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/linux/sctp.h | 4 ++--
include/net/sctp/sctp.h | 4 ++--
net/sctp/stream_interleave.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 0ff36a2737a3..9815b801fec0 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -603,7 +603,7 @@ struct sctp_fwdtsn_skip {
struct sctp_fwdtsn_hdr {
__be32 new_cum_tsn;
- struct sctp_fwdtsn_skip skip[];
+ /* struct sctp_fwdtsn_skip skip[]; */
};
struct sctp_fwdtsn_chunk {
@@ -620,7 +620,7 @@ struct sctp_ifwdtsn_skip {
struct sctp_ifwdtsn_hdr {
__be32 new_cum_tsn;
- struct sctp_ifwdtsn_skip skip[];
+ /* struct sctp_ifwdtsn_skip skip[]; */
};
struct sctp_ifwdtsn_chunk {
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 74fae532b944..2a67100b2a17 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -452,8 +452,8 @@ for (err = (struct sctp_errhdr *)((void *)chunk_hdr + \
_sctp_walk_fwdtsn((pos), (chunk), ntohs((chunk)->chunk_hdr->length) - sizeof(struct sctp_fwdtsn_chunk))
#define _sctp_walk_fwdtsn(pos, chunk, end)\
-for (pos = chunk->subh.fwdtsn_hdr->skip;\
- (void *)pos <= (void *)chunk->subh.fwdtsn_hdr->skip + end - sizeof(struct sctp_fwdtsn_skip);\
+for (pos = (void *)(chunk->subh.fwdtsn_hdr + 1);\
+ (void *)pos <= (void *)(chunk->subh.fwdtsn_hdr + 1) + end - sizeof(struct sctp_fwdtsn_skip);\
pos++)
/* External references. */
diff --git a/net/sctp/stream_interleave.c b/net/sctp/stream_interleave.c
index b046b11200c9..840f24045ae2 100644
--- a/net/sctp/stream_interleave.c
+++ b/net/sctp/stream_interleave.c
@@ -1153,8 +1153,8 @@ static void sctp_generate_iftsn(struct sctp_outq *q, __u32 ctsn)
}
#define _sctp_walk_ifwdtsn(pos, chunk, end) \
- for (pos = chunk->subh.ifwdtsn_hdr->skip; \
- (void *)pos <= (void *)chunk->subh.ifwdtsn_hdr->skip + (end) - \
+ for (pos = (void *)(chunk->subh.ifwdtsn_hdr + 1); \
+ (void *)pos <= (void *)(chunk->subh.ifwdtsn_hdr + 1) + (end) - \
sizeof(struct sctp_ifwdtsn_skip); pos++)
#define sctp_walk_ifwdtsn(pos, ch) \
--
2.39.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 3/6] sctp: delete the nested flexible array variable
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
2023-04-19 15:16 ` [PATCH net-next 1/6] sctp: delete the nested flexible array params Xin Long
2023-04-19 15:16 ` [PATCH net-next 2/6] sctp: delete the nested flexible array skip Xin Long
@ 2023-04-19 15:16 ` Xin Long
2023-04-19 15:16 ` [PATCH net-next 4/6] sctp: delete the nested flexible array peer_init Xin Long
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Xin Long @ 2023-04-19 15:16 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Marcelo Ricardo Leitner
This patch deletes the flexible-array variable[] from the structure
sctp_sackhdr and sctp_errhdr to avoid some sparse warnings:
# make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
net/sctp/sm_statefuns.c: note: in included file (through include/net/sctp/structs.h, include/net/sctp/sctp.h):
./include/linux/sctp.h:451:28: warning: nested flexible array
./include/linux/sctp.h:393:29: warning: nested flexible array
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/linux/sctp.h | 4 ++--
net/sctp/outqueue.c | 11 +++++++----
net/sctp/sm_sideeffect.c | 3 +--
net/sctp/sm_statefuns.c | 2 +-
4 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 9815b801fec0..01a0eb7e9fa1 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -385,7 +385,7 @@ struct sctp_sackhdr {
__be32 a_rwnd;
__be16 num_gap_ack_blocks;
__be16 num_dup_tsns;
- union sctp_sack_variable variable[];
+ /* union sctp_sack_variable variable[]; */
};
struct sctp_sack_chunk {
@@ -443,7 +443,7 @@ struct sctp_shutdown_chunk {
struct sctp_errhdr {
__be16 cause;
__be16 length;
- __u8 variable[];
+ /* __u8 variable[]; */
};
struct sctp_operr_chunk {
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index 20831079fb09..0dc6b8ab9963 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -1231,7 +1231,7 @@ static void sctp_sack_update_unack_data(struct sctp_association *assoc,
unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
- frags = sack->variable;
+ frags = (union sctp_sack_variable *)(sack + 1);
for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
unack_data -= ((ntohs(frags[i].gab.end) -
ntohs(frags[i].gab.start) + 1));
@@ -1252,7 +1252,6 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
struct sctp_transport *transport;
struct sctp_chunk *tchunk = NULL;
struct list_head *lchunk, *transport_list, *temp;
- union sctp_sack_variable *frags = sack->variable;
__u32 sack_ctsn, ctsn, tsn;
__u32 highest_tsn, highest_new_tsn;
__u32 sack_a_rwnd;
@@ -1313,8 +1312,12 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
/* Get the highest TSN in the sack. */
highest_tsn = sack_ctsn;
- if (gap_ack_blocks)
+ if (gap_ack_blocks) {
+ union sctp_sack_variable *frags =
+ (union sctp_sack_variable *)(sack + 1);
+
highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
+ }
if (TSN_lt(asoc->highest_sacked, highest_tsn))
asoc->highest_sacked = highest_tsn;
@@ -1789,7 +1792,7 @@ static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
* Block are assumed to have been received correctly.
*/
- frags = sack->variable;
+ frags = (union sctp_sack_variable *)(sack + 1);
blocks = ntohs(sack->num_gap_ack_blocks);
tsn_offset = tsn - ctsn;
for (i = 0; i < blocks; ++i) {
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index 463c4a58d2c3..7fbeb99d8d32 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -984,8 +984,7 @@ static void sctp_cmd_process_operr(struct sctp_cmd_seq *cmds,
{
struct sctp_chunkhdr *unk_chunk_hdr;
- unk_chunk_hdr = (struct sctp_chunkhdr *)
- err_hdr->variable;
+ unk_chunk_hdr = (struct sctp_chunkhdr *)(err_hdr + 1);
switch (unk_chunk_hdr->type) {
/* ADDIP 4.1 A9) If the peer responds to an ASCONF with
* an ERROR chunk reporting that it did not recognized
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 39d416e7f795..8d0cfd689b20 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -1337,7 +1337,7 @@ static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa,
* throughout the code today.
*/
errhdr = (struct sctp_errhdr *)buffer;
- addrparm = (union sctp_addr_param *)errhdr->variable;
+ addrparm = (union sctp_addr_param *)(errhdr + 1);
/* Copy into a parm format. */
len = af->to_addr_param(ssa, addrparm);
--
2.39.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 4/6] sctp: delete the nested flexible array peer_init
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
` (2 preceding siblings ...)
2023-04-19 15:16 ` [PATCH net-next 3/6] sctp: delete the nested flexible array variable Xin Long
@ 2023-04-19 15:16 ` Xin Long
2023-04-19 15:16 ` [PATCH net-next 5/6] sctp: delete the nested flexible array hmac Xin Long
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Xin Long @ 2023-04-19 15:16 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Marcelo Ricardo Leitner
This patch deletes the flexible-array peer_init[] from the structure
sctp_cookie to avoid some sparse warnings:
# make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
net/sctp/sm_make_chunk.c: note: in included file (through include/net/sctp/sctp.h):
./include/net/sctp/structs.h:1588:28: warning: nested flexible array
./include/net/sctp/structs.h:343:28: warning: nested flexible array
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/sctp/structs.h | 2 +-
net/sctp/associola.c | 5 +++--
net/sctp/sm_make_chunk.c | 4 ++--
net/sctp/sm_statefuns.c | 8 +++-----
4 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 070c9458fff4..5c72d1864dd6 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -332,7 +332,7 @@ struct sctp_cookie {
* the association TCB is re-constructed from the cookie.
*/
__u32 raw_addr_list_len;
- struct sctp_init_chunk peer_init[];
+ /* struct sctp_init_chunk peer_init[]; */
};
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 63ba5551c13f..796529167e8d 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -1597,9 +1597,10 @@ int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *asoc,
struct sctp_cookie *cookie,
gfp_t gfp)
{
- int var_size2 = ntohs(cookie->peer_init->chunk_hdr.length);
+ struct sctp_init_chunk *peer_init = (struct sctp_init_chunk *)(cookie + 1);
+ int var_size2 = ntohs(peer_init->chunk_hdr.length);
int var_size3 = cookie->raw_addr_list_len;
- __u8 *raw = (__u8 *)cookie->peer_init + var_size2;
+ __u8 *raw = (__u8 *)peer_init + var_size2;
return sctp_raw_to_bind_addrs(&asoc->base.bind_addr, raw, var_size3,
asoc->ep->base.bind_addr.port, gfp);
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 4dbbbc2a7742..08527d882e56 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1707,11 +1707,11 @@ static struct sctp_cookie_param *sctp_pack_cookie(
ktime_get_real());
/* Copy the peer's init packet. */
- memcpy(&cookie->c.peer_init[0], init_chunk->chunk_hdr,
+ memcpy(cookie + 1, init_chunk->chunk_hdr,
ntohs(init_chunk->chunk_hdr->length));
/* Copy the raw local address list of the association. */
- memcpy((__u8 *)&cookie->c.peer_init[0] +
+ memcpy((__u8 *)(cookie + 1) +
ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len);
if (sctp_sk(ep->base.sk)->hmac) {
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 8d0cfd689b20..7b8eb735fa88 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -794,8 +794,7 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
/* This is a brand-new association, so these are not yet side
* effects--it is safe to run them here.
*/
- peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
-
+ peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
if (!sctp_process_init(new_asoc, chunk,
&chunk->subh.cookie_hdr->c.peer_addr,
peer_init, GFP_ATOMIC))
@@ -1869,8 +1868,7 @@ static enum sctp_disposition sctp_sf_do_dupcook_a(
/* new_asoc is a brand-new association, so these are not yet
* side effects--it is safe to run them here.
*/
- peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
-
+ peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
GFP_ATOMIC))
goto nomem;
@@ -1990,7 +1988,7 @@ static enum sctp_disposition sctp_sf_do_dupcook_b(
/* new_asoc is a brand-new association, so these are not yet
* side effects--it is safe to run them here.
*/
- peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
+ peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
GFP_ATOMIC))
goto nomem;
--
2.39.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 5/6] sctp: delete the nested flexible array hmac
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
` (3 preceding siblings ...)
2023-04-19 15:16 ` [PATCH net-next 4/6] sctp: delete the nested flexible array peer_init Xin Long
@ 2023-04-19 15:16 ` Xin Long
2023-04-19 15:16 ` [PATCH net-next 6/6] sctp: delete the nested flexible array payload Xin Long
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Xin Long @ 2023-04-19 15:16 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Marcelo Ricardo Leitner
This patch deletes the flexible-array hmac[] from the structure
sctp_authhdr to avoid some sparse warnings:
# make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
net/sctp/auth.c: note: in included file (through include/net/sctp/structs.h, include/net/sctp/sctp.h):
./include/linux/sctp.h:735:29: warning: nested flexible array
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/linux/sctp.h | 2 +-
net/sctp/auth.c | 2 +-
net/sctp/sm_statefuns.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 01a0eb7e9fa1..d182e8c41985 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -727,7 +727,7 @@ struct sctp_addip_chunk {
struct sctp_authhdr {
__be16 shkey_id;
__be16 hmac_id;
- __u8 hmac[];
+ /* __u8 hmac[]; */
};
struct sctp_auth_chunk {
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index 34964145514e..c58fffc86a0c 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -738,7 +738,7 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
tfm = asoc->ep->auth_hmacs[hmac_id];
- digest = auth->auth_hdr.hmac;
+ digest = (u8 *)(&auth->auth_hdr + 1);
if (crypto_shash_setkey(tfm, &asoc_key->data[0], asoc_key->len))
goto free;
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 7b8eb735fa88..97f1155a2045 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -4391,7 +4391,7 @@ static enum sctp_ierror sctp_sf_authenticate(
* 3. Compute the new digest
* 4. Compare saved and new digests.
*/
- digest = auth_hdr->hmac;
+ digest = (u8 *)(auth_hdr + 1);
skb_pull(chunk->skb, sig_len);
save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
--
2.39.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 6/6] sctp: delete the nested flexible array payload
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
` (4 preceding siblings ...)
2023-04-19 15:16 ` [PATCH net-next 5/6] sctp: delete the nested flexible array hmac Xin Long
@ 2023-04-19 15:16 ` Xin Long
2023-04-20 1:18 ` [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Jakub Kicinski
2023-04-21 7:50 ` patchwork-bot+netdevbpf
7 siblings, 0 replies; 12+ messages in thread
From: Xin Long @ 2023-04-19 15:16 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Marcelo Ricardo Leitner
This patch deletes the flexible-array payload[] from the structure
sctp_datahdr to avoid some sparse warnings:
# make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
net/sctp/socket.c: note: in included file (through include/net/sctp/structs.h, include/net/sctp/sctp.h):
./include/linux/sctp.h:230:29: warning: nested flexible array
This member is not even used anywhere.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/linux/sctp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index d182e8c41985..836a7e200f39 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -222,7 +222,7 @@ struct sctp_datahdr {
__be16 stream;
__be16 ssn;
__u32 ppid;
- __u8 payload[];
+ /* __u8 payload[]; */
};
struct sctp_data_chunk {
--
2.39.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/6] sctp: delete the nested flexible array skip
2023-04-19 15:16 ` [PATCH net-next 2/6] sctp: delete the nested flexible array skip Xin Long
@ 2023-04-19 15:31 ` Stephen Hemminger
2023-04-20 1:20 ` Jakub Kicinski
0 siblings, 1 reply; 12+ messages in thread
From: Stephen Hemminger @ 2023-04-19 15:31 UTC (permalink / raw)
To: Xin Long
Cc: network dev, linux-sctp, davem, kuba, Eric Dumazet, Paolo Abeni,
Marcelo Ricardo Leitner
On Wed, 19 Apr 2023 11:16:29 -0400
Xin Long <lucien.xin@gmail.com> wrote:
> diff --git a/include/linux/sctp.h b/include/linux/sctp.h
> index 0ff36a2737a3..9815b801fec0 100644
> --- a/include/linux/sctp.h
> +++ b/include/linux/sctp.h
> @@ -603,7 +603,7 @@ struct sctp_fwdtsn_skip {
>
> struct sctp_fwdtsn_hdr {
> __be32 new_cum_tsn;
> - struct sctp_fwdtsn_skip skip[];
> + /* struct sctp_fwdtsn_skip skip[]; */
> };
>
Why leave the old structure in comments.
Remove unused code and data structures please.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
` (5 preceding siblings ...)
2023-04-19 15:16 ` [PATCH net-next 6/6] sctp: delete the nested flexible array payload Xin Long
@ 2023-04-20 1:18 ` Jakub Kicinski
2023-12-14 16:55 ` Kees Cook
2023-04-21 7:50 ` patchwork-bot+netdevbpf
7 siblings, 1 reply; 12+ messages in thread
From: Jakub Kicinski @ 2023-04-20 1:18 UTC (permalink / raw)
To: Kees Cook
Cc: Xin Long, network dev, linux-sctp, davem, Eric Dumazet,
Paolo Abeni, Marcelo Ricardo Leitner
On Wed, 19 Apr 2023 11:16:27 -0400 Xin Long wrote:
> Paolo noticed a compile warning in SCTP,
>
> ../net/sctp/stream_sched_fc.c: note: in included file (through ../include/net/sctp/sctp.h):
> ../include/net/sctp/structs.h:335:41: warning: array of flexible structures
>
> But not only this, there are actually quite a lot of such warnings in
> some SCTP structs. This patchset fixes most of warnings by deleting
> these nested flexible array members.
>
> After this patchset, there are still some warnings left:
>
> # make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
> ./include/net/sctp/structs.h:1145:41: warning: nested flexible array
> ./include/uapi/linux/sctp.h:641:34: warning: nested flexible array
> ./include/uapi/linux/sctp.h:643:34: warning: nested flexible array
> ./include/uapi/linux/sctp.h:644:33: warning: nested flexible array
> ./include/uapi/linux/sctp.h:650:40: warning: nested flexible array
> ./include/uapi/linux/sctp.h:653:39: warning: nested flexible array
>
> the 1st is caused by __data[] in struct ip_options, not in SCTP;
> the others are in uapi, and we should not touch them.
>
> Note that instead of completely deleting it, we just leave it as a
> comment in the struct, signalling to the reader that we do expect
> such variable parameters over there, as Marcelo suggested.
Hi Kees, is there no workaround for nested flexible arrays within
the kernel? Any recommendations?
https://lore.kernel.org/all/cover.1681917361.git.lucien.xin@gmail.com/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/6] sctp: delete the nested flexible array skip
2023-04-19 15:31 ` Stephen Hemminger
@ 2023-04-20 1:20 ` Jakub Kicinski
0 siblings, 0 replies; 12+ messages in thread
From: Jakub Kicinski @ 2023-04-20 1:20 UTC (permalink / raw)
To: Stephen Hemminger
Cc: Xin Long, network dev, linux-sctp, davem, Eric Dumazet,
Paolo Abeni, Marcelo Ricardo Leitner
On Wed, 19 Apr 2023 08:31:25 -0700 Stephen Hemminger wrote:
> > struct sctp_fwdtsn_hdr {
> > __be32 new_cum_tsn;
> > - struct sctp_fwdtsn_skip skip[];
> > + /* struct sctp_fwdtsn_skip skip[]; */
> > };
> >
>
> Why leave the old structure in comments.
> Remove unused code and data structures please.
Did you see the note in the cover letter?
Is there any reason why this is not an acceptable way of documenting
what follows?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
` (6 preceding siblings ...)
2023-04-20 1:18 ` [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Jakub Kicinski
@ 2023-04-21 7:50 ` patchwork-bot+netdevbpf
7 siblings, 0 replies; 12+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-04-21 7:50 UTC (permalink / raw)
To: Xin Long; +Cc: netdev, linux-sctp, davem, kuba, edumazet, pabeni,
marcelo.leitner
Hello:
This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Wed, 19 Apr 2023 11:16:27 -0400 you wrote:
> Paolo noticed a compile warning in SCTP,
>
> ../net/sctp/stream_sched_fc.c: note: in included file (through ../include/net/sctp/sctp.h):
> ../include/net/sctp/structs.h:335:41: warning: array of flexible structures
>
> But not only this, there are actually quite a lot of such warnings in
> some SCTP structs. This patchset fixes most of warnings by deleting
> these nested flexible array members.
>
> [...]
Here is the summary with links:
- [net-next,1/6] sctp: delete the nested flexible array params
https://git.kernel.org/netdev/net-next/c/add7370a3989
- [net-next,2/6] sctp: delete the nested flexible array skip
https://git.kernel.org/netdev/net-next/c/73175a042955
- [net-next,3/6] sctp: delete the nested flexible array variable
https://git.kernel.org/netdev/net-next/c/9789c1c6619e
- [net-next,4/6] sctp: delete the nested flexible array peer_init
https://git.kernel.org/netdev/net-next/c/f97278ff346a
- [net-next,5/6] sctp: delete the nested flexible array hmac
https://git.kernel.org/netdev/net-next/c/2ab399a931dd
- [net-next,6/6] sctp: delete the nested flexible array payload
https://git.kernel.org/netdev/net-next/c/dbda0fba7a14
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings
2023-04-20 1:18 ` [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Jakub Kicinski
@ 2023-12-14 16:55 ` Kees Cook
0 siblings, 0 replies; 12+ messages in thread
From: Kees Cook @ 2023-12-14 16:55 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Xin Long, network dev, linux-sctp, davem, Eric Dumazet,
Paolo Abeni, Marcelo Ricardo Leitner, linux-hardening
On Wed, Apr 19, 2023 at 06:18:24PM -0700, Jakub Kicinski wrote:
> On Wed, 19 Apr 2023 11:16:27 -0400 Xin Long wrote:
> > Paolo noticed a compile warning in SCTP,
> >
> > ../net/sctp/stream_sched_fc.c: note: in included file (through ../include/net/sctp/sctp.h):
> > ../include/net/sctp/structs.h:335:41: warning: array of flexible structures
> >
> > But not only this, there are actually quite a lot of such warnings in
> > some SCTP structs. This patchset fixes most of warnings by deleting
> > these nested flexible array members.
> >
> > After this patchset, there are still some warnings left:
> >
> > # make C=2 CF="-Wflexible-array-nested" M=./net/sctp/
> > ./include/net/sctp/structs.h:1145:41: warning: nested flexible array
> > ./include/uapi/linux/sctp.h:641:34: warning: nested flexible array
> > ./include/uapi/linux/sctp.h:643:34: warning: nested flexible array
> > ./include/uapi/linux/sctp.h:644:33: warning: nested flexible array
> > ./include/uapi/linux/sctp.h:650:40: warning: nested flexible array
> > ./include/uapi/linux/sctp.h:653:39: warning: nested flexible array
> >
> > the 1st is caused by __data[] in struct ip_options, not in SCTP;
> > the others are in uapi, and we should not touch them.
> >
> > Note that instead of completely deleting it, we just leave it as a
> > comment in the struct, signalling to the reader that we do expect
> > such variable parameters over there, as Marcelo suggested.
>
> Hi Kees, is there no workaround for nested flexible arrays within
> the kernel? Any recommendations?
>
> https://lore.kernel.org/all/cover.1681917361.git.lucien.xin@gmail.com/
*thread necromancy*
Hi, I apologize for missing this thread back in April!
There's no need for a work-around: this situation isn't a problem.
Composite structures that end with a flexible array are perfectly valid
(the compiler can unambiguously reason about sizes). So none of these
patches are needed (and actually reduce the compiler's ability to reason
about object sizes). We shouldn't run sparse with -Wflexible-array-nested
as this isn't an actual problem.
The only problem that can happen like this is when a flex array
ends up in the _middle_ of a composite structure, in which
case yes, this needs to be fixed. This check is supported by
GCC 14+ with -Wflex-array-member-not-at-end. For example, see:
https://lore.kernel.org/all/1da736106d8e0806aeafa6e471a13ced490eae22.1698117815.git.gustavoars@kernel.org/
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-12-14 16:55 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-19 15:16 [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Xin Long
2023-04-19 15:16 ` [PATCH net-next 1/6] sctp: delete the nested flexible array params Xin Long
2023-04-19 15:16 ` [PATCH net-next 2/6] sctp: delete the nested flexible array skip Xin Long
2023-04-19 15:31 ` Stephen Hemminger
2023-04-20 1:20 ` Jakub Kicinski
2023-04-19 15:16 ` [PATCH net-next 3/6] sctp: delete the nested flexible array variable Xin Long
2023-04-19 15:16 ` [PATCH net-next 4/6] sctp: delete the nested flexible array peer_init Xin Long
2023-04-19 15:16 ` [PATCH net-next 5/6] sctp: delete the nested flexible array hmac Xin Long
2023-04-19 15:16 ` [PATCH net-next 6/6] sctp: delete the nested flexible array payload Xin Long
2023-04-20 1:18 ` [PATCH net-next 0/6] sctp: fix a plenty of flexible-array-nested warnings Jakub Kicinski
2023-12-14 16:55 ` Kees Cook
2023-04-21 7:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).