Commit 25d41d8455ec1ee7433e146ee94436dc4195f420

Authored by Jan Kara
Committed by Greg Kroah-Hartman
1 parent b38360a284

debugfs: Fix filesystem reference counting on debugfs_remove() failure

When __debugfs_remove() fails (because simple_rmdir() fails e.g. when a
directory is not empty), we must not decrement use count of the filesystem
as nothing was in fact deleted.

This fixes use after free caused by debugfs in some cases.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 1 changed file with 7 additions and 4 deletions Side-by-side Diff

... ... @@ -307,7 +307,7 @@
307 307 }
308 308 EXPORT_SYMBOL_GPL(debugfs_create_symlink);
309 309  
310   -static void __debugfs_remove(struct dentry *dentry, struct dentry *parent)
  310 +static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
311 311 {
312 312 int ret = 0;
313 313  
... ... @@ -330,6 +330,7 @@
330 330 dput(dentry);
331 331 }
332 332 }
  333 + return ret;
333 334 }
334 335  
335 336 /**
... ... @@ -348,7 +349,8 @@
348 349 void debugfs_remove(struct dentry *dentry)
349 350 {
350 351 struct dentry *parent;
351   -
  352 + int ret;
  353 +
352 354 if (!dentry)
353 355 return;
354 356  
355 357  
... ... @@ -357,9 +359,10 @@
357 359 return;
358 360  
359 361 mutex_lock(&parent->d_inode->i_mutex);
360   - __debugfs_remove(dentry, parent);
  362 + ret = __debugfs_remove(dentry, parent);
361 363 mutex_unlock(&parent->d_inode->i_mutex);
362   - simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  364 + if (!ret)
  365 + simple_release_fs(&debugfs_mount, &debugfs_mount_count);
363 366 }
364 367 EXPORT_SYMBOL_GPL(debugfs_remove);
365 368