linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: fix possible memory leak in f2fs_init_sysfs()
@ 2022-10-18  7:32 Yang Yingliang via Linux-f2fs-devel
  2022-10-20  8:45 ` Chao Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang via Linux-f2fs-devel @ 2022-10-18  7:32 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: jaegeuk, yangyingliang

Inject fault while probing module, kset_register() may fail,
if it fails, but the refcount of kobject is not decreased to
0, the name allocated in kobject_set_name() is leaked. Fix
this by calling kset_put(), so that name can be freed in
callback function kobject_cleanup().

unreferenced object 0xffff888101b7cc80 (size 8):
  comm "modprobe", pid 252, jiffies 4294691378 (age 31.760s)
  hex dump (first 8 bytes):
    66 32 66 73 00 88 ff ff                          f2fs....
  backtrace:
    [<000000001db5b408>] __kmalloc_node_track_caller+0x44/0x1b0
    [<000000002783a073>] kstrdup+0x3a/0x70
    [<00000000ead2b281>] kstrdup_const+0x63/0x80
    [<000000003e5cf8f7>] kvasprintf_const+0x149/0x180
    [<00000000c4d949ff>] kobject_set_name_vargs+0x56/0x150
    [<0000000044611660>] kobject_set_name+0xab/0xe0

Fixes: bf9e697ecd42 ("f2fs: expose features to sysfs entry")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 fs/f2fs/sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index df27afd71ef4..2ef7a48967be 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -1250,8 +1250,10 @@ int __init f2fs_init_sysfs(void)
 	kobject_set_name(&f2fs_kset.kobj, "f2fs");
 	f2fs_kset.kobj.parent = fs_kobj;
 	ret = kset_register(&f2fs_kset);
-	if (ret)
+	if (ret) {
+		kset_put(&f2fs_kset);
 		return ret;
+	}
 
 	ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
 				   NULL, "features");
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix possible memory leak in f2fs_init_sysfs()
  2022-10-18  7:32 [f2fs-dev] [PATCH] f2fs: fix possible memory leak in f2fs_init_sysfs() Yang Yingliang via Linux-f2fs-devel
@ 2022-10-20  8:45 ` Chao Yu
  2022-10-28  0:58   ` Chao Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2022-10-20  8:45 UTC (permalink / raw)
  To: Yang Yingliang, linux-f2fs-devel; +Cc: jaegeuk

On 2022/10/18 15:32, Yang Yingliang wrote:
> Inject fault while probing module, kset_register() may fail,
> if it fails, but the refcount of kobject is not decreased to
> 0, the name allocated in kobject_set_name() is leaked. Fix
> this by calling kset_put(), so that name can be freed in
> callback function kobject_cleanup().
> 
> unreferenced object 0xffff888101b7cc80 (size 8):
>    comm "modprobe", pid 252, jiffies 4294691378 (age 31.760s)
>    hex dump (first 8 bytes):
>      66 32 66 73 00 88 ff ff                          f2fs....
>    backtrace:
>      [<000000001db5b408>] __kmalloc_node_track_caller+0x44/0x1b0
>      [<000000002783a073>] kstrdup+0x3a/0x70
>      [<00000000ead2b281>] kstrdup_const+0x63/0x80
>      [<000000003e5cf8f7>] kvasprintf_const+0x149/0x180
>      [<00000000c4d949ff>] kobject_set_name_vargs+0x56/0x150
>      [<0000000044611660>] kobject_set_name+0xab/0xe0
> 
> Fixes: bf9e697ecd42 ("f2fs: expose features to sysfs entry")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix possible memory leak in f2fs_init_sysfs()
  2022-10-20  8:45 ` Chao Yu
@ 2022-10-28  0:58   ` Chao Yu
  2022-10-28  3:26     ` Jaegeuk Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2022-10-28  0:58 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, Yang Yingliang

Jaegeuk,

There is a generic fix [1], let's drop this one...

https://lore.kernel.org/lkml/20221025071549.1280528-1-yangyingliang@huawei.com/T/

