BUG: unable to handle kernel NULL pointer dereference in sctp_stream_free

20 views
Skip to first unread message

syzbot

unread,
Dec 20, 2017, 3:51:04 PM12/20/17
to da...@davemloft.net, linux-...@vger.kernel.org, linux...@vger.kernel.org, net...@vger.kernel.org, nho...@tuxdriver.com, syzkall...@googlegroups.com, vyas...@gmail.com
Hello,

syzkaller hit the following crash on
6084b576dca2e898f5c101baef151f7bfdbb606d
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/master
compiler: gcc (GCC) 7.1.1 20170620
.config is attached
Raw console output is attached.

Unfortunately, I don't have any reproducer for this bug yet.


RAX: ffffffffffffffda RBX: 000000000071bea0 RCX: 0000000000452a09
RDX: 0000000000000010 RSI: 00000000200ba000 RDI: 0000000000000013
RBP: 000000000000004e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000212 R12: 00000000006ed7f0
R13: 0000000000000014 R14: 000000000071bf00 R15: ffffffffffffffff
BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
IP: sctp_stream_free+0x38/0x70 net/sctp/stream.c:209
PGD 1fff84067 P4D 1fff84067 PUD 1fc97b067 PMD 0
Oops: 0000 [#1] SMP
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 0 PID: 17287 Comm: syz-executor2 Not tainted 4.15.0-rc3-next-20171214+
#67
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
RIP: 0010:sctp_stream_free+0x38/0x70 net/sctp/stream.c:209
RSP: 0018:ffffc90000f87a28 EFLAGS: 00010202
RAX: 0000000000000000 RBX: 0000000000000001 RCX: ffffffff82407e51
RDX: 000000000000b1ed RSI: ffffc90001031000 RDI: ffff88020f8126d8
RBP: ffffc90000f87a40 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: ffff88020f8126d8 R14: ffff8802157464b0 R15: ffff8801fa982000
FS: 00007fe140a3f700(0000) GS:ffff88021fc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020616ff8 CR3: 0000000200d69003 CR4: 00000000001606f0
DR0: 0000000020000000 DR1: 0000000020000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000600
Call Trace:
sctp_association_free+0xd8/0x270 net/sctp/associola.c:367
sctp_sf_do_unexpected_init.isra.30+0x25e/0x530 net/sctp/sm_statefuns.c:1589
sctp_sf_do_5_2_2_dupinit+0x35/0x40 net/sctp/sm_statefuns.c:1646
sctp_do_sm+0x80/0x1dc0 net/sctp/sm_sideeffect.c:1190
sctp_endpoint_bh_rcv+0x142/0x2a0 net/sctp/endpointola.c:456
sctp_inq_push+0x6a/0xb0 net/sctp/inqueue.c:95
sctp_backlog_rcv+0x61/0x3a0 net/sctp/input.c:350
sk_backlog_rcv include/net/sock.h:907 [inline]
__release_sock+0x85/0x160 net/core/sock.c:2264
release_sock+0x37/0xe0 net/core/sock.c:2779
sctp_connect+0x6c/0x80 net/sctp/socket.c:4333
inet_dgram_connect+0x78/0xb0 net/ipv4/af_inet.c:541
SYSC_connect+0xaf/0x130 net/socket.c:1619
SyS_connect+0x24/0x30 net/socket.c:1600
entry_SYSCALL_64_fastpath+0x1f/0x96
RIP: 0033:0x452a09
RSP: 002b:00007fe140a3ec58 EFLAGS: 00000212 ORIG_RAX: 000000000000002a
RAX: ffffffffffffffda RBX: 000000000071bea0 RCX: 0000000000452a09
RDX: 0000000000000010 RSI: 00000000200ba000 RDI: 0000000000000013
RBP: 000000000000004e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000212 R12: 00000000006ed7f0
R13: 0000000000000014 R14: 000000000071bf00 R15: ffffffffffffffff
Code: 0f 25 eb fe 4c 89 ef e8 c7 3c 00 00 4c 89 ef ff 50 20 66 41 83 7d 10
00 74 28 45 31 e4 31 db e8 ef 24 eb fe 49 8b 45 00 83 c3 01 <4a> 8b 7c 20
08 49 83 c4 18 e8 ea 5d fd fe 41 0f b7 45 10 39 d8
RIP: sctp_stream_free+0x38/0x70 net/sctp/stream.c:209 RSP: ffffc90000f87a28
CR2: 0000000000000008
---[ end trace 5fbb25ea4389478d ]---


---
This bug is generated by a dumb bot. It may contain errors.
See https://goo.gl/tpsmEJ for details.
Direct all questions to syzk...@googlegroups.com.
Please credit me with: Reported-by: syzbot <syzk...@googlegroups.com>

syzbot will keep track of this bug report.
Once a fix for this bug is merged into any tree, reply to this email with:
#syz fix: exact-commit-title
To mark this as a duplicate of another syzbot report, please reply with:
#syz dup: exact-subject-of-another-report
If it's a one-off invalid bug report, please reply with:
#syz invalid
Note: if the crash happens again, it will cause creation of a new bug
report.
Note: all commands must start from beginning of the line in the email body.
config.txt
raw.log

Xin Long

unread,
Dec 22, 2017, 12:31:28 AM12/22/17
to Marcelo Ricardo Leitner, syzbot, davem, LKML, linux...@vger.kernel.org, network dev, Neil Horman, syzkall...@googlegroups.com, Vlad Yasevich
On Thu, Dec 21, 2017 at 9:13 PM, Marcelo Ricardo Leitner
<marcelo...@gmail.com> wrote:
> 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;
> }

