syzbot


KASAN: slab-out-of-bounds Write in watch_queue_set_filter

Status: internal: reported C repro on 2022/03/17 15:44
Reported-by: syzbot+@syzkaller.appspotmail.com
Fix commit: c993ee0f9f81 watch_queue: Fix filter limit check
Patched on: [ci-qemu-upstream ci-qemu-upstream-386 ci-qemu2-arm32 ci-qemu2-arm64 ci-qemu2-arm64-compat ci-qemu2-arm64-mte ci-upstream-bpf-kasan-gce ci-upstream-bpf-next-kasan-gce ci-upstream-gce-leak ci-upstream-kasan-gce ci-upstream-kasan-gce-386 ci-upstream-kasan-gce-root ci-upstream-kasan-gce-selinux-root ci-upstream-kasan-gce-smack-root ci-upstream-kmsan-gce ci-upstream-kmsan-gce-386 ci-upstream-linux-next-kasan-gce-root ci-upstream-net-kasan-gce ci-upstream-net-this-kasan-gce ci2-upstream-kcsan-gce ci2-upstream-usb], missing on: [ci-qemu2-riscv64]
First crash: 103d, last: 100d

Cause bisection: the issue happens on the oldest tested release (bisect log)
Crash: KASAN: slab-out-of-bounds Write in watch_queue_set_filter (log)
Repro: C syz .config

Sample crash report:
==================================================================
BUG: KASAN: slab-out-of-bounds in watch_queue_set_filter+0x78d/0x810 kernel/watch_queue.c:343
Write of size 4 at addr ffff888024c6221c by task syz-executor171/3595

CPU: 1 PID: 3595 Comm: syz-executor171 Not tainted 5.17.0-rc6-next-20220303-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description.constprop.0.cold+0xeb/0x495 mm/kasan/report.c:313
 print_report mm/kasan/report.c:429 [inline]
 kasan_report.cold+0xf4/0x1c6 mm/kasan/report.c:491
 watch_queue_set_filter+0x78d/0x810 kernel/watch_queue.c:343
 pipe_ioctl+0x25b/0x2b0 fs/pipe.c:637
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl fs/ioctl.c:856 [inline]
 __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f2a91a94049
Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd823e2278 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f2a91a94049
RDX: 0000000020000300 RSI: 0000000000005761 RDI: 0000000000000004
RBP: 00007f2a91a58030 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f2a91a580c0
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
 </TASK>

Allocated by task 3595:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:436 [inline]
 ____kasan_kmalloc mm/kasan/common.c:515 [inline]
 ____kasan_kmalloc mm/kasan/common.c:474 [inline]
 __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:524
 kmalloc include/linux/slab.h:589 [inline]
 kzalloc include/linux/slab.h:717 [inline]
 watch_queue_set_filter+0x2f2/0x810 kernel/watch_queue.c:332
 pipe_ioctl+0x25b/0x2b0 fs/pipe.c:637
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl fs/ioctl.c:856 [inline]
 __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

The buggy address belongs to the object at ffff888024c62200
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 28 bytes inside of
 32-byte region [ffff888024c62200, ffff888024c62220)

