Unverified Commit 423b2799 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!2820 Fix memleak in disassociate_ctty()

Merge Pull Request from: @ci-robot 
 
PR sync from: Yi Yang <yiyang13@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/DNNWU6GWE43KHSQXBVHMSM654CMOOHOX/ 
Fix it by revert hulk patch and backport patch from mainline.

Yi Yang (2):
  Revert "tty: fix pid memleak in disassociate_ctty()"
  tty: tty_jobctrl: fix pid memleak in disassociate_ctty()


-- 
2.25.1
 
https://gitee.com/openeuler/kernel/issues/I7LEZX 
 
Link:https://gitee.com/openeuler/kernel/pulls/2820

 

Reviewed-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parents 67bbb5bd 064bd850
Loading
Loading
Loading
Loading
+11 −18
Original line number Diff line number Diff line
@@ -291,12 +291,7 @@ void disassociate_ctty(int on_exit)
		return;
	}

	spin_lock_irq(&current->sighand->siglock);
	put_pid(current->signal->tty_old_pgrp);
	current->signal->tty_old_pgrp = NULL;
	tty = tty_kref_get(current->signal->tty);
	spin_unlock_irq(&current->sighand->siglock);

	tty = get_current_tty();
	if (tty) {
		unsigned long flags;

@@ -309,19 +304,17 @@ void disassociate_ctty(int on_exit)
		spin_unlock_irqrestore(&tty->ctrl_lock, flags);
		tty_unlock(tty);
		tty_kref_put(tty);
	}

		/*
		 * Race with tty_signal_session_leader(), current->signal
		 * ->tty_old_pgrp may be reassigned, put_pid() again to ensure
		 *  the pid does not leak memory.
	/* If tty->ctrl.pgrp is not NULL, it may be assigned to
	 * current->signal->tty_old_pgrp in a race condition, and
	 * cause pid memleak. Release current->signal->tty_old_pgrp
	 * after tty->ctrl.pgrp set to NULL.
	 */
		if (on_exit) {
	spin_lock_irq(&current->sighand->siglock);
	put_pid(current->signal->tty_old_pgrp);
	current->signal->tty_old_pgrp = NULL;
	spin_unlock_irq(&current->sighand->siglock);
		}
	}

	/* Now clear signal->tty under the lock */
	read_lock(&tasklist_lock);