KASAN: use-after-free Write in afs_manage_cell

21 views
Skip to first unread message

syzbot

unread,
Aug 7, 2020, 3:07:17ā€ÆAM8/7/20
to dhow...@redhat.com, linu...@lists.infradead.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: fffe3ae0 Merge tag 'for-linus-hmm' of git://git.kernel.org..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1053efea900000
kernel config: https://syzkaller.appspot.com/x/.config?x=18bb86f2e4ebfda2
dashboard link: https://syzkaller.appspot.com/bug?extid=f59c67285cb61166a0cf
compiler: gcc (GCC) 10.1.0-syz 20200507

Unfortunately, I don't have any reproducer for this issue yet.

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

==================================================================
BUG: KASAN: use-after-free in afs_activate_cell fs/afs/cell.c:626 [inline]
BUG: KASAN: use-after-free in afs_manage_cell+0xf72/0x11c0 fs/afs/cell.c:697
Write of size 8 at addr ffff88808ecf5888 by task kworker/1:2/2576

CPU: 1 PID: 2576 Comm: kworker/1:2 Not tainted 5.8.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: afs afs_manage_cell
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x18f/0x20d lib/dump_stack.c:118
print_address_description.constprop.0.cold+0xae/0x436 mm/kasan/report.c:383
__kasan_report mm/kasan/report.c:513 [inline]
kasan_report.cold+0x1f/0x37 mm/kasan/report.c:530
afs_activate_cell fs/afs/cell.c:626 [inline]
afs_manage_cell+0xf72/0x11c0 fs/afs/cell.c:697
process_one_work+0x94c/0x1670 kernel/workqueue.c:2269
worker_thread+0x64c/0x1120 kernel/workqueue.c:2415
kthread+0x3b5/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294

Allocated by task 16538:
save_stack+0x1b/0x40 mm/kasan/common.c:48
set_track mm/kasan/common.c:56 [inline]
__kasan_kmalloc.constprop.0+0xc2/0xd0 mm/kasan/common.c:494
kmem_cache_alloc_trace+0x14f/0x2d0 mm/slab.c:3551
kmalloc include/linux/slab.h:555 [inline]
kzalloc include/linux/slab.h:669 [inline]
afs_alloc_cell fs/afs/cell.c:151 [inline]
afs_lookup_cell+0x5c8/0x1440 fs/afs/cell.c:262
afs_parse_source fs/afs/super.c:290 [inline]
afs_parse_param+0x404/0x8c0 fs/afs/super.c:326
vfs_parse_fs_param fs/fs_context.c:117 [inline]
vfs_parse_fs_param+0x203/0x550 fs/fs_context.c:98
vfs_parse_fs_string+0xe6/0x150 fs/fs_context.c:161
do_new_mount fs/namespace.c:2869 [inline]
do_mount+0x658/0x1fe0 fs/namespace.c:3200
__do_sys_mount fs/namespace.c:3410 [inline]
__se_sys_mount fs/namespace.c:3387 [inline]
__x64_sys_mount+0x18f/0x230 fs/namespace.c:3387
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 7033:
save_stack+0x1b/0x40 mm/kasan/common.c:48
set_track mm/kasan/common.c:56 [inline]
kasan_set_free_info mm/kasan/common.c:316 [inline]
__kasan_slab_free+0xf5/0x140 mm/kasan/common.c:455
__cache_free mm/slab.c:3426 [inline]
kfree+0x103/0x2c0 mm/slab.c:3757
rcu_do_batch kernel/rcu/tree.c:2427 [inline]
rcu_core+0x5c7/0x1190 kernel/rcu/tree.c:2655
__do_softirq+0x2de/0xa24 kernel/softirq.c:298

The buggy address belongs to the object at ffff88808ecf5800
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 136 bytes inside of
1024-byte region [ffff88808ecf5800, ffff88808ecf5c00)
The buggy address belongs to the page:
page:ffffea00023b3d40 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0
flags: 0xfffe0000000200(slab)
raw: 00fffe0000000200 ffffea0002896a48 ffffea0002784e88 ffff8880aa000c40
raw: 0000000000000000 ffff88808ecf5000 0000000100000002 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff88808ecf5780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88808ecf5800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88808ecf5880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88808ecf5900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88808ecf5980: 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

unread,
Aug 26, 2020, 5:45:24ā€ÆAM8/26/20
to dhow...@redhat.com, linu...@lists.infradead.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
syzbot has found a reproducer for the following issue on:

