[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200726052804.GA51199@xin-virtual-machine>
Date: Sun, 26 Jul 2020 13:28:04 +0800
From: Xin Xiong <xiongx18@...an.edu.cn>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jslaby@...e.com>, linux-kernel@...r.kernel.org
Cc: Xiyu Yang <xiyuyang19@...an.edu.cn>,
Xin Tan <tanxin.ctf@...il.com>, yuanxzhang@...an.edu.cn,
Xin Xiong <xiongx18@...an.edu.cn>
Subject: [PATCH] tty: fix pid refcount leak in tty_signal_session_leader
In the loop, every time when p->signal->leader is true, the function
tty_signal_session_leader() will invoke get_pid() and return a
reference of tty->pgrp with increased refcount to the local variable
tty_pgrp or return NULL if it fails. After finishing the loop, the
function invokes put_pid() for only once, decreasing the refcount that
tty_pgrp keeps.
Refcount leaks may occur when the scenario that p->signal->leader is
true happens more than once. In this assumption, if the above scenario
happens n times in the loop, the function forgets to decrease the
refcount for n-1 times, which causes refcount leaks.
Fix the issue by decreasing the current refcount of the local variable
tty_pgrp before assigning new objects to it.
Signed-off-by: Xiyu Yang <xiyuyang19@...an.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@...il.com>
Signed-off-by: Xin Xiong <xiongx18@...an.edu.cn>
---
drivers/tty/tty_jobctrl.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/tty/tty_jobctrl.c b/drivers/tty/tty_jobctrl.c
index f8ed50a16848..9e6bf693ade1 100644
--- a/drivers/tty/tty_jobctrl.c
+++ b/drivers/tty/tty_jobctrl.c
@@ -212,6 +212,8 @@ int tty_signal_session_leader(struct tty_struct *tty, int exit_session)
__group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
put_pid(p->signal->tty_old_pgrp); /* A noop */
spin_lock(&tty->ctrl_lock);
+ if (tty_pgrp)
+ put_pid(tty_pgrp);
tty_pgrp = get_pid(tty->pgrp);
if (tty->pgrp)
p->signal->tty_old_pgrp = get_pid(tty->pgrp);
--
2.25.1
Powered by blists - more mailing lists