public inbox for linux-kernel@vger.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

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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox