Chen Tingjie
c70dbb1e79
tty: fix memleak in alloc_pid
...
There is memleak in alloc_pid:
------------------------------
unreferenced object 0xd3453a80 (size 64):
comm "adbd", pid 1730, jiffies 66363 (age 6586.950s)
hex dump (first 32 bytes):
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 40 c2 f6 d5 00 d3 25 c1 59 28 00 00 ....@.....%.Y(..
backtrace:
[<c1a6f15c>] kmemleak_alloc+0x3c/0xa0
[<c1320546>] kmem_cache_alloc+0xc6/0x190
[<c125d51e>] alloc_pid+0x1e/0x400
[<c123d344>] copy_process.part.39+0xad4/0x1120
[<c123da59>] do_fork+0x99/0x330
[<c123dd58>] sys_fork+0x28/0x30
[<c1a89a08>] syscall_call+0x7/0xb
[<ffffffff>] 0xffffffff
the leak is due to unreleased pid->count, which execute in function:
get_pid()(pid->count++) and put_pid()(pid->count--).
The race condition as following:
task[dumpsys] task[adbd]
in disassociate_ctty() in tty_signal_session_leader()
----------------------- -------------------------
tty = get_current_tty();
// tty is not NULL
...
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);
spin_lock_irq(&p->sighand->siglock);
...
p->signal->tty = NULL;
...
spin_unlock_irq(&p->sighand->siglock);
tty = get_current_tty();
// tty NULL, goto else branch by accident.
if (tty) {
...
put_pid(tty_session);
put_pid(tty_pgrp);
...
} else {
print msg
}
in task[dumpsys], in disassociate_ctty(), tty is set NULL by task[adbd],
tty_signal_session_leader(), then it goto else branch and lack of
put_pid(), cause memleak.
move spin_unlock(sighand->siglock) after get_current_tty() can avoid
the race and fix the memleak.
Signed-off-by: Zhang Jun <jun.zhang@intel.com>
Signed-off-by: Chen Tingjie <tingjie.chen@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-04-16 14:31:13 -07:00
..
2014-04-07 10:34:27 +10:00
2014-02-28 16:31:00 -08:00
2014-04-16 14:20:34 -07:00
2014-02-28 16:25:47 -08:00
2014-01-07 17:05:21 -08:00
2013-09-30 19:09:37 -07:00
2013-12-20 12:21:57 -08:00
2013-10-09 20:04:04 -05:00
2014-01-07 17:05:21 -08:00
2013-01-15 22:30:15 -08:00
2014-01-09 17:52:12 -06:00
2013-05-20 12:30:32 -07:00
2013-11-15 09:32:21 +09:00
2013-03-18 16:24:29 -07:00
2013-05-22 10:26:02 -07:00
2014-02-07 08:40:54 -08:00
2013-12-08 16:56:05 -08:00
2014-02-13 10:18:48 -08:00
2013-10-16 13:08:16 -07:00
2013-07-24 15:12:53 -07:00
2013-12-08 17:09:07 -08:00
2014-01-07 17:05:21 -08:00
2014-03-17 16:13:23 -07:00
2014-03-17 16:13:23 -07:00
2013-10-16 13:01:44 -07:00
2014-03-20 10:11:55 -04:00
2014-02-28 16:31:00 -08:00
2014-04-16 14:31:13 -07:00
2013-09-25 17:52:17 -07:00
2014-01-07 17:05:21 -08:00
2014-02-09 21:18:54 +01:00
2012-10-24 11:34:51 -07:00
2014-01-07 17:05:21 -08:00