Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: use-after-free Write in lo_open
==================================================================
BUG: KASAN: use-after-free in instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
BUG: KASAN: use-after-free in atomic_inc include/asm-generic/atomic-instrumented.h:240 [inline]
BUG: KASAN: use-after-free in lo_open+0x93/0xc0 drivers/block/loop.c:1894
Write of size 4 at addr ffff88810ec98004 by task udevd/426
CPU: 0 PID: 426 Comm: udevd Not tainted 5.10.117-syzkaller-986967-g0974b8411a58-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack_lvl+0x1e2/0x24b lib/dump_stack.c:118
print_address_description+0x81/0x3c0 mm/kasan/report.c:233
__kasan_report mm/kasan/report.c:419 [inline]
kasan_report+0x1a4/0x1f0 mm/kasan/report.c:436
check_region_inline mm/kasan/generic.c:135 [inline]
kasan_check_range+0x2aa/0x2e0 mm/kasan/generic.c:186
__kasan_check_write+0x14/0x20 mm/kasan/shadow.c:37
instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
atomic_inc include/asm-generic/atomic-instrumented.h:240 [inline]
lo_open+0x93/0xc0 drivers/block/loop.c:1894
__blkdev_get+0x599/0x1360 fs/block_dev.c:1511
blkdev_get fs/block_dev.c:1651 [inline]
blkdev_open+0x21a/0x450 fs/block_dev.c:1768
do_dentry_open+0x7a2/0x1090 fs/open.c:819
vfs_open+0x73/0x80 fs/open.c:942
do_open fs/namei.c:3327 [inline]
path_openat+0x2638/0x2fd0 fs/namei.c:3444
do_filp_open+0x200/0x440 fs/namei.c:3471
do_sys_openat2+0x13b/0x470 fs/open.c:1211
do_sys_open fs/open.c:1227 [inline]
__do_sys_openat fs/open.c:1243 [inline]
__se_sys_openat fs/open.c:1238 [inline]
__x64_sys_openat+0x243/0x290 fs/open.c:1238
do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f966d0e3697
Code: 25 00 00 41 00 3d 00 00 41 00 74 37 64 8b 04 25 18 00 00 00 85 c0 75 5b 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 0f 87 85 00 00 00 48 83 c4 68 5d 41 5c c3 0f 1f
RSP: 002b:00007ffe5994ef10 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00005589d5104590 RCX: 00007f966d0e3697
RDX: 00000000000a0800 RSI: 00005589d50fd4a0 RDI: 00000000ffffff9c
RBP: 00005589d50fd4a0 R08: 00000000ffffffff R09: 00007ffe599e90b8
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000000a0800
R13: 00005589d5112970 R14: 0000000000000001 R15: 00005589d50d42c0
Allocated by task 460:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:428 [inline]
____kasan_kmalloc+0xdc/0x110 mm/kasan/common.c:507
__kasan_kmalloc+0x9/0x10 mm/kasan/common.c:516
kasan_kmalloc include/linux/kasan.h:269 [inline]
kmem_cache_alloc_trace+0x1dd/0x330 mm/slub.c:2983
kmalloc include/linux/slab.h:552 [inline]
kzalloc include/linux/slab.h:664 [inline]
loop_add+0x5a/0x770 drivers/block/loop.c:2083
loop_control_ioctl+0x564/0x740 drivers/block/loop.c:2294
vfs_ioctl fs/ioctl.c:48 [inline]
__do_sys_ioctl fs/ioctl.c:753 [inline]
__se_sys_ioctl+0x115/0x190 fs/ioctl.c:739
__x64_sys_ioctl+0x7b/0x90 fs/ioctl.c:739
do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
Freed by task 460:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track+0x4c/0x80 mm/kasan/common.c:46
kasan_set_free_info+0x23/0x40 mm/kasan/generic.c:357
____kasan_slab_free+0x121/0x160 mm/kasan/common.c:360
__kasan_slab_free+0x11/0x20 mm/kasan/common.c:368
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:1604 [inline]
slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1630
slab_free mm/slub.c:3212 [inline]
kfree+0xc3/0x290 mm/slub.c:4200
loop_add+0x591/0x770 drivers/block/loop.c:2182
loop_control_ioctl+0x564/0x740 drivers/block/loop.c:2294
vfs_ioctl fs/ioctl.c:48 [inline]
__do_sys_ioctl fs/ioctl.c:753 [inline]
__se_sys_ioctl+0x115/0x190 fs/ioctl.c:739
__x64_sys_ioctl+0x7b/0x90 fs/ioctl.c:739
do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
The buggy address belongs to the object at ffff88810ec98000
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 4 bytes inside of
1024-byte region [ffff88810ec98000, ffff88810ec98400)
The buggy address belongs to the page:
page:ffffea00043b2600 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10ec98
head:ffffea00043b2600 order:3 compound_mapcount:0 compound_pincount:0
flags: 0x8000000000010200(slab|head)
raw: 8000000000010200 dead000000000100 dead000000000122 ffff888100042f00
raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0x1d2000(__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 456, ts 42959091328, free_ts 42665339927
set_page_owner include/linux/page_owner.h:35 [inline]
post_alloc_hook mm/page_alloc.c:2385 [inline]
prep_new_page mm/page_alloc.c:2391 [inline]
get_page_from_freelist+0x745/0x760 mm/page_alloc.c:4067
__alloc_pages_nodemask+0x3b6/0x890 mm/page_alloc.c:5117
alloc_slab_page mm/slub.c:1815 [inline]
allocate_slab+0x78/0x540 mm/slub.c:1817
new_slab mm/slub.c:1878 [inline]
new_slab_objects mm/slub.c:2637 [inline]
___slab_alloc+0x131/0x2e0 mm/slub.c:2800
__slab_alloc+0x63/0xa0 mm/slub.c:2840
slab_alloc_node mm/slub.c:2922 [inline]
slab_alloc mm/slub.c:2964 [inline]
__kmalloc+0x24f/0x360 mm/slub.c:4038
__kmalloc_node include/linux/slab.h:418 [inline]
kmalloc_array_node include/linux/slab.h:627 [inline]
kcalloc_node include/linux/slab.h:632 [inline]
blk_mq_alloc_rq_map+0xa2/0x190 block/blk-mq.c:2428
__blk_mq_alloc_map_and_request block/blk-mq.c:2882 [inline]
__blk_mq_alloc_rq_maps block/blk-mq.c:3396 [inline]
blk_mq_alloc_map_and_requests+0x12e/0x7d0 block/blk-mq.c:3422
blk_mq_alloc_tag_set+0x662/0xd40 block/blk-mq.c:3575
loop_add+0x241/0x770 drivers/block/loop.c:2111
loop_control_ioctl+0x564/0x740 drivers/block/loop.c:2294
vfs_ioctl fs/ioctl.c:48 [inline]
__do_sys_ioctl fs/ioctl.c:753 [inline]
__se_sys_ioctl+0x115/0x190 fs/ioctl.c:739
__x64_sys_ioctl+0x7b/0x90 fs/ioctl.c:739
do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
page last free stack trace:
reset_page_owner include/linux/page_owner.h:28 [inline]
free_pages_prepare mm/page_alloc.c:1331 [inline]
__free_pages_ok+0x7f8/0x830 mm/page_alloc.c:1611
free_the_page mm/page_alloc.c:5178 [inline]
__free_pages+0x2d2/0x4c0 mm/page_alloc.c:5184
__free_slab+0xd3/0x190 mm/slub.c:1903
free_slab mm/slub.c:1918 [inline]
discard_slab mm/slub.c:1924 [inline]
unfreeze_partials+0x17d/0x1b0 mm/slub.c:2418
put_cpu_partial+0xc8/0x190 mm/slub.c:2454
__slab_free+0x2d8/0x3a0 mm/slub.c:3104
do_slab_free mm/slub.c:3200 [inline]
___cache_free+0x11f/0x140 mm/slub.c:3219
qlink_free+0x38/0x40 mm/kasan/quarantine.c:146
qlist_free_all+0x4c/0xc0 mm/kasan/quarantine.c:165
kasan_quarantine_reduce+0x15a/0x170 mm/kasan/quarantine.c:272
__kasan_slab_alloc+0x2f/0xe0 mm/kasan/common.c:438
kasan_slab_alloc include/linux/kasan.h:259 [inline]
slab_post_alloc_hook mm/slab.h:583 [inline]
slab_alloc_node mm/slub.c:2956 [inline]
slab_alloc mm/slub.c:2964 [inline]
kmem_cache_alloc+0x16c/0x300 mm/slub.c:2969
getname_flags+0xba/0x510 fs/namei.c:141
user_path_at_empty+0x2d/0x50 fs/namei.c:2726
user_path_at include/linux/namei.h:59 [inline]
ksys_umount fs/namespace.c:1761 [inline]
__do_sys_umount fs/namespace.c:1769 [inline]
__se_sys_umount fs/namespace.c:1767 [inline]
__x64_sys_umount+0xf0/0x170 fs/namespace.c:1767
do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
Memory state around the buggy address:
ffff88810ec97f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88810ec97f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88810ec98000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88810ec98080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88810ec98100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
------------[ cut here ]------------
refcount_t: addition on 0; use-after-free.
WARNING: CPU: 0 PID: 426 at lib/refcount.c:25 refcount_warn_saturate+0x147/0x1b0 lib/refcount.c:25
Modules linked in:
CPU: 0 PID: 426 Comm: udevd Tainted: G B 5.10.117-syzkaller-986967-g0974b8411a58-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:refcount_warn_saturate+0x147/0x1b0 lib/refcount.c:25
Code: c7 e0 be 43 85 31 c0 e8 57 22 f2 fe 0f 0b eb a1 e8 ee e7 1f ff c6 05 7a 6c 0f 04 01 48 c7 c7 60 bf 43 85 31 c0 e8 39 22 f2 fe <0f> 0b eb 83 e8 d0 e7 1f ff c6 05 5d 6c 0f 04 01 48 c7 c7 c0 bf 43
RSP: 0018:ffffc90000d37670 EFLAGS: 00010246
RAX: 17664f3077409100 RBX: 0000000000000002 RCX: ffff8881065b4f00
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: ffffc90000d37680 R08: ffffffff8153a998 R09: ffffed103ee4a5d8
R10: ffffed103ee4a5d8 R11: 1ffff1103ee4a5d7 R12: dffffc0000000000
R13: ffff88810ed96000 R14: 0000000000000002 R15: ffff88810ed96000
FS: 00007f966cf8c840(0000) GS:ffff8881f7200000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f56c0f5b090 CR3: 000000010d77d000 CR4: 00000000003506b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
__refcount_add include/linux/refcount.h:200 [inline]
__refcount_inc include/linux/refcount.h:250 [inline]
refcount_inc include/linux/refcount.h:267 [inline]
kref_get include/linux/kref.h:45 [inline]
bdi_get+0x83/0x90 include/linux/backing-dev.h:24
__blkdev_get+0x120c/0x1360 fs/block_dev.c:1554
blkdev_get fs/block_dev.c:1651 [inline]
blkdev_open+0x21a/0x450 fs/block_dev.c:1768
do_dentry_open+0x7a2/0x1090 fs/open.c:819
vfs_open+0x73/0x80 fs/open.c:942
do_open fs/namei.c:3327 [inline]
path_openat+0x2638/0x2fd0 fs/namei.c:3444
do_filp_open+0x200/0x440 fs/namei.c:3471
do_sys_openat2+0x13b/0x470 fs/open.c:1211
do_sys_open fs/open.c:1227 [inline]
__do_sys_openat fs/open.c:1243 [inline]
__se_sys_openat fs/open.c:1238 [inline]
__x64_sys_openat+0x243/0x290 fs/open.c:1238
do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f966d0e3697
Code: 25 00 00 41 00 3d 00 00 41 00 74 37 64 8b 04 25 18 00 00 00 85 c0 75 5b 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 0f 87 85 00 00 00 48 83 c4 68 5d 41 5c c3 0f 1f
RSP: 002b:00007ffe5994ef10 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00005589d5104590 RCX: 00007f966d0e3697
RDX: 00000000000a0800 RSI: 00005589d50fd4a0 RDI: 00000000ffffff9c
RBP: 00005589d50fd4a0 R08: 00000000ffffffff R09: 00007ffe599e90b8
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000000a0800
R13: 00005589d5112970 R14: 0000000000000001 R15: 00005589d50d42c0
---[ end trace c7267627e521d031 ]---
------------[ cut here ]------------
refcount_t: saturated; leaking memory.
WARNING: CPU: 1 PID: 426 at lib/refcount.c:22 refcount_warn_saturate+0x129/0x1b0 lib/refcount.c:22
Modules linked in:
CPU: 1 PID: 426 Comm: udevd Tainted: G B W 5.10.117-syzkaller-986967-g0974b8411a58-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:refcount_warn_saturate+0x129/0x1b0 lib/refcount.c:22
Code: c7 80 c0 43 85 31 c0 e8 75 22 f2 fe 0f 0b eb bf e8 0c e8 1f ff c6 05 97 6c 0f 04 01 48 c7 c7 e0 be 43 85 31 c0 e8 57 22 f2 fe <0f> 0b eb a1 e8 ee e7 1f ff c6 05 7a 6c 0f 04 01 48 c7 c7 60 bf 43
RSP: 0018:ffffc90000d37670 EFLAGS: 00010246
RAX: 17664f3077409100 RBX: 0000000000000001 RCX: ffff8881065b4f00
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: ffffc90000d37680 R08: ffffffff8153a998 R09: ffffed103ee6a5d8
R10: ffffed103ee6a5d8 R11: 1ffff1103ee6a5d7 R12: 00000000c0000001
R13: ffff88810eea1000 R14: 0000000000000001 R15: ffff88810eea1000
FS: 00007f966cf8c840(0000) GS:ffff8881f7300000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005589d51578c0 CR3: 000000010d77d000 CR4: 00000000003506a0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
__refcount_add include/linux/refcount.h:200 [inline]
__refcount_inc include/linux/refcount.h:250 [inline]
refcount_inc include/linux/refcount.h:267 [inline]
kref_get include/linux/kref.h:45 [inline]
bdi_get+0x83/0x90 include/linux/backing-dev.h:24
__blkdev_get+0x120c/0x1360 fs/block_dev.c:1554
blkdev_get fs/block_dev.c:1651 [inline]
blkdev_open+0x21a/0x450 fs/block_dev.c:1768
do_dentry_open+0x7a2/0x1090 fs/open.c:819
vfs_open+0x73/0x80 fs/open.c:942
do_open fs/namei.c:3327 [inline]
path_openat+0x2638/0x2fd0 fs/namei.c:3444
do_filp_open+0x200/0x440 fs/namei.c:3471
do_sys_openat2+0x13b/0x470 fs/open.c:1211
do_sys_open fs/open.c:1227 [inline]
__do_sys_openat fs/open.c:1243 [inline]
__se_sys_openat fs/open.c:1238 [inline]
__x64_sys_openat+0x243/0x290 fs/open.c:1238
do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f966d0e3697
Code: 25 00 00 41 00 3d 00 00 41 00 74 37 64 8b 04 25 18 00 00 00 85 c0 75 5b 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 0f 87 85 00 00 00 48 83 c4 68 5d 41 5c c3 0f 1f
RSP: 002b:00007ffe5994ef10 EFLAGS: 00000246
ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00005589d5104590 RCX: 00007f966d0e3697
RDX: 00000000000a0800 RSI: 00005589d50d7f20 RDI: 00000000ffffff9c
RBP: 00005589d50d7f20 R08: 00000000ffffffff R09: 00007ffe599e90b8
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000000a0800
R13: 00005589d5112970 R14: 0000000000000001 R15: 00005589d50d42c0
---[ end trace c7267627e521d033 ]---
udevd[426]: inotify_add_watch(7, /dev/loop0, 10) failed: No such file or directory
udevd[426]: inotify_add_watch(7, /dev/loop0, 10) failed: No such file or directory
Tested on:
commit: 0974b841 Merge 5.10.117 into android12-5.10-lts
git tree: android12-5.10-lts
console output:
https://syzkaller.appspot.com/x/log.txt?x=12b86c03f00000
kernel config:
https://syzkaller.appspot.com/x/.config?x=89bdb361ba397fca
dashboard link:
https://syzkaller.appspot.com/bug?extid=7308a6f9b7c24d5cf1d5
compiler: Debian clang version 13.0.1-++20220126092033+75e33f71c2da-1~exp1~20220126212112.63, GNU ld (GNU Binutils for Debian) 2.35.2
patch:
https://syzkaller.appspot.com/x/patch.diff?x=1198daf3f00000