HEAD commit: abb3438d Merge tag 'm68knommu-for-v5.9-rc3' of git://git.k..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1753522e900000
kernel config: https://syzkaller.appspot.com/x/.config?x=978db74cb30aa994
dashboard link: https://syzkaller.appspot.com/bug?extid=f59c67285cb61166a0cf
compiler: gcc (GCC) 10.1.0-syz 20200507
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13a9888e900000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=157cb346900000

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

FS-Cache: N-cookie c=00000000a6a6ef54 [p=000000005b0520e2 fl=2 nc=0 na=1]
FS-Cache: N-cookie d=00000000a15022ee n=0000000040eaeaa1
FS-Cache: N-key=[5] '23ee2ea1fb'
==================================================================
BUG: KASAN: use-after-free in afs_activate_cell fs/afs/cell.c:609 [inline]
BUG: KASAN: use-after-free in afs_manage_cell+0xea0/0x11c0 fs/afs/cell.c:697
Write of size 8 at addr ffff888098036890 by task kworker/0:0/5

CPU: 0 PID: 5 Comm: kworker/0:0 Not tainted 5.9.0-rc2-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: afs afs_manage_cell
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x18f/0x20d lib/dump_stack.c:118
print_address_description.constprop.0.cold+0xae/0x497 mm/kasan/report.c:383
__kasan_report mm/kasan/report.c:513 [inline]
kasan_report.cold+0x1f/0x37 mm/kasan/report.c:530
afs_activate_cell fs/afs/cell.c:609 [inline]
afs_manage_cell+0xea0/0x11c0 fs/afs/cell.c:697
process_one_work+0x94c/0x1670 kernel/workqueue.c:2269
worker_thread+0x64c/0x1120 kernel/workqueue.c:2415
kthread+0x3b5/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294

Allocated by task 8859:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_set_track mm/kasan/common.c:56 [inline]
__kasan_kmalloc.constprop.0+0xbf/0xd0 mm/kasan/common.c:461
kmem_cache_alloc_trace+0x16e/0x2c0 mm/slab.c:3550
kmalloc include/linux/slab.h:554 [inline]
kzalloc include/linux/slab.h:666 [inline]
afs_alloc_cell fs/afs/cell.c:151 [inline]
afs_lookup_cell+0x5c8/0x1440 fs/afs/cell.c:262
afs_parse_source fs/afs/super.c:290 [inline]
afs_parse_param+0x404/0x8c0 fs/afs/super.c:326
vfs_parse_fs_param fs/fs_context.c:117 [inline]
vfs_parse_fs_param+0x203/0x550 fs/fs_context.c:98
vfs_parse_fs_string+0xe6/0x150 fs/fs_context.c:161
generic_parse_monolithic+0x16f/0x1f0 fs/fs_context.c:201
do_new_mount fs/namespace.c:2871 [inline]
path_mount+0x133f/0x2070 fs/namespace.c:3192
do_mount fs/namespace.c:3205 [inline]
__do_sys_mount fs/namespace.c:3413 [inline]
__se_sys_mount fs/namespace.c:3390 [inline]
__x64_sys_mount+0x27f/0x300 fs/namespace.c:3390
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 3903:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_set_track+0x1c/0x30 mm/kasan/common.c:56
kasan_set_free_info+0x1b/0x30 mm/kasan/generic.c:355
__kasan_slab_free+0xd8/0x120 mm/kasan/common.c:422
__cache_free mm/slab.c:3418 [inline]
kfree+0x103/0x2c0 mm/slab.c:3756
rcu_do_batch kernel/rcu/tree.c:2428 [inline]
rcu_core+0x5c7/0x1190 kernel/rcu/tree.c:2656
__do_softirq+0x2de/0xa24 kernel/softirq.c:298

Last call_rcu():
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_record_aux_stack+0x82/0xb0 mm/kasan/generic.c:346
__call_rcu kernel/rcu/tree.c:2894 [inline]
call_rcu+0x14f/0x7e0 kernel/rcu/tree.c:2968
afs_manage_cell+0x250/0x11c0 fs/afs/cell.c:751
process_one_work+0x94c/0x1670 kernel/workqueue.c:2269
worker_thread+0x64c/0x1120 kernel/workqueue.c:2415
kthread+0x3b5/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294

