public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] debugfs: Fix NULL pointer dereference at debugfs_read_file_str
@ 2025-12-22  9:36 yangshiguang1011
  2025-12-22 11:54 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: yangshiguang1011 @ 2025-12-22  9:36 UTC (permalink / raw)
  To: gregkh; +Cc: rafael, dakr, peterz, linux-kernel, yangshiguang, stable

From: yangshiguang <yangshiguang@xiaomi.com>

Check in debugfs_read_file_str() if the string pointer is NULL.

When creating a node using debugfs_create_str(), the string parameter
value can be NULL to indicate empty/unused/ignored.
However, reading this node using debugfs_read_file_str() will cause a
kernel panic.
This should not be fatal, so return an invalid error.

Signed-off-by: yangshiguang <yangshiguang@xiaomi.com>
Fixes: 9af0440ec86e ("debugfs: Implement debugfs_create_str()")
Cc: stable@vger.kernel.org
---
 fs/debugfs/file.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 3ec3324c2060..a22ff0ceb230 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -1026,6 +1026,9 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
 		return ret;
 
 	str = *(char **)file->private_data;
+	if (!str)
+		return -EINVAL;
+
 	len = strlen(str) + 1;
 	copy = kmalloc(len, GFP_KERNEL);
 	if (!copy) {
-- 
2.43.0


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

end of thread, other threads:[~2025-12-23  9:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-22  9:36 [PATCH] debugfs: Fix NULL pointer dereference at debugfs_read_file_str yangshiguang1011
2025-12-22 11:54 ` Greg KH
2025-12-22 12:41   ` yangshiguang
2025-12-22 14:11     ` Greg KH
2025-12-23  2:12       ` yangshiguang
2025-12-23  9:19         ` Greg KH

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