Skip to content

Commit 3e62abf

Browse files
author
Vlad Yasevich
committed
sctp: Fix data segmentation with small frag_size
Since an application may specify the maximum SCTP fragment size that all data should be fragmented to, we need to fix how we do segmentation. Right now, if a user specifies a small fragment size, the segment size can go negative in the presence of AUTH or COOKIE_ECHO bundling. What we need to do is track the largest possbile DATA chunk that can fit into the mtu. Then if the fragment size specified is bigger then this maximum length, we'll shrink it down. Otherwise, we just use the smaller segment size without changing it further. Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
1 parent bec9640 commit 3e62abf

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

‎net/sctp/chunk.c‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
158158
{
159159
int max, whole, i, offset, over, err;
160160
int len, first_len;
161+
int max_data;
161162
struct sctp_chunk *chunk;
162163
struct sctp_datamsg *msg;
163164
struct list_head *pos, *temp;
@@ -179,8 +180,14 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
179180
__func__, msg, msg->expires_at, jiffies);
180181
}
181182

182-
max = asoc->frag_point;
183+
/* This is the biggest possible DATA chunk that can fit into
184+
* the packet
185+
*/
186+
max_data = asoc->pathmtu -
187+
sctp_sk(asoc->base.sk)->pf->af->net_header_len -
188+
sizeof(struct sctphdr) - sizeof(struct sctp_data_chunk);
183189

190+
max = asoc->frag_point;
184191
/* If the the peer requested that we authenticate DATA chunks
185192
* we need to accound for bundling of the AUTH chunks along with
186193
* DATA.
@@ -189,23 +196,30 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
189196
struct sctp_hmac *hmac_desc = sctp_auth_asoc_get_hmac(asoc);
190197

191198
if (hmac_desc)
192-
max -= WORD_ROUND(sizeof(sctp_auth_chunk_t) +
199+
max_data -= WORD_ROUND(sizeof(sctp_auth_chunk_t) +
193200
hmac_desc->hmac_len);
194201
}
195202

203+
/* Now, check if we need to reduce our max */
204+
if (max > max_data)
205+
max = max_data;
206+
196207
whole = 0;
197208
first_len = max;
198209

199210
/* Encourage Cookie-ECHO bundling. */
200211
if (asoc->state < SCTP_STATE_COOKIE_ECHOED) {
201-
whole = msg_len / (max - SCTP_ARBITRARY_COOKIE_ECHO_LEN);
212+
max_data -= SCTP_ARBITRARY_COOKIE_ECHO_LEN;
202213

203-
/* Account for the DATA to be bundled with the COOKIE-ECHO. */
204-
if (whole) {
205-
first_len = max - SCTP_ARBITRARY_COOKIE_ECHO_LEN;
206-
msg_len -= first_len;
207-
whole = 1;
208-
}
214+
/* This is the biggesr first_len we can have */
215+
if (first_len > max_data)
216+
first_len = max_data;
217+
}
218+
219+
/* Account for a different sized first fragment */
220+
if (msg_len >= first_len) {
221+
msg_len -= first_len;
222+
whole = 1;
209223
}
210224

211225
/* How many full sized? How many bytes leftover? */

0 commit comments

Comments
 (0)