From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Ricardo Leitner Subject: Re: [PATCH net] sctp: make sure stream nums can match optlen in sctp_setsockopt_reset_streams Date: Sun, 10 Dec 2017 11:51:49 -0200 Message-ID: <20171210135149.GB4514@localhost.localdomain> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: network dev , linux-sctp@vger.kernel.org, davem@davemloft.net, Neil Horman , syzkaller@googlegroups.com To: Xin Long Return-path: Received: from mail-qt0-f193.google.com ([209.85.216.193]:40899 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751374AbdLJNvy (ORCPT ); Sun, 10 Dec 2017 08:51:54 -0500 Content-Disposition: inline In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: On Sun, Dec 10, 2017 at 03:40:51PM +0800, Xin Long wrote: > Now in sctp_setsockopt_reset_streams, it only does the check > optlen < sizeof(*params) for optlen. But it's not enough, as > params->srs_number_streams should also match optlen. > > If the streams in params->srs_stream_list are less than stream > nums in params->srs_number_streams, later when dereferencing > the stream list, it could cause a slab-out-of-bounds crash, as > reported by syzbot. > > This patch is to fix it by also checking the stream numbers in > sctp_setsockopt_reset_streams to make sure at least it's not > greater than the streams in the list. > > Fixes: 7f9d68ac944e ("sctp: implement sender-side procedures for SSN Reset Request Parameter") > Reported-by: Dmitry Vyukov > Signed-off-by: Xin Long Acked-by: Marcelo Ricardo Leitner > --- > net/sctp/socket.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/net/sctp/socket.c b/net/sctp/socket.c > index 014847e..dbf140d 100644 > --- a/net/sctp/socket.c > +++ b/net/sctp/socket.c > @@ -3891,13 +3891,17 @@ static int sctp_setsockopt_reset_streams(struct sock *sk, > struct sctp_association *asoc; > int retval = -EINVAL; > > - if (optlen < sizeof(struct sctp_reset_streams)) > + if (optlen < sizeof(*params)) > return -EINVAL; > > params = memdup_user(optval, optlen); > if (IS_ERR(params)) > return PTR_ERR(params); > > + if (params->srs_number_streams * sizeof(__u16) > > + optlen - sizeof(*params)) > + goto out; > + > asoc = sctp_id2assoc(sk, params->srs_assoc_id); > if (!asoc) > goto out; > -- > 2.1.0 >