linux-sctp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: general protection fault in sctp_stream_free
       [not found] <001a113a6750ca1607055d3836d8@google.com>
@ 2018-01-30 23:02 ` Eric Biggers
  2019-12-20  3:45   ` general protection fault in sctp_stream_free (2) syzbot
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2018-01-30 23:02 UTC (permalink / raw)
  To: syzbot
  Cc: davem, linux-kernel, linux-sctp, netdev, nhorman, syzkaller-bugs,
	vyasevich

On Sun, Nov 05, 2017 at 01:35:02AM -0700, syzbot wrote:
> Hello,
> 
> syzkaller hit the following crash on
> 2a171788ba7bb61995e98e8163204fc7880f63b2
> git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git/master
> compiler: gcc (GCC) 7.1.1 20170620
> .config is attached
> Raw console output is attached.
> 
> 
> 
> 
> R13: 00007ff7d3281b58 R14: 00000000004b7560 R15: 0000000000000000
> kasan: CONFIG_KASAN_INLINE enabled
> kasan: GPF could be caused by NULL-ptr deref or user memory access
> general protection fault: 0000 [#1] SMP KASAN
> Dumping ftrace buffer:
>    (ftrace buffer empty)
> Modules linked in:
> CPU: 1 PID: 17823 Comm: syz-executor4 Not tainted 4.14.0-rc7+ #109
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
> Google 01/01/2011
> task: ffff8801c6002380 task.stack: ffff8801c5fe0000
> RIP: 0010:sctp_stream_free+0xc3/0x1b0 net/sctp/stream.c:209
> RSP: 0018:ffff8801c5fe6fa0 EFLAGS: 00010202
> RAX: 0000000000000000 RBX: ffff8801c33fd0b0 RCX: ffffc90003989000
> RDX: 0000000000000001 RSI: ffffffff84837f78 RDI: 0000000000000008
> RBP: ffff8801c5fe6fe0 R08: 0000000000000000 R09: 1ffff10038bfcd69
> R10: 000000009cb59878 R11: 00000000f5f9e5c7 R12: 0000000000000000
> R13: 0000000000000000 R14: dffffc0000000000 R15: ffffed003867fa16
> FS:  00007ff7d3282700(0000) GS:ffff8801db300000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000020b50ffc CR3: 00000001c4a5c000 CR4: 00000000001406e0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
>  sctp_association_free+0x301/0x930 net/sctp/associola.c:367
>  sctp_sf_do_unexpected_init.isra.28+0x67e/0x13b0
> net/sctp/sm_statefuns.c:1589
>  sctp_sf_do_5_2_1_siminit+0x35/0x40 net/sctp/sm_statefuns.c:1645
>  sctp_do_sm+0x18a/0x6a30 net/sctp/sm_sideeffect.c:1190
>  sctp_assoc_bh_rcv+0x283/0x4b0 net/sctp/associola.c:1065
>  sctp_inq_push+0x23b/0x300 net/sctp/inqueue.c:95
>  sctp_backlog_rcv+0x177/0xaa0 net/sctp/input.c:350
>  sk_backlog_rcv include/net/sock.h:912 [inline]
>  __release_sock+0x124/0x360 net/core/sock.c:2266
>  release_sock+0xa4/0x2a0 net/core/sock.c:2778
>  sctp_sendmsg+0x18d1/0x32b0 net/sctp/socket.c:2051
>  inet_sendmsg+0x11f/0x5e0 net/ipv4/af_inet.c:763
>  sock_sendmsg_nosec net/socket.c:633 [inline]
>  sock_sendmsg+0xca/0x110 net/socket.c:643
>  SYSC_sendto+0x352/0x5a0 net/socket.c:1750
>  SyS_sendto+0x40/0x50 net/socket.c:1718
>  entry_SYSCALL_64_fastpath+0x1f/0xbe
> RIP: 0033:0x452869
> RSP: 002b:00007ff7d3281be8 EFLAGS: 00000212 ORIG_RAX: 000000000000002c
> RAX: ffffffffffffffda RBX: 00000000007580d8 RCX: 0000000000452869
> RDX: 0000000000000001 RSI: 00000000206a6000 RDI: 0000000000000013
> RBP: 00007ff7d3281a20 R08: 000000002064b000 R09: 000000000000001c
> R10: 0000000020000040 R11: 0000000000000212 R12: 00000000004b7550
> R13: 00007ff7d3281b58 R14: 00000000004b7560 R15: 0000000000000000
> Code: 48 c1 e8 03 4c 01 f0 48 89 45 d0 e8 d8 b4 ea fc 41 80 3f 00 0f 85 f1
> 00 00 00 48 8b 03 4c 01 e8 48 8d 78 08 48 89 fa 48 c1 ea 03 <42> 80 3c 32 00
> 0f 85 c3 00 00 00 48 8b 78 08 41 83 c4 01 e8 85
> RIP: sctp_stream_free+0xc3/0x1b0 net/sctp/stream.c:209 RSP: ffff8801c5fe6fa0
> ---[ end trace cf03319dc427fb51 ]---
> 
> 
> ---
> This bug is generated by a dumb bot. It may contain errors.
> See https://goo.gl/tpsmEJ for details.
> Direct all questions to syzkaller@googlegroups.com.
> Please credit me with: Reported-by: syzbot <syzkaller@googlegroups.com>
> 
> syzbot will keep track of this bug report.
> Once a fix for this bug is committed, please reply to this email with:
> #syz fix: exact-commit-title

This crash seems to have stopped occurring now.  I presume it was fixed by:

#syz fix: sctp: fix error path in sctp_stream_init

^ permalink raw reply	[flat|nested] 4+ messages in thread

* general protection fault in sctp_stream_free (2)
  2018-01-30 23:02 ` general protection fault in sctp_stream_free Eric Biggers
@ 2019-12-20  3:45   ` syzbot
  2019-12-20 15:28     ` Marcelo Ricardo Leitner
  0 siblings, 1 reply; 4+ messages in thread
From: syzbot @ 2019-12-20  3:45 UTC (permalink / raw)
  To: davem, linux-kernel, linux-sctp, lucien.xin, marcelo.leitner,
	netdev, nhorman, syzkaller-bugs, vyasevich

Hello,

syzbot found the following crash on:

HEAD commit:    6fa9a115 Merge branch 'stmmac-fixes'
git tree:       net
console output: https://syzkaller.appspot.com/x/log.txt?x\x10c4fe99e00000
kernel config:  https://syzkaller.appspot.com/x/.config?x!6dca5e1758db87
dashboard link: https://syzkaller.appspot.com/bug?extidš1bc632e78a1a98488b
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x\x178ada71e00000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x\x144f23a6e00000

The bug was bisected to:

commit 951c6db954a1adefab492f6da805decacabbd1a7
Author: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Date:   Tue Dec 17 01:01:16 2019 +0000

     sctp: fix memleak on err handling of stream initialization

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x\x13ffbdb6e00000
final crash:    https://syzkaller.appspot.com/x/report.txt?x\x10007db6e00000
console output: https://syzkaller.appspot.com/x/log.txt?x\x17ffbdb6e00000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+9a1bc632e78a1a98488b@syzkaller.appspotmail.com
Fixes: 951c6db954a1 ("sctp: fix memleak on err handling of stream  
initialization")

RBP: 0000000000000004 R08: 0000000000000008 R09: 00007ffc57730031
R10: 0000000020000040 R11: 0000000000000246 R12: 0000000000401f20
R13: 0000000000401fb0 R14: 0000000000000000 R15: 0000000000000000
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] PREEMPT SMP KASAN
CPU: 1 PID: 9129 Comm: syz-executor521 Not tainted 5.5.0-rc1-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
RIP: 0010:sctp_stream_free+0xe4/0x180 net/sctp/stream.c:183
Code: 07 48 89 d1 48 69 d2 aa 00 00 00 48 c1 e1 0c 48 29 d0 48 8d 04 40 48  
8d 34 c1 e8 57 24 54 fc 48 8d 78 08 48 89 fa 48 c1 ea 03 <42> 80 3c 32 00  
75 6f 48 8b 78 08 e8 1c 4c 77 fa 41 0f b6 45 00 84
RSP: 0018:ffffc90001e17770 EFLAGS: 00010202
RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff838f50f6
RDX: 0000000000000001 RSI: ffffffff838f5170 RDI: 0000000000000008
RBP: ffffc90001e177a8 R08: ffff888094206000 R09: fffffbfff16599c2
R10: fffffbfff16599c1 R11: ffffffff8b2cce0f R12: ffff8880a70126e8
R13: ffffed1014e024df R14: dffffc0000000000 R15: ffff8880a70120a8
FS:  0000000000f03880(0000) GS:ffff8880ae900000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020000100 CR3: 000000000986d000 CR4: 00000000001406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
  sctp_association_free+0x235/0x7e0 net/sctp/associola.c:350
  sctp_cmd_delete_tcb net/sctp/sm_sideeffect.c:934 [inline]
  sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1322 [inline]
  sctp_side_effects net/sctp/sm_sideeffect.c:1189 [inline]
  sctp_do_sm+0x3a6a/0x5190 net/sctp/sm_sideeffect.c:1160
  sctp_primitive_ABORT+0xa0/0xd0 net/sctp/primitive.c:104
  sctp_close+0x259/0x960 net/sctp/socket.c:1513
  inet_release+0xed/0x200 net/ipv4/af_inet.c:427
  __sock_release+0xce/0x280 net/socket.c:592
  sock_close+0x1e/0x30 net/socket.c:1270
  __fput+0x2ff/0x890 fs/file_table.c:280
  ____fput+0x16/0x20 fs/file_table.c:313
  task_work_run+0x145/0x1c0 kernel/task_work.c:113
  exit_task_work include/linux/task_work.h:22 [inline]
  do_exit+0x8e7/0x2ef0 kernel/exit.c:797
  do_group_exit+0x135/0x360 kernel/exit.c:895
  __do_sys_exit_group kernel/exit.c:906 [inline]
  __se_sys_exit_group kernel/exit.c:904 [inline]
  __x64_sys_exit_group+0x44/0x50 kernel/exit.c:904
  do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x43f2f8
Code: Bad RIP value.
RSP: 002b:00007ffc5773ea88 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 000000000043f2f8
RDX: 0000000000000000 RSI: 000000000000003c RDI: 0000000000000000
RBP: 00000000004bf0c8 R08: 00000000000000e7 R09: ffffffffffffffd0
R10: 0000000020000040 R11: 0000000000000246 R12: 0000000000000001
R13: 00000000006d1180 R14: 0000000000000000 R15: 0000000000000000
Modules linked in:
---[ end trace 0df255c71a71b566 ]---
RIP: 0010:sctp_stream_free+0xe4/0x180 net/sctp/stream.c:183
Code: 07 48 89 d1 48 69 d2 aa 00 00 00 48 c1 e1 0c 48 29 d0 48 8d 04 40 48  
8d 34 c1 e8 57 24 54 fc 48 8d 78 08 48 89 fa 48 c1 ea 03 <42> 80 3c 32 00  
75 6f 48 8b 78 08 e8 1c 4c 77 fa 41 0f b6 45 00 84
RSP: 0018:ffffc90001e17770 EFLAGS: 00010202
RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff838f50f6
RDX: 0000000000000001 RSI: ffffffff838f5170 RDI: 0000000000000008
RBP: ffffc90001e177a8 R08: ffff888094206000 R09: fffffbfff16599c2
R10: fffffbfff16599c1 R11: ffffffff8b2cce0f R12: ffff8880a70126e8
R13: ffffed1014e024df R14: dffffc0000000000 R15: ffff8880a70120a8
FS:  0000000000f03880(0000) GS:ffff8880ae900000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000000043f2ce CR3: 000000000986d000 CR4: 00000000001406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: general protection fault in sctp_stream_free (2)
  2019-12-20  3:45   ` general protection fault in sctp_stream_free (2) syzbot
@ 2019-12-20 15:28     ` Marcelo Ricardo Leitner
  2019-12-20 16:05       ` Marcelo Ricardo Leitner
  0 siblings, 1 reply; 4+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-12-20 15:28 UTC (permalink / raw)
  To: syzbot
  Cc: davem, linux-kernel, linux-sctp, lucien.xin, netdev, nhorman,
	syzkaller-bugs, vyasevich

On Thu, Dec 19, 2019 at 07:45:09PM -0800, syzbot wrote:
> Hello,
> 
> syzbot found the following crash on:
> 
> HEAD commit:    6fa9a115 Merge branch 'stmmac-fixes'
> git tree:       net
> console output: https://syzkaller.appspot.com/x/log.txt?x\x10c4fe99e00000
> kernel config:  https://syzkaller.appspot.com/x/.config?x!6dca5e1758db87
> dashboard link: https://syzkaller.appspot.com/bug?extidš1bc632e78a1a98488b
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x\x178ada71e00000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x\x144f23a6e00000
> 
> The bug was bisected to:
> 
> commit 951c6db954a1adefab492f6da805decacabbd1a7
> Author: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Date:   Tue Dec 17 01:01:16 2019 +0000
> 
>     sctp: fix memleak on err handling of stream initialization

Ouch... this wasn't a good fix.
When called from sctp_stream_init(), it is doing the right thing.
But when called from sctp_send_add_streams(), it can't free the
genradix. Ditto from sctp_process_strreset_addstrm_in().

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: general protection fault in sctp_stream_free (2)
  2019-12-20 15:28     ` Marcelo Ricardo Leitner
@ 2019-12-20 16:05       ` Marcelo Ricardo Leitner
  0 siblings, 0 replies; 4+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-12-20 16:05 UTC (permalink / raw)
  To: syzbot
  Cc: davem, linux-kernel, linux-sctp, lucien.xin, netdev, nhorman,
	syzkaller-bugs, vyasevich

On Fri, Dec 20, 2019 at 12:28:10PM -0300, Marcelo Ricardo Leitner wrote:
> On Thu, Dec 19, 2019 at 07:45:09PM -0800, syzbot wrote:
> > Hello,
> > 
> > syzbot found the following crash on:
> > 
> > HEAD commit:    6fa9a115 Merge branch 'stmmac-fixes'
> > git tree:       net
> > console output: https://syzkaller.appspot.com/x/log.txt?x\x10c4fe99e00000
> > kernel config:  https://syzkaller.appspot.com/x/.config?x!6dca5e1758db87
> > dashboard link: https://syzkaller.appspot.com/bug?extidš1bc632e78a1a98488b
> > compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> > syz repro:      https://syzkaller.appspot.com/x/repro.syz?x\x178ada71e00000
> > C reproducer:   https://syzkaller.appspot.com/x/repro.c?x\x144f23a6e00000
> > 
> > The bug was bisected to:
> > 
> > commit 951c6db954a1adefab492f6da805decacabbd1a7
> > Author: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> > Date:   Tue Dec 17 01:01:16 2019 +0000
> > 
> >     sctp: fix memleak on err handling of stream initialization
> 
> Ouch... this wasn't a good fix.
> When called from sctp_stream_init(), it is doing the right thing.
> But when called from sctp_send_add_streams(), it can't free the
> genradix. Ditto from sctp_process_strreset_addstrm_in().

Tentative fix. I'll post after additional tests.

--8<--

diff --git a/net/sctp/stream.c b/net/sctp/stream.c
index 6a30392068a0..c1a100d2fed3 100644
--- a/net/sctp/stream.c
+++ b/net/sctp/stream.c
@@ -84,10 +84,8 @@ static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt,
 		return 0;
 
 	ret = genradix_prealloc(&stream->out, outcnt, gfp);
-	if (ret) {
-		genradix_free(&stream->out);
+	if (ret)
 		return ret;
-	}
 
 	stream->outcnt = outcnt;
 	return 0;
@@ -102,10 +100,8 @@ static int sctp_stream_alloc_in(struct sctp_stream *stream, __u16 incnt,
 		return 0;
 
 	ret = genradix_prealloc(&stream->in, incnt, gfp);
-	if (ret) {
-		genradix_free(&stream->in);
+	if (ret)
 		return ret;
-	}
 
 	stream->incnt = incnt;
 	return 0;
@@ -123,7 +119,7 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
 	 * a new one with new outcnt to save memory if needed.
 	 */
 	if (outcnt = stream->outcnt)
-		goto in;
+		goto handle_in;
 
 	/* Filter out chunks queued on streams that won't exist anymore */
 	sched->unsched_all(stream);
@@ -132,24 +128,28 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
 
 	ret = sctp_stream_alloc_out(stream, outcnt, gfp);
 	if (ret)
-		goto out;
+		goto out_err;
 
 	for (i = 0; i < stream->outcnt; i++)
 		SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
 
-in:
+handle_in:
 	sctp_stream_interleave_init(stream);
 	if (!incnt)
 		goto out;
 
 	ret = sctp_stream_alloc_in(stream, incnt, gfp);
-	if (ret) {
-		sched->free(stream);
-		genradix_free(&stream->out);
-		stream->outcnt = 0;
-		goto out;
-	}
+	if (ret)
+		goto in_err;
+
+	goto out;
 
+in_err:
+	sched->free(stream);
+	genradix_free(&stream->in);
+out_err:
+	genradix_free(&stream->out);
+	stream->outcnt = 0;
 out:
 	return ret;
 }

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-20 16:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <001a113a6750ca1607055d3836d8@google.com>
2018-01-30 23:02 ` general protection fault in sctp_stream_free Eric Biggers
2019-12-20  3:45   ` general protection fault in sctp_stream_free (2) syzbot
2019-12-20 15:28     ` Marcelo Ricardo Leitner
2019-12-20 16:05       ` Marcelo Ricardo Leitner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).