[syzbot] KASAN: use-after-free Read in bdev_evict_inode

11 views
Skip to first unread message

syzbot

unread,
Aug 14, 2021, 7:07:24ā€ÆAM8/14/21
to ax...@kernel.dk, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com, vi...@zeniv.linux.org.uk
Hello,

syzbot found the following issue on:

HEAD commit: 92d00774360d Add linux-next specific files for 20210810
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=10922209300000
kernel config: https://syzkaller.appspot.com/x/.config?x=a6933fa6f9a86ca9
dashboard link: https://syzkaller.appspot.com/bug?extid=1fb38bb7d3ce0fa3e1c4
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.1
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=115c5381300000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17c7d036300000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+1fb38b...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in wb_put_many include/linux/backing-dev-defs.h:250 [inline]
BUG: KASAN: use-after-free in wb_put include/linux/backing-dev-defs.h:268 [inline]
BUG: KASAN: use-after-free in inode_detach_wb include/linux/writeback.h:251 [inline]
BUG: KASAN: use-after-free in bdev_evict_inode+0x3c3/0x410 fs/block_dev.c:832
Read of size 8 at addr ffff888146568060 by task syz-executor103/6845

CPU: 1 PID: 6845 Comm: syz-executor103 Not tainted 5.14.0-rc5-next-20210810-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
print_address_description.constprop.0.cold+0x6c/0x309 mm/kasan/report.c:256
__kasan_report mm/kasan/report.c:442 [inline]
kasan_report.cold+0x83/0xdf mm/kasan/report.c:459
wb_put_many include/linux/backing-dev-defs.h:250 [inline]
wb_put include/linux/backing-dev-defs.h:268 [inline]
inode_detach_wb include/linux/writeback.h:251 [inline]
bdev_evict_inode+0x3c3/0x410 fs/block_dev.c:832
evict+0x2ed/0x6b0 fs/inode.c:590
iput_final fs/inode.c:1670 [inline]
iput.part.0+0x539/0x850 fs/inode.c:1696
iput+0x58/0x70 fs/inode.c:1686
device_release+0x9f/0x240 drivers/base/core.c:2193
kobject_cleanup lib/kobject.c:705 [inline]
kobject_release lib/kobject.c:736 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x1c8/0x540 lib/kobject.c:753
put_device+0x1b/0x30 drivers/base/core.c:3463
put_disk block/genhd.c:1338 [inline]
blk_cleanup_disk+0x6b/0x80 block/genhd.c:1354
loop_remove drivers/block/loop.c:2415 [inline]
loop_control_remove drivers/block/loop.c:2463 [inline]
loop_control_ioctl+0x3db/0x450 drivers/block/loop.c:2495
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:874 [inline]
__se_sys_ioctl fs/ioctl.c:860 [inline]
__x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860
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:0x444dc9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 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:00007fffbac3e7b8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 000000000002bef4 RCX: 0000000000444dc9
RDX: 0000000000000000 RSI: 0000000000004c81 RDI: 0000000000000003
RBP: 0000000000000000 R08: 00007fffbac3e7e0 R09: 00007fffbac3e7e0
R10: 0000000000000000 R11: 0000000000000246 R12: 00007fffbac3e7dc
R13: 00007fffbac3e810 R14: 00007fffbac3e7f0 R15: 000000000000003c

