KASAN: double-free or invalid-free in relay_open

82 views
Skip to first unread message

syzbot

unread,
Oct 31, 2017, 9:04:03 AM10/31/17
to adob...@gmail.com, ak...@linux-foundation.org, dan.ca...@oracle.com, dave....@intel.com, linux-...@vger.kernel.org, ross.z...@linux.intel.com, syzkall...@googlegroups.com, vi...@zeniv.linux.org.uk
Hello,

syzkaller hit the following crash on
36ef71cae353f88fd6e095e2aaa3e5953af1685d
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.
C reproducer is attached
syzkaller reproducer is attached. See https://goo.gl/kgGztJ
for information about syzkaller reproducers


==================================================================
BUG: KASAN: double-free or invalid-free in relay_open+0x6a1/0xa40
kernel/relay.c:614

CPU: 2 PID: 2990 Comm: syzkaller414652 Not tainted
4.14.0-rc5-next-20171018+ #8
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:16 [inline]
dump_stack+0x194/0x257 lib/dump_stack.c:52
print_address_description+0x73/0x250 mm/kasan/report.c:252
kasan_report_double_free+0x55/0x80 mm/kasan/report.c:333
kasan_slab_free+0xa3/0xc0 mm/kasan/kasan.c:514
__cache_free mm/slab.c:3492 [inline]
kfree+0xca/0x250 mm/slab.c:3807
relay_open+0x6a1/0xa40 kernel/relay.c:614
do_blk_trace_setup+0x4a4/0xcf0 kernel/trace/blktrace.c:517
blk_trace_setup+0xbd/0x180 kernel/trace/blktrace.c:564
sg_ioctl+0xc71/0x2d90 drivers/scsi/sg.c:1089
vfs_ioctl fs/ioctl.c:45 [inline]
do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:685
SYSC_ioctl fs/ioctl.c:700 [inline]
SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691
entry_SYSCALL_64_fastpath+0x1f/0xbe
RIP: 0033:0x439149
RSP: 002b:00007ffe878e2f78 EFLAGS: 00000206 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00000000004002c8 RCX: 0000000000439149
RDX: 000000002084cf90 RSI: 00000000c0481273 RDI: 0000000000000003
RBP: 0000000000000082 R08: 00000000000000fe R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000
R13: 0000000000401da0 R14: 0000000000401e30 R15: 0000000000000000

Allocated by task 2990:
save_stack+0x43/0xd0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:551
kmem_cache_alloc_trace+0x136/0x750 mm/slab.c:3614
kmalloc include/linux/slab.h:502 [inline]
kzalloc include/linux/slab.h:691 [inline]
relay_open+0xf2/0xa40 kernel/relay.c:576
do_blk_trace_setup+0x4a4/0xcf0 kernel/trace/blktrace.c:517
blk_trace_setup+0xbd/0x180 kernel/trace/blktrace.c:564
sg_ioctl+0xc71/0x2d90 drivers/scsi/sg.c:1089
vfs_ioctl fs/ioctl.c:45 [inline]
do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:685
SYSC_ioctl fs/ioctl.c:700 [inline]
SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691
entry_SYSCALL_64_fastpath+0x1f/0xbe

Freed by task 2990:
save_stack+0x43/0xd0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_slab_free+0x71/0xc0 mm/kasan/kasan.c:524
__cache_free mm/slab.c:3492 [inline]
kfree+0xca/0x250 mm/slab.c:3807
relay_destroy_channel kernel/relay.c:199 [inline]
kref_put include/linux/kref.h:70 [inline]
relay_open+0x84a/0xa40 kernel/relay.c:612
do_blk_trace_setup+0x4a4/0xcf0 kernel/trace/blktrace.c:517
blk_trace_setup+0xbd/0x180 kernel/trace/blktrace.c:564
sg_ioctl+0xc71/0x2d90 drivers/scsi/sg.c:1089
vfs_ioctl fs/ioctl.c:45 [inline]
do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:685
SYSC_ioctl fs/ioctl.c:700 [inline]
SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691
entry_SYSCALL_64_fastpath+0x1f/0xbe

The buggy address belongs to the object at ffff88003c97dd00
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 0 bytes inside of
512-byte region [ffff88003c97dd00, ffff88003c97df00)
The buggy address belongs to the page:
page:ffffea0000f25f40 count:1 mapcount:0 mapping:ffff88003c97d080 index:0x0
flags: 0x100000000000100(slab)
raw: 0100000000000100 ffff88003c97d080 0000000000000000 0000000100000006
raw: ffffea0000f25f20 ffffea0000f261e0 ffff88003e800940 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff88003c97dc00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88003c97dc80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> ffff88003c97dd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88003c97dd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88003c97de00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


---
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 committed, please 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.
config.txt
raw.log
repro.txt
repro.c

Eric Biggers

unread,
Jan 26, 2018, 7:49:16 PM1/26/18
to linux-...@vger.kernel.org, Andrew Morton, Zhouyi Zhou, Jens Axboe, linux...@vger.kernel.org, syzkall...@googlegroups.com, Eric Biggers, sta...@vger.kernel.org
From: Eric Biggers <ebig...@google.com>

This reverts commit ba62bafe942b159a6109cbec780d36496e06b6c5.

This commit introduced a double free bug, because 'chan' is already
freed by the line:

kref_put(&chan->kref, relay_destroy_channel);

This bug was found by syzkaller, using the BLKTRACESETUP ioctl.

Fixes: ba62bafe942b ("kernel/relay.c: fix potential memory leak")
Reported-by: syzbot <syzk...@googlegroups.com>
Cc: <sta...@vger.kernel.org> # v4.7+
Signed-off-by: Eric Biggers <ebig...@google.com>
---
kernel/relay.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/kernel/relay.c b/kernel/relay.c
index 39a9dfc69486..55da824f4adc 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -611,7 +611,6 @@ struct rchan *relay_open(const char *base_filename,

kref_put(&chan->kref, relay_destroy_channel);
mutex_unlock(&relay_channels_mutex);
- kfree(chan);
return NULL;
}
EXPORT_SYMBOL_GPL(relay_open);
--
2.16.0.rc1.238.g530d649a79-goog

Eric Biggers

unread,
Feb 9, 2018, 2:17:42 PM2/9/18
to syzbot, syzkall...@googlegroups.com
Fixed by commit a1be1f3931bf:

#syz fix: kernel/relay.c: revert "kernel/relay.c: fix potential memory leak"

- Eric
Reply all
Reply to author
Forward
0 new messages