Subject: Re: BUG: unable to handle kernel NULL pointer dereference in sctp_stream_free

From: Marcelo Ricardo Leitner <[email-masked]>
Date: Thu, 21 Dec 2017 11:13:33 -0200

On Wed, Dec 20, 2017 at 12:51:01PM -0800, syzbot wrote:

from the log:
[   89.451366] FAULT_INJECTION: forcing a failure.^M
[   89.451366] name failslab, interval 1, probability 0, space 0,
times 0^M
[   89.451374] CPU: 0 PID: 17287 Comm: syz-executor2 Not tainted
+4.15.0-rc3-next-20171214+ #67^M
[   89.451377] Hardware name: Google Google Compute Engine/Google
Compute Engine, BIOS
+Google 01/01/2011^M
[   89.451380] Call Trace:^M
[   89.451395]  dump_stack+0xe9/0x14b^M
[   89.451408]  should_fail+0x1e5/0x220^M
[   89.451419]  should_failslab+0x73/0x90^M
[   89.451428]  __kmalloc+0x63/0x730^M
[   89.451439]  ? rcu_read_lock_sched_held+0x74/0x80^M
[   89.451446]  ? __kmalloc+0x4ac/0x730^M
[   89.451452]  ? sctp_stream_alloc_in+0x2f/0x100^M
[   89.451464]  sctp_stream_alloc_in+0x2f/0x100^M
[   89.451473]  sctp_stream_init+0xfa/0x140^M
[   89.451485]  sctp_process_init+0x676/0xc50^M

this is what caused the panic later, because in the error path we free
out but don't zero outcnt. This patch should fix it. Can you please
try it? Thanks

----8<---

diff --git a/net/sctp/stream.c b/net/sctp/stream.c
index 06b644dd858c..50ab09029f00 100644
--- a/net/sctp/stream.c
+++ b/net/sctp/stream.c
@@ -184,6 +184,7 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
 	sched->free(stream);
 	kfree(stream->out);
 	stream->out = NULL;
+	stream->outcnt = 0;
 out:
 	return ret;
 }