diff --git a/drivers/tty/tty_jobctrl.c b/drivers/tty/tty_jobctrl.c index ffcab80ba77d9e7bad5b83930acc4b5e8a5f5032..e04360de3757c424b654bc9d635c268100fcc889 100644 --- a/drivers/tty/tty_jobctrl.c +++ b/drivers/tty/tty_jobctrl.c @@ -308,6 +308,18 @@ 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 (on_exit) { + spin_lock_irq(¤t->sighand->siglock); + put_pid(current->signal->tty_old_pgrp); + current->signal->tty_old_pgrp = NULL; + spin_unlock_irq(¤t->sighand->siglock); + } } /* Now clear signal->tty under the lock */