KASAN: use-after-free Read in path_init (2)

19 views
Skip to first unread message

syzbot

unread,
Aug 11, 2020, 11:17:17ā€ÆPM8/11/20
to ar...@arndb.de, christia...@ubuntu.com, h...@lst.de, linu...@vger.kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, li...@dominikbrodowski.net, syzkall...@googlegroups.com, vi...@zeniv.linux.org.uk
Hello,

syzbot found the following issue on:

HEAD commit: 5631c5e0 Merge tag 'xfs-5.9-merge-7' of git://git.kernel.o..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17076984900000
kernel config: https://syzkaller.appspot.com/x/.config?x=afba7c06f91e56eb
dashboard link: https://syzkaller.appspot.com/bug?extid=bbeb1c88016c7db4aa24
compiler: gcc (GCC) 10.1.0-syz 20200507
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1502ce02900000

The issue was bisected to:

commit e24ab0ef689de43649327f54cd1088f3dad25bb3
Author: Christoph Hellwig <h...@lst.de>
Date: Tue Jul 21 08:48:15 2020 +0000

fs: push the getname from do_rmdir into the callers

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=155f36c2900000
final oops: https://syzkaller.appspot.com/x/report.txt?x=175f36c2900000
console output: https://syzkaller.appspot.com/x/log.txt?x=135f36c2900000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+bbeb1c...@syzkaller.appspotmail.com
Fixes: e24ab0ef689d ("fs: push the getname from do_rmdir into the callers")

==================================================================
BUG: KASAN: use-after-free in path_init+0x116b/0x13c0 fs/namei.c:2207
Read of size 8 at addr ffff88807853c940 by task syz-executor.2/8233

CPU: 0 PID: 8233 Comm: syz-executor.2 Not tainted 5.8.0-syzkaller #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+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
path_init+0x116b/0x13c0 fs/namei.c:2207
path_parentat+0x22/0x1b0 fs/namei.c:2384
filename_parentat+0x188/0x560 fs/namei.c:2407
do_rmdir+0xa8/0x440 fs/namei.c:3732
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x45ce79
Code: 2d b6 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 fb b5 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f756fb2bc78 EFLAGS: 00000246 ORIG_RAX: 0000000000000054
RAX: ffffffffffffffda RBX: 00000000000260c0 RCX: 000000000045ce79
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000200000c0
RBP: 000000000118bff0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000118bfcc
R13: 00007ffedeb9931f R14: 00007f756fb2c9c0 R15: 000000000118bfcc

Allocated by task 8233:
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
slab_post_alloc_hook mm/slab.h:586 [inline]
slab_alloc mm/slab.c:3320 [inline]
kmem_cache_alloc+0x12c/0x3b0 mm/slab.c:3484
getname_flags.part.0+0x50/0x4f0 fs/namei.c:138
getname_flags include/linux/audit.h:320 [inline]
getname fs/namei.c:209 [inline]
__do_sys_rmdir fs/namei.c:3783 [inline]
__se_sys_rmdir fs/namei.c:3781 [inline]
__x64_sys_rmdir+0xb1/0x100 fs/namei.c:3781
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 8233:
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]
kmem_cache_free+0x7f/0x310 mm/slab.c:3694
putname+0xe1/0x120 fs/namei.c:259
do_rmdir+0x145/0x440 fs/namei.c:3773
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff88807853c940
which belongs to the cache names_cache of size 4096
The buggy address is located 0 bytes inside of
4096-byte region [ffff88807853c940, ffff88807853d940)
The buggy address belongs to the page:
page:ffffea0001e14f00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 head:ffffea0001e14f00 order:1 compound_mapcount:0
flags: 0xfffe0000010200(slab|head)
raw: 00fffe0000010200 ffffea0001e14e88 ffffea0001e14f88 ffff8880aa246380
raw: 0000000000000000 ffff88807853c940 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff88807853c800: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88807853c880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88807853c900: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
^
ffff88807853c980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807853ca00: 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.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

Al Viro

unread,
Aug 12, 2020, 12:15:37ā€ÆAM8/12/20
to Linus Torvalds, ar...@arndb.de, christia...@ubuntu.com, h...@lst.de, linu...@vger.kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, li...@dominikbrodowski.net, syzkall...@googlegroups.com, syzbot
On Tue, Aug 11, 2020 at 08:17:16PM -0700, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 5631c5e0 Merge tag 'xfs-5.9-merge-7' of git://git.kernel.o..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=17076984900000
> kernel config: https://syzkaller.appspot.com/x/.config?x=afba7c06f91e56eb
> dashboard link: https://syzkaller.appspot.com/bug?extid=bbeb1c88016c7db4aa24
> compiler: gcc (GCC) 10.1.0-syz 20200507
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1502ce02900000

fix breakage in do_rmdir()

putname() should happen only after we'd *not* branched to
retry, same as it's done in do_unlinkat().

Fixes: e24ab0ef689d "fs: push the getname from do_rmdir into the callers"
Signed-off-by: Al Viro <vi...@zeniv.linux.org.uk>
---
diff --git a/fs/namei.c b/fs/namei.c
index fde8fe086c09..9fa10c614de7 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3770,11 +3770,11 @@ long do_rmdir(int dfd, struct filename *name)
mnt_drop_write(path.mnt);
exit1:
path_put(&path);
- putname(name);
if (retry_estale(error, lookup_flags)) {
lookup_flags |= LOOKUP_REVAL;
goto retry;
}
+ putname(name);
return error;
}

Linus Torvalds

