mm: BUG in munlock_vma_pages_range

From: Dmitry Vyukov
Date: Mon Nov 14 2016 - 23:49:15 EST


Hello,

The following program triggers BUG in munlock_vma_pages_range:

// autogenerated by syzkaller (http://github.com/google/syzkaller)
#include <sys/mman.h>

int main()
{
mmap((void*)0x20105000ul, 0xc00000ul, 0x2ul, 0x2172ul, -1, 0);
mremap((void*)0x201fd000ul, 0x4000ul, 0xc00000ul, 0x3ul, 0x203f0000ul);
return 0;
}


page:ffffea0001847cc0 count:0 mapcount:1 mapping:dead000000000400
index:0x20400 compound_mapcount: 1
flags: 0x5fffc0000000000()
page dumped because: VM_BUG_ON_PAGE(PageMlocked(page))
------------[ cut here ]------------
kernel BUG at mm/mlock.c:460!
invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN
Modules linked in:
CPU: 2 PID: 6526 Comm: a.out Not tainted 4.9.0-rc5+ #28
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
task: ffff8800681ca0c0 task.stack: ffff8800637f0000
RIP: 0010:[<ffffffff81965272>] [<ffffffff81965272>]
munlock_vma_pages_range+0xcc2/0x1010 mm/mlock.c:460
RSP: 0018:ffff8800637f7178 EFLAGS: 00010292
RAX: 0000000000000000 RBX: ffffea0001847cc0 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffff88006d016e08 RDI: ffffed000c6fee20
RBP: ffff8800637f7638 R08: 0000000000000001 R09: 0000000000000000
R10: dffffc0000000000 R11: 0000000000000001 R12: ffffea0001847ce0
R13: ffffea0001840000 R14: dffffc0000000000 R15: ffff8800637f7610
FS: 0000000000000000(0000) GS:ffff88006d000000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00000000004b2080 CR3: 0000000064f87000 CR4: 00000000000006e0
Stack:
0000000041b58ab3 ffffffff894cfa90 ffff8800637f74f0 ffff8800637f7578
0000000000000005 ffff88007fff8000 1ffff1000c6fee42 ffff8800637f74b0
0000000020400000 000000050c6fee41 ffffea000196c55c ffffed000c6feeaf
Call Trace:
[< inline >] munlock_vma_pages_all mm/internal.h:277
[<ffffffff8197261b>] exit_mmap+0x1bb/0x4e0 mm/mmap.c:2924
[< inline >] __mmput kernel/fork.c:866
[<ffffffff813f24ce>] mmput+0x20e/0x4c0 kernel/fork.c:888
[< inline >] exit_mm kernel/exit.c:512
[<ffffffff814119a0>] do_exit+0x960/0x2640 kernel/exit.c:815
[<ffffffff8141383e>] do_group_exit+0x14e/0x420 kernel/exit.c:931
[< inline >] SYSC_exit_group kernel/exit.c:942
[<ffffffff81413b32>] SyS_exit_group+0x22/0x30 kernel/exit.c:940
[<ffffffff88143885>] entry_SYSCALL_64_fastpath+0x23/0xc6
arch/x86/entry/entry_64.S:209
Code: 0b e8 53 2e d8 ff 48 c7 c6 c0 32 31 88 48 89 df e8 54 2e fd ff
0f 0b e8 3d 2e d8 ff 48 c7 c6 80 35 31 88 48 89 df e8 3e 2e fd ff <0f>
0b 48 89 85 a8 fb ff ff e8 20 2e d8 ff 48 8b 85 a8 fb ff ff
RIP [<ffffffff81965272>] munlock_vma_pages_range+0xcc2/0x1010 mm/mlock.c:460
RSP <ffff8800637f7178>
---[ end trace 694dc6462f524cf9 ]---
Fixing recursive fault but reboot is needed!


On commit a25f0944ba9b1d8a6813fd6f1a86f1bd59ac25a6 (Nov 13).