public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fork: fix pid refcount leaks when destroying file
@ 2020-07-26  4:49 Xin Xiong
  2020-07-26  9:06 ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Xin Xiong @ 2020-07-26  4:49 UTC (permalink / raw)
  To: Christian Brauner, Andrew Morton, Thomas Gleixner,
	Eric W. Biederman, Peter Zijlstra, Eugene Syromiatnikov,
	Jason Gunthorpe, Christian Kellner, Adrian Reber, Aleksa Sarai,
	linux-kernel
  Cc: Xiyu Yang, Xin Tan, yuanxzhang, Xin Xiong

When clone_flags & CLONE_PIDFD is true,the function creates a new file
object called pidfile,and invokes get_pid(),which increases the refcnt
of pid for pidfile to hold.

The reference counting issues take place in the error handling paths.
When error occurs after the construction of pidfile, the function only
invokes fput() to destroy pidfile, in which the increased refcount
won't be decreased, resulting in a refcount leak.

Fix this issue by adding put_pid() in the error handling path
bad_fork_put_pidfd.

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

diff --git a/kernel/fork.c b/kernel/fork.c
index 142b23645d82..7cbfb2c4fce3 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2319,6 +2319,7 @@ static __latent_entropy struct task_struct *copy_process(
 bad_fork_put_pidfd:
 	if (clone_flags & CLONE_PIDFD) {
 		fput(pidfile);
+		put_pid(pid);
 		put_unused_fd(pidfd);
 	}
 bad_fork_free_pid:
-- 
2.25.1


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

end of thread, other threads:[~2020-07-26  9:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-26  4:49 [PATCH] fork: fix pid refcount leaks when destroying file Xin Xiong
2020-07-26  9:06 ` Christian Brauner

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