Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH 2/2] debugfs: Fix crash problem caused by accessing uninitialized nodes
@ 2024-08-30 10:23 Yibin Ding
  2024-08-30 10:35 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Yibin Ding @ 2024-08-30 10:23 UTC (permalink / raw)
  To: djakov, gregkh, rafael
  Cc: yibin.ding01, niuzhiguo84, linux-pm, linux-kernel, Hao_hao.Wang,
	Ke.Wang

From: Yibin Ding <Yibin.ding@unisoc.com>

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.

Signed-off-by: Yibin Ding <Yibin.ding@unisoc.com>
---
 fs/debugfs/file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index c6f4a9a98b85..8bbe7df6dfd1 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -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) {
-- 
2.25.1


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

end of thread, other threads:[~2024-08-30 10:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-30 10:23 [PATCH 2/2] debugfs: Fix crash problem caused by accessing uninitialized nodes Yibin Ding
2024-08-30 10:35 ` Greg KH

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