Skip to content

debugfs: fix UAF and double-free in debugfs_str read/write

Aldo Ariel Panzardo driver-core lkml stable 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 5 repliesIn review
  2. v32 patches 1 replySuperseded
  3. v22 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v11 patch1 replySuperseded

Changes in v4 from the cover letter

- 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.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2debugfs: fix use-after-free in debugfs_read_file_str()fs/debugfs/file.c+25 -145 replies
2/2debugfs: serialize concurrent writers in debugfs_write_file_str()fs/debugfs/file.c+10 -60 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/2] debugfs: fix UAF and double-free in debugfs_str read/write

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/[email protected]/

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