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@xxxxxxxxxxxxxxxxxxxxxxxxx > Signed-off-by: Xin Long <lucien.xin@xxxxxxxxx> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@xxxxxxxxx> > --- > 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 >