All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/4][Trivial] lib/kobject.c : Check ktype in kobject_add_internal
@ 2012-04-21  9:58 yan
  2012-04-23 20:40 ` greg
  0 siblings, 1 reply; 2+ messages in thread
From: yan @ 2012-04-21  9:58 UTC (permalink / raw)
  To: greg; +Cc: kernel, message

If someone calls kobject_init with null kobj_type, kobject_init can 
detect it. But it does not have a return value, it just dumps stack.
In this case, a kobject_add after that will result in:
   -->kobject_add_varg
    -->kobject_add_internal
     -->create_dir
      -->sysfs_create_dir
       -->sysfs_read_ns_type
        -->kobj_child_ns_ops
In the end, it will call ->ktype->child_ns_type directly and we have
an oops.

Check ktype before really add a kobject.

Signed-off-by: Yan Hong <clouds.yan@gmail.com>
---
 lib/kobject.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 85d5e9b..3ba6216 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -164,6 +164,9 @@ static int kobject_add_internal(struct kobject *kobj)
 	if (!kobj)
 		return -ENOENT;
 
+	if (!kobj->ktype)
+		return -EINVAL;
+
 	if (!kobj->name || !kobj->name[0]) {
 		WARN(1, "kobject: (%p): attempted to be registered with empty "
 			 "name!\n", kobj);
-- 
1.7.5.1








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

* Re: [PATCH 3/4][Trivial] lib/kobject.c : Check ktype in kobject_add_internal
  2012-04-21  9:58 [PATCH 3/4][Trivial] lib/kobject.c : Check ktype in kobject_add_internal yan
@ 2012-04-23 20:40 ` greg
  0 siblings, 0 replies; 2+ messages in thread
From: greg @ 2012-04-23 20:40 UTC (permalink / raw)
  To: yan; +Cc: kernel, message

On Sat, Apr 21, 2012 at 05:58:31PM +0800, yan wrote:
> If someone calls kobject_init with null kobj_type, kobject_init can 
> detect it. But it does not have a return value, it just dumps stack.
> In this case, a kobject_add after that will result in:
>    -->kobject_add_varg
>     -->kobject_add_internal
>      -->create_dir
>       -->sysfs_create_dir
>        -->sysfs_read_ns_type
>         -->kobj_child_ns_ops
> In the end, it will call ->ktype->child_ns_type directly and we have
> an oops.
> 
> Check ktype before really add a kobject.

But how can we add a kobject without a valid ktype?

At the most, I'd prefer to warn about this, much like we warn about not
having a name, and not just returning an error without a hint as to what
went wrong.

greg k-h

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

end of thread, other threads:[~2012-04-23 20:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-21  9:58 [PATCH 3/4][Trivial] lib/kobject.c : Check ktype in kobject_add_internal yan
2012-04-23 20:40 ` greg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.