WARNING: kmalloc bug in relay_open_buf

18 views
Skip to first unread message

syzbot

unread,
Feb 6, 2018, 5:58:02 PM2/6/18
to adob...@gmail.com, ak...@linux-foundation.org, ar...@arndb.de, dave....@intel.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com, vi...@zeniv.linux.org.uk
Hello,

syzbot hit the following crash on upstream commit
e237f98a9c134c3d600353f21e07db915516875b (Mon Feb 5 21:35:56 2018 +0000)
Merge tag 'xfs-4.16-merge-5' of
git://git.kernel.org/pub/scm/fs/xfs/xfs-linux

C reproducer is attached.
syzkaller reproducer is attached.
Raw console output is attached.
compiler: gcc (GCC) 7.1.1 20170620
.config is attached.

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+7525b1...@syzkaller.appspotmail.com
It will help syzbot understand when the bug is fixed. See footer for
details.
If you forward the report, please keep this part and the footer.

audit: type=1400 audit(1517939984.452:7): avc: denied { map } for
pid=4159 comm="syzkaller032522" path="/root/syzkaller032522586" dev="sda1"
ino=16481 scontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023
tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=1
WARNING: CPU: 0 PID: 4159 at mm/slab_common.c:1012 kmalloc_slab+0x5d/0x70
mm/slab_common.c:1012
Kernel panic - not syncing: panic_on_warn set ...

CPU: 0 PID: 4159 Comm: syzkaller032522 Not tainted 4.15.0+ #299
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:17 [inline]
dump_stack+0x194/0x257 lib/dump_stack.c:53
panic+0x1e4/0x41c kernel/panic.c:183
__warn+0x1dc/0x200 kernel/panic.c:547
report_bug+0x211/0x2d0 lib/bug.c:184
fixup_bug.part.11+0x37/0x80 arch/x86/kernel/traps.c:178
fixup_bug arch/x86/kernel/traps.c:247 [inline]
do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296
do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315
invalid_op+0x22/0x40 arch/x86/entry/entry_64.S:984
RIP: 0010:kmalloc_slab+0x5d/0x70 mm/slab_common.c:1012
RSP: 0018:ffff8801b128f510 EFLAGS: 00010246
RAX: 0000000000000000 RBX: ffff8801cb661180 RCX: ffffffff81726847
RDX: 1ffff100397e0e02 RSI: 0000000000000000 RDI: 00000000b0d80008
RBP: ffff8801b128f510 R08: 1ffff10036251e16 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: ffff8801cbf07010
R13: 0000000000000000 R14: 00000000014000c0 R15: ffffffff868bab20
__do_kmalloc mm/slab.c:3700 [inline]
__kmalloc+0x25/0x760 mm/slab.c:3714
kmalloc include/linux/slab.h:517 [inline]
relay_create_buf kernel/relay.c:172 [inline]
relay_open_buf.part.10+0xc8/0x9b0 kernel/relay.c:449
relay_open_buf kernel/relay.c:446 [inline]
relay_open+0x57a/0xa40 kernel/relay.c:596
do_blk_trace_setup+0x4a4/0xcd0 kernel/trace/blktrace.c:544
__blk_trace_setup+0xbe/0x150 kernel/trace/blktrace.c:589
blk_trace_ioctl+0x206/0x2e0 kernel/trace/blktrace.c:728
blkdev_ioctl+0x1845/0x1e00 block/ioctl.c:587
block_ioctl+0xde/0x120 fs/block_dev.c:1860
vfs_ioctl fs/ioctl.c:46 [inline]
do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
SYSC_ioctl fs/ioctl.c:701 [inline]
SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692
do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287
entry_SYSCALL_64_after_hwframe+0x26/0x9b
RIP: 0033:0x443e79
RSP: 002b:00007ffe0625e398 EFLAGS: 00000202 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00000000004002e0 RCX: 0000000000443e79
RDX: 0000000020beaf68 RSI: 00000000c0481273 RDI: 0000000000000003
RBP: 00000000006ce018 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000401b20
R13: 0000000000401bb0 R14: 0000000000000000 R15: 0000000000000000
Dumping ftrace buffer:
(ftrace buffer empty)
Kernel Offset: disabled
Rebooting in 86400 seconds..