Allocated by task 1:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:434 [inline]
____kasan_kmalloc mm/kasan/common.c:513 [inline]
____kasan_kmalloc mm/kasan/common.c:472 [inline]
__kasan_kmalloc+0x9b/0xd0 mm/kasan/common.c:522
kmalloc_node include/linux/slab.h:609 [inline]
kzalloc_node include/linux/slab.h:732 [inline]
bdi_alloc+0x43/0x180 mm/backing-dev.c:810
__alloc_disk_node+0x6e/0x500 block/genhd.c:1270
__blk_mq_alloc_disk+0xec/0x190 block/blk-mq.c:3145
loop_add+0x324/0x940 drivers/block/loop.c:2344
loop_init+0x1f4/0x216 drivers/block/loop.c:2575
do_one_initcall+0x103/0x650 init/main.c:1285
do_initcall_level init/main.c:1360 [inline]
do_initcalls init/main.c:1376 [inline]
do_basic_setup init/main.c:1395 [inline]
kernel_init_freeable+0x6b1/0x73a init/main.c:1597
kernel_init+0x1a/0x1d0 init/main.c:1489
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Freed by task 6845:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_set_track+0x1c/0x30 mm/kasan/common.c:46
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:360
____kasan_slab_free mm/kasan/common.c:366 [inline]
____kasan_slab_free mm/kasan/common.c:328 [inline]
__kasan_slab_free+0xfb/0x130 mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:230 [inline]
slab_free_hook mm/slub.c:1681 [inline]
slab_free_freelist_hook+0x7e/0x190 mm/slub.c:1706
slab_free mm/slub.c:3444 [inline]
kfree+0xe4/0x530 mm/slub.c:4504
kref_put include/linux/kref.h:65 [inline]
bdi_put+0x72/0xa0 mm/backing-dev.c:976
disk_release+0x7b/0x270 block/genhd.c:1089
device_release+0x9f/0x240 drivers/base/core.c:2193
kobject_cleanup lib/kobject.c:705 [inline]
kobject_release lib/kobject.c:736 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x1c8/0x540 lib/kobject.c:753
put_device+0x1b/0x30 drivers/base/core.c:3463
put_disk block/genhd.c:1338 [inline]
blk_cleanup_disk+0x6b/0x80 block/genhd.c:1354
loop_remove drivers/block/loop.c:2415 [inline]
loop_control_remove drivers/block/loop.c:2463 [inline]
loop_control_ioctl+0x3db/0x450 drivers/block/loop.c:2495
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:874 [inline]
__se_sys_ioctl fs/ioctl.c:860 [inline]
__x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860
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

Last potentially related work creation:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_record_aux_stack+0xe5/0x110 mm/kasan/generic.c:348
insert_work+0x48/0x370 kernel/workqueue.c:1332
__queue_work+0x5c1/0xed0 kernel/workqueue.c:1498
flush_delayed_work+0xc6/0xf0 kernel/workqueue.c:3195
wb_shutdown+0x1bb/0x230 mm/backing-dev.c:363
bdi_unregister+0x180/0x5a0 mm/backing-dev.c:947
del_gendisk+0x5a6/0x730 block/genhd.c:616
loop_remove drivers/block/loop.c:2414 [inline]
loop_control_remove drivers/block/loop.c:2463 [inline]
loop_control_ioctl+0x3b5/0x450 drivers/block/loop.c:2495
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:874 [inline]
__se_sys_ioctl fs/ioctl.c:860 [inline]
__x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860
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

