Re: Possible "struct pid" leak from tty_io.c

From: Catalin Marinas
Date: Wed Mar 14 2007 - 05:59:40 EST


On 13/03/07, Eric W. Biederman <ebiederm@xxxxxxxxxxxx> wrote:
"Catalin Marinas" <catalin.marinas@xxxxxxxxx> writes:
> void proc_clear_tty(struct task_struct *p)
> {
> + struct tty_struct *tty;
> +
> spin_lock_irq(&p->sighand->siglock);
> + tty = p->signal->tty;
> + if (tty) {
> + put_pid(tty->session);
> + put_pid(tty->pgrp);
> + }
> p->signal->tty = NULL;
> spin_unlock_irq(&p->sighand->siglock);
> }

This patch can't be right. Not the way proc_clear_tty is called
once for each process in the session, plus we aren't clearing
tty->session and tty->pgrp here.

If the above patch works it's a fluke.

I looked at the logs and the pointer isn't freed indeed. It is just a
false negative in kmemleak and it would appear as a leak at some
point. But the previous patch (do_tty_hangup) seems to fix one of the
leaks.

For the 2nd leak, proc_set_tty is called and, for symmetry, I added
put_pid in proc_clear_tty (but without any deep thought). I also
haven't checked any lockdep issues with adding put_pid when
p->sighand->siglock is held.

--
Catalin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/