On 2022/10/20 16:45, Chao Yu wrote:
> On 2022/10/18 15:32, Yang Yingliang wrote:
>> Inject fault while probing module, kset_register() may fail,
>> if it fails, but the refcount of kobject is not decreased to
>> 0, the name allocated in kobject_set_name() is leaked. Fix
>> this by calling kset_put(), so that name can be freed in
>> callback function kobject_cleanup().
>>
>> unreferenced object 0xffff888101b7cc80 (size 8):
>>    comm "modprobe", pid 252, jiffies 4294691378 (age 31.760s)
>>    hex dump (first 8 bytes):
>>      66 32 66 73 00 88 ff ff                          f2fs....
>>    backtrace:
>>      [<000000001db5b408>] __kmalloc_node_track_caller+0x44/0x1b0
>>      [<000000002783a073>] kstrdup+0x3a/0x70
>>      [<00000000ead2b281>] kstrdup_const+0x63/0x80
>>      [<000000003e5cf8f7>] kvasprintf_const+0x149/0x180
>>      [<00000000c4d949ff>] kobject_set_name_vargs+0x56/0x150
>>      [<0000000044611660>] kobject_set_name+0xab/0xe0
>>
>> Fixes: bf9e697ecd42 ("f2fs: expose features to sysfs entry")
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> 
> Reviewed-by: Chao Yu <chao@kernel.org>
> 
> Thanks,
> 
> 
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix possible memory leak in f2fs_init_sysfs()
  2022-10-28  0:58   ` Chao Yu
@ 2022-10-28  3:26     ` Jaegeuk Kim
  0 siblings, 0 replies; 4+ messages in thread
From: Jaegeuk Kim @ 2022-10-28  3:26 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-f2fs-devel, Yang Yingliang

On 10/28, Chao Yu wrote:
> Jaegeuk,
> 
> There is a generic fix [1], let's drop this one...

Ok, thanks.

> 
> https://lore.kernel.org/lkml/20221025071549.1280528-1-yangyingliang@huawei.com/T/
> 
> On 2022/10/20 16:45, Chao Yu wrote:
> > On 2022/10/18 15:32, Yang Yingliang wrote:
> > > Inject fault while probing module, kset_register() may fail,
> > > if it fails, but the refcount of kobject is not decreased to
> > > 0, the name allocated in kobject_set_name() is leaked. Fix
> > > this by calling kset_put(), so that name can be freed in
> > > callback function kobject_cleanup().
> > > 
> > > unreferenced object 0xffff888101b7cc80 (size 8):
> > >    comm "modprobe", pid 252, jiffies 4294691378 (age 31.760s)
> > >    hex dump (first 8 bytes):
> > >      66 32 66 73 00 88 ff ff                          f2fs....
> > >    backtrace:
> > >      [<000000001db5b408>] __kmalloc_node_track_caller+0x44/0x1b0
> > >      [<000000002783a073>] kstrdup+0x3a/0x70
> > >      [<00000000ead2b281>] kstrdup_const+0x63/0x80
> > >      [<000000003e5cf8f7>] kvasprintf_const+0x149/0x180
> > >      [<00000000c4d949ff>] kobject_set_name_vargs+0x56/0x150
> > >      [<0000000044611660>] kobject_set_name+0xab/0xe0
> > > 
> > > Fixes: bf9e697ecd42 ("f2fs: expose features to sysfs entry")
> > > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > 
> > Reviewed-by: Chao Yu <chao@kernel.org>
> > 
> > Thanks,
> > 
> > 
> > _______________________________________________
> > Linux-f2fs-devel mailing list
> > Linux-f2fs-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-28  3:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18  7:32 [f2fs-dev] [PATCH] f2fs: fix possible memory leak in f2fs_init_sysfs() Yang Yingliang via Linux-f2fs-devel
2022-10-20  8:45 ` Chao Yu
2022-10-28  0:58   ` Chao Yu
2022-10-28  3:26     ` Jaegeuk Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).