]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
interconnect: debugfs: fix devm_kstrdup and kfree mismatch
authorGui-Dong Han <hanguidong02@gmail.com>
Wed, 18 Mar 2026 02:48:15 +0000 (10:48 +0800)
committerGeorgi Djakov <djakov@kernel.org>
Thu, 2 Apr 2026 07:39:01 +0000 (10:39 +0300)
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>
Reviewed-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Link: https://msgid.link/20260318024815.7655-1-hanguidong02@gmail.com
Signed-off-by: Georgi Djakov <djakov@kernel.org>
drivers/interconnect/debugfs-client.c

index 5107bff53173eaaa2449889ff3d3574ac1ce73ce..08df9188ef94e9e58d636d72b14218144a0ecf84 100644 (file)
@@ -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);