Skip to contentSkip to conversation

kobject: kzfree object in _release function

PATCH In review [email protected] 3 participants 4 messages Apr 11, 2009 – Apr 13, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kobject: kzfree object in _release function

From: Ming Lei <[email protected]>

It helps to troubleshoot the __buggy__ case, in which unreferenced objects are still accessed, using kzfree to free objects safely in _release function.

---
 lib/kobject.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
lib/kobject.c +2 -2
index a6dec32..cb5a562 100644
@@ -597,7 +597,7 @@ void kobject_put(struct kobject *kobj)
 static void dynamic_kobj_release(struct kobject *kobj)
 {
 	pr_debug("kobject: (%p): %s\n", kobj, __func__);
-	kfree(kobj);
+	kzfree(kobj);
 }
 
 static struct kobj_type dynamic_kobj_ktype = {
@@ -762,7 +762,7 @@ static void kset_release(struct kobject *kobj)
 	struct kset *kset = container_of(kobj, struct kset, kobj);
 	pr_debug("kobject: '%s' (%p): %s\n",
 		 kobject_name(kobj), kobj, __func__);
-	kfree(kset);
+	kzfree(kset);
 }
 
 static struct kobj_type kset_ktype = {
Signature · 1 line
1.6.0.GIT
#1 lore raw
Quoted 25 lines · On Sun, Apr 12, 2009 at 12:16:26AM +0800, [email protected] wrote:

From: Ming Lei <[email protected]>

It helps to troubleshoot the __buggy__ case, in which unreferenced objects are still accessed, using kzfree to free objects safely in _release function.

---
 lib/kobject.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
lib/kobject.c +1 -1
index a6dec32..cb5a562 100644
@@ -597,7 +597,7 @@ void kobject_put(struct kobject *kobj)
 static void dynamic_kobj_release(struct kobject *kobj)
 {
 	pr_debug("kobject: (%p): %s\n", kobj, __func__);
-	kfree(kobj);
+	kzfree(kobj);
 }
 
 static struct kobj_type dynamic_kobj_ktype = {

lib/kobject.c static void kset_release(struct kobject *kobj) · line 765

Quoted 5 lines
lib/kobject.c +1 -1
@@ -762,7 +762,7 @@ static void kset_release(struct kobject *kobj)
 	struct kset *kset = container_of(kobj, struct kset, kobj);
 	pr_debug("kobject: '%s' (%p): %s\n",
 		 kobject_name(kobj), kobj, __func__);
-	kfree(kset);
+	kzfree(kset);

What about slab-poisoning? Shouldn't we just rely on that instead?

thanks,

greg k-h

#2 lore raw

Hi Greg,

Quoted 24 lines · Greg KH
Quoted 23 lines · On Sun, Apr 12, 2009 at 12:16:26AM +0800, [email protected] wrote:

From: Ming Lei <[email protected]>

It helps to troubleshoot the __buggy__ case, in which unreferenced objects are still accessed, using kzfree to free objects safely in _release function.

---
 lib/kobject.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
lib/kobject.c +1 -1
index a6dec32..cb5a562 100644
@@ -597,7 +597,7 @@ void kobject_put(struct kobject *kobj)
  static void dynamic_kobj_release(struct kobject *kobj)
  {
       pr_debug("kobject: (%p): %s\n", kobj, __func__);
-     kfree(kobj);
+     kzfree(kobj);
  }
 
Quoted 10 lines

lib/kobject.c static void kset_release(struct kobject *kobj) · line 765

Quoted 7 lines
lib/kobject.c +1 -1
  static struct kobj_type dynamic_kobj_ktype = {
@@ -762,7 +762,7 @@ static void kset_release(struct kobject *kobj)
       struct kset *kset = container_of(kobj, struct kset, kobj);
       pr_debug("kobject: '%s' (%p): %s\n",
                kobject_name(kobj), kobj, __func__);
-     kfree(kset);
+     kzfree(kset);

What about slab-poisoning?  Shouldn't we just rely on that instead?

Yes, you should. kzfree() strictly for cases where _correctness_ of the program requires it (i.e. security concerns).

#3 lore raw
Quoted 38 lines · Pekka Enberg

Hi Greg,

Quoted 24 lines · Greg KH
Quoted 23 lines · On Sun, Apr 12, 2009 at 12:16:26AM +0800, [email protected] wrote:

From: Ming Lei <[email protected]>

It helps to troubleshoot the __buggy__ case, in which unreferenced objects are still accessed, using kzfree to free objects safely in _release function.

---
 lib/kobject.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
lib/kobject.c +1 -1
index a6dec32..cb5a562 100644
@@ -597,7 +597,7 @@ void kobject_put(struct kobject *kobj)
  static void dynamic_kobj_release(struct kobject *kobj)
  {
       pr_debug("kobject: (%p): %s\n", kobj, __func__);
-     kfree(kobj);
+     kzfree(kobj);
  }
 
Quoted 10 lines

lib/kobject.c static void kset_release(struct kobject *kobj) · line 765

Quoted 7 lines
lib/kobject.c +1 -1
  static struct kobj_type dynamic_kobj_ktype = {
@@ -762,7 +762,7 @@ static void kset_release(struct kobject *kobj)
       struct kset *kset = container_of(kobj, struct kset, kobj);
       pr_debug("kobject: '%s' (%p): %s\n",
                kobject_name(kobj), kobj, __func__);
-     kfree(kset);
+     kzfree(kset);

What about slab-poisoning?  Shouldn't we just rely on that instead?

Quoted 2 lines

Yes, you should. kzfree() strictly for cases where _correctness_ of the program requires it (i.e. security concerns).

Thanks for letting us know. As such, I'll not be applying this patch.

greg k-h