The buggy address belongs to the physical page:
page:ffffea0000931880 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x24c62
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea00006a9b80 dead000000000003 ffff888010c41500
raw: 0000000000000000 0000000080400040 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x12c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY), pid 2964, tgid 2964 (udevadm), ts 14549069631, free_ts 12873352607
 prep_new_page mm/page_alloc.c:2438 [inline]
 get_page_from_freelist+0xa7f/0x3ec0 mm/page_alloc.c:4182
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5400
 alloc_pages+0x1aa/0x310 mm/mempolicy.c:2268
 alloc_slab_page mm/slub.c:1799 [inline]
 allocate_slab+0x26c/0x3c0 mm/slub.c:1944
 new_slab mm/slub.c:2004 [inline]
 ___slab_alloc+0x8d0/0xf30 mm/slub.c:3018
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3105
 slab_alloc_node mm/slub.c:3196 [inline]
 slab_alloc mm/slub.c:3238 [inline]
 __kmalloc+0x318/0x350 mm/slub.c:4434
 kmalloc include/linux/slab.h:589 [inline]
 kzalloc include/linux/slab.h:717 [inline]
 tomoyo_encode2.part.0+0xe9/0x3a0 security/tomoyo/realpath.c:45
 tomoyo_encode2 security/tomoyo/realpath.c:31 [inline]
 tomoyo_encode+0x28/0x50 security/tomoyo/realpath.c:80
 tomoyo_realpath_from_path+0x186/0x620 security/tomoyo/realpath.c:288
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_check_open_permission+0x272/0x380 security/tomoyo/file.c:771
 tomoyo_file_open security/tomoyo/tomoyo.c:311 [inline]
 tomoyo_file_open+0xa3/0xd0 security/tomoyo/tomoyo.c:306
 security_file_open+0x45/0xb0 security/security.c:1651
 do_dentry_open+0x358/0x1250 fs/open.c:944
 do_open fs/namei.c:3476 [inline]
 path_openat+0x1c9e/0x2940 fs/namei.c:3609
 do_filp_open+0x1aa/0x400 fs/namei.c:3636
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1353 [inline]
 free_pcp_prepare+0x549/0xd20 mm/page_alloc.c:1403
 free_unref_page_prepare mm/page_alloc.c:3325 [inline]
 free_unref_page+0x19/0x690 mm/page_alloc.c:3420
 kasan_depopulate_vmalloc_pte+0x5c/0x70 mm/kasan/shadow.c:359
 apply_to_pte_range mm/memory.c:2547 [inline]
 apply_to_pmd_range mm/memory.c:2591 [inline]
 apply_to_pud_range mm/memory.c:2627 [inline]
 apply_to_p4d_range mm/memory.c:2663 [inline]
 __apply_to_page_range+0x686/0x1030 mm/memory.c:2697
 kasan_release_vmalloc+0xa7/0xc0 mm/kasan/shadow.c:469
 __purge_vmap_area_lazy+0x8f9/0x1c50 mm/vmalloc.c:1735
 _vm_unmap_aliases.part.0+0x3f0/0x500 mm/vmalloc.c:2140
 _vm_unmap_aliases mm/vmalloc.c:2114 [inline]
 vm_unmap_aliases+0x45/0x50 mm/vmalloc.c:2163
 change_page_attr_set_clr+0x241/0x500 arch/x86/mm/pat/set_memory.c:1743
 change_page_attr_set arch/x86/mm/pat/set_memory.c:1793 [inline]
 set_memory_nx+0xb2/0x110 arch/x86/mm/pat/set_memory.c:1941
 free_init_pages+0x73/0xc0 arch/x86/mm/init.c:898
 kernel_init+0x2e/0x1d0 init/main.c:1516
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Memory state around the buggy address:
 ffff888024c62100: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
 ffff888024c62180: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
>ffff888024c62200: 00 00 00 fc fc fc fc fc fa fb fb fb fc fc fc fc
                            ^
 ffff888024c62280: 00 00 00 05 fc fc fc fc fa fb fb fb fc fc fc fc
 ffff888024c62300: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
==================================================================

Crashes (7):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-linux-next-kasan-gce-root 2022/03/17 23:56 linux-next 91265a6da44d e2d91b1d .config log report syz C KASAN: slab-out-of-bounds Write in watch_queue_set_filter
ci-upstream-linux-next-kasan-gce-root 2022/03/20 21:53 linux-next 91265a6da44d e2d91b1d .config log report info KASAN: slab-out-of-bounds Write in watch_queue_set_filter
ci-upstream-linux-next-kasan-gce-root 2022/03/20 00:05 linux-next 91265a6da44d e2d91b1d .config log report info KASAN: slab-out-of-bounds Write in watch_queue_set_filter
ci-upstream-linux-next-kasan-gce-root 2022/03/19 11:05 linux-next 91265a6da44d e2d91b1d .config log report info KASAN: slab-out-of-bounds Write in watch_queue_set_filter
ci-upstream-linux-next-kasan-gce-root 2022/03/17 23:44 linux-next 91265a6da44d e2d91b1d .config log report info KASAN: slab-out-of-bounds Write in watch_queue_set_filter
ci-upstream-linux-next-kasan-gce-root 2022/03/17 15:43 linux-next 91265a6da44d dfa9a8ed .config log report info KASAN: slab-out-of-bounds Write in watch_queue_set_filter
ci-upstream-linux-next-kasan-gce-root 2022/03/17 15:43 linux-next 91265a6da44d dfa9a8ed .config log report info KASAN: slab-out-of-bounds Write in watch_queue_set_filter