Second to last potentially related work creation:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_record_aux_stack+0xe5/0x110 mm/kasan/generic.c:348
insert_work+0x48/0x370 kernel/workqueue.c:1332
__queue_work+0x5c1/0xed0 kernel/workqueue.c:1498
__queue_delayed_work+0x1c8/0x270 kernel/workqueue.c:1645
mod_delayed_work_on+0xdd/0x220 kernel/workqueue.c:1719
mod_delayed_work include/linux/workqueue.h:537 [inline]
wb_shutdown+0x178/0x230 mm/backing-dev.c:360
bdi_unregister+0x180/0x5a0 mm/backing-dev.c:947
del_gendisk+0x5a6/0x730 block/genhd.c:616
loop_remove drivers/block/loop.c:2414 [inline]
loop_control_remove drivers/block/loop.c:2463 [inline]
loop_control_ioctl+0x3b5/0x450 drivers/block/loop.c:2495
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:874 [inline]
__se_sys_ioctl fs/ioctl.c:860 [inline]
__x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860
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 ffff888146568000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 96 bytes inside of
4096-byte region [ffff888146568000, ffff888146569000)
The buggy address belongs to the page:
page:ffffea0005195a00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x146568
head:ffffea0005195a00 order:3 compound_mapcount:0 compound_pincount:0
flags: 0x57ff00000010200(slab|head|node=1|zone=2|lastcpupid=0x7ff)
raw: 057ff00000010200 dead000000000100 dead000000000122 ffff888010842140
raw: 0000000000000000 0000000000040004 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 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 1, ts 8085403015, free_ts 0
prep_new_page mm/page_alloc.c:2424 [inline]
get_page_from_freelist+0xa72/0x2f80 mm/page_alloc.c:4152
__alloc_pages+0x1b2/0x500 mm/page_alloc.c:5374
alloc_page_interleave+0x1e/0x200 mm/mempolicy.c:2033
alloc_pages+0x29f/0x300 mm/mempolicy.c:2183
alloc_slab_page mm/slub.c:1744 [inline]
allocate_slab mm/slub.c:1881 [inline]
new_slab+0x319/0x490 mm/slub.c:1944
___slab_alloc+0x8b9/0xf50 mm/slub.c:2955
__slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3042
slab_alloc_node mm/slub.c:3133 [inline]
kmem_cache_alloc_node_trace+0x183/0x400 mm/slub.c:3217
kmalloc_node include/linux/slab.h:609 [inline]
kzalloc_node include/linux/slab.h:732 [inline]
bdi_alloc+0x43/0x180 mm/backing-dev.c:810
__alloc_disk_node+0x6e/0x500 block/genhd.c:1270
__blk_mq_alloc_disk+0xec/0x190 block/blk-mq.c:3145
loop_add+0x324/0x940 drivers/block/loop.c:2344
loop_init+0x1f4/0x216 drivers/block/loop.c:2575
do_one_initcall+0x103/0x650 init/main.c:1285
do_initcall_level init/main.c:1360 [inline]
do_initcalls init/main.c:1376 [inline]
do_basic_setup init/main.c:1395 [inline]
kernel_init_freeable+0x6b1/0x73a init/main.c:1597
kernel_init+0x1a/0x1d0 init/main.c:1489
page_owner free stack trace missing

Memory state around the buggy address:
ffff888146567f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888146567f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888146568000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888146568080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888146568100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

syzbot

unread,
Aug 15, 2021, 2:58:10ā€ÆAM8/15/21
to phin...@gmail.com, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
general protection fault in wb_timer_fn

