From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
"Catalin Marinas" <catalin.marinas@gmail.com>
Subject: [PATCH 2/4] tty: Simplify calling of put_pid.
Date: Sun, 18 Mar 2007 13:03:08 -0600 [thread overview]
Message-ID: <m1fy82jrwz.fsf_-_@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <m1mz2ajs6g.fsf_-_@ebiederm.dsl.xmission.com> (Eric W. Biederman's message of "Sun, 18 Mar 2007 12:57:27 -0600")
This patch should contain no functional changes.
At somepoint I got confused and thought put_pid could not
be called while a spin lock was held. While it may be nice
to avoid that to reduce lock hold times put_pid can be safely
called while we hold a spin lock.
This patch removes all of the complications from the code
introduced by my misunderstanding, making the code a little
more readable.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
drivers/char/tty_io.c | 23 ++++++-----------------
1 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 583730f..01fcfaf 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -155,8 +155,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
unsigned int cmd, unsigned long arg);
static int tty_fasync(int fd, struct file * filp, int on);
static void release_tty(struct tty_struct *tty, int idx);
-static struct pid *__proc_set_tty(struct task_struct *tsk,
- struct tty_struct *tty);
+static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
/**
* alloc_tty_struct - allocate a tty object
@@ -1534,10 +1533,9 @@ void disassociate_ctty(int on_exit)
}
spin_lock_irq(¤t->sighand->siglock);
- tty_pgrp = current->signal->tty_old_pgrp;
+ put_pid(current->signal->tty_old_pgrp);
current->signal->tty_old_pgrp = NULL;
spin_unlock_irq(¤t->sighand->siglock);
- put_pid(tty_pgrp);
mutex_lock(&tty_mutex);
/* It is possible that do_tty_hangup has free'd this tty */
@@ -2508,7 +2506,6 @@ static int tty_open(struct inode * inode, struct file * filp)
int index;
dev_t device = inode->i_rdev;
unsigned short saved_flags = filp->f_flags;
- struct pid *old_pgrp;
nonseekable_open(inode, filp);
@@ -2602,17 +2599,15 @@ got_driver:
goto retry_open;
}
- old_pgrp = NULL;
mutex_lock(&tty_mutex);
spin_lock_irq(¤t->sighand->siglock);
if (!noctty &&
current->signal->leader &&
!current->signal->tty &&
tty->session == NULL)
- old_pgrp = __proc_set_tty(current, tty);
+ __proc_set_tty(current, tty);
spin_unlock_irq(¤t->sighand->siglock);
mutex_unlock(&tty_mutex);
- put_pid(old_pgrp);
return 0;
}
@@ -3838,9 +3833,8 @@ void proc_clear_tty(struct task_struct *p)
spin_unlock_irq(&p->sighand->siglock);
}
-static struct pid *__proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
+static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
{
- struct pid *old_pgrp;
if (tty) {
/* We should not have a session or pgrp to here but.... */
put_pid(tty->session);
@@ -3848,21 +3842,16 @@ static struct pid *__proc_set_tty(struct task_struct *tsk, struct tty_struct *tt
tty->session = get_pid(task_session(tsk));
tty->pgrp = get_pid(task_pgrp(tsk));
}
- old_pgrp = tsk->signal->tty_old_pgrp;
+ put_pid(tsk->signal->tty_old_pgrp);
tsk->signal->tty = tty;
tsk->signal->tty_old_pgrp = NULL;
- return old_pgrp;
}
void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
{
- struct pid *old_pgrp;
-
spin_lock_irq(&tsk->sighand->siglock);
- old_pgrp = __proc_set_tty(tsk, tty);
+ __proc_set_tty(tsk, tty);
spin_unlock_irq(&tsk->sighand->siglock);
-
- put_pid(old_pgrp);
}
struct tty_struct *get_current_tty(void)
--
1.5.0.g53756
next prev parent reply other threads:[~2007-03-18 19:04 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-08 17:27 Possible "struct pid" leak from tty_io.c Catalin Marinas
2007-03-08 18:11 ` Eric W. Biederman
2007-03-09 10:53 ` Catalin Marinas
2007-03-09 16:13 ` Eric W. Biederman
2007-03-09 16:53 ` Catalin Marinas
2007-03-09 16:44 ` Catalin Marinas
2007-03-09 17:09 ` Eric W. Biederman
2007-03-12 15:07 ` Catalin Marinas
2007-03-12 16:12 ` Eric W. Biederman
2007-03-13 19:31 ` Eric W. Biederman
2007-03-14 9:59 ` Catalin Marinas
2007-03-14 14:40 ` Eric W. Biederman
2007-03-14 17:08 ` Catalin Marinas
2007-03-15 19:15 ` Eric W. Biederman
2007-03-16 22:01 ` Eric W. Biederman
2007-03-16 22:44 ` Catalin Marinas
2007-03-18 18:45 ` [PATCH] tty: Fix two reported pid leaks Eric W. Biederman
2007-03-18 18:52 ` [PATCH 0/4] tty: small fixes and cleanups Eric W. Biederman
2007-03-18 18:57 ` [PATCH 1/4] tty: Remove unnecessary export of proc_clear_tty Eric W. Biederman
2007-03-18 19:03 ` Eric W. Biederman [this message]
2007-03-18 19:08 ` [PATCH 3/4] tty: Introduce no_tty and use it in selinux Eric W. Biederman
2007-03-18 19:13 ` [PATCH 4/4] tty: In tiocsctty when we steal a tty hang it up Eric W. Biederman
2007-03-18 20:55 ` [PATCH 3/4] tty: Introduce no_tty and use it in selinux Alan Cox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1fy82jrwz.fsf_-_@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®