UPSTREAM: fs: erofs: add sanity check for kobject in erofs_unregister_sysfs

Syzkaller hit 'WARNING: kobject bug in erofs_unregister_sysfs'. This bug
is triggered by injecting fault in kobject_init_and_add of
erofs_unregister_sysfs.

Fix this by adding sanity check for kobject in erofs_unregister_sysfs

Note that I've tested the patch and the crash does not occur any more.

Bug: 254441685
Link: https://lore.kernel.org/r/20220315132814.12332-1-dzm91@hust.edu.cn
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
Fixes: 168e9a7620 ("erofs: add sysfs interface")
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
(cherry picked from commit a942da24ab)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I9b074a6b2d087b1fa4bd4fa50ccfda46d56c98d8
This commit is contained in:
Dongliang Mu
2022-03-15 21:28:14 +08:00
committed by Treehugger Robot
parent e7bbb89470
commit 7923c77f8f

View File

@@ -204,9 +204,11 @@ void erofs_unregister_sysfs(struct super_block *sb)
{
struct erofs_sb_info *sbi = EROFS_SB(sb);
kobject_del(&sbi->s_kobj);
kobject_put(&sbi->s_kobj);
wait_for_completion(&sbi->s_kobj_unregister);
if (sbi->s_kobj.state_in_sysfs) {
kobject_del(&sbi->s_kobj);
kobject_put(&sbi->s_kobj);
wait_for_completion(&sbi->s_kobj_unregister);
}
}
int __init erofs_init_sysfs(void)