From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17530C282C4 for ; Tue, 12 Feb 2019 15:47:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E75A1217D9 for ; Tue, 12 Feb 2019 15:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730711AbfBLPri (ORCPT ); Tue, 12 Feb 2019 10:47:38 -0500 Received: from charlotte.tuxdriver.com ([70.61.120.58]:36817 "EHLO smtp.tuxdriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726238AbfBLPri (ORCPT ); Tue, 12 Feb 2019 10:47:38 -0500 Received: from cpe-2606-a000-111b-405a-9816-2c85-c514-8f7a.dyn6.twc.com ([2606:a000:111b:405a:9816:2c85:c514:8f7a] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1gtaHP-0001D5-Q8; Tue, 12 Feb 2019 10:47:35 -0500 Date: Tue, 12 Feb 2019 10:46:55 -0500 From: Neil Horman To: Xin Long Cc: linux-kernel@vger.kernel.org, network dev , linux-sctp@vger.kernel.org, davem@davemloft.net, Marcelo Ricardo Leitner Subject: Re: [PATCH net] sctp: set stream ext to NULL after freeing it in sctp_stream_outq_migrate Message-ID: <20190212154655.GA2151@hmswarspite.think-freely.org> References: <0cb9e543c21495df48c3723044d6c9f64f238eca.1549968661.git.lucien.xin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0cb9e543c21495df48c3723044d6c9f64f238eca.1549968661.git.lucien.xin@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Feb 12, 2019 at 06:51:01PM +0800, Xin Long wrote: > In sctp_stream_init(), after sctp_stream_outq_migrate() freed the > surplus streams' ext, but sctp_stream_alloc_out() returns -ENOMEM, > stream->outcnt will not be set to 'outcnt'. > > With the bigger value on stream->outcnt, when closing the assoc and > freeing its streams, the ext of those surplus streams will be freed > again since those stream exts were not set to NULL after freeing in > sctp_stream_outq_migrate(). Then the invalid-free issue reported by > syzbot would be triggered. > > We fix it by simply setting them to NULL after freeing. > > Fixes: 5bbbbe32a431 ("sctp: introduce stream scheduler foundations") > Reported-by: syzbot+58e480e7b28f2d890bfd@syzkaller.appspotmail.com > Signed-off-by: Xin Long > --- > net/sctp/stream.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/net/sctp/stream.c b/net/sctp/stream.c > index f246331..2936ed1 100644 > --- a/net/sctp/stream.c > +++ b/net/sctp/stream.c > @@ -144,8 +144,10 @@ static void sctp_stream_outq_migrate(struct sctp_stream *stream, > } > } > > - for (i = outcnt; i < stream->outcnt; i++) > + for (i = outcnt; i < stream->outcnt; i++) { > kfree(SCTP_SO(stream, i)->ext); > + SCTP_SO(stream, i)->ext = NULL; > + } > } > > static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt, > -- > 2.1.0 > > Acked-by: Neil Horman