summaryrefslogtreecommitdiff
path: root/net/sctp
diff options
context:
space:
mode:
authorJakub Audykowicz <jakub.audykowicz@gmail.com>2018-12-04 22:27:41 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-12-13 10:52:29 +0300
commitf033651fba25689f1bfa87bed8140add1b5adeab (patch)
tree495f600b0b491424bf356f4dd19864ea9b2d3ac5 /net/sctp
parent253c617ea626cb569c91215b7bbdfb53f2205a2b (diff)
downloadlinux-f033651fba25689f1bfa87bed8140add1b5adeab.tar.xz
sctp: frag_point sanity check
[ Upstream commit afd0a8006e98b1890908f81746c94ca5dae29d7c ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net/sctp')
-rw-r--r--net/sctp/chunk.c6
-rw-r--r--net/sctp/socket.c3
2 files changed, 7 insertions, 2 deletions
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,
* the packet
*/
max_data = asoc->frag_point;
+ if (unlikely(!max_data)) {
+ max_data = sctp_min_frag_point(sctp_sk(asoc->base.sk),
+ sctp_datachk_len(&asoc->stream));
+ pr_warn_ratelimited("%s: asoc:%p frag_point is zero, forcing max_data to default minimum (%Zu)",
+ __func__, asoc, max_data);
+ }
/* If the the peer requested that we authenticate DATA chunks
* 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 e7a11cd7633f..95f9068b8549 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -3328,8 +3328,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
__u16 datasize = asoc ? sctp_datachk_len(&asoc->stream) :
sizeof(struct sctp_data_chunk);
- min_len = sctp_mtu_payload(sp, SCTP_DEFAULT_MINSEGMENT,
- datasize);
+ min_len = sctp_min_frag_point(sp, datasize);
max_len = SCTP_MAX_CHUNK_LEN - datasize;
if (val < min_len || val > max_len)