Re: memory leak in do_seccomp

From: Tycho Andersen
Date: Mon Aug 31 2020 - 20:10:49 EST


On Mon, Aug 31, 2020 at 04:25:35PM -0700, Kees Cook wrote:
> On Sun, Aug 30, 2020 at 08:50:15PM -0700, syzbot wrote:
> > syzbot has found a reproducer for the following issue on:
> >
> > HEAD commit: dcc5c6f0 Merge tag 'x86-urgent-2020-08-30' of git://git.ke..
> > git tree: upstream
> > console output: https://syzkaller.appspot.com/x/log.txt?x=10b297d5900000
> > kernel config: https://syzkaller.appspot.com/x/.config?x=903b9fecc3c6d231
> > dashboard link: https://syzkaller.appspot.com/bug?extid=3ad9614a12f80994c32e
> > compiler: gcc (GCC) 10.1.0-syz 20200507
> > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14649561900000
> > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=118aacc1900000
> >
> > IMPORTANT: if you fix the issue, please add the following tag to the commit:
> > Reported-by: syzbot+3ad9614a12f80994c32e@xxxxxxxxxxxxxxxxxxxxxxxxx
> >
> > executing program
> > executing program
> > executing program
> > executing program
> > executing program
> > BUG: memory leak
> > unreferenced object 0xffff88811ba93600 (size 64):
> > comm "syz-executor680", pid 6503, jiffies 4294951104 (age 21.940s)
> > hex dump (first 32 bytes):
> > 00 00 00 00 00 00 00 00 08 36 a9 1b 81 88 ff ff .........6......
> > 08 36 a9 1b 81 88 ff ff 11 ce 98 89 3a d5 b4 8f .6..........:...
> > backtrace:
> > [<00000000896418b0>] kmalloc include/linux/slab.h:554 [inline]
> > [<00000000896418b0>] kzalloc include/linux/slab.h:666 [inline]
> > [<00000000896418b0>] init_listener kernel/seccomp.c:1473 [inline]
> > [<00000000896418b0>] seccomp_set_mode_filter kernel/seccomp.c:1546 [inline]
> > [<00000000896418b0>] do_seccomp+0x8ce/0xd40 kernel/seccomp.c:1649
> > [<000000002b04976c>] do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
> > [<00000000322b4126>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>
> I haven't narrowed this down yet (and it *might* be a false positive),
> but it looks like this is filter->notif. The only way that's possible is
> if seccomp_notify_release() was never called *and* seccomp_filter_free()
> got called... which would imply a reference counting problem. The way
> there doesn't jump out at me yet, but I haven't yet decoded the C
> reproducer into the actual seccomp arguments, etc.

Looks like it's just a bunch of threads in the same thread group
trying to install a filter with TSYNC and NEW_LISTENER turned on. Does
the patch below look reasonable?

I didn't send it separately since I'm in the process of switching my
e-mail address to tycho@tycho.pizza; let this e-mail serve as proof
that that e-mail really is me too :). I can send it the normal way if
it looks good.