aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Audykowicz <jakub.audykowicz@gmail.com>2018-12-04 14:27:41 -0500
committerDavid S. Miller <davem@davemloft.net>2018-12-05 23:37:52 -0500
commitafd0a8006e98b1890908f81746c94ca5dae29d7c (patch)
tree22a7070a7d5b13891bc65368b42bcb18cc56d6f1
parentb2b7af861122a0c0f6260155c29a1b2e594cd5b5 (diff)
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>
-rw-r--r--include/net/sctp/sctp.h5
-rw-r--r--net/sctp/chunk.c6
-rw-r--r--net/sctp/socket.c3
3 files changed, 12 insertions, 2 deletions
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index ab9242e51d9e..2abbc15824af 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -620,4 +620,9 @@ static inline bool sctp_transport_pmtu_check(struct sctp_transport *t)
620 return false; 620 return false;
621} 621}
622 622
623static 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
623#endif /* __net_sctp_h__ */ 628#endif /* __net_sctp_h__ */
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index ce8087846f05..d2048de86e7c 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -191,6 +191,12 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
191 * the packet 191 * the packet
192 */ 192 */
193 max_data = asoc->frag_point; 193 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 }
194 200
195 /* If the the peer requested that we authenticate DATA chunks 201 /* If the the peer requested that we authenticate DATA chunks
196 * we need to account for bundling of the AUTH chunks along with 202 * we need to account for bundling of the AUTH chunks along with
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index bf618d1b41fd..b8cebd5a87e5 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -3324,8 +3324,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
3324 __u16 datasize = asoc ? sctp_datachk_len(&asoc->stream) : 3324 __u16 datasize = asoc ? sctp_datachk_len(&asoc->stream) :
3325 sizeof(struct sctp_data_chunk); 3325 sizeof(struct sctp_data_chunk);
3326 3326
3327 min_len = sctp_mtu_payload(sp, SCTP_DEFAULT_MINSEGMENT, 3327 min_len = sctp_min_frag_point(sp, datasize);
3328 datasize);
3329 max_len = SCTP_MAX_CHUNK_LEN - datasize; 3328 max_len = SCTP_MAX_CHUNK_LEN - datasize;
3330 3329
3331 if (val < min_len || val > max_len) 3330 if (val < min_len || val > max_len)