Skip to content

Commit 0fc2ea9

Browse files
lxindavem330
authored andcommitted
sctp: implement validate_ftsn for sctp_stream_interleave
validate_ftsn is added as a member of sctp_stream_interleave, used to validate ssn/chunk type for fwdtsn or mid (message id)/chunk type for ifwdtsn, called in sctp_sf_eat_fwd_tsn, just as validate_data. If this check fails, an abort packet will be sent, as said in section 2.3.1 of RFC8260. As ifwdtsn and fwdtsn chunks have different length, it also defines ftsn_chunk_len for sctp_stream_interleave to describe the chunk size. Then it replaces all sizeof(struct sctp_fwdtsn_chunk) with sctp_ftsnchk_len. It also adds the process for ifwdtsn in rx path. As Marcelo pointed out, there's no need to add event table for ifwdtsn, but just share prsctp_chunk_event_table with fwdtsn's. It would drop fwdtsn chunk for ifwdtsn and drop ifwdtsn chunk for fwdtsn by calling validate_ftsn in sctp_sf_eat_fwd_tsn. After this patch, the ifwdtsn can be accepted. Note that this patch also removes the sctp.intl_enable check for idata chunks in sctp_chunk_event_lookup, as it will do this check in validate_data later. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo R. Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8e0c3b7 commit 0fc2ea9

File tree

5 files changed

+66
-18
lines changed

5 files changed

+66
-18
lines changed

