public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] interconnect: debugfs: fix devm_kstrdup and kfree mismatch
@ 2026-03-18  2:48 Gui-Dong Han
  2026-03-18  4:26 ` Kuan-Wei Chiu
  2026-03-22  9:34 ` Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Gui-Dong Han @ 2026-03-18  2:48 UTC (permalink / raw)
  To: Georgi Djakov
  Cc: Kuan-Wei Chiu, linux-pm, linux-kernel, akaieurus, me,
	Gui-Dong Han

debugfs_write_file_str() uses standard kfree() to release old strings.
Initializing src_node and dst_node with devm_kstrdup() creates a memory
management mismatch. If a user writes to these debugfs nodes, the
devm-allocated memory is freed via kfree(), leaving a dangling pointer
in the device resource list that can lead to a double free.

Fix this by using standard kstrdup() instead. Since the interconnect
subsystem is strictly built-in and cannot be unloaded as a module, there
is no exit path requiring manual cleanup of these strings. The error
handling path is also simplified by taking advantage of the fact that
kfree(NULL) is a safe no-op.

Fixes: 8cc27f5c6dd1 ("interconnect: debugfs: initialize src_node and dst_node to empty strings")
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
---
I noticed this memory management mismatch while working on similar
debugfs string initialization fixes [1] recently.

[1] https://lore.kernel.org/driver-core/20260317185920.43387-1-hanguidong02@gmail.com/
---
 drivers/interconnect/debugfs-client.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/interconnect/debugfs-client.c b/drivers/interconnect/debugfs-client.c
index 5107bff53173..08df9188ef94 100644
--- a/drivers/interconnect/debugfs-client.c
+++ b/drivers/interconnect/debugfs-client.c
@@ -150,10 +150,13 @@ int icc_debugfs_client_init(struct dentry *icc_dir)
 		return ret;
 	}
 
-	src_node = devm_kstrdup(&pdev->dev, "", GFP_KERNEL);
-	dst_node = devm_kstrdup(&pdev->dev, "", GFP_KERNEL);
-	if (!src_node || !dst_node)
+	src_node = kstrdup("", GFP_KERNEL);
+	dst_node = kstrdup("", GFP_KERNEL);
+	if (!src_node || !dst_node) {
+		kfree(dst_node);
+		kfree(src_node);
 		return -ENOMEM;
+	}
 
 	client_dir = debugfs_create_dir("test_client", icc_dir);
 
-- 
2.43.0


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

end of thread, other threads:[~2026-03-22  9:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18  2:48 [PATCH] interconnect: debugfs: fix devm_kstrdup and kfree mismatch Gui-Dong Han
2026-03-18  4:26 ` Kuan-Wei Chiu
2026-03-22  9:34 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox