Re: KASAN: use-after-free Read in unregister_shrinker

From: Kirill Tkhai
Date: Thu Jun 06 2019 - 03:52:11 EST


On 05.06.2019 21:42, syzbot wrote:
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit:ÂÂÂ b2924447 Add linux-next specific files for 20190605
> git tree:ÂÂÂÂÂÂ linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=17e867eea00000
> kernel config:Â https://syzkaller.appspot.com/x/.config?x=4248d6bc70076f7d
> dashboard link: https://syzkaller.appspot.com/bug?extid=83a43746cebef3508b49
> compiler:ÂÂÂÂÂÂ gcc (GCC) 9.0.0 20181231 (experimental)
> syz repro:ÂÂÂÂÂ https://syzkaller.appspot.com/x/repro.syz?x=1122965aa00000
>
> The bug was bisected to:
>
> commit db17b61765c2c63b9552d316551550557ff0fcfd
> Author: J. Bruce Fields <bfields@xxxxxxxxxx>
> Date:ÂÂ Fri May 17 13:03:38 2019 +0000
>
> ÂÂÂ nfsd4: drc containerization
>
> bisection log:Â https://syzkaller.appspot.com/x/bisect.txt?x=110cd22ea00000
> final crash:ÂÂÂ https://syzkaller.appspot.com/x/report.txt?x=130cd22ea00000
> console output: https://syzkaller.appspot.com/x/log.txt?x=150cd22ea00000
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+83a43746cebef3508b49@xxxxxxxxxxxxxxxxxxxxxxxxx
> Fixes: db17b61765c2 ("nfsd4: drc containerization")
>
> ==================================================================
> BUG: KASAN: use-after-free in __list_del_entry_valid+0xe6/0xf5 lib/list_debug.c:51
> Read of size 8 at addr ffff88808a5bd128 by task syz-executor.2/12471
>
> CPU: 0 PID: 12471 Comm: syz-executor.2 Not tainted 5.2.0-rc3-next-20190605 #9
> 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+0x172/0x1f0 lib/dump_stack.c:113
> Âprint_address_description.cold+0xd4/0x306 mm/kasan/report.c:351
> Â__kasan_report.cold+0x1b/0x36 mm/kasan/report.c:482
> Âkasan_report+0x12/0x20 mm/kasan/common.c:614
> Â__asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:132
> Â__list_del_entry_valid+0xe6/0xf5 lib/list_debug.c:51
> Â__list_del_entry include/linux/list.h:117 [inline]
> Âlist_del include/linux/list.h:125 [inline]
> Âunregister_shrinker+0xb2/0x2e0 mm/vmscan.c:443
> Ânfsd_reply_cache_shutdown+0x26/0x360 fs/nfsd/nfscache.c:194
> Ânfsd_exit_net+0x170/0x4b0 fs/nfsd/nfsctl.c:1272
> Âops_exit_list.isra.0+0xaa/0x150 net/core/net_namespace.c:154
> Âsetup_net+0x400/0x740 net/core/net_namespace.c:333
> Âcopy_net_ns+0x1df/0x340 net/core/net_namespace.c:439
> Âcreate_new_namespaces+0x400/0x7b0 kernel/nsproxy.c:107
> Âunshare_nsproxy_namespaces+0xc2/0x200 kernel/nsproxy.c:206
> Âksys_unshare+0x444/0x980 kernel/fork.c:2718
> Â__do_sys_unshare kernel/fork.c:2786 [inline]
> Â__se_sys_unshare kernel/fork.c:2784 [inline]
> Â__x64_sys_unshare+0x31/0x40 kernel/fork.c:2784
> Âdo_syscall_64+0xfd/0x680 arch/x86/entry/common.c:301
> Âentry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x459279
> Code: fd b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 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 0f 83 cb b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00
> RSP: 002b:00007f7ae73e1c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000110
> RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 0000000000459279
> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000040000000
> RBP: 000000000075bfc0 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 00007f7ae73e26d4
> R13: 00000000004c84ef R14: 00000000004decb0 R15: 00000000ffffffff
>
> Allocated by task 12460:
> Âsave_stack+0x23/0x90 mm/kasan/common.c:71
> Âset_track mm/kasan/common.c:79 [inline]
> Â__kasan_kmalloc mm/kasan/common.c:489 [inline]
> Â__kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:462
> Âkasan_kmalloc+0x9/0x10 mm/kasan/common.c:503
> Â__do_kmalloc mm/slab.c:3654 [inline]
> Â__kmalloc+0x15c/0x740 mm/slab.c:3663
> Âkmalloc include/linux/slab.h:552 [inline]
> Âkzalloc include/linux/slab.h:742 [inline]
> Âops_init+0xff/0x410 net/core/net_namespace.c:120
> Âsetup_net+0x2d3/0x740 net/core/net_namespace.c:316
> Âcopy_net_ns+0x1df/0x340 net/core/net_namespace.c:439
> Âcreate_new_namespaces+0x400/0x7b0 kernel/nsproxy.c:107
> Âunshare_nsproxy_namespaces+0xc2/0x200 kernel/nsproxy.c:206
> Âksys_unshare+0x444/0x980 kernel/fork.c:2718
> Â__do_sys_unshare kernel/fork.c:2786 [inline]
> Â__se_sys_unshare kernel/fork.c:2784 [inline]
> Â__x64_sys_unshare+0x31/0x40 kernel/fork.c:2784
> Âdo_syscall_64+0xfd/0x680 arch/x86/entry/common.c:301
> Âentry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> Freed by task 12460:
> Âsave_stack+0x23/0x90 mm/kasan/common.c:71
> Âset_track mm/kasan/common.c:79 [inline]
> Â__kasan_slab_free+0x102/0x150 mm/kasan/common.c:451
> Âkasan_slab_free+0xe/0x10 mm/kasan/common.c:459
> Â__cache_free mm/slab.c:3426 [inline]
> Âkfree+0x106/0x2a0 mm/slab.c:3753
> Âops_init+0xd1/0x410 net/core/net_namespace.c:135
> Âsetup_net+0x2d3/0x740 net/core/net_namespace.c:316
> Âcopy_net_ns+0x1df/0x340 net/core/net_namespace.c:439
> Âcreate_new_namespaces+0x400/0x7b0 kernel/nsproxy.c:107
> Âunshare_nsproxy_namespaces+0xc2/0x200 kernel/nsproxy.c:206
> Âksys_unshare+0x444/0x980 kernel/fork.c:2718
> Â__do_sys_unshare kernel/fork.c:2786 [inline]
> Â__se_sys_unshare kernel/fork.c:2784 [inline]
> Â__x64_sys_unshare+0x31/0x40 kernel/fork.c:2784
> Âdo_syscall_64+0xfd/0x680 arch/x86/entry/common.c:301
> Âentry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> The buggy address belongs to the object at ffff88808a5bcdc0
> Âwhich belongs to the cache kmalloc-1k of size 1024
> The buggy address is located 872 bytes inside of
> Â1024-byte region [ffff88808a5bcdc0, ffff88808a5bd1c0)
> The buggy address belongs to the page:
> page:ffffea0002296f00 refcount:1 mapcount:0 mapping:ffff8880aa400ac0 index:0x0 compound_mapcount: 0
> flags: 0x1fffc0000010200(slab|head)
> raw: 01fffc0000010200 ffffea000249ea08 ffffea000235a588 ffff8880aa400ac0
> raw: 0000000000000000 ffff88808a5bc040 0000000100000007 0000000000000000
> page dumped because: kasan: bad access detected
>
> Memory state around the buggy address:
> Âffff88808a5bd000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> Âffff88808a5bd080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>> ffff88808a5bd100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
> Âffff88808a5bd180: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
> Âffff88808a5bd200: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
> ==================================================================

This may be connected with that shrinker unregistering is forgotten on error path.

---
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index ea39497205f0..8705e7d09717 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -181,6 +181,7 @@ int nfsd_reply_cache_init(struct nfsd_net *nn)

return 0;
out_nomem:
+ unregister_shrinker(&nn->nfsd_reply_cache_shrinker);
printk(KERN_ERR "nfsd: failed to allocate reply cache\n");
return -ENOMEM;
}