From: yangshiguang <yangshiguang1011@163.com>
To: "Greg KH" <gregkh@linuxfoundation.org>
Cc: rafael@kernel.org, dakr@kernel.org, peterz@infradead.org,
linux-kernel@vger.kernel.org, yangshiguang@xiaomi.com,
stable@vger.kernel.org
Subject: Re:Re: Re: [PATCH] debugfs: Fix NULL pointer dereference at debugfs_read_file_str
Date: Tue, 23 Dec 2025 10:12:48 +0800 (CST) [thread overview]
Message-ID: <2de8b181.5007.19b48fb047f.Coremail.yangshiguang1011@163.com> (raw)
In-Reply-To: <2025122221-gag-malt-75ba@gregkh>
At 2025-12-22 22:11:38, "Greg KH" <gregkh@linuxfoundation.org> wrote:
>On Mon, Dec 22, 2025 at 08:41:33PM +0800, yangshiguang wrote:
>>
>> At 2025-12-22 19:54:22, "Greg KH" <gregkh@linuxfoundation.org> wrote:
>> >On Mon, Dec 22, 2025 at 05:36:16PM +0800, yangshiguang1011@163.com wrote:
>> >> 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.
>> >
>> >Why would you create an empty debugfs string file? That is not ok, we
>> >should change that to not allow this.
>>
>> Hi greg k-h,
>>
>> Thanks for your reply.
>>
>> This is due to the usage step, should write first and then read.
>> However, there is no way to guarantee that everyone will know about this step.
>
>True.
>
>> And debugfs_create_str() allows passing in a NULL string.
>
>Then we should fix that :)
>
>> Therefore, when reading a NULL string, should return an invalid error
>> instead of panic.
>
>If you call write on a NULL string, then you could call strlen() of that
>NULL string, and do a memcpy out of that NULL string. All not good
>things, so your quick fix here really doesn't solve the root problem :(
>
We all know that the problem is a NULL pointer exceptions that occur in strlen().
However, strlen() is basic function, and we cannot pass abnormal parameters.
We should intercept them, and this is common in the kernel.
That's why I submitted this patch.
>> >> str = *(char **)file->private_data;
>> >> + if (!str)
>> >> + return -EINVAL;
>> >
>> >What in kernel user causes this to happen? Let's fix that up instead
>> >please.
>> >
>>
>> Currently I known problematic nodes in the kernel:
>>
>> drivers/interconnect/debugfs-client.c:
>> 155: debugfs_create_str("src_node", 0600, client_dir, &src_node);
>> 156: debugfs_create_str("dst_node", 0600, client_dir, &dst_node);
>
>Ick, ok, that should be fixed.
>
>> drivers/soundwire/debugfs.c:
>> 362: debugfs_create_str("firmware_file", 0200, d, &firmware_file);
>
>That too should be fixed, all should just create an "empty" string to
>start with.
>
>> test case:
>> 1. create a NULL string node
>> char *test_node = NULL;
>> debugfs_create_str("test_node", 0600, parent_dir, &test_node);
>>
>> 2. read the node, like bellow:
>> cat /sys/kernel/debug/test_node
>
>With your patch, you could change step 2 to do a write, and still cause
>a crash :)
>
This shouldn't happen. The write node calls debugfs_write_file_str().
My test results:
$: cat dst_node
$: cat: dst_node: Invalid argument
1|&: echo 1 > dst_node
$: cat dst_node
$: 1
Anyway, please show the stack.
>So let's fix this properly, let's just fail the creation of NULL
>strings, and fix up all callers.
>
As mentioned above, we shold allow the creation of NULL string nodes
to indicate empty/unused/ignored.
>thanks,
>
>greg k-h
next prev parent reply other threads:[~2025-12-23 2:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-12-23 9:19 ` 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=2de8b181.5007.19b48fb047f.Coremail.yangshiguang1011@163.com \
--to=yangshiguang1011@163.com \
--cc=dakr@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=stable@vger.kernel.org \
--cc=yangshiguang@xiaomi.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