From: Yibin Ding <Yibin.Ding@unisoc.com>
To: <djakov@kernel.org>, <gregkh@linuxfoundation.org>, <rafael@kernel.org>
Cc: <yibin.ding01@gmail.com>, <niuzhiguo84@gmail.com>,
<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<Hao_hao.Wang@unisoc.com>, <Ke.Wang@unisoc.com>
Subject: [PATCH 2/2] debugfs: Fix crash problem caused by accessing uninitialized nodes
Date: Fri, 30 Aug 2024 18:23:14 +0800 [thread overview]
Message-ID: <20240830102314.409307-1-Yibin.Ding@unisoc.com> (raw)
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
next reply other threads:[~2024-08-30 10:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-30 10:23 Yibin Ding [this message]
2024-08-30 10:35 ` [PATCH 2/2] debugfs: Fix crash problem caused by accessing uninitialized nodes Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240830102314.409307-1-Yibin.Ding@unisoc.com \
--to=yibin.ding@unisoc.com \
--cc=Hao_hao.Wang@unisoc.com \
--cc=Ke.Wang@unisoc.com \
--cc=djakov@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=niuzhiguo84@gmail.com \
--cc=rafael@kernel.org \
--cc=yibin.ding01@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox