Chen Zhongjin
90c38f57a8
configfs: fix possible memory leak in configfs_create_dir()
...
[ Upstream commit c65234b283a65cfbfc94619655e820a5e55199eb ]
kmemleak reported memory leaks in configfs_create_dir():
unreferenced object 0xffff888009f6af00 (size 192):
comm "modprobe", pid 3777, jiffies 4295537735 (age 233.784s)
backtrace:
kmem_cache_alloc (mm/slub.c:3250 mm/slub.c:3256 mm/slub.c:3263 mm/slub.c:3273)
new_fragment (./include/linux/slab.h:600 fs/configfs/dir.c:163)
configfs_register_subsystem (fs/configfs/dir.c:1857)
basic_write (drivers/hwtracing/stm/p_basic.c:14) stm_p_basic
do_one_initcall (init/main.c:1296)
do_init_module (kernel/module/main.c:2455)
...
unreferenced object 0xffff888003ba7180 (size 96):
comm "modprobe", pid 3777, jiffies 4295537735 (age 233.784s)
backtrace:
kmem_cache_alloc (mm/slub.c:3250 mm/slub.c:3256 mm/slub.c:3263 mm/slub.c:3273)
configfs_new_dirent (./include/linux/slab.h:723 fs/configfs/dir.c:194)
configfs_make_dirent (fs/configfs/dir.c:248)
configfs_create_dir (fs/configfs/dir.c:296)
configfs_attach_group.isra.28 (fs/configfs/dir.c:816 fs/configfs/dir.c:852)
configfs_register_subsystem (fs/configfs/dir.c:1881)
basic_write (drivers/hwtracing/stm/p_basic.c:14) stm_p_basic
do_one_initcall (init/main.c:1296)
do_init_module (kernel/module/main.c:2455)
...
This is because the refcount is not correct in configfs_make_dirent().
For normal stage, the refcount is changing as:
configfs_register_subsystem()
configfs_create_dir()
configfs_make_dirent()
configfs_new_dirent() # set s_count = 1
dentry->d_fsdata = configfs_get(sd); # s_count = 2
...
configfs_unregister_subsystem()
configfs_remove_dir()
remove_dir()
configfs_remove_dirent() # s_count = 1
dput() ...
*dentry_unlink_inode()*
configfs_d_iput() # s_count = 0, release
However, if we failed in configfs_create():
configfs_register_subsystem()
configfs_create_dir()
configfs_make_dirent() # s_count = 2
...
configfs_create() # fail
->out_remove:
configfs_remove_dirent(dentry)
configfs_put(sd) # s_count = 1
return PTR_ERR(inode);
There is no inode in the error path, so the configfs_d_iput() is lost
and makes sd and fragment memory leaked.
To fix this, when we failed in configfs_create(), manually call
configfs_put(sd) to keep the refcount correct.
Fixes: 7063fbf22611 ("[PATCH] configfs: User-driven configuration filesystem")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-01-18 11:41:09 +01:00
..
2022-06-22 14:11:02 +02:00
2021-03-04 10:26:48 +01:00
2022-12-08 11:23:03 +01:00
2019-10-25 00:03:11 -04:00
2021-01-06 14:48:39 +01:00
2022-12-14 11:30:41 +01:00
2020-11-05 11:43:36 +01:00
2022-12-08 11:23:00 +01:00
2022-11-25 17:42:16 +01:00
2023-01-18 11:41:09 +01:00
2019-11-23 21:44:49 -05:00
2021-09-12 08:56:38 +02:00
2023-01-18 11:40:56 +01:00
2022-02-01 17:24:34 +01:00
2022-10-26 13:22:14 +02:00
2021-05-26 12:05:19 +02:00
2020-12-02 08:49:53 +01:00
2022-08-25 11:17:36 +02:00
2019-11-10 11:56:05 -05:00
2022-08-25 11:17:28 +02:00
2022-11-10 17:57:56 +01:00
2022-10-26 13:22:46 +02:00
2022-06-14 18:11:30 +02:00
2021-09-22 12:26:25 +02:00
2022-12-08 11:23:01 +01:00
2022-11-25 17:42:22 +01:00
2023-01-18 11:40:59 +01:00
2021-05-19 10:08:29 +02:00
2021-04-14 08:24:14 +02:00
2022-05-09 09:03:28 +02:00
2022-06-14 18:11:36 +02:00
2021-11-12 14:43:03 +01:00
2022-10-26 13:22:17 +02:00
2022-06-14 18:11:55 +02:00
2022-06-14 18:11:29 +02:00
2022-11-03 23:56:54 +09:00
2021-09-22 12:26:34 +02:00
2022-04-15 14:18:35 +02:00
2023-01-18 11:41:07 +01:00
2020-12-30 11:51:22 +01:00
2023-01-18 11:40:55 +01:00
2022-12-08 11:23:04 +01:00
2022-06-14 18:11:34 +02:00
2022-11-25 17:42:22 +01:00
2023-01-18 11:40:56 +01:00
2022-01-20 09:19:17 +01:00
2022-08-25 11:17:23 +02:00
2022-10-29 10:20:36 +02:00
2023-01-18 11:40:52 +01:00
2021-09-30 10:09:26 +02:00
2022-10-26 13:22:14 +02:00
2020-10-29 09:57:53 +01:00
2021-08-12 13:21:05 +02:00
2020-08-26 10:40:51 +02:00
2021-05-19 10:08:29 +02:00
2021-03-07 12:20:48 +01:00
2023-01-18 11:40:58 +01:00
2022-09-20 12:28:00 +02:00
2022-04-15 14:18:31 +02:00
2023-01-18 11:40:47 +01:00
2020-08-21 13:05:37 +02:00
2021-10-06 15:42:30 +02:00
2022-11-25 17:42:03 +01:00
2021-12-14 14:49:02 +01:00
2022-08-25 11:17:21 +02:00
2021-10-06 15:42:35 +02:00
2022-06-14 18:11:23 +02:00
2021-03-17 17:03:57 +01:00
2021-05-22 11:38:29 +02:00
2022-11-25 17:42:22 +01:00
2020-01-14 20:08:18 +01:00
2022-06-22 14:11:03 +02:00
2020-12-11 13:23:30 +01:00
2020-10-29 09:57:45 +01:00
2022-06-14 18:11:41 +02:00
2020-10-01 13:17:19 +02:00
2021-04-14 08:24:11 +02:00
2020-01-12 12:21:37 +01:00
2020-02-11 04:35:37 -08:00
2022-12-08 11:23:05 +01:00
2022-06-06 08:33:50 +02:00
2021-09-15 09:47:28 +02:00
2022-05-25 09:14:34 +02:00
2022-03-02 11:41:18 +01:00
2020-04-17 10:50:21 +02:00
2022-02-08 18:24:29 +01:00
2022-06-14 18:11:44 +02:00
2022-10-15 07:54:36 +02:00
2021-07-31 08:19:37 +02:00
2022-10-26 13:22:59 +02:00
2019-12-17 19:55:30 +01:00
2023-01-18 11:40:55 +01:00
2020-03-25 08:25:41 +01:00
2020-01-17 19:48:21 +01:00
2022-11-25 17:42:22 +01:00
2021-08-26 08:36:22 -04:00
2020-03-18 07:17:51 +01:00
2021-08-12 13:21:02 +02:00
2020-05-02 08:48:44 +02:00
2021-03-17 17:03:33 +01:00
2020-02-11 04:35:23 -08:00
2021-04-21 12:56:16 +02:00
2022-01-29 10:25:11 +01:00
2021-07-20 16:10:54 +02:00
2022-09-05 10:27:47 +02:00
2022-10-17 17:24:32 +02:00
2022-04-27 13:50:48 +02:00
2019-10-03 14:21:35 -07:00
2022-02-23 11:59:55 +01:00
2022-10-26 13:22:21 +02:00
2020-02-11 04:35:12 -08:00
2023-01-18 11:40:53 +01:00