From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753266AbXCRTOm (ORCPT ); Sun, 18 Mar 2007 15:14:42 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753273AbXCRTOm (ORCPT ); Sun, 18 Mar 2007 15:14:42 -0400 Received: from ebiederm.dsl.xmission.com ([166.70.28.69]:36706 "EHLO ebiederm.dsl.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753266AbXCRTOl (ORCPT ); Sun, 18 Mar 2007 15:14:41 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Andrew Morton Cc: "Linux Kernel Mailing List" , "Catalin Marinas" Subject: [PATCH 4/4] tty: In tiocsctty when we steal a tty hang it up. References: Date: Sun, 18 Mar 2007 13:13:37 -0600 In-Reply-To: (Eric W. Biederman's message of "Sun, 18 Mar 2007 13:08:34 -0600") Message-ID: User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org The linux implementation of TIOCSCTTY includes an extention that provides for making a tty that is already the controlling tty of another session our controlling tty. To do this it must steal the tty away from the previous group that used it as a controlling tty. The way we are currently stealing the controlling tty away is weird. In general there is a well defined process for loosing the controlling tty. TTY hangup processing. However the linux extension that steals the tty from another process group does not invoke that. And instead just forgets the controlling tty of the processes that were part of the session. I can not imagine how our current behaviour of stealling a tty is correct or how a set of processes could deal with it reasonably. So this patch modifies the tty stealing to call tty_vhangup so we get full hanup processing when we steal a tty. I did a quick survey of user space the only application I found using this extended behaviour is sysvinit. I perform a limited amount of testing and nothing appears to have broken with this change. And I did see sysvinit pass through this piece of code. In terms of the tty leaks that started this patch series this fix should remove the last path into proc_clear_tty that has a session or a process group. Signed-off-by: Eric W. Biederman --- drivers/char/tty_io.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 0843fcb..0f5a781 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -2982,9 +2982,7 @@ static int tiocsctty(struct tty_struct *tty, int arg) /* * Steal it away */ - read_lock(&tasklist_lock); - session_clear_tty(tty->session); - read_unlock(&tasklist_lock); + tty_vhangup(tty); } else { ret = -EPERM; goto unlock; -- 1.5.0.g53756