Skip to content

Commit afd0a80

Browse files
kubaaudavem330
authored andcommitted
sctp: frag_point sanity check
If for some reason an association's fragmentation point is zero, sctp_datamsg_from_user will try to endlessly try to divide a message into zero-sized chunks. This eventually causes kernel panic due to running out of memory. Although this situation is quite unlikely, it has occurred before as reported. I propose to add this simple last-ditch sanity check due to the severity of the potential consequences. Signed-off-by: Jakub Audykowicz <jakub.audykowicz@gmail.com> Acked-by: Neil Horman <nhorman@tuxdriver.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b2b7af8 commit afd0a80

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

include/net/sctp/sctp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,4 +620,9 @@ static inline bool sctp_transport_pmtu_check(struct sctp_transport *t)
620620
return false;
621621
}
622622

623+
static inline __u32 sctp_min_frag_point(struct sctp_sock *sp, __u16 datasize)
624+
{
625+
return sctp_mtu_payload(sp, SCTP_DEFAULT_MINSEGMENT, datasize);
626+
}
627+
623628
#endif /* __net_sctp_h__ */

net/sctp/chunk.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
191191
* the packet
192192
*/
193193
max_data = asoc->frag_point;
194+
if (unlikely(!max_data)) {
195+
max_data = sctp_min_frag_point(sctp_sk(asoc->base.sk),
196+
sctp_datachk_len(&asoc->stream));
197+
pr_warn_ratelimited("%s: asoc:%p frag_point is zero, forcing max_data to default minimum (%Zu)",
198+
__func__, asoc, max_data);
199+
}
194200

195201
/* If the the peer requested that we authenticate DATA chunks
196202
* we need to account for bundling of the AUTH chunks along with

net/sctp/socket.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,8 +3324,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
33243324
__u16 datasize = asoc ? sctp_datachk_len(&asoc->stream) :
33253325
sizeof(struct sctp_data_chunk);
33263326

3327-
min_len = sctp_mtu_payload(sp, SCTP_DEFAULT_MINSEGMENT,
3328-
datasize);
3327+
min_len = sctp_min_frag_point(sp, datasize);
33293328
max_len = SCTP_MAX_CHUNK_LEN - datasize;
33303329

33313330
if (val < min_len || val > max_len)

0 commit comments

Comments
 (0)