In case it can't be verified due to no reproducer yet, I modified some
code in sctp_stream_init() to confirm Marcelo's deduction:
- i = sctp_stream_alloc_in(stream, incnt, gfp);
+ i = 1;
if (i) {
ret = -ENOMEM;
goto free;

And got the same call trace as the mail:

[ 301.488065] BUG: unable to handle kernel NULL pointer dereference
at 0000000000000008
[ 301.488618] IP: sctp_stream_free+0x2c/0x60 [sctp]
[ 301.488928] PGD 59a3b067 P4D 59a3b067 PUD 5994e067 PMD 0
[ 301.489372] Oops: 0000 [#1] SMP
[...]
[ 301.497647] Call Trace:
[ 301.497812] <IRQ>
[ 301.497955] sctp_association_free+0xb8/0x210 [sctp]
[ 301.498306] sctp_sf_do_5_1B_init+0x1c4/0x360 [sctp]
[ 301.498654] sctp_do_sm+0x9a/0x2d0 [sctp]
[ 301.498921] ? sctp_has_association+0x130/0x130 [sctp]
[ 301.499301] ? kernel_text_address+0xba/0xe0
[ 301.499615] ? check_usage_backwards+0x88/0x150
[ 301.499911] ? __lock_acquire+0x280/0x1080
[ 301.500200] ? sctp_endpoint_lookup_assoc+0x95/0x140 [sctp]
[ 301.500593] sctp_endpoint_bh_rcv+0x11e/0x220 [sctp]
[ 301.500923] sctp_rcv+0x9f5/0xbe0 [sctp]

And Marcelo's patch could fix it.

Since the "free:" part only works for if (i), maybe the patch can also do:
if (i) {
sched->free(stream);
kfree(stream->out);
stream->out = NULL;
stream->outcnt = 0;

ret = -ENOMEM;
goto out;
}

and remove the "free:" path.

Marcelo Ricardo Leitner

unread,
Dec 22, 2017, 2:35:14 AM12/22/17
to syzbot, da...@davemloft.net, linux-...@vger.kernel.org, linux...@vger.kernel.org, net...@vger.kernel.org, nho...@tuxdriver.com, syzkall...@googlegroups.com, vyas...@gmail.com
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
raw.log

Eric Biggers

unread,
Jan 30, 2018, 6:03:53 PM1/30/18
to Xin Long, Marcelo Ricardo Leitner, syzbot, davem, LKML, linux...@vger.kernel.org, network dev, Neil Horman, syzkall...@googlegroups.com, Vlad Yasevich
This crash seems to have stopped occurring now. I presume it was fixed by the
following commit, so let's tell syzbot to close the bug:

#syz fix: sctp: fix error path in sctp_stream_init

Marcelo Ricardo Leitner

unread,
Jan 31, 2018, 2:23:52 AM1/31/18
to Eric Biggers, Xin Long, syzbot, davem, LKML, linux...@vger.kernel.org, network dev, Neil Horman, syzkall...@googlegroups.com, Vlad Yasevich
Yes, thanks Eric.
Reply all
Reply to author
Forward
0 new messages