Skip to contentSkip to conversation

kobject ->k_name memory leak

DISCUSSION Alexey Dobriyan 5 participants 10 messages Dec 3, 2007 – Dec 23, 2007

lore
Share & tools
lore
#0 lore raw

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
#1 lore raw
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

thanks,

greg k-h

#2 lore raw
Quoted 17 lines · Greg KH
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
Quoted 2 lines

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

Ouch!

Quoted 8 lines

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

The one which is passed to kobject_set_name() in mod_sysfs_init()..

#3 lore raw
Quoted 26 lines · Alexey Dobriyan
Quoted 17 lines · Greg KH
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
Quoted 2 lines

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

Ouch!

Quoted 3 lines

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

Quoted 7 lines
Quoted 5 lines

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

The one which is passed to kobject_set_name() in mod_sysfs_init()..

That one should be set to the module_ktype, which is in kernel/params.c, so the release function there should... oh crap, there is no release function. That's a bug. After I get out of meetings tonight I'll write up a patch for that, unless someone beats me to it :)

thanks,

greg k-h

#4 lore raw
Quoted 33 lines · Greg KH
Quoted 32 lines · Alexey Dobriyan
Quoted 17 lines · Greg KH
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
Quoted 2 lines

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

Ouch!

Quoted 8 lines

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

Quoted 6 lines
Quoted 1 line

The one which is passed to kobject_set_name() in mod_sysfs_init()..

That one should be set to the module_ktype, which is in kernel/params.c, so the release function there should... oh crap, there is no release function. That's a bug. After I get out of meetings tonight I'll write up a patch for that, unless someone beats me to it :)

Ok, this is a mess. We can't really have a release function for this kobject, as the structure it is embedded it has it's own memory management issues.

To fix this properly is going to take some major kobject/module surgery, it's not a simple fix at all. I'll tackle it for 2.6.25, as it fits in nicely with the other kobject rework that I've already done in the -mm tree.

So, for now, can we just live with this tiny memory leak on module unload?

Or is the above trace something that users will see when unloading modules?

thanks,

greg k-h

#5 lore raw
Quoted 45 lines · Greg KH
Quoted 33 lines · Greg KH
Quoted 32 lines · Alexey Dobriyan
Quoted 17 lines · Greg KH
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
Quoted 2 lines

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

Ouch!

Quoted 8 lines

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

Quoted 6 lines
Quoted 1 line

The one which is passed to kobject_set_name() in mod_sysfs_init()..

That one should be set to the module_ktype, which is in kernel/params.c, so the release function there should... oh crap, there is no release function. That's a bug. After I get out of meetings tonight I'll write up a patch for that, unless someone beats me to it :)

Ok, this is a mess. We can't really have a release function for this kobject, as the structure it is embedded it has it's own memory management issues.

Quoted 7 lines

To fix this properly is going to take some major kobject/module surgery, it's not a simple fix at all. I'll tackle it for 2.6.25, as it fits in nicely with the other kobject rework that I've already done in the -mm tree.

So, for now, can we just live with this tiny memory leak on module unload?

For the record, this leak screws any testing one can do wrt module unload races. You can't really leave box overnight running modprobe/rmmod in a loop, because OOM killer will finally kick in. Hey, this is exactly how it was noticed at all.

Quoted 2 lines

Or is the above trace something that users will see when unloading modules?

No, it's added debugging.

#6 lore raw
Quoted 59 lines · Alexey Dobriyan
Quoted 45 lines · Greg KH
Quoted 33 lines · Greg KH
Quoted 32 lines · Alexey Dobriyan
Quoted 17 lines · Greg KH
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
Quoted 2 lines

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

Ouch!

Quoted 8 lines

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

Quoted 6 lines
Quoted 1 line

The one which is passed to kobject_set_name() in mod_sysfs_init()..

That one should be set to the module_ktype, which is in kernel/params.c, so the release function there should... oh crap, there is no release function. That's a bug. After I get out of meetings tonight I'll write up a patch for that, unless someone beats me to it :)

Ok, this is a mess. We can't really have a release function for this kobject, as the structure it is embedded it has it's own memory management issues.

