Chen Zhongjin
07f82dca11
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>
2022-12-31 13:14:15 +01:00
..
2022-08-17 14:24:07 +02:00
2022-12-08 11:28:41 +01:00
2021-10-20 21:09:02 -04:00
2021-08-19 09:02:55 +09:00
2022-12-14 11:37:16 +01:00
2022-07-02 16:41:14 +02:00
2022-12-02 17:41:01 +01:00
2022-12-14 11:37:18 +01:00
2022-12-31 13:14:15 +01:00
2022-11-10 18:15:37 +01:00
2022-12-31 13:14:03 +01:00
2022-02-01 17:27:01 +01:00
2022-10-29 10:12:57 +02:00
2022-07-02 16:41:14 +02:00
2022-12-08 11:28:37 +01:00
2022-07-29 17:25:30 +02:00
2022-06-09 10:23:32 +02:00
2022-10-26 12:35:51 +02:00
2022-12-02 17:41:08 +01:00
2022-11-10 18:15:42 +01:00
2022-06-09 10:22:42 +02:00
2021-10-04 22:13:12 +01:00
2022-12-02 17:41:11 +01:00
2022-11-26 09:24:51 +01:00
2022-12-31 13:14:05 +01:00
2021-08-26 22:28:02 +02:00
2021-07-27 11:00:36 +02:00
2022-11-26 09:24:33 +01:00
2022-06-09 10:22:55 +02:00
2021-11-12 15:05:50 +01:00
2022-10-26 12:34:28 +02:00
2022-06-14 18:36:10 +02:00
2022-06-09 10:22:41 +02:00
2022-11-03 23:59:13 +09:00
2022-12-19 12:36:39 +01:00
2022-12-31 13:14:05 +01:00
2022-04-13 20:59:10 +02:00
2021-12-29 12:28:59 +01:00
2022-12-31 13:14:13 +01:00
2021-10-04 22:02:17 +01:00
2022-12-31 13:14:03 +01:00
2022-12-08 11:28:42 +01:00
2022-06-09 10:22:50 +02:00
2022-11-26 09:24:52 +01:00
2022-10-26 12:34:36 +02:00
2022-12-31 13:14:02 +01:00
2022-01-20 09:13:13 +01:00
2022-12-31 13:14:00 +01:00
2022-10-29 10:12:58 +02:00
2022-12-31 13:14:00 +01:00
2021-09-21 08:36:48 -07:00
2022-10-26 12:34:21 +02:00
2021-09-03 15:33:47 -07:00
2021-12-14 10:57:12 +01:00
2021-08-16 10:50:32 -06:00
2021-08-06 13:05:28 +02:00
2022-12-31 13:14:05 +01:00
2022-09-20 12:39:43 +02:00
2022-04-08 14:24:08 +02:00
2022-12-21 17:36:36 +01:00
2021-08-19 09:02:55 +09:00
2021-09-27 11:26:21 -07:00
2021-09-22 10:56:34 -07:00
2022-10-26 12:34:27 +02:00
2022-12-02 17:41:10 +01:00
2021-12-14 10:57:22 +01:00
2022-08-17 14:22:50 +02:00
2021-08-18 22:08:24 +02:00
2021-09-05 10:15:05 -07:00
2022-04-08 14:24:17 +02:00
2022-11-03 23:59:12 +09:00
2022-06-09 10:22:26 +02:00
2022-11-26 09:24:51 +01:00
2022-04-08 14:24:18 +02:00
2021-09-02 10:07:29 -07:00
2022-09-28 11:11:56 +02:00
2021-09-03 09:58:10 -07:00
2022-10-26 12:35:49 +02:00
2022-08-17 14:22:59 +02:00
2022-11-03 23:59:12 +09:00
2021-09-03 10:08:28 -07:00
2022-10-26 12:34:58 +02:00
2022-12-14 11:37:15 +01:00
2021-08-23 01:25:40 -04:00
2022-01-20 09:13:14 +01:00
2021-09-07 16:07:47 -04:00
2022-12-02 17:41:07 +01:00
2022-10-12 09:53:26 +02:00
2022-10-26 12:34:58 +02:00
2022-05-25 09:57:26 +02:00
2021-09-12 10:10:21 -07:00
2021-07-25 22:33:03 -07:00
2021-10-18 20:22:03 -10:00
2022-12-31 13:14:03 +01:00
2021-09-07 11:21:48 -07:00
2022-12-14 11:37:31 +01:00
2022-08-17 14:22:57 +02:00
2022-11-26 09:24:51 +01:00
2022-08-31 17:16:37 +02:00
2022-10-26 12:34:58 +02:00
2022-06-06 08:43:37 +02:00
2022-07-02 16:41:17 +02:00
2022-07-02 16:41:14 +02:00
2022-12-19 12:36:39 +01:00
2022-07-21 21:24:14 +02:00
2022-01-29 10:58:25 +01:00
2022-07-12 16:35:08 +02:00
2021-12-14 10:57:15 +01:00
2022-10-26 12:34:17 +02:00
2022-04-27 14:38:57 +02:00
2022-11-10 18:15:37 +01:00
2022-04-27 14:38:50 +02:00
2021-08-10 17:57:22 +02:00
2022-10-26 12:34:36 +02:00
2022-12-31 13:14:01 +01:00