unread,
Aug 12, 2020, 12:30:07ā€ÆAM8/12/20
to Al Viro, Arnd Bergmann, Christian Brauner, Christoph Hellwig, Linux API, linux-fsdevel, Linux Kernel Mailing List, Dominik Brodowski, syzkaller-bugs, syzbot
On Tue, Aug 11, 2020 at 9:15 PM Al Viro <vi...@zeniv.linux.org.uk> wrote:
>
> fix breakage in do_rmdir()
>
> putname() should happen only after we'd *not* branched to
> retry, same as it's done in do_unlinkat().

Looks obviously correct.

Do you want me to apply directly, or do you have other fixes pending
and I'll get a pull request?

Linus

Al Viro

unread,
Aug 12, 2020, 1:56:03ā€ÆAM8/12/20
to Linus Torvalds, Arnd Bergmann, Christian Brauner, Christoph Hellwig, Linux API, linux-fsdevel, Linux Kernel Mailing List, Dominik Brodowski, syzkaller-bugs, syzbot
Not at the moment - I can throw it into #fixes and send a pull request
if you wish, but there won't be anything else in it...

Linus Torvalds

unread,
Aug 12, 2020, 1:23:40ā€ÆPM8/12/20
to Al Viro, Arnd Bergmann, Christian Brauner, Christoph Hellwig, Linux API, linux-fsdevel, Linux Kernel Mailing List, Dominik Brodowski, syzkaller-bugs, syzbot
Ok, I applied the patch directly. Thanks,

Linus

syzbot

unread,
Aug 12, 2020, 5:28:17ā€ÆPM8/12/20
to ar...@arndb.de, christia...@ubuntu.com, h...@lst.de, linu...@vger.kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, li...@dominikbrodowski.net, syzkall...@googlegroups.com, torv...@linux-foundation.org, vi...@zeniv.linux.org.uk
syzbot has found a reproducer for the following issue on:

HEAD commit: fb893de3 Merge tag 'tag-chrome-platform-for-v5.9' of git:/..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=16139be2900000
kernel config: https://syzkaller.appspot.com/x/.config?x=f1fedc63022bf07e
dashboard link: https://syzkaller.appspot.com/bug?extid=bbeb1c88016c7db4aa24
compiler: gcc (GCC) 10.1.0-syz 20200507
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15fa83e2900000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15920c4a900000

The issue was bisected to:

commit e24ab0ef689de43649327f54cd1088f3dad25bb3
Author: Christoph Hellwig <h...@lst.de>
Date: Tue Jul 21 08:48:15 2020 +0000

fs: push the getname from do_rmdir into the callers

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=155f36c2900000
final oops: https://syzkaller.appspot.com/x/report.txt?x=175f36c2900000
console output: https://syzkaller.appspot.com/x/log.txt?x=135f36c2900000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+bbeb1c...@syzkaller.appspotmail.com
Fixes: e24ab0ef689d ("fs: push the getname from do_rmdir into the callers")

==================================================================
BUG: KASAN: use-after-free in path_init+0x116b/0x13c0 fs/namei.c:2207
Read of size 8 at addr ffff8880950a8a80 by task syz-executor167/6821

CPU: 0 PID: 6821 Comm: syz-executor167 Not tainted 5.8.0-syzkaller #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+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
path_init+0x116b/0x13c0 fs/namei.c:2207
path_parentat+0x22/0x1b0 fs/namei.c:2384
filename_parentat+0x188/0x560 fs/namei.c:2407
do_rmdir+0xa8/0x440 fs/namei.c:3732
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x4403e9
Code: 18 89 d0 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 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 0f 83 7b 13 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffd4e3bdb58 EFLAGS: 00000246 ORIG_RAX: 0000000000000054
RAX: ffffffffffffffda RBX: 69662f7375622f2e RCX: 00000000004403e9
RDX: 00000000004403e9 RSI: 00000000004403e9 RDI: 0000000020000080
RBP: 2f31656c69662f2e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000401bf0
R13: 0000000000401c80 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 6821:
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
slab_post_alloc_hook mm/slab.h:518 [inline]
slab_alloc mm/slab.c:3312 [inline]
kmem_cache_alloc+0x138/0x3a0 mm/slab.c:3482
getname_flags.part.0+0x50/0x4f0 fs/namei.c:138
getname_flags include/linux/audit.h:320 [inline]
getname fs/namei.c:209 [inline]
__do_sys_rmdir fs/namei.c:3783 [inline]
__se_sys_rmdir fs/namei.c:3781 [inline]
__x64_sys_rmdir+0xb1/0x100 fs/namei.c:3781
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 6821:
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]
kmem_cache_free.part.0+0x67/0x1f0 mm/slab.c:3693
putname+0xe1/0x120 fs/namei.c:259
do_rmdir+0x145/0x440 fs/namei.c:3773
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff8880950a8a80
which belongs to the cache names_cache of size 4096
The buggy address is located 0 bytes inside of
4096-byte region [ffff8880950a8a80, ffff8880950a9a80)
The buggy address belongs to the page:
page:00000000c8532513 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x950a8
head:00000000c8532513 order:1 compound_mapcount:0
flags: 0xfffe0000010200(slab|head)
raw: 00fffe0000010200 ffffea0002540e88 ffffea000251ef88 ffff88821bc47a00
raw: 0000000000000000 ffff8880950a8a80 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8880950a8980: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8880950a8a00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880950a8a80: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880950a8b00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880950a8b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Reply all
Reply to author
Forward
0 new messages