Skip to content

Commit 1f2c0e8

Browse files
z00467499hubcapsc
authored andcommitted
orangefs: Fix kmemleak in orangefs_sysfs_init()
When insert and remove the orangefs module, there are kobjects memory leaked as below: unreferenced object 0xffff88810f95af00 (size 64): comm "insmod", pid 783, jiffies 4294813439 (age 65.512s) hex dump (first 32 bytes): a0 83 af 01 81 88 ff ff 08 af 95 0f 81 88 ff ff ................ 08 af 95 0f 81 88 ff ff 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000031ab7788>] kmalloc_trace+0x27/0xa0 [<000000005a6e4dfe>] orangefs_sysfs_init+0x42/0x3a0 [<00000000722645ca>] 0xffffffffa02780fe [<000000004232d9f7>] do_one_initcall+0x87/0x2a0 [<0000000054f22384>] do_init_module+0xdf/0x320 [<000000003263bdea>] load_module+0x2f98/0x3330 [<0000000052cd4153>] __do_sys_finit_module+0x113/0x1b0 [<00000000250ae02b>] do_syscall_64+0x35/0x80 [<00000000f11c03c7>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 unreferenced object 0xffff88810f95ae80 (size 64): comm "insmod", pid 783, jiffies 4294813439 (age 65.512s) hex dump (first 32 bytes): c8 90 0f 02 81 88 ff ff 88 ae 95 0f 81 88 ff ff ................ 88 ae 95 0f 81 88 ff ff 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000031ab7788>] kmalloc_trace+0x27/0xa0 [<000000001a4841fa>] orangefs_sysfs_init+0xc7/0x3a0 [<00000000722645ca>] 0xffffffffa02780fe [<000000004232d9f7>] do_one_initcall+0x87/0x2a0 [<0000000054f22384>] do_init_module+0xdf/0x320 [<000000003263bdea>] load_module+0x2f98/0x3330 [<0000000052cd4153>] __do_sys_finit_module+0x113/0x1b0 [<00000000250ae02b>] do_syscall_64+0x35/0x80 [<00000000f11c03c7>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 unreferenced object 0xffff88810f95ae00 (size 64): comm "insmod", pid 783, jiffies 4294813440 (age 65.511s) hex dump (first 32 bytes): 60 87 a1 00 81 88 ff ff 08 ae 95 0f 81 88 ff ff `............... 08 ae 95 0f 81 88 ff ff 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000031ab7788>] kmalloc_trace+0x27/0xa0 [<000000005915e797>] orangefs_sysfs_init+0x12b/0x3a0 [<00000000722645ca>] 0xffffffffa02780fe [<000000004232d9f7>] do_one_initcall+0x87/0x2a0 [<0000000054f22384>] do_init_module+0xdf/0x320 [<000000003263bdea>] load_module+0x2f98/0x3330 [<0000000052cd4153>] __do_sys_finit_module+0x113/0x1b0 [<00000000250ae02b>] do_syscall_64+0x35/0x80 [<00000000f11c03c7>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 unreferenced object 0xffff88810f95ad80 (size 64): comm "insmod", pid 783, jiffies 4294813440 (age 65.511s) hex dump (first 32 bytes): 78 90 0f 02 81 88 ff ff 88 ad 95 0f 81 88 ff ff x............... 88 ad 95 0f 81 88 ff ff 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000031ab7788>] kmalloc_trace+0x27/0xa0 [<000000007a14eb35>] orangefs_sysfs_init+0x1ac/0x3a0 [<00000000722645ca>] 0xffffffffa02780fe [<000000004232d9f7>] do_one_initcall+0x87/0x2a0 [<0000000054f22384>] do_init_module+0xdf/0x320 [<000000003263bdea>] load_module+0x2f98/0x3330 [<0000000052cd4153>] __do_sys_finit_module+0x113/0x1b0 [<00000000250ae02b>] do_syscall_64+0x35/0x80 [<00000000f11c03c7>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 unreferenced object 0xffff88810f95ac00 (size 64): comm "insmod", pid 783, jiffies 4294813440 (age 65.531s) hex dump (first 32 bytes): e0 ff 67 02 81 88 ff ff 08 ac 95 0f 81 88 ff ff ..g............. 08 ac 95 0f 81 88 ff ff 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000031ab7788>] kmalloc_trace+0x27/0xa0 [<000000001f38adcb>] orangefs_sysfs_init+0x291/0x3a0 [<00000000722645ca>] 0xffffffffa02780fe [<000000004232d9f7>] do_one_initcall+0x87/0x2a0 [<0000000054f22384>] do_init_module+0xdf/0x320 [<000000003263bdea>] load_module+0x2f98/0x3330 [<0000000052cd4153>] __do_sys_finit_module+0x113/0x1b0 [<00000000250ae02b>] do_syscall_64+0x35/0x80 [<00000000f11c03c7>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 unreferenced object 0xffff88810f95ab80 (size 64): comm "insmod", pid 783, jiffies 4294813441 (age 65.530s) hex dump (first 32 bytes): 50 bf 2f 02 81 88 ff ff 88 ab 95 0f 81 88 ff ff P./............. 88 ab 95 0f 81 88 ff ff 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000031ab7788>] kmalloc_trace+0x27/0xa0 [<000000009cc7d95b>] orangefs_sysfs_init+0x2f5/0x3a0 [<00000000722645ca>] 0xffffffffa02780fe [<000000004232d9f7>] do_one_initcall+0x87/0x2a0 [<0000000054f22384>] do_init_module+0xdf/0x320 [<000000003263bdea>] load_module+0x2f98/0x3330 [<0000000052cd4153>] __do_sys_finit_module+0x113/0x1b0 [<00000000250ae02b>] do_syscall_64+0x35/0x80 [<00000000f11c03c7>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 Should add release function for each kobject_type to free the memory. Signed-off-by: Zhang Xiaoxu <[email protected]> Signed-off-by: Mike Marshall <[email protected]>
1 parent d23417a commit 1f2c0e8

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

fs/orangefs/orangefs-sysfs.c

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -896,9 +896,18 @@ static struct attribute *orangefs_default_attrs[] = {
896896
};
897897
ATTRIBUTE_GROUPS(orangefs_default);
898898

899+
static struct kobject *orangefs_obj;
900+
901+
static void orangefs_obj_release(struct kobject *kobj)
902+
{
903+
kfree(orangefs_obj);
904+
orangefs_obj = NULL;
905+
}
906+
899907
static struct kobj_type orangefs_ktype = {
900908
.sysfs_ops = &orangefs_sysfs_ops,
901909
.default_groups = orangefs_default_groups,
910+
.release = orangefs_obj_release,
902911
};
903912

904913
static struct orangefs_attribute acache_hard_limit_attribute =
@@ -934,9 +943,18 @@ static struct attribute *acache_orangefs_default_attrs[] = {
934943
};
935944
ATTRIBUTE_GROUPS(acache_orangefs_default);
936945

946+
static struct kobject *acache_orangefs_obj;
947+
948+
static void acache_orangefs_obj_release(struct kobject *kobj)
949+
{
950+
kfree(acache_orangefs_obj);
951+
acache_orangefs_obj = NULL;
952+
}
953+
937954
static struct kobj_type acache_orangefs_ktype = {
938955
.sysfs_ops = &orangefs_sysfs_ops,
939956
.default_groups = acache_orangefs_default_groups,
957+
.release = acache_orangefs_obj_release,
940958
};
941959

942960
static struct orangefs_attribute capcache_hard_limit_attribute =
@@ -972,9 +990,18 @@ static struct attribute *capcache_orangefs_default_attrs[] = {
972990
};
973991
ATTRIBUTE_GROUPS(capcache_orangefs_default);
974992

993+
static struct kobject *capcache_orangefs_obj;
994+
995+
static void capcache_orangefs_obj_release(struct kobject *kobj)
996+
{
997+
kfree(capcache_orangefs_obj);
998+
capcache_orangefs_obj = NULL;
999+
}
1000+
9751001
static struct kobj_type capcache_orangefs_ktype = {
9761002
.sysfs_ops = &orangefs_sysfs_ops,
9771003
.default_groups = capcache_orangefs_default_groups,
1004+
.release = capcache_orangefs_obj_release,
9781005
};
9791006

9801007
static struct orangefs_attribute ccache_hard_limit_attribute =
@@ -1010,9 +1037,18 @@ static struct attribute *ccache_orangefs_default_attrs[] = {
10101037
};
10111038
ATTRIBUTE_GROUPS(ccache_orangefs_default);
10121039

1040+
static struct kobject *ccache_orangefs_obj;
1041+
1042+
static void ccache_orangefs_obj_release(struct kobject *kobj)
1043+
{
1044+
kfree(ccache_orangefs_obj);
1045+
ccache_orangefs_obj = NULL;
1046+
}
1047+
10131048
static struct kobj_type ccache_orangefs_ktype = {
10141049
.sysfs_ops = &orangefs_sysfs_ops,
10151050
.default_groups = ccache_orangefs_default_groups,
1051+
.release = ccache_orangefs_obj_release,
10161052
};
10171053

10181054
static struct orangefs_attribute ncache_hard_limit_attribute =
@@ -1048,9 +1084,18 @@ static struct attribute *ncache_orangefs_default_attrs[] = {
10481084
};
10491085
ATTRIBUTE_GROUPS(ncache_orangefs_default);
10501086

1087+
static struct kobject *ncache_orangefs_obj;
1088+
1089+
static void ncache_orangefs_obj_release(struct kobject *kobj)
1090+
{
1091+
kfree(ncache_orangefs_obj);
1092+
ncache_orangefs_obj = NULL;
1093+
}
1094+
10511095
static struct kobj_type ncache_orangefs_ktype = {
10521096
.sysfs_ops = &orangefs_sysfs_ops,
10531097
.default_groups = ncache_orangefs_default_groups,
1098+
.release = ncache_orangefs_obj_release,
10541099
};
10551100

10561101
static struct orangefs_attribute pc_acache_attribute =
@@ -1079,9 +1124,18 @@ static struct attribute *pc_orangefs_default_attrs[] = {
10791124
};
10801125
ATTRIBUTE_GROUPS(pc_orangefs_default);
10811126

1127+
static struct kobject *pc_orangefs_obj;
1128+
1129+
static void pc_orangefs_obj_release(struct kobject *kobj)
1130+
{
1131+
kfree(pc_orangefs_obj);
1132+
pc_orangefs_obj = NULL;
1133+
}
1134+
10821135
static struct kobj_type pc_orangefs_ktype = {
10831136
.sysfs_ops = &orangefs_sysfs_ops,
10841137
.default_groups = pc_orangefs_default_groups,
1138+
.release = pc_orangefs_obj_release,
10851139
};
10861140

10871141
static struct orangefs_attribute stats_reads_attribute =
@@ -1103,19 +1157,20 @@ static struct attribute *stats_orangefs_default_attrs[] = {
11031157
};
11041158
ATTRIBUTE_GROUPS(stats_orangefs_default);
11051159

1160+
static struct kobject *stats_orangefs_obj;
1161+
1162+
static void stats_orangefs_obj_release(struct kobject *kobj)
1163+
{
1164+
kfree(stats_orangefs_obj);
1165+
stats_orangefs_obj = NULL;
1166+
}
1167+
11061168
static struct kobj_type stats_orangefs_ktype = {
11071169
.sysfs_ops = &orangefs_sysfs_ops,
11081170
.default_groups = stats_orangefs_default_groups,
1171+
.release = stats_orangefs_obj_release,
11091172
};
11101173

1111-
static struct kobject *orangefs_obj;
1112-
static struct kobject *acache_orangefs_obj;
1113-
static struct kobject *capcache_orangefs_obj;
1114-
static struct kobject *ccache_orangefs_obj;
1115-
static struct kobject *ncache_orangefs_obj;
1116-
static struct kobject *pc_orangefs_obj;
1117-
static struct kobject *stats_orangefs_obj;
1118-
11191174
int orangefs_sysfs_init(void)
11201175
{
11211176
int rc = -EINVAL;

0 commit comments

Comments
 (0)