Quoted 7 lines

To fix this properly is going to take some major kobject/module surgery, it's not a simple fix at all. I'll tackle it for 2.6.25, as it fits in nicely with the other kobject rework that I've already done in the -mm tree.

So, for now, can we just live with this tiny memory leak on module unload?

For the record, this leak screws any testing one can do wrt module unload races. You can't really leave box overnight running modprobe/rmmod in a loop, because OOM killer will finally kick in. Hey, this is exactly how it was noticed at all.

Quoted 4 lines
Quoted 2 lines

Or is the above trace something that users will see when unloading modules?

No, it's added debugging.

Can't we add an empty release function? It would free the name with the current logic, right?

Kay

#7 lore raw
Quoted 60 lines · Kay Sievers
Quoted 59 lines · Alexey Dobriyan
Quoted 45 lines · Greg KH
Quoted 33 lines · Greg KH
Quoted 32 lines · Alexey Dobriyan
Quoted 17 lines · Greg KH
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
Quoted 2 lines

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

Ouch!

Quoted 8 lines

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

Quoted 6 lines
Quoted 1 line

The one which is passed to kobject_set_name() in mod_sysfs_init()..

That one should be set to the module_ktype, which is in kernel/params.c, so the release function there should... oh crap, there is no release function. That's a bug. After I get out of meetings tonight I'll write up a patch for that, unless someone beats me to it :)

Ok, this is a mess. We can't really have a release function for this kobject, as the structure it is embedded it has it's own memory management issues.

Quoted 7 lines

To fix this properly is going to take some major kobject/module surgery, it's not a simple fix at all. I'll tackle it for 2.6.25, as it fits in nicely with the other kobject rework that I've already done in the -mm tree.

So, for now, can we just live with this tiny memory leak on module unload?

For the record, this leak screws any testing one can do wrt module unload races. You can't really leave box overnight running modprobe/rmmod in a loop, because OOM killer will finally kick in. Hey, this is exactly how it was noticed at all.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Or is the above trace something that users will see when unloading modules?

No, it's added debugging.

Can't we add an empty release function? It would free the name with the current logic, right?

Doh, that should be easy.

Alexey, can you see if the patch below fixes this issue for you?

thanks,

greg k-h

-------------------

---
 kernel/params.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
kernel/params.c +10 -0
@@ -697,8 +697,18 @@ static struct kset_uevent_ops module_uev
 decl_subsys(module, &module_ktype, &module_uevent_ops);
 int module_sysfs_initialized;
 
