Skip to contentSkip to conversation

debugfs: Fix crash problem caused by accessing uninitialized nodes

PATCH In review Yibin Ding 1 participant 1 message Sep 14, 2024 Driver core

lore
Share & tools
lore

Yibin Ding

author
#0 lore raw

PATCH v2 2/2 debugfs: Fix crash problem caused by accessing uninitialized nodes

From: Yibin Ding <[email protected]>

For uninitialized nodes such as /sys/kernel/debug/interconnect/test_client/dst_node, if the cat operation is performed directly without writing content to the node, it will cause a crash due to accessing a null pointer. So it is necessary to add a null pointer check in the debugfs_read_file_str() function.

---
 fs/debugfs/file.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/debugfs/file.c +4 -0
index c6f4a9a98b85..8bbe7df6dfd1 100644
@@ -970,6 +970,10 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
 		return ret;
 
 	str = *(char **)file->private_data;
+	if (!str) {
+		debugfs_file_put(dentry);
+		return -EINVAL;
+	}
 	len = strlen(str) + 1;
 	copy = kmalloc(len, GFP_KERNEL);
 	if (!copy) {
Signature · 1 line
2.25.1