Second to last call_rcu():
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_record_aux_stack+0x82/0xb0 mm/kasan/generic.c:346
__call_rcu kernel/rcu/tree.c:2894 [inline]
call_rcu+0x14f/0x7e0 kernel/rcu/tree.c:2968
afs_manage_cell+0x250/0x11c0 fs/afs/cell.c:751
process_one_work+0x94c/0x1670 kernel/workqueue.c:2269
worker_thread+0x64c/0x1120 kernel/workqueue.c:2415
kthread+0x3b5/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294

The buggy address belongs to the object at ffff888098036800
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 144 bytes inside of
1024-byte region [ffff888098036800, ffff888098036c00)
The buggy address belongs to the page:
page:00000000a84846b4 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x98036
flags: 0xfffe0000000200(slab)
raw: 00fffe0000000200 ffffea000225ef48 ffffea000225e008 ffff8880aa040700
raw: 0000000000000000 ffff888098036000 0000000100000002 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff888098036780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888098036800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888098036880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888098036900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888098036980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

syzbot

unread,
Aug 26, 2020, 9:11:09ā€ÆPM8/26/20
to dhow...@redhat.com, linu...@lists.infradead.org, linux-...@redhat.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com, vi...@zeniv.linux.org.uk
syzbot has bisected this issue to:

commit c99c2171fc61476afac0dfb59fb2c447a01fb1e0
Author: David Howells <dhow...@redhat.com>
Date: Thu Nov 1 23:07:27 2018 +0000

afs: Use fs_context to pass parameters over automount

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=10679fa9900000
start commit: abb3438d Merge tag 'm68knommu-for-v5.9-rc3' of git://git.k..
git tree: upstream
final oops: https://syzkaller.appspot.com/x/report.txt?x=12679fa9900000
console output: https://syzkaller.appspot.com/x/log.txt?x=14679fa9900000
kernel config: https://syzkaller.appspot.com/x/.config?x=891ca5711a9f1650
dashboard link: https://syzkaller.appspot.com/bug?extid=f59c67285cb61166a0cf
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10d97d46900000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14eb9fa9900000

Reported-by: syzbot+f59c67...@syzkaller.appspotmail.com
Fixes: c99c2171fc61 ("afs: Use fs_context to pass parameters over automount")

For information about bisection process see: https://goo.gl/tpsmEJ#bisection

Hillf Danton

unread,
Aug 26, 2020, 11:44:37ā€ÆPM8/26/20
to syzbot, dhow...@redhat.com, Hillf Danton, linu...@lists.infradead.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com

On Wed, 26 Aug 2020 02:45:22 -0700
Wait cell's work done in the rcu context to avoid UAF.

--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -493,6 +493,8 @@ static void afs_cell_destroy(struct rcu_

ASSERTCMP(atomic_read(&cell->usage), ==, 0);

+ flush_work(&cell->manager);
+
afs_put_volume(cell->net, cell->root_volume, afs_volume_trace_put_cell_root);
afs_put_vlserverlist(cell->net, rcu_access_pointer(cell->vl_servers));
afs_put_cell(cell->net, cell->alias_of);

syzbot

unread,
Nov 14, 2020, 8:58:10ā€ÆAM11/14/20
to dhow...@redhat.com, foxh...@gmail.com, hda...@sina.com, linu...@lists.infradead.org, linux-cach...@redhat.com, linux-...@redhat.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com, vi...@zeniv.linux.org.uk
syzbot suspects this issue was fixed by commit:

commit 1d0e850a49a5b56f8f3cb51e74a11e2fedb96be6
Author: David Howells <dhow...@redhat.com>
Date: Fri Oct 16 12:21:14 2020 +0000

afs: Fix cell removal

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=15b78dba500000
start commit: da690031 Merge branch 'i2c/for-current' of git://git.kerne..
git tree: upstream
kernel config: https://syzkaller.appspot.com/x/.config?x=de7f697da23057c7
dashboard link: https://syzkaller.appspot.com/bug?extid=f59c67285cb61166a0cf
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10960a8b900000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17e938cf900000

If the result looks correct, please mark the issue as fixed by replying with:

#syz fix: afs: Fix cell removal

Dmitry Vyukov

unread,
Nov 14, 2020, 9:42:09ā€ÆAM11/14/20
to syzbot, David Howells, Fox Chen, Hillf Danton, linu...@lists.infradead.org, linux-cach...@redhat.com, linux-...@redhat.com, LKML, syzkaller-bugs, Al Viro
Reply all
Reply to author
Forward
0 new messages