[PATCH v4 0/2] debugfs: fix UAF and double-free in debugfs_str read/write
From: Aldo Ariel Panzardo
Date: Sat Sep 26 2026 - 15:59:13 EST
Changes since v3:
- Patch 1/2: drop GFP_ATOMIC as suggested by Danilo. Measure the
string length under rcu_read_lock(), allocate with GFP_KERNEL
outside the RCU critical section, then re-read and copy with
strscpy() under a second rcu_read_lock(). If the current string
no longer fits the allocated buffer, retry with a PAGE_SIZE
allocation (upper bound enforced by the write path).
- Patch 2/2: unchanged.
- KASAN stress testing with both fixes applied completed with 0
reports; the concurrent-writer reproducer produces ~3900 double-free
reports without patch 2.
Danilo also suggested introducing a struct debugfs_string with explicit
synchronization to provide callers with a proper synchronization
contract. I agree that would address the broader API issue,
and I'd be happy to work on it as a separate follow-up series
if you think that would be useful.
v3: regenerate patches with git format-patch (v2 failed to apply).
v2: split into two patches, add Assisted-by, include KASAN splat.
v1: https://lore.kernel.org/driver-core/20260925175831.3701812-1-qwe.aldo@xxxxxxxxx/
Aldo Ariel Panzardo (2):
debugfs: fix use-after-free in debugfs_read_file_str()
debugfs: serialize concurrent writers in debugfs_write_file_str()
fs/debugfs/file.c | 55 ++++++++++++++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 20 deletions(-)
base-commit: 6812ce4e4379ffc99c52401ec28f0d7ffbc36206
--
2.43.0