general protection fault, probably for non-canonical address 0xdffffc00000000b2: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000590-0x0000000000000597]
CPU: 0 PID: 9248 Comm: syz-executor.1 Not tainted 5.14.0-rc5-next-20210813-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:latency_exceeded block/blk-wbt.c:237 [inline]
RIP: 0010:wb_timer_fn+0x149/0x1740 block/blk-wbt.c:360
Code: 03 80 3c 02 00 0f 85 68 13 00 00 48 8b 9b c8 00 00 00 48 b8 00 00 00 00 00 fc ff df 48 8d bb 90 05 00 00 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 35 13 00 00 48 8b 9b 90 05 00 00 48 b8 00 00 00
RSP: 0018:ffffc90000007cd8 EFLAGS: 00010206
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000100
RDX: 00000000000000b2 RSI: ffffffff83d22f9d RDI: 0000000000000590
RBP: ffff888075b2fc00 R08: 0000000000000003 R09: ffff888075b2fd83
R10: ffffffff83d22f92 R11: 0000000000000000 R12: 0000000000000003
R13: 0000000000000000 R14: ffff888060f5a280 R15: ffff888075b2fcd0
FS: 00007fcb09939700(0000) GS:ffff8880b9c00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000970004 CR3: 0000000060eb7000 CR4: 00000000001506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<IRQ>
call_timer_fn+0x1a5/0x6b0 kernel/time/timer.c:1421
expire_timers kernel/time/timer.c:1466 [inline]
__run_timers.part.0+0x675/0xa20 kernel/time/timer.c:1734
__run_timers kernel/time/timer.c:1715 [inline]
run_timer_softirq+0xb3/0x1d0 kernel/time/timer.c:1747
__do_softirq+0x29b/0x9c2 kernel/softirq.c:558
invoke_softirq kernel/softirq.c:432 [inline]
__irq_exit_rcu+0x123/0x180 kernel/softirq.c:636
irq_exit_rcu+0x5/0x20 kernel/softirq.c:648
sysvec_apic_timer_interrupt+0x93/0xc0 arch/x86/kernel/apic/apic.c:1097
</IRQ>
asm_sysvec_apic_timer_interrupt+0x12/0x20 arch/x86/include/asm/idtentry.h:638
RIP: 0010:preempt_count arch/x86/include/asm/preempt.h:27 [inline]
RIP: 0010:check_kcov_mode kernel/kcov.c:163 [inline]
RIP: 0010:__sanitizer_cov_trace_pc+0x0/0x60 kernel/kcov.c:197
Code: 01 f0 4d 89 03 e9 63 fd ff ff b9 ff ff ff ff ba 08 00 00 00 4d 8b 03 48 0f bd ca 49 8b 45 00 48 63 c9 e9 64 ff ff ff 0f 1f 00 <65> 8b 05 99 1e 8c 7e 89 c1 48 8b 34 24 81 e1 00 01 00 00 65 48 8b
RSP: 0018:ffffc9000d3c76e8 EFLAGS: 00000293
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff888079829c80 RSI: ffffffff815d419c RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: ffffffff815d4192 R11: 0000000000000000 R12: ffffffff84c5dc60
R13: 0000000000000200 R14: ffffc9000d3c7748 R15: dffffc0000000000
console_unlock+0x6c2/0xb70 kernel/printk/printk.c:2718
vprintk_emit+0x198/0x4f0 kernel/printk/printk.c:2247
vprintk+0x80/0x90 kernel/printk/printk_safe.c:50
_printk+0xba/0xed kernel/printk/printk.c:2268
set_capacity_and_notify.cold+0x1b/0x90 block/genhd.c:84
loop_set_size drivers/block/loop.c:298 [inline]
loop_configure+0x1011/0x1960 drivers/block/loop.c:1297
lo_ioctl+0x403/0x1880 drivers/block/loop.c:1837
blkdev_ioctl+0x2a1/0x700 block/ioctl.c:589
block_ioctl+0xf9/0x140 fs/block_dev.c:1415
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:874 [inline]
__se_sys_ioctl fs/ioctl.c:860 [inline]
__x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860
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:0x4663a7
Code: 3c 1c 48 f7 d8 49 39 c4 72 b8 e8 a4 48 02 00 85 c0 78 bd 48 83 c4 08 4c 89 e0 5b 41 5c c3 0f 1f 44 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fcb09938f48 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00000000004afcc0 RCX: 00000000004663a7
RDX: 0000000000000003 RSI: 0000000000004c00 RDI: 0000000000000004
RBP: 0000000000000004 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003
R13: 0000000000000003 R14: 0000000020000370 R15: 0000000000000002
Modules linked in:
---[ end trace dd6049440b554534 ]---
RIP: 0010:latency_exceeded block/blk-wbt.c:237 [inline]
RIP: 0010:wb_timer_fn+0x149/0x1740 block/blk-wbt.c:360
Code: 03 80 3c 02 00 0f 85 68 13 00 00 48 8b 9b c8 00 00 00 48 b8 00 00 00 00 00 fc ff df 48 8d bb 90 05 00 00 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 35 13 00 00 48 8b 9b 90 05 00 00 48 b8 00 00 00
RSP: 0018:ffffc90000007cd8 EFLAGS: 00010206
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000100
RDX: 00000000000000b2 RSI: ffffffff83d22f9d RDI: 0000000000000590
RBP: ffff888075b2fc00 R08: 0000000000000003 R09: ffff888075b2fd83
R10: ffffffff83d22f92 R11: 0000000000000000 R12: 0000000000000003
R13: 0000000000000000 R14: ffff888060f5a280 R15: ffff888075b2fcd0
FS: 00007fcb09939700(0000) GS:ffff8880b9c00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000970004 CR3: 0000000060eb7000 CR4: 00000000001506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: 03 80 3c 02 00 0f add 0xf00023c(%rax),%eax
6: 85 68 13 test %ebp,0x13(%rax)
9: 00 00 add %al,(%rax)
b: 48 8b 9b c8 00 00 00 mov 0xc8(%rbx),%rbx
12: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax
19: fc ff df
1c: 48 8d bb 90 05 00 00 lea 0x590(%rbx),%rdi
23: 48 89 fa mov %rdi,%rdx
26: 48 c1 ea 03 shr $0x3,%rdx
2a: 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) <-- trapping instruction
2e: 0f 85 35 13 00 00 jne 0x1369
34: 48 8b 9b 90 05 00 00 mov 0x590(%rbx),%rbx
3b: 48 rex.W
3c: b8 .byte 0xb8
3d: 00 00 add %al,(%rax)


