[PATCH v2 0/3] debugfs: disallow NULL string creation and fix callers
From: Gui-Dong Han
Date: Mon Mar 23 2026 - 05:09:07 EST
A recent bug report [1] highlighted a NULL pointer dereference when
reading a debugfs string file created with a NULL pointer. The community
discussed the issue and agreed that creating string nodes with NULL is
invalid and should be forbidden at creation time [2]. Since no fix was
submitted following the discussion, I have implemented the agreed
solution.
Patch 1 modifies debugfs_create_str() to reject NULL pointers, returning
early and triggering a WARN_ON to expose offending callers.
Patch 2 is a code hygiene fix. While modifying the file, I noticed the
EXPORT_SYMBOL_GPL for debugfs_create_str() was misplaced far away from
the function body. This patch moves it to the correct location.
I carefully audited existing callers across the kernel tree. Some
drivers passing NULL have already been independently identified and
fixed [3]. The remaining subsystem (soundwire) is addressed in patch 3
by initializing its string parameter to an empty string (""). The
existing code correctly and safely handles empty strings.
While auditing, I also noticed a devm_kstrdup/kfree mismatch in the
interconnect subsystem which has been addressed in a separate patch [4].
Changes in v2:
- Link to v1: https://lore.kernel.org/driver-core/20260317185920.43387-1-hanguidong02@xxxxxxxxx/
- Patch 1 & 2: No changes.
- Patch 3: Rewritten to use kstrdup() instead of devm_kstrdup() to match
debugfs's kfree() behavior. Moved initialization to sdw_debugfs_init()
to correctly handle the global pointer and avoid overwriting during
slave probe.
- Patch 4 (drm/i915): Dropped. Further analysis confirmed those specific
pointers are not passed to debugfs_create_str() [5].
[1] https://lore.kernel.org/lkml/17647e4c.d461.19b46144a4e.Coremail.yangshiguang1011@xxxxxxx/
[2] https://lore.kernel.org/lkml/2025122221-gag-malt-75ba@gregkh/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8cc27f5c6dd1
[4] https://lore.kernel.org/linux-pm/20260318024815.7655-1-hanguidong02@xxxxxxxxx/
[5] https://lore.kernel.org/driver-core/8ac4b6ef2dfbc1dce0047dee55f2df609287a3ec@xxxxxxxxx/
Gui-Dong Han (3):
debugfs: check for NULL pointer in debugfs_create_str()
debugfs: fix placement of EXPORT_SYMBOL_GPL for debugfs_create_str()
soundwire: debugfs: initialize firmware_file to empty string
drivers/soundwire/debugfs.c | 9 +++++++--
fs/debugfs/file.c | 7 +++++--
2 files changed, 12 insertions(+), 4 deletions(-)
--
2.43.0