---
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.

syzbot will keep track of this bug report.
If you forgot to add the Reported-by tag, once the fix for this bug is
merged
into any tree, please reply to this email with:
#syz fix: exact-commit-title
If you want to test a patch for this bug, please reply with:
#syz test: git://repo/address.git branch
and provide the patch inline or as an attachment.
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.
raw.log.txt
repro.syz.txt
repro.c.txt
config.txt

Andrew Morton

unread,
Feb 6, 2018, 6:21:52 PM2/6/18
to syzbot, adob...@gmail.com, ar...@arndb.de, dave....@intel.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com, vi...@zeniv.linux.org.uk, David Rientjes
On Tue, 06 Feb 2018 14:58:02 -0800 syzbot <syzbot+7525b1...@syzkaller.appspotmail.com> wrote:

> Hello,
>
> syzbot hit the following crash on upstream commit
> e237f98a9c134c3d600353f21e07db915516875b (Mon Feb 5 21:35:56 2018 +0000)
> Merge tag 'xfs-4.16-merge-5' of
> git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
>
> C reproducer is attached.
> syzkaller reproducer is attached.
> Raw console output is attached.
> compiler: gcc (GCC) 7.1.1 20170620
> .config is attached.
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+7525b1...@syzkaller.appspotmail.com
> It will help syzbot understand when the bug is fixed. See footer for
> details.
> If you forward the report, please keep this part and the footer.
>
> audit: type=1400 audit(1517939984.452:7): avc: denied { map } for
> pid=4159 comm="syzkaller032522" path="/root/syzkaller032522586" dev="sda1"
> ino=16481 scontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023
> tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=1
> WARNING: CPU: 0 PID: 4159 at mm/slab_common.c:1012 kmalloc_slab+0x5d/0x70
> mm/slab_common.c:1012
> Kernel panic - not syncing: panic_on_warn set ...


David sent a fix today which I believe will address this.


From: David Rientjes <rien...@google.com>
Subject: kernel/relay.c: limit kmalloc size to KMALLOC_MAX_SIZE

chan->n_subbufs is set by the user and relay_create_buf() does a kmalloc()
of chan->n_subbufs * sizeof(size_t *).

kmalloc_slab() will generate a warning when this fails if
chan->subbufs * sizeof(size_t *) > KMALLOC_MAX_SIZE.

Limit chan->n_subbufs to the maximum allowed kmalloc() size.

Link: http://lkml.kernel.org/r/alpine.DEB.2.10.18...@chino.kir.corp.google.com
Fixes: f6302f1bcd75 ("relay: prevent integer overflow in relay_open()")
Signed-off-by: David Rientjes <rien...@google.com>
Reviewed-by: Andrew Morton <ak...@linux-foundation.org>
Cc: Jens Axboe <ax...@kernel.dk>
Cc: Dave Jiang <dave....@intel.com>
Cc: Al Viro <vi...@zeniv.linux.org.uk>
Cc: Dan Carpenter <dan.ca...@oracle.com>
Signed-off-by: Andrew Morton <ak...@linux-foundation.org>
---

kernel/relay.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff -puN kernel/relay.c~kernel-relay-limit-kmalloc-size-to-kmalloc_max_size kernel/relay.c
--- a/kernel/relay.c~kernel-relay-limit-kmalloc-size-to-kmalloc_max_size
+++ a/kernel/relay.c
@@ -163,7 +163,7 @@ static struct rchan_buf *relay_create_bu
{
struct rchan_buf *buf;

- if (chan->n_subbufs > UINT_MAX / sizeof(size_t *))
+ if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *))
return NULL;

buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
_

Dmitry Vyukov

unread,
Feb 6, 2018, 11:57:42 PM2/6/18
to Andrew Morton, syzbot, Alexey Dobriyan, Arnd Bergmann, Dave Jiang, LKML, syzkall...@googlegroups.com, Al Viro, David Rientjes
Thanks
Let's tell syzbot about the fix:
#syz fix: kernel/relay.c: limit kmalloc size to KMALLOC_MAX_SIZE
Reply all
Reply to author
Forward
0 new messages