include/net/sctp/stream_interleave.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
struct sctp_stream_interleave {
3535
__u16 data_chunk_len;
36+
__u16 ftsn_chunk_len;
3637
/* (I-)DATA process */
3738
struct sctp_chunk *(*make_datafrag)(const struct sctp_association *asoc,
3839
const struct sctp_sndrcvinfo *sinfo,
@@ -49,6 +50,7 @@ struct sctp_stream_interleave {
4950
void (*abort_pd)(struct sctp_ulpq *ulpq, gfp_t gfp);
5051
/* (I-)FORWARD-TSN process */
5152
void (*generate_ftsn)(struct sctp_outq *q, __u32 ctsn);
53+
bool (*validate_ftsn)(struct sctp_chunk *chunk);
5254
};
5355

5456
void sctp_stream_interleave_init(struct sctp_stream *stream);

include/net/sctp/structs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,16 @@ static inline __u16 sctp_datahdr_len(const struct sctp_stream *stream)
14431443
return stream->si->data_chunk_len - sizeof(struct sctp_chunkhdr);
14441444
}
14451445

1446+
static inline __u16 sctp_ftsnchk_len(const struct sctp_stream *stream)
1447+
{
1448+
return stream->si->ftsn_chunk_len;
1449+
}
1450+
1451+
static inline __u16 sctp_ftsnhdr_len(const struct sctp_stream *stream)
1452+
{
1453+
return stream->si->ftsn_chunk_len - sizeof(struct sctp_chunkhdr);
1454+
}
1455+
14461456
/* SCTP_GET_ASSOC_STATS counters */
14471457
struct sctp_priv_assoc_stats {
14481458
/* Maximum observed rto in the association during subsequent

net/sctp/sm_statefuns.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,7 +3957,6 @@ enum sctp_disposition sctp_sf_eat_fwd_tsn(struct net *net,
39573957
{
39583958
struct sctp_fwdtsn_hdr *fwdtsn_hdr;
39593959
struct sctp_chunk *chunk = arg;
3960-
struct sctp_fwdtsn_skip *skip;
39613960
__u16 len;
39623961
__u32 tsn;
39633962

@@ -3971,7 +3970,7 @@ enum sctp_disposition sctp_sf_eat_fwd_tsn(struct net *net,
39713970
return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
39723971

39733972
/* Make sure that the FORWARD_TSN chunk has valid length. */
3974-
if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3973+
if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
39753974
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
39763975
commands);
39773976

@@ -3990,14 +3989,11 @@ enum sctp_disposition sctp_sf_eat_fwd_tsn(struct net *net,
39903989
if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
39913990
goto discard_noforce;
39923991

3993-
/* Silently discard the chunk if stream-id is not valid */
3994-
sctp_walk_fwdtsn(skip, chunk) {
3995-
if (ntohs(skip->stream) >= asoc->stream.incnt)
3996-
goto discard_noforce;
3997-
}
3992+
if (!asoc->stream.si->validate_ftsn(chunk))
3993+
goto discard_noforce;
39983994

39993995
sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
4000-
if (len > sizeof(struct sctp_fwdtsn_hdr))
3996+
if (len > sctp_ftsnhdr_len(&asoc->stream))
40013997
sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
40023998
SCTP_CHUNK(chunk));
40033999

@@ -4028,7 +4024,6 @@ enum sctp_disposition sctp_sf_eat_fwd_tsn_fast(
40284024
{
40294025
struct sctp_fwdtsn_hdr *fwdtsn_hdr;
40304026
struct sctp_chunk *chunk = arg;
4031-
struct sctp_fwdtsn_skip *skip;
40324027
__u16 len;
40334028
__u32 tsn;
40344029

@@ -4042,7 +4037,7 @@ enum sctp_disposition sctp_sf_eat_fwd_tsn_fast(
40424037
return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
40434038

40444039
/* Make sure that the FORWARD_TSN chunk has a valid length. */
4045-
if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
4040+
if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
40464041
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
40474042
commands);
40484043

@@ -4061,14 +4056,11 @@ enum sctp_disposition sctp_sf_eat_fwd_tsn_fast(
40614056
if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
40624057
goto gen_shutdown;
40634058

4064-
/* Silently discard the chunk if stream-id is not valid */
4065-
sctp_walk_fwdtsn(skip, chunk) {
4066-
if (ntohs(skip->stream) >= asoc->stream.incnt)
4067-
goto gen_shutdown;
4068-
}
4059+
if (!asoc->stream.si->validate_ftsn(chunk))
4060+
goto gen_shutdown;
40694061

40704062
sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
4071-
if (len > sizeof(struct sctp_fwdtsn_hdr))
4063+
if (len > sctp_ftsnhdr_len(&asoc->stream))
40724064
sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
40734065
SCTP_CHUNK(chunk));
40744066

net/sctp/sm_statetable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,14 +985,14 @@ static const struct sctp_sm_table_entry *sctp_chunk_event_lookup(
985985
if (state > SCTP_STATE_MAX)
986986
return &bug;
987987

988-
if (net->sctp.intl_enable && cid == SCTP_CID_I_DATA)
988+
if (cid == SCTP_CID_I_DATA)
989989
cid = SCTP_CID_DATA;
990990

991991
if (cid <= SCTP_CID_BASE_MAX)
992992
return &chunk_event_table[cid][state];
993993

994994
if (net->sctp.prsctp_enable) {
995-
if (cid == SCTP_CID_FWD_TSN)
995+
if (cid == SCTP_CID_FWD_TSN || cid == SCTP_CID_I_FWD_TSN)
996996
return &prsctp_chunk_event_table[0][state];
997997
}
998998

net/sctp/stream_interleave.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,49 @@ static void sctp_generate_iftsn(struct sctp_outq *q, __u32 ctsn)
11531153
}
11541154
}
11551155

1156+
#define _sctp_walk_ifwdtsn(pos, chunk, end) \
1157+
for (pos = chunk->subh.ifwdtsn_hdr->skip; \
1158+
(void *)pos < (void *)chunk->subh.ifwdtsn_hdr->skip + (end); pos++)
1159+
1160+
#define sctp_walk_ifwdtsn(pos, ch) \
1161+
_sctp_walk_ifwdtsn((pos), (ch), ntohs((ch)->chunk_hdr->length) - \
1162+
sizeof(struct sctp_ifwdtsn_chunk))
1163+
1164+
static bool sctp_validate_fwdtsn(struct sctp_chunk *chunk)
1165+
{
1166+
struct sctp_fwdtsn_skip *skip;
1167+
__u16 incnt;
1168+
1169+
if (chunk->chunk_hdr->type != SCTP_CID_FWD_TSN)
1170+
return false;
1171+
1172+
incnt = chunk->asoc->stream.incnt;
1173+
sctp_walk_fwdtsn(skip, chunk)
1174+
if (ntohs(skip->stream) >= incnt)
1175+
return false;
1176+
1177+
return true;
1178+
}
1179+
1180+
static bool sctp_validate_iftsn(struct sctp_chunk *chunk)
1181+
{
1182+
struct sctp_ifwdtsn_skip *skip;
1183+
__u16 incnt;
1184+
1185+
if (chunk->chunk_hdr->type != SCTP_CID_I_FWD_TSN)
1186+
return false;
1187+
1188+
incnt = chunk->asoc->stream.incnt;
1189+
sctp_walk_ifwdtsn(skip, chunk)
1190+
if (ntohs(skip->stream) >= incnt)
1191+
return false;
1192+
1193+
return true;
1194+
}
1195+
11561196
static struct sctp_stream_interleave sctp_stream_interleave_0 = {
11571197
.data_chunk_len = sizeof(struct sctp_data_chunk),
1198+
.ftsn_chunk_len = sizeof(struct sctp_fwdtsn_chunk),
11581199
/* DATA process functions */
11591200
.make_datafrag = sctp_make_datafrag_empty,
11601201
.assign_number = sctp_chunk_assign_ssn,
@@ -1166,10 +1207,12 @@ static struct sctp_stream_interleave sctp_stream_interleave_0 = {
11661207
.abort_pd = sctp_ulpq_abort_pd,
11671208
/* FORWARD-TSN process functions */
11681209
.generate_ftsn = sctp_generate_fwdtsn,
1210+
.validate_ftsn = sctp_validate_fwdtsn,
11691211
};
11701212

11711213
static struct sctp_stream_interleave sctp_stream_interleave_1 = {
11721214
.data_chunk_len = sizeof(struct sctp_idata_chunk),
1215+
.ftsn_chunk_len = sizeof(struct sctp_ifwdtsn_chunk),
11731216
/* I-DATA process functions */
11741217
.make_datafrag = sctp_make_idatafrag_empty,
11751218
.assign_number = sctp_chunk_assign_mid,
@@ -1181,6 +1224,7 @@ static struct sctp_stream_interleave sctp_stream_interleave_1 = {
11811224
.abort_pd = sctp_intl_abort_pd,
11821225
/* I-FORWARD-TSN process functions */
11831226
.generate_ftsn = sctp_generate_iftsn,
1227+
.validate_ftsn = sctp_validate_iftsn,
11841228
};
11851229

11861230
void sctp_stream_interleave_init(struct sctp_stream *stream)

0 commit comments

Comments
 (0)