KASAN: use-after-free Read in fscache_alloc_cookie

10 views
Skip to first unread message

syzbot

unread,
Sep 25, 2020, 4:57:17 AM9/25/20
to dhow...@redhat.com, linux-...@redhat.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 171d4ff7 Merge tag 'mmc-v5.9-rc4-2' of git://git.kernel.or..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17d457b5900000
kernel config: https://syzkaller.appspot.com/x/.config?x=5f4c828c9e3cef97
dashboard link: https://syzkaller.appspot.com/bug?extid=2d0585e5efcd43d113c2
compiler: gcc (GCC) 10.1.0-syz 20200507
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16a33ad3900000

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

==================================================================
BUG: KASAN: use-after-free in memcpy include/linux/string.h:406 [inline]
BUG: KASAN: use-after-free in fscache_set_key fs/fscache/cookie.c:93 [inline]
BUG: KASAN: use-after-free in fscache_alloc_cookie+0xff/0x730 fs/fscache/cookie.c:153
Read of size 10 at addr ffff8880a6c28200 by task kworker/1:6/8760

CPU: 1 PID: 8760 Comm: kworker/1:6 Not tainted 5.9.0-rc6-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+0x198/0x1fd 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
check_memory_region_inline mm/kasan/generic.c:186 [inline]
check_memory_region+0x13d/0x180 mm/kasan/generic.c:192
memcpy+0x20/0x60 mm/kasan/common.c:105
memcpy include/linux/string.h:406 [inline]
fscache_set_key fs/fscache/cookie.c:93 [inline]
fscache_alloc_cookie+0xff/0x730 fs/fscache/cookie.c:153
__fscache_acquire_cookie+0x16c/0x610 fs/fscache/cookie.c:288
fscache_acquire_cookie include/linux/fscache.h:334 [inline]
afs_activate_cell fs/afs/cell.c:609 [inline]
afs_manage_cell+0x4fa/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 10197:
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
__do_kmalloc mm/slab.c:3655 [inline]
__kmalloc+0x1b0/0x360 mm/slab.c:3664
kmalloc include/linux/slab.h:559 [inline]
afs_alloc_cell fs/afs/cell.c:157 [inline]
afs_lookup_cell+0x5e9/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/0x20a0 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 16:
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+0x10e/0x2b0 mm/slab.c:3756
afs_cell_destroy+0x1b0/0x240 fs/afs/cell.c:500
rcu_do_batch kernel/rcu/tree.c:2428 [inline]
rcu_core+0x5ca/0x1130 kernel/rcu/tree.c:2656
__do_softirq+0x1f8/0xb23 kernel/softirq.c:298

The buggy address belongs to the object at ffff8880a6c28200
which belongs to the cache kmalloc-32 of size 32
The buggy address is located 0 bytes inside of
32-byte region [ffff8880a6c28200, ffff8880a6c28220)
The buggy address belongs to the page:
page:00000000c2f50dc7 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff8880a6c28fc1 pfn:0xa6c28
flags: 0xfffe0000000200(slab)
raw: 00fffe0000000200 ffffea00028969c8 ffffea00025ca748 ffff8880aa040100
raw: ffff8880a6c28fc1 ffff8880a6c28000 000000010000003f 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8880a6c28100: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
ffff8880a6c28180: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
>ffff8880a6c28200: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
^
ffff8880a6c28280: 00 00 00 00 fc fc fc fc 00 fc fc fc fc fc fc fc
ffff8880a6c28300: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
==================================================================


---
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

Hillf Danton

unread,
Sep 25, 2020, 9:50:03 AM9/25/20
to syzbot, dhow...@redhat.com, linux-...@redhat.com, Hillf Danton, linux-...@vger.kernel.org, syzkall...@googlegroups.com

Fri, 25 Sep 2020 01:57:16 -0700
Flush the manager work before releasing cell's resources to avoid uaf.
To that end, add the AFS_CELL_DESTROYING cell state to infom the kworker
that there's no more job to do.

--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -344,6 +344,7 @@ enum afs_cell_state {
AFS_CELL_DEACTIVATING,
AFS_CELL_INACTIVE,
AFS_CELL_FAILED,
+ AFS_CELL_DESTROYING,
};

