linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kobject: Safe return of kobject_get_path with NULL
@ 2021-06-23 14:47 Christian Löhle
  2021-06-23 14:49 ` Christian Löhle
  2021-06-23 15:11 ` gregkh
  0 siblings, 2 replies; 6+ messages in thread
From: Christian Löhle @ 2021-06-23 14:47 UTC (permalink / raw)
  To: gregkh, linux-kernel, Christian Löhle; +Cc: rafael

Prevent NULL dereference within get_kobj_path_length

Calling kobject_get_path could provoke a NULL dereference
if NULL was passed. while fill_kobj_path will return
with a sane 0 for NULL, kobjet_get_path_length did not.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
---
 lib/kobject.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/kobject.c b/lib/kobject.c
index ea53b30cf483..735159c13a94 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -130,6 +130,8 @@ static int get_kobj_path_length(struct kobject *kobj)
 {
 	int length = 1;
 	struct kobject *parent = kobj;
+	if (!kobj)
+		return 0;
 
 	/* walk up the ancestors until we hit the one pointing to the
 	 * root.
-- 
2.32.0

Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz
Managing Directors: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782


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

end of thread, other threads:[~2021-06-24  9:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23 14:47 [PATCH] kobject: Safe return of kobject_get_path with NULL Christian Löhle
2021-06-23 14:49 ` Christian Löhle
2021-06-23 15:12   ` gregkh
2021-06-23 15:11 ` gregkh
2021-06-24  6:42   ` Christian Löhle
2021-06-24  9:02     ` gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).