linux-IllusionX/fs/nilfs2
Nanyong Sun 5f5dec07ac nilfs2: fix memory leak in nilfs_sysfs_create_device_group
Patch series "nilfs2: fix incorrect usage of kobject".

This patchset from Nanyong Sun fixes memory leak issues and a NULL
pointer dereference issue caused by incorrect usage of kboject in nilfs2
sysfs implementation.

This patch (of 6):

Reported by syzkaller:

  BUG: memory leak
  unreferenced object 0xffff888100ca8988 (size 8):
  comm "syz-executor.1", pid 1930, jiffies 4294745569 (age 18.052s)
  hex dump (first 8 bytes):
  6c 6f 6f 70 31 00 ff ff loop1...
  backtrace:
    kstrdup+0x36/0x70 mm/util.c:60
    kstrdup_const+0x35/0x60 mm/util.c:83
    kvasprintf_const+0xf1/0x180 lib/kasprintf.c:48
    kobject_set_name_vargs+0x56/0x150 lib/kobject.c:289
    kobject_add_varg lib/kobject.c:384 [inline]
    kobject_init_and_add+0xc9/0x150 lib/kobject.c:473
    nilfs_sysfs_create_device_group+0x150/0x7d0 fs/nilfs2/sysfs.c:986
    init_nilfs+0xa21/0xea0 fs/nilfs2/the_nilfs.c:637
    nilfs_fill_super fs/nilfs2/super.c:1046 [inline]
    nilfs_mount+0x7b4/0xe80 fs/nilfs2/super.c:1316
    legacy_get_tree+0x105/0x210 fs/fs_context.c:592
    vfs_get_tree+0x8e/0x2d0 fs/super.c:1498
    do_new_mount fs/namespace.c:2905 [inline]
    path_mount+0xf9b/0x1990 fs/namespace.c:3235
    do_mount+0xea/0x100 fs/namespace.c:3248
    __do_sys_mount fs/namespace.c:3456 [inline]
    __se_sys_mount fs/namespace.c:3433 [inline]
    __x64_sys_mount+0x14b/0x1f0 fs/namespace.c:3433
    do_syscall_x64 arch/x86/entry/common.c:50 [inline]
    do_syscall_64+0x3b/0x90 arch/x86/entry/common.c:80
    entry_SYSCALL_64_after_hwframe+0x44/0xae

If kobject_init_and_add return with error, then the cleanup of kobject
is needed because memory may be allocated in kobject_init_and_add
without freeing.

And the place of cleanup_dev_kobject should use kobject_put to free the
memory associated with the kobject.  As the section "Kobject removal" of
"Documentation/core-api/kobject.rst" says, kobject_del() just makes the
kobject "invisible", but it is not cleaned up.  And no more cleanup will
do after cleanup_dev_kobject, so kobject_put is needed here.

Link: https://lkml.kernel.org/r/1625651306-10829-1-git-send-email-konishi.ryusuke@gmail.com
Link: https://lkml.kernel.org/r/1625651306-10829-2-git-send-email-konishi.ryusuke@gmail.com
Reported-by: Hulk Robot <hulkci@huawei.com>
Link: https://lkml.kernel.org/r/20210629022556.3985106-2-sunnanyong@huawei.com
Signed-off-by: Nanyong Sun <sunnanyong@huawei.com>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-09-08 11:50:27 -07:00
..
alloc.c nilfs2: use a more common logging style 2020-08-12 10:58:01 -07:00
alloc.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
bmap.c nilfs2: fix some kernel-doc warnings for nilfs2 2020-10-16 11:11:22 -07:00
bmap.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
btnode.c XArray: Change xa_insert to return -EBUSY 2019-02-06 13:12:15 -05:00
btnode.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
btree.c nilfs2: remove redundant continue statement in a while-loop 2021-07-01 11:06:06 -07:00
btree.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
cpfile.c nilfs2: fix typos in comments 2021-05-06 19:24:13 -07:00
cpfile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
dat.c nilfs2: use a more common logging style 2020-08-12 10:58:01 -07:00
dat.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
dir.c nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
direct.c nilfs2: use a more common logging style 2020-08-12 10:58:01 -07:00
direct.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
export.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
file.c nilfs2: convert to fileattr 2021-04-12 15:04:30 +02:00
gcinode.c nilfs2: use a more common logging style 2020-08-12 10:58:01 -07:00
ifile.c nilfs2: use a more common logging style 2020-08-12 10:58:01 -07:00
ifile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
inode.c fs: make helpers idmap mount aware 2021-01-24 14:27:20 +01:00
ioctl.c nilfs2: fix typos in comments 2021-05-06 19:24:13 -07:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mdt.c mm: require ->set_page_dirty to be explicitly wired up 2021-06-29 10:53:48 -07:00
mdt.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
namei.c Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2021-05-02 09:14:01 -07:00
nilfs.h nilfs2: convert to fileattr 2021-04-12 15:04:30 +02:00
page.c nilfs2: fix some kernel-doc warnings for nilfs2 2020-10-16 11:11:22 -07:00
page.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
recovery.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
segbuf.c block: rename BIO_MAX_PAGES to BIO_MAX_VECS 2021-03-11 07:47:48 -07:00
segbuf.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
segment.c fs/nilfs2: fix misspellings using codespell tool 2021-05-06 19:24:13 -07:00
segment.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
sufile.c nilfs2: fix some kernel-doc warnings for nilfs2 2020-10-16 11:11:22 -07:00
sufile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
super.c [PATCH] reduce boilerplate in fsid handling 2020-09-18 16:45:50 -04:00
sysfs.c nilfs2: fix memory leak in nilfs_sysfs_create_device_group 2021-09-08 11:50:27 -07:00
sysfs.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
the_nilfs.c nilfs2: fix typos in comments 2021-05-06 19:24:13 -07:00
the_nilfs.h block: use an on-stack bio in blkdev_issue_flush 2021-01-27 09:51:48 -07:00