Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: Guangshuo Li <lgs201920130244@gmail.com>
To: Johannes Berg <johannes@sipsolutions.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	linux-kernel@vger.kernel.org, driver-core@lists.linux.dev
Cc: Guangshuo Li <lgs201920130244@gmail.com>
Subject: [PATCH] devcoredump: Fix double free on device_add() failure
Date: Thu, 30 Apr 2026 14:42:14 +0800	[thread overview]
Message-ID: <20260430064214.450099-1-lgs201920130244@gmail.com> (raw)

If device_add() fails after device_initialize(), the error path calls
put_device(&devcd->devcd_dev). This may drop the last reference to the
device and invoke devcd_dev_release(), which frees the coredump data,
drops the module reference and frees the devcd entry.

The error path then falls through to put_module and free, causing the
module reference and the coredump data to be released a second time.

Return after put_device() in this path since the device release callback
has already taken care of the resources owned by the devcd entry.

This issue was found by a static analysis tool I am developing.

Fixes: 833c95456a70 ("device coredump: add new device coredump class")
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/base/devcoredump.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
index 7e4a491bf15e..cdefdc8e83eb 100644
--- a/drivers/base/devcoredump.c
+++ b/drivers/base/devcoredump.c
@@ -437,6 +437,7 @@ void dev_coredumpm_timeout(struct device *dev, struct module *owner,
 	mutex_unlock(&devcd->mutex);
 	cancel_delayed_work_sync(&devcd->del_wk);
 	put_device(&devcd->devcd_dev);
+	return;
 
  put_module:
 	module_put(owner);
-- 
2.43.0


                 reply	other threads:[~2026-04-30  6:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260430064214.450099-1-lgs201920130244@gmail.com \
    --to=lgs201920130244@gmail.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=johannes@sipsolutions.net \
    --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