Re: WARNING in __fsnotify_recalc_mask

From: Amir Goldstein
Date: Sun Aug 19 2018 - 07:16:50 EST


On Sat, Aug 18, 2018 at 7:26 PM syzbot
<syzbot+c34692a51b9a6ca93540@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit: 1f7a4c73a739 Merge tag '9p-for-4.19-2' of git://github.com..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=10cccef2400000
> kernel config: https://syzkaller.appspot.com/x/.config?x=68e80edb3c9718c5
> dashboard link: https://syzkaller.appspot.com/bug?extid=c34692a51b9a6ca93540
> compiler: gcc (GCC) 8.0.1 20180413 (experimental)
> syzkaller repro:https://syzkaller.appspot.com/x/repro.syz?x=11c12e86400000
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+c34692a51b9a6ca93540@xxxxxxxxxxxxxxxxxxxxxxxxx
>

Hello syzbot,

Thanks for the report!
Please test:
#syz test: https://github.com/amir73il/linux.git fsnotify-fixes

FYI, I wasn't able to reproduce with repro, but didn't wait for more than 1
minute so maybe I was being impatient.

Jan,

Patch attached for reference.
If you don't like the empty else-if statement, you may
merge it with the else case.

Thanks,
Amir.

> IPv6: ADDRCONF(NETDEV_CHANGE): veth0: link becomes ready
> 8021q: adding VLAN 0 to HW filter on device team0
> WARNING: CPU: 1 PID: 12015 at fs/notify/mark.c:139
> __fsnotify_recalc_mask+0x2d7/0x350 fs/notify/mark.c:139
> Kernel panic - not syncing: panic_on_warn set ...
>
> CPU: 1 PID: 12015 Comm: syz-executor0 Not tainted 4.18.0+ #195
> 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+0x1c9/0x2b4 lib/dump_stack.c:113
> panic+0x238/0x4e7 kernel/panic.c:184
> __warn.cold.8+0x163/0x1ba kernel/panic.c:536
> report_bug+0x252/0x2d0 lib/bug.c:186
> fixup_bug arch/x86/kernel/traps.c:178 [inline]
> do_error_trap+0x1fc/0x4d0 arch/x86/kernel/traps.c:296
> do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:316
> invalid_op+0x14/0x20 arch/x86/entry/entry_64.S:993
> RIP: 0010:__fsnotify_recalc_mask+0x2d7/0x350 fs/notify/mark.c:139
> Code: 90 00 00 00 48 83 c4 68 5b 41 5c 41 5d 41 5e 41 5f 5d c3 e8 eb 2d a2
> ff 49 83 ec 04 eb 82 e8 e0 2d a2 ff 0f 0b e8 d9 2d a2 ff <0f> 0b eb a5 e8
> 60 24 e1 ff e9 11 ff ff ff 48 89 df e8 f3 24 e1 ff
> RSP: 0018:ffff8801b509f5c8 EFLAGS: 00010293
> RAX: ffff8801b2c0a180 RBX: 0000000000000002 RCX: ffffffff81dabc96
> RDX: 0000000000000000 RSI: ffffffff81dabd67 RDI: 0000000000000005
> RBP: ffff8801b509f658 R08: ffff8801b2c0a180 R09: ffffed00398cb796
> R10: ffffed00398cb796 R11: ffff8801cc65bcb3 R12: dffffc0000000000
> R13: ffff8801cc65bcb0 R14: 0000000000000000 R15: 0000000000000000
> fsnotify_put_mark+0x523/0xab0 fs/notify/mark.c:240
> fsnotify_destroy_marks+0x2d1/0x5c0 fs/notify/mark.c:741
> fsnotify_clear_marks_by_inode fs/notify/fsnotify.h:39 [inline]
> __fsnotify_inode_delete+0x19/0x20 fs/notify/fsnotify.c:35
> fsnotify_inoderemove include/linux/fsnotify.h:136 [inline]
> dentry_unlink_inode+0x48b/0x5e0 fs/dcache.c:370
> __dentry_kill+0x44c/0x7a0 fs/dcache.c:566
> dentry_kill+0xc9/0x5a0 fs/dcache.c:685
> dput.part.26+0x66b/0x7a0 fs/dcache.c:846
> dput+0x15/0x20 fs/dcache.c:828
> __fput+0x4c2/0x860 fs/file_table.c:264
> ____fput+0x15/0x20 fs/file_table.c:282
> task_work_run+0x1e8/0x2a0 kernel/task_work.c:113
> tracehook_notify_resume include/linux/tracehook.h:193 [inline]
> exit_to_usermode_loop+0x318/0x380 arch/x86/entry/common.c:166
> prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
> syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
> do_syscall_64+0x6be/0x820 arch/x86/entry/common.c:293
> entry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x457089
> Code: fd b4 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 b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00
> RSP: 002b:00007fcfa3e50c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000021
> RAX: 000000000000000a RBX: 00007fcfa3e516d4 RCX: 0000000000457089
> RDX: 0000000000000000 RSI: 000000000000000a RDI: 0000000000000008
> RBP: 00000000009300a0 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
> R13: 00000000004cb6d0 R14: 00000000004c31f3 R15: 0000000000000000
> Dumping ftrace buffer:
> (ftrace buffer empty)
> Kernel Offset: disabled
> Rebooting in 86400 seconds..
>
>
From 2df79a019776d3aca2436c2b5be6b5b555e641ff Mon Sep 17 00:00:00 2001
From: Amir Goldstein <amir73il@xxxxxxxxx>
Date: Sun, 19 Aug 2018 13:57:07 +0300
Subject: [PATCH] fsnotify: fix false positive warning on inode delete

Reported-by: syzbot+c34692a51b9a6ca93540@xxxxxxxxxxxxxxxxxxxxxxxxx
Fixes: 3ac70bfcde81 ("fsnotify: add helper to get mask from connector")
Signed-off-by: Amir Goldstein <amir73il@xxxxxxxxx>
---
fs/notify/mark.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 05506d60131c..d559a8ffe7ed 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -236,6 +236,13 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
if (hlist_empty(&conn->list)) {
inode = fsnotify_detach_connector_from_object(conn);
free_conn = true;
+ } else if (conn->type == FSNOTIFY_OBJ_TYPE_DETACHED) {
+ /*
+ * fsnotify_destroy_marks() detaches conn from object before
+ * put on last mark of object list and other marks on the list
+ * may still have elevated refcounts. We don't need to recalc
+ * mask nor to free_conn in that case.
+ */
} else {
__fsnotify_recalc_mask(conn);
}
--
2.7.4