/*
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -493,6 +493,7 @@ 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);
@@ -672,13 +673,17 @@ static void afs_manage_cell(struct work_
again:
_debug("state %u", cell->state);
switch (cell->state) {
+ case AFS_CELL_DESTROYING:
+ return;
case AFS_CELL_INACTIVE:
case AFS_CELL_FAILED:
write_seqlock(&net->cells_lock);
usage = 1;
deleted = atomic_try_cmpxchg_relaxed(&cell->usage, &usage, 0);
- if (deleted)
+ if (deleted) {
rb_erase(&cell->net_node, &net->cells);
+ cell->state = AFS_CELL_DESTROYING;
+ }
write_sequnlock(&net->cells_lock);
if (deleted)
goto final_destruction;

syzbot

unread,
Oct 11, 2020, 8:28:06 AM10/11/20
to dhow...@redhat.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 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=17960d58500000
start commit: 171d4ff7 Merge tag 'mmc-v5.9-rc4-2' of git://git.kernel.or..
git tree: upstream
final oops: https://syzkaller.appspot.com/x/report.txt?x=14560d58500000
console output: https://syzkaller.appspot.com/x/log.txt?x=10560d58500000
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16a33ad3900000

Reported-by: syzbot+2d0585...@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

David Howells

unread,
Oct 13, 2020, 4:13:09 PM10/13/20
to syzbot, dhow...@redhat.com, linux-...@redhat.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git f8eb8d1c6a853f617ca9ee233bb2d230401c5bdc

syzbot

unread,
Oct 13, 2020, 7:22:11 PM10/13/20
to dhow...@redhat.com, linux-...@redhat.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING: proc registration bug in afs_manage_cell_work

------------[ cut here ]------------
proc_dir_entry 'afs/^]$[+%]0${' already registered
WARNING: CPU: 0 PID: 8309 at fs/proc/generic.c:371 proc_register+0x34c/0x700 fs/proc/generic.c:371
Kernel panic - not syncing: panic_on_warn set ...
CPU: 0 PID: 8309 Comm: kworker/0:4 Not tainted 5.9.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: afs afs_manage_cell_work
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x198/0x1fd lib/dump_stack.c:118
panic+0x382/0x7fb kernel/panic.c:231
__warn.cold+0x20/0x4b kernel/panic.c:600
report_bug+0x1bd/0x210 lib/bug.c:198
handle_bug+0x38/0x90 arch/x86/kernel/traps.c:234
exc_invalid_op+0x14/0x40 arch/x86/kernel/traps.c:254
asm_exc_invalid_op+0x12/0x20 arch/x86/include/asm/idtentry.h:536
RIP: 0010:proc_register+0x34c/0x700 fs/proc/generic.c:371
Code: df 48 89 f9 48 c1 e9 03 80 3c 01 00 0f 85 5d 03 00 00 48 8b 44 24 28 48 c7 c7 a0 62 9a 88 48 8b b0 d8 00 00 00 e8 46 03 5d ff <0f> 0b 48 c7 c7 e0 f6 1e 8a e8 36 df 3d 06 48 8b 4c 24 38 48 b8 00
RSP: 0018:ffffc90009dffac8 EFLAGS: 00010282
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff8880923a4480 RSI: ffffffff815f5a55 RDI: fffff520013bff4b
RBP: ffff888088829b88 R08: 0000000000000001 R09: ffff8880ae4318e7
R10: 0000000000000000 R11: 0000000000000000 R12: ffff8880904699d8
R13: ffff8880931d3340 R14: dffffc0000000000 R15: 000000000000000a
proc_mkdir_data+0x140/0x1a0 fs/proc/generic.c:487
proc_net_mkdir include/linux/proc_fs.h:201 [inline]
afs_proc_cell_setup+0xb2/0x1f0 fs/afs/proc.c:619
afs_activate_cell fs/afs/cell.c:684 [inline]
afs_manage_cell fs/afs/cell.c:768 [inline]
afs_manage_cell_work+0x5b7/0x11c0 fs/afs/cell.c:832
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
Kernel Offset: disabled
Rebooting in 86400 seconds..


Tested on:

commit: f8eb8d1c afs: Add tracing for cell refcount and active use..
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git
console output: https://syzkaller.appspot.com/x/log.txt?x=1414b0d8500000
kernel config: https://syzkaller.appspot.com/x/.config?x=302928762dfb5528
Reply all
Reply to author
Forward
0 new messages