Skip to content

Commit 4976d9e

Browse files
lgs2513gregkh
authored andcommitted
f2fs: fix uninitialized kobject put in f2fs_init_sysfs()
commit b635f2e upstream. In f2fs_init_sysfs(), all failure paths after kset_register() jump to put_kobject, which unconditionally releases both f2fs_tune and f2fs_feat. If kobject_init_and_add(&f2fs_feat, ...) fails, f2fs_tune has not been initialized yet, so calling kobject_put(&f2fs_tune) is invalid. Fix this by splitting the unwind path so each error path only releases objects that were successfully initialized. Fixes: a907f3a ("f2fs: add a sysfs entry to reclaim POSIX_FADV_NOREUSE pages") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0559a0e commit 4976d9e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

fs/f2fs/sysfs.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,24 +1984,26 @@ int __init f2fs_init_sysfs(void)
19841984
ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
19851985
NULL, "features");
19861986
if (ret)
1987-
goto put_kobject;
1987+
goto unregister_kset;
19881988

19891989
ret = kobject_init_and_add(&f2fs_tune, &f2fs_tune_ktype,
19901990
NULL, "tuning");
19911991
if (ret)
1992-
goto put_kobject;
1992+
goto put_feat;
19931993

19941994
f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
19951995
if (!f2fs_proc_root) {
19961996
ret = -ENOMEM;
1997-
goto put_kobject;
1997+
goto put_tune;
19981998
}
19991999

20002000
return 0;
20012001

2002-
put_kobject:
2002+
put_tune:
20032003
kobject_put(&f2fs_tune);
2004+
put_feat:
20042005
kobject_put(&f2fs_feat);
2006+
unregister_kset:
20052007
kset_unregister(&f2fs_kset);
20062008
return ret;
20072009
}

0 commit comments

Comments
 (0)