+static void module_release(struct kobject *kobj)
+{
+	/*
+	 * Stupid empty release function to allow the memory for the kobject to
+	 * be properly cleaned up.  This will not need to be present for 2.6.25
+	 * with the upcoming kobject core rework.
+	 */
+}
+
 static struct kobj_type module_ktype = {
 	.sysfs_ops =	&module_sysfs_ops,
+	.release = module_release,
 };
 
 /*
#8 lore raw
Quoted 64 lines · Greg KH
Quoted 63 lines · Kay Sievers
Quoted 62 lines · Alexey Dobriyan
Quoted 45 lines · Greg KH
Quoted 33 lines · Greg KH
Quoted 32 lines · Alexey Dobriyan
Quoted 17 lines · Greg KH
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
Quoted 2 lines

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

Ouch!

Quoted 8 lines

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

Quoted 6 lines
Quoted 1 line

The one which is passed to kobject_set_name() in mod_sysfs_init()..

That one should be set to the module_ktype, which is in kernel/params.c, so the release function there should... oh crap, there is no release function. That's a bug. After I get out of meetings tonight I'll write up a patch for that, unless someone beats me to it :)

Ok, this is a mess. We can't really have a release function for this kobject, as the structure it is embedded it has it's own memory management issues.

Quoted 7 lines

To fix this properly is going to take some major kobject/module surgery, it's not a simple fix at all. I'll tackle it for 2.6.25, as it fits in nicely with the other kobject rework that I've already done in the -mm tree.

So, for now, can we just live with this tiny memory leak on module unload?

For the record, this leak screws any testing one can do wrt module unload races. You can't really leave box overnight running modprobe/rmmod in a loop, because OOM killer will finally kick in. Hey, this is exactly how it was noticed at all.

Quoted 2 lines

Or is the above trace something that users will see when unloading modules?

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

No, it's added debugging.

Can't we add an empty release function? It would free the name with the current logic, right?

Doh, that should be easy.

Alexey, can you see if the patch below fixes this issue for you?

Yep, it helps!

Quoted 21 lines
kernel/params.c +10 -0
@@ -697,8 +697,18 @@ static struct kset_uevent_ops module_uev
 decl_subsys(module, &module_ktype, &module_uevent_ops);
 int module_sysfs_initialized;
 
+static void module_release(struct kobject *kobj)
+{
+	/*
+	 * Stupid empty release function to allow the memory for the kobject to
+	 * be properly cleaned up.  This will not need to be present for 2.6.25
+	 * with the upcoming kobject core rework.
+	 */
+}
+
 static struct kobj_type module_ktype = {
 	.sysfs_ops =	&module_sysfs_ops,
+	.release = module_release,
 };
 
 /*
#9 lore raw
Quoted 67 lines · Alexey Dobriyan
Quoted 66 lines · Greg KH
Quoted 65 lines · Kay Sievers
Quoted 63 lines · Alexey Dobriyan
Quoted 45 lines · Greg KH
Quoted 33 lines · Greg KH
Quoted 32 lines · Alexey Dobriyan
Quoted 17 lines · Greg KH
Quoted 7 lines · Alexey Dobriyan

Hi, Greg!

Commit ce2c9cb0259acd2aed184499ebe41ab00da13b25 aka "kobject: remove the static array for the name" introduced memory leak of a module name after modprobe/rmmod. Apparently for modules ->release callback is NULL.

Quoted 8 lines

kobject_cleanup: ->release = 00000000, name = 'foo_sysctl'
Pid: 1927, comm: rmmod Not tainted 2.6.24-rc3-e1cca7e8d484390169777b423a7fe46c7021fec1 #5

 [<c10d4a58>] kobject_cleanup+0xb8/0xc0
 [<c10d4a60>] kobject_release+0x0/0x10
 [<c10d587b>] kref_put+0x2b/0xa0
 [<c11dbe85>] _spin_unlock+0x25/0x40
 [<c1045b78>] free_module+0x78/0xd0
 [<c104773f>] sys_delete_module+0x12f/0x1a0
Quoted 2 lines

Hm, _which_ kobject associated with a module, there are 3 of them I think :)

Ouch!

Quoted 8 lines

They should all have a release function, and if they do not, we think it's a "static" kobject and it is not safe to free that name.

I've been working on cleaning this up a lot in the -mm tree with over 80 patches for the kset/kobject apis and interfaces.

But if we have a dynamic kobject, and we aren't freeing it properly, please let me know which one it is and I'll work to fix it for 2.6.24.

Quoted 6 lines
Quoted 1 line

The one which is passed to kobject_set_name() in mod_sysfs_init()..

That one should be set to the module_ktype, which is in kernel/params.c, so the release function there should... oh crap, there is no release function. That's a bug. After I get out of meetings tonight I'll write up a patch for that, unless someone beats me to it :)

Ok, this is a mess. We can't really have a release function for this kobject, as the structure it is embedded it has it's own memory management issues.

Quoted 7 lines

To fix this properly is going to take some major kobject/module surgery, it's not a simple fix at all. I'll tackle it for 2.6.25, as it fits in nicely with the other kobject rework that I've already done in the -mm tree.

So, for now, can we just live with this tiny memory leak on module unload?

For the record, this leak screws any testing one can do wrt module unload races. You can't really leave box overnight running modprobe/rmmod in a loop, because OOM killer will finally kick in. Hey, this is exactly how it was noticed at all.

Quoted 2 lines

Or is the above trace something that users will see when unloading modules?

No, it's added debugging.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Can't we add an empty release function? It would free the name with the current logic, right?

Doh, that should be easy.

Alexey, can you see if the patch below fixes this issue for you?

Yep, it helps!

Great, thanks for testing, I'll send the fix to Linus in a bit.

greg k-h