Tested on:

commit: 4b358aab Add linux-next specific files for 20210813
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=14316165300000
kernel config: https://syzkaller.appspot.com/x/.config?x=b99612666fbe2d6a

Hillf Danton

unread,
Aug 15, 2021, 9:49:51ā€ÆAM8/15/21
to syzbot, ax...@kernel.dk, Christoph Hellwig, linux...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sat, 14 Aug 2021 04:07:23 -0700
After putting bdi in wb_exit(), wb->bdi is no longer stable. To fix the uaf,
add the WB_put bit to avoid derefering a unstable pointer.

Only for thoughts.

+++ x/include/linux/backing-dev-defs.h
@@ -26,6 +26,7 @@ enum wb_state {
WB_writeback_running, /* Writeback is in progress */
WB_has_dirty_io, /* Dirty inodes on ->b_{dirty|io|more_io} */
WB_start_all, /* nr_pages == 0 (all) work pending */
+ WB_put, /* wb != &wb->bdi->wb */
};

enum wb_congested_state {
@@ -255,7 +256,7 @@ static inline void wb_put_many(struct bd
return;
}

- if (wb != &wb->bdi->wb)
+ if (test_bit(WB_put, &wb->state))
percpu_ref_put_many(&wb->refcnt, nr);
}

+++ x/mm/backing-dev.c
@@ -291,8 +291,10 @@ static int wb_init(struct bdi_writeback

memset(wb, 0, sizeof(*wb));

- if (wb != &bdi->wb)
+ if (wb != &bdi->wb) {
bdi_get(bdi);
+ set_bit(WB_put, &wb->state);
+ }
wb->bdi = bdi;
wb->last_old_flush = jiffies;
INIT_LIST_HEAD(&wb->b_dirty);

Christoph Hellwig

unread,
Aug 16, 2021, 5:34:54ā€ÆAM8/16/21
to Hillf Danton, syzbot, ax...@kernel.dk, Christoph Hellwig, linux...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sun, Aug 15, 2021 at 09:49:30PM +0800, Hillf Danton wrote:
> After putting bdi in wb_exit(), wb->bdi is no longer stable. To fix the uaf,
> add the WB_put bit to avoid derefering a unstable pointer.
>
> Only for thoughts.

This doesn't help with the fact that the bdi needs to be alive
until after inode_detach_wb is called. I posted a patch for that last
week, although I'm about to post a v2 as there are more lingering issues
in this area.
Reply all
Reply to author
Forward
0 new messages