public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] configfs: Fix config_item refcnt leak in configfs_rmdir()
@ 2020-04-25 12:52 Xiyu Yang
  2020-04-27  6:17 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Xiyu Yang @ 2020-04-25 12:52 UTC (permalink / raw)
  To: Joel Becker, Christoph Hellwig, linux-kernel
  Cc: yuanxzhang, kjlu, Xiyu Yang, Xin Tan

configfs_rmdir() invokes configfs_get_config_item(), which returns a
reference of the specified config_item object to "parent_item" with
increased refcnt.

When configfs_rmdir() returns, local variable "parent_item" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The reference counting issue happens in one exception handling path of
configfs_rmdir(). When down_write_killable() fails, the function forgets
to decrease the refcnt increased by configfs_get_config_item(), causing
a refcnt leak.

Fix this issue by calling config_item_put() when down_write_killable()
fails.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
---
 fs/configfs/dir.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index cf7b7e1d5bd7..cb733652ecca 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -1519,6 +1519,7 @@ static int configfs_rmdir(struct inode *dir, struct dentry *dentry)
 		spin_lock(&configfs_dirent_lock);
 		configfs_detach_rollback(dentry);
 		spin_unlock(&configfs_dirent_lock);
+		config_item_put(parent_item);
 		return -EINTR;
 	}
 	frag->frag_dead = true;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] configfs: Fix config_item refcnt leak in configfs_rmdir()
  2020-04-25 12:52 [PATCH] configfs: Fix config_item refcnt leak in configfs_rmdir() Xiyu Yang
@ 2020-04-27  6:17 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2020-04-27  6:17 UTC (permalink / raw)
  To: Xiyu Yang
  Cc: Joel Becker, Christoph Hellwig, linux-kernel, yuanxzhang, kjlu,
	Xin Tan

Thanks,

applied to the configfs tree.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-27  6:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-25 12:52 [PATCH] configfs: Fix config_item refcnt leak in configfs_rmdir() Xiyu Yang
2020-04-27  6:17 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox