mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Soenke Huster <soenke.huster@eknoes.de>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Cc: Soenke Huster <soenke.huster@eknoes.de>, linux-kernel@vger.kernel.org
Subject: [PATCH] driver core: fix null pointer deref in device_find_child
Date: Thu, 20 Jan 2022 16:02:46 +0100	[thread overview]
Message-ID: <20220120150246.6216-1-soenke.huster@eknoes.de> (raw)

Similar to device_for_each_child, device_find_child should not ooops
if parent->p is NULL. While fuzzing the Bluetooth subsystem, I got a null
pointer dereference in next_device, which is prevented by this change.

Buglink: https://bugzilla.kernel.org/show_bug.cgi?id=215497
Signed-off-by: Soenke Huster <soenke.huster@eknoes.de>
---
I found this while fuzzing the bluetooth subsystem and reported this bug
in bugzilla. As I feel more like a kernelnewbie, I am not sure whether
this needs to be patched in driver core, or is just an issue of the
bluetooth subsystem itself. If the latter is the case: sorry for the
spam!

A similar fix was applied in 014c90dbb9b6 ("driver core: prevent
device_for_each_child from oopsing") for device_for_each_child, which is
mentioned in the docstring of device_find_child as similar function.

 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 7bb957b11861..654d904631f9 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3780,7 +3780,7 @@ struct device *device_find_child(struct device *parent, void *data,
 	struct klist_iter i;
 	struct device *child;
 
-	if (!parent)
+	if (!parent || !parent->p)
 		return NULL;
 
 	klist_iter_init(&parent->p->klist_children, &i);
-- 
2.34.1


             reply	other threads:[~2022-01-20 15:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 15:02 Soenke Huster [this message]
2022-01-20 15:38 ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220120150246.6216-1-soenke.huster@eknoes.de \
    --to=soenke.huster@eknoes.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®