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

If user turns to the simple interface kobject_init_and_add 
and gives a null kobject, kobject_init can detect it but 
just dumps the stack. Then there is:
  -->kobject_add_varg
   -->kobject_set_name_vargs
In the end, it will reference kobj->name and we have an oops.

Check whether we have a valid kobject in kobject_init_and_add.

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 dd67855..bc05922 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -380,6 +380,9 @@ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
 	va_list args;
 	int retval;
 
+	if (!kobj)
+		return -EINVAL;
+
 	kobject_init(kobj, ktype);
 
 	va_start(args, fmt);
-- 
1.7.5.1




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

* Re: [PATCH 4/4][Trivial] lib/kobject.c : check parameter in kobject_init_and_add
  2012-04-21 10:17 [PATCH 4/4][Trivial] lib/kobject.c : check parameter in kobject_init_and_add yan
@ 2012-04-23 20:41 ` greg
  0 siblings, 0 replies; 2+ messages in thread
From: greg @ 2012-04-23 20:41 UTC (permalink / raw)
  To: yan; +Cc: kernel, message

On Sat, Apr 21, 2012 at 06:17:49PM +0800, yan wrote:
> If user turns to the simple interface kobject_init_and_add 
> and gives a null kobject, kobject_init can detect it but 
> just dumps the stack. Then there is:
>   -->kobject_add_varg
>    -->kobject_set_name_vargs
> In the end, it will reference kobj->name and we have an oops.
> 
> Check whether we have a valid kobject in kobject_init_and_add.

Why would anyone ever call this function without a valid kobject?

Again, sorry, this patch isn't ok.

greg k-h

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-21 10:17 [PATCH 4/4][Trivial] lib/kobject.c : check parameter in kobject_init_and_add yan
2012-04-23 20:41 ` 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.