Skip to content

Commit e2598db

Browse files
committed
Merge branch 'sctp-nested-flex-arrays'
Xin Long says: ==================== sctp: fix a plenty of flexible-array-nested warnings 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. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 2f3a247 + dbda0fb commit e2598db

12 files changed

Lines changed: 49 additions & 48 deletions

File tree

include/linux/sctp.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct sctp_datahdr {
222222
__be16 stream;
223223
__be16 ssn;
224224
__u32 ppid;
225-
__u8 payload[];
225+
/* __u8 payload[]; */
226226
};
227227

228228
struct sctp_data_chunk {
@@ -270,7 +270,7 @@ struct sctp_inithdr {
270270
__be16 num_outbound_streams;
271271
__be16 num_inbound_streams;
272272
__be32 initial_tsn;
273-
__u8 params[];
273+
/* __u8 params[]; */
274274
};
275275

276276
struct sctp_init_chunk {
@@ -385,7 +385,7 @@ struct sctp_sackhdr {
385385
__be32 a_rwnd;
386386
__be16 num_gap_ack_blocks;
387387
__be16 num_dup_tsns;
388-
union sctp_sack_variable variable[];
388+
/* union sctp_sack_variable variable[]; */
389389
};
390390

391391
struct sctp_sack_chunk {
@@ -443,7 +443,7 @@ struct sctp_shutdown_chunk {
443443
struct sctp_errhdr {
444444
__be16 cause;
445445
__be16 length;
446-
__u8 variable[];
446+
/* __u8 variable[]; */
447447
};
448448

449449
struct sctp_operr_chunk {
@@ -603,7 +603,7 @@ struct sctp_fwdtsn_skip {
603603

604604
struct sctp_fwdtsn_hdr {
605605
__be32 new_cum_tsn;
606-
struct sctp_fwdtsn_skip skip[];
606+
/* struct sctp_fwdtsn_skip skip[]; */
607607
};
608608

609609
struct sctp_fwdtsn_chunk {
@@ -620,7 +620,7 @@ struct sctp_ifwdtsn_skip {
620620

621621
struct sctp_ifwdtsn_hdr {
622622
__be32 new_cum_tsn;
623-
struct sctp_ifwdtsn_skip skip[];
623+
/* struct sctp_ifwdtsn_skip skip[]; */
624624
};
625625

626626
struct sctp_ifwdtsn_chunk {
@@ -667,7 +667,7 @@ struct sctp_addip_param {
667667

668668
struct sctp_addiphdr {
669669
__be32 serial;
670-
__u8 params[];
670+
/* __u8 params[]; */
671671
};
672672

673673
struct sctp_addip_chunk {
@@ -727,7 +727,7 @@ struct sctp_addip_chunk {
727727
struct sctp_authhdr {
728728
__be16 shkey_id;
729729
__be16 hmac_id;
730-
__u8 hmac[];
730+
/* __u8 hmac[]; */
731731
};
732732

733733
struct sctp_auth_chunk {
@@ -742,7 +742,7 @@ struct sctp_infox {
742742

743743
struct sctp_reconf_chunk {
744744
struct sctp_chunkhdr chunk_hdr;
745-
__u8 params[];
745+
/* __u8 params[]; */
746746
};
747747

748748
struct sctp_strreset_outreq {

include/net/sctp/sctp.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,11 @@ static inline bool sctp_chunk_pending(const struct sctp_chunk *chunk)
425425
* the chunk length to indicate when to stop. Make sure
426426
* there is room for a param header too.
427427
*/
428-
#define sctp_walk_params(pos, chunk, member)\
429-
_sctp_walk_params((pos), (chunk), ntohs((chunk)->chunk_hdr.length), member)
428+
#define sctp_walk_params(pos, chunk)\
429+
_sctp_walk_params((pos), (chunk), ntohs((chunk)->chunk_hdr.length))
430430

431-
#define _sctp_walk_params(pos, chunk, end, member)\
432-
for (pos.v = chunk->member;\
431+
#define _sctp_walk_params(pos, chunk, end)\
432+
for (pos.v = (u8 *)(chunk + 1);\
433433
(pos.v + offsetof(struct sctp_paramhdr, length) + sizeof(pos.p->length) <=\
434434
(void *)chunk + end) &&\
435435
pos.v <= (void *)chunk + end - ntohs(pos.p->length) &&\
@@ -452,8 +452,8 @@ for (err = (struct sctp_errhdr *)((void *)chunk_hdr + \
452452
_sctp_walk_fwdtsn((pos), (chunk), ntohs((chunk)->chunk_hdr->length) - sizeof(struct sctp_fwdtsn_chunk))
453453

454454
#define _sctp_walk_fwdtsn(pos, chunk, end)\
455-
for (pos = chunk->subh.fwdtsn_hdr->skip;\
456-
(void *)pos <= (void *)chunk->subh.fwdtsn_hdr->skip + end - sizeof(struct sctp_fwdtsn_skip);\
455+
for (pos = (void *)(chunk->subh.fwdtsn_hdr + 1);\
456+
(void *)pos <= (void *)(chunk->subh.fwdtsn_hdr + 1) + end - sizeof(struct sctp_fwdtsn_skip);\
457457
pos++)
458458

459459
/* External references. */

include/net/sctp/structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ struct sctp_cookie {
332332
* the association TCB is re-constructed from the cookie.
333333
*/
334334
__u32 raw_addr_list_len;
335-
struct sctp_init_chunk peer_init[];
335+
/* struct sctp_init_chunk peer_init[]; */
336336
};
337337

338338

net/sctp/associola.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,9 +1597,10 @@ int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *asoc,
15971597
struct sctp_cookie *cookie,
15981598
gfp_t gfp)
15991599
{
1600-
int var_size2 = ntohs(cookie->peer_init->chunk_hdr.length);
1600+
struct sctp_init_chunk *peer_init = (struct sctp_init_chunk *)(cookie + 1);
1601+
int var_size2 = ntohs(peer_init->chunk_hdr.length);
16011602
int var_size3 = cookie->raw_addr_list_len;
1602-
__u8 *raw = (__u8 *)cookie->peer_init + var_size2;
1603+
__u8 *raw = (__u8 *)peer_init + var_size2;
16031604

16041605
return sctp_raw_to_bind_addrs(&asoc->base.bind_addr, raw, var_size3,
16051606
asoc->ep->base.bind_addr.port, gfp);

net/sctp/auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
738738

739739
tfm = asoc->ep->auth_hmacs[hmac_id];
740740

741-
digest = auth->auth_hdr.hmac;
741+
digest = (u8 *)(&auth->auth_hdr + 1);
742742
if (crypto_shash_setkey(tfm, &asoc_key->data[0], asoc_key->len))
743743
goto free;
744744

net/sctp/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ static struct sctp_association *__sctp_rcv_init_lookup(struct net *net,
11501150
init = (struct sctp_init_chunk *)skb->data;
11511151

11521152
/* Walk the parameters looking for embedded addresses. */
1153-
sctp_walk_params(params, init, init_hdr.params) {
1153+
sctp_walk_params(params, init) {
11541154

11551155
/* Note: Ignoring hostname addresses. */
11561156
af = sctp_get_af_specific(param_type2af(params.p->type));

net/sctp/outqueue.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ static void sctp_sack_update_unack_data(struct sctp_association *assoc,
12311231

12321232
unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
12331233

1234-
frags = sack->variable;
1234+
frags = (union sctp_sack_variable *)(sack + 1);
12351235
for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
12361236
unack_data -= ((ntohs(frags[i].gab.end) -
12371237
ntohs(frags[i].gab.start) + 1));
@@ -1252,7 +1252,6 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
12521252
struct sctp_transport *transport;
12531253
struct sctp_chunk *tchunk = NULL;
12541254
struct list_head *lchunk, *transport_list, *temp;
1255-
union sctp_sack_variable *frags = sack->variable;
12561255
__u32 sack_ctsn, ctsn, tsn;
12571256
__u32 highest_tsn, highest_new_tsn;
12581257
__u32 sack_a_rwnd;
@@ -1313,8 +1312,12 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
13131312

13141313
/* Get the highest TSN in the sack. */
13151314
highest_tsn = sack_ctsn;
1316-
if (gap_ack_blocks)
1315+
if (gap_ack_blocks) {
1316+
union sctp_sack_variable *frags =
1317+
(union sctp_sack_variable *)(sack + 1);
1318+
13171319
highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
1320+
}
13181321

13191322
if (TSN_lt(asoc->highest_sacked, highest_tsn))
13201323
asoc->highest_sacked = highest_tsn;
@@ -1789,7 +1792,7 @@ static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
17891792
* Block are assumed to have been received correctly.
17901793
*/
17911794

1792-
frags = sack->variable;
1795+
frags = (union sctp_sack_variable *)(sack + 1);
17931796
blocks = ntohs(sack->num_gap_ack_blocks);
17941797
tsn_offset = tsn - ctsn;
17951798
for (i = 0; i < blocks; ++i) {

net/sctp/sm_make_chunk.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,11 +1707,11 @@ static struct sctp_cookie_param *sctp_pack_cookie(
17071707
ktime_get_real());
17081708

17091709
/* Copy the peer's init packet. */
1710-
memcpy(&cookie->c.peer_init[0], init_chunk->chunk_hdr,
1710+
memcpy(cookie + 1, init_chunk->chunk_hdr,
17111711
ntohs(init_chunk->chunk_hdr->length));
17121712

17131713
/* Copy the raw local address list of the association. */
1714-
memcpy((__u8 *)&cookie->c.peer_init[0] +
1714+
memcpy((__u8 *)(cookie + 1) +
17151715
ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len);
17161716

17171717
if (sctp_sk(ep->base.sk)->hmac) {
@@ -2306,7 +2306,7 @@ int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep,
23062306
ntohl(peer_init->init_hdr.a_rwnd) < SCTP_DEFAULT_MINWINDOW)
23072307
return sctp_process_inv_mandatory(asoc, chunk, errp);
23082308

2309-
sctp_walk_params(param, peer_init, init_hdr.params) {
2309+
sctp_walk_params(param, peer_init) {
23102310
if (param.p->type == SCTP_PARAM_STATE_COOKIE)
23112311
has_cookie = true;
23122312
}
@@ -2329,7 +2329,7 @@ int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep,
23292329
chunk, errp);
23302330

23312331
/* Verify all the variable length parameters */
2332-
sctp_walk_params(param, peer_init, init_hdr.params) {
2332+
sctp_walk_params(param, peer_init) {
23332333
result = sctp_verify_param(net, ep, asoc, param, cid,
23342334
chunk, errp);
23352335
switch (result) {
@@ -2381,7 +2381,7 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
23812381
src_match = 1;
23822382

23832383
/* Process the initialization parameters. */
2384-
sctp_walk_params(param, peer_init, init_hdr.params) {
2384+
sctp_walk_params(param, peer_init) {
23852385
if (!src_match &&
23862386
(param.p->type == SCTP_PARAM_IPV4_ADDRESS ||
23872387
param.p->type == SCTP_PARAM_IPV6_ADDRESS)) {
@@ -3202,7 +3202,7 @@ bool sctp_verify_asconf(const struct sctp_association *asoc,
32023202
union sctp_params param;
32033203

32043204
addip = (struct sctp_addip_chunk *)chunk->chunk_hdr;
3205-
sctp_walk_params(param, addip, addip_hdr.params) {
3205+
sctp_walk_params(param, addip) {
32063206
size_t length = ntohs(param.p->length);
32073207

32083208
*errp = param.p;
@@ -3215,14 +3215,14 @@ bool sctp_verify_asconf(const struct sctp_association *asoc,
32153215
/* ensure there is only one addr param and it's in the
32163216
* beginning of addip_hdr params, or we reject it.
32173217
*/
3218-
if (param.v != addip->addip_hdr.params)
3218+
if (param.v != (addip + 1))
32193219
return false;
32203220
addr_param_seen = true;
32213221
break;
32223222
case SCTP_PARAM_IPV6_ADDRESS:
32233223
if (length != sizeof(struct sctp_ipv6addr_param))
32243224
return false;
3225-
if (param.v != addip->addip_hdr.params)
3225+
if (param.v != (addip + 1))
32263226
return false;
32273227
addr_param_seen = true;
32283228
break;
@@ -3302,7 +3302,7 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
33023302
goto done;
33033303

33043304
/* Process the TLVs contained within the ASCONF chunk. */
3305-
sctp_walk_params(param, addip, addip_hdr.params) {
3305+
sctp_walk_params(param, addip) {
33063306
/* Skip preceeding address parameters. */
33073307
if (param.p->type == SCTP_PARAM_IPV4_ADDRESS ||
33083308
param.p->type == SCTP_PARAM_IPV6_ADDRESS)
@@ -3636,7 +3636,7 @@ static struct sctp_chunk *sctp_make_reconf(const struct sctp_association *asoc,
36363636
return NULL;
36373637

36383638
reconf = (struct sctp_reconf_chunk *)retval->chunk_hdr;
3639-
retval->param_hdr.v = reconf->params;
3639+
retval->param_hdr.v = (u8 *)(reconf + 1);
36403640

36413641
return retval;
36423642
}
@@ -3878,7 +3878,7 @@ bool sctp_verify_reconf(const struct sctp_association *asoc,
38783878
__u16 cnt = 0;
38793879

38803880
hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
3881-
sctp_walk_params(param, hdr, params) {
3881+
sctp_walk_params(param, hdr) {
38823882
__u16 length = ntohs(param.p->length);
38833883

38843884
*errp = param.p;

net/sctp/sm_sideeffect.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,7 @@ static void sctp_cmd_process_operr(struct sctp_cmd_seq *cmds,
984984
{
985985
struct sctp_chunkhdr *unk_chunk_hdr;
986986

987-
unk_chunk_hdr = (struct sctp_chunkhdr *)
988-
err_hdr->variable;
987+
unk_chunk_hdr = (struct sctp_chunkhdr *)(err_hdr + 1);
989988
switch (unk_chunk_hdr->type) {
990989
/* ADDIP 4.1 A9) If the peer responds to an ASCONF with
991990
* an ERROR chunk reporting that it did not recognized

net/sctp/sm_statefuns.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,7 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
794794
/* This is a brand-new association, so these are not yet side
795795
* effects--it is safe to run them here.
796796
*/
797-
peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
798-
797+
peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
799798
if (!sctp_process_init(new_asoc, chunk,
800799
&chunk->subh.cookie_hdr->c.peer_addr,
801800
peer_init, GFP_ATOMIC))
@@ -1337,7 +1336,7 @@ static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa,
13371336
* throughout the code today.
13381337
*/
13391338
errhdr = (struct sctp_errhdr *)buffer;
1340-
addrparm = (union sctp_addr_param *)errhdr->variable;
1339+
addrparm = (union sctp_addr_param *)(errhdr + 1);
13411340

13421341
/* Copy into a parm format. */
13431342
len = af->to_addr_param(ssa, addrparm);
@@ -1869,8 +1868,7 @@ static enum sctp_disposition sctp_sf_do_dupcook_a(
18691868
/* new_asoc is a brand-new association, so these are not yet
18701869
* side effects--it is safe to run them here.
18711870
*/
1872-
peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1873-
1871+
peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
18741872
if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
18751873
GFP_ATOMIC))
18761874
goto nomem;
@@ -1990,7 +1988,7 @@ static enum sctp_disposition sctp_sf_do_dupcook_b(
19901988
/* new_asoc is a brand-new association, so these are not yet
19911989
* side effects--it is safe to run them here.
19921990
*/
1993-
peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1991+
peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
19941992
if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
19951993
GFP_ATOMIC))
19961994
goto nomem;
@@ -4142,7 +4140,7 @@ enum sctp_disposition sctp_sf_do_reconf(struct net *net,
41424140
(void *)err_param, commands);
41434141

41444142
hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
4145-
sctp_walk_params(param, hdr, params) {
4143+
sctp_walk_params(param, hdr) {
41464144
struct sctp_chunk *reply = NULL;
41474145
struct sctp_ulpevent *ev = NULL;
41484146

@@ -4393,7 +4391,7 @@ static enum sctp_ierror sctp_sf_authenticate(
43934391
* 3. Compute the new digest
43944392
* 4. Compare saved and new digests.
43954393
*/
4396-
digest = auth_hdr->hmac;
4394+
digest = (u8 *)(auth_hdr + 1);
43974395
skb_pull(chunk->skb, sig_len);
43984396

43994397
save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);

0 commit comments

Comments
 (0)