Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Gui-Dong Han <hanguidong02@gmail.com>
To: gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org,
	vkoul@kernel.org, yung-chuan.liao@linux.intel.com,
	pierre-louis.bossart@linux.dev
Cc: peterz@infradead.org, cristian.marussi@arm.com,
	sudeep.holla@kernel.org, linux-sound@vger.kernel.org,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
	akaieurus@gmail.com, me@ziyao.cc,
	Gui-Dong Han <hanguidong02@gmail.com>,
	yangshiguang <yangshiguang@xiaomi.com>
Subject: [PATCH v2 1/3] debugfs: check for NULL pointer in debugfs_create_str()
Date: Mon, 23 Mar 2026 16:58:44 +0800	[thread overview]
Message-ID: <20260323085930.88894-2-hanguidong02@gmail.com> (raw)
In-Reply-To: <20260323085930.88894-1-hanguidong02@gmail.com>

Passing a NULL pointer to debugfs_create_str() leads to a NULL pointer
dereference when the debugfs file is read. Following upstream
discussions, forbid the creation of debugfs string files with NULL
pointers. Add a WARN_ON() to expose offending callers and return early.

Fixes: 9af0440ec86e ("debugfs: Implement debugfs_create_str()")
Reported-by: yangshiguang <yangshiguang@xiaomi.com>
Closes: https://lore.kernel.org/lkml/2025122221-gag-malt-75ba@gregkh/
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
---
v2:
* No changes.
---
 fs/debugfs/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 3376ab6a519d..a941d73251b0 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -1127,7 +1127,7 @@ static const struct file_operations fops_str_wo = {
  *          directory dentry if set.  If this parameter is %NULL, then the
  *          file will be created in the root of the debugfs filesystem.
  * @value: a pointer to the variable that the file should read to and write
- *         from.
+ *         from. This pointer and the string it points to must not be %NULL.
  *
  * This function creates a file in debugfs with the given name that
  * contains the value of the variable @value.  If the @mode variable is so
@@ -1136,6 +1136,9 @@ static const struct file_operations fops_str_wo = {
 void debugfs_create_str(const char *name, umode_t mode,
 			struct dentry *parent, char **value)
 {
+	if (WARN_ON(!value || !*value))
+		return;
+
 	debugfs_create_mode_unsafe(name, mode, parent, value, &fops_str,
 				   &fops_str_ro, &fops_str_wo);
 }
-- 
2.43.0


  reply	other threads:[~2026-03-23  9:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23  8:58 [PATCH v2 0/3] debugfs: disallow NULL string creation and fix callers Gui-Dong Han
2026-03-23  8:58 ` Gui-Dong Han [this message]
2026-03-23  8:58 ` [PATCH v2 2/3] debugfs: fix placement of EXPORT_SYMBOL_GPL for debugfs_create_str() Gui-Dong Han
2026-03-23  8:58 ` [PATCH v2 3/3] soundwire: debugfs: initialize firmware_file to empty string Gui-Dong Han

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=20260323085930.88894-2-hanguidong02@gmail.com \
    --to=hanguidong02@gmail.com \
    --cc=akaieurus@gmail.com \
    --cc=cristian.marussi@arm.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=me@ziyao.cc \
    --cc=peterz@infradead.org \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=rafael@kernel.org \
    --cc=sudeep.holla@kernel.org \
    --cc=vkoul@kernel.org \
    --cc=yangshiguang@xiaomi.com \
    --cc=yung-chuan.liao@linux.intel.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