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-08 21:34:51 +02:00
2014-04-05 15:37:40 -07:00
2014-04-02 16:23:38 -07:00
2014-03-25 21:06:02 -04:00
2014-04-11 13:25:08 -07:00
2014-03-27 14:20:04 -04:00
2014-04-12 14:49:50 -07:00
2014-04-02 20:53:45 -07:00
2014-04-05 15:37:40 -07:00
2014-04-16 14:21:06 -07:00
2014-04-07 10:24:18 -07:00
2014-04-07 14:55:46 -07:00
2014-04-02 20:53:45 -07:00
2014-04-08 13:28:02 +02:00
2014-04-08 13:27:40 +02:00
2014-04-03 09:28:16 -07:00
2014-03-21 11:16:30 +09:00
2014-04-10 08:55:08 -07:00
2014-04-04 09:50:07 -07:00
2014-03-19 14:41:58 +09:00
2014-04-11 11:58:33 -07:00
2014-04-07 10:24:18 -07:00
2014-04-08 09:52:16 -07:00
2014-04-04 09:50:07 -07:00
2014-04-01 16:13:21 -07:00
2014-04-09 08:35:31 -07:00
2014-04-09 08:45:40 -07:00
2014-04-08 13:27:40 +02:00
2014-04-07 10:24:18 -07:00
2014-04-12 16:51:08 -07:00
2014-04-05 18:32:31 -07:00
2014-04-05 18:46:26 -07:00
2014-04-05 15:37:40 -07:00
2014-04-08 12:41:13 -04:00
2014-04-10 09:06:10 -07:00
2014-04-07 16:35:52 -07:00
2014-04-11 17:20:38 -07:00
2014-04-08 11:01:12 -03:00
2014-04-01 15:14:04 -07:00
2014-04-09 08:39:39 -07:00
2014-04-07 16:36:09 -07:00
2014-04-09 08:39:39 -07:00
2014-04-07 10:17:30 -07:00
2014-04-12 17:31:22 -07:00
2014-04-07 10:59:20 -07:00
2014-04-07 10:17:30 -07:00
2014-03-20 13:43:46 +01:00
2014-04-06 09:38:07 -07:00
2014-04-01 15:14:04 -07:00
2014-04-05 15:37:40 -07:00
2014-04-03 16:44:15 -07:00
2014-04-10 12:11:56 -04:00
2014-04-02 14:10:21 -07:00
2014-04-07 14:55:46 -07:00
2014-04-01 16:43:18 -04:00
2014-04-05 18:32:31 -07:00
2014-04-07 16:36:07 -07:00
2014-04-11 13:30:05 -07:00
2014-03-27 01:28:19 +01:00
2014-04-05 15:37:40 -07:00
2014-04-08 12:02:28 -07:00
2014-04-12 18:02:16 -07:00
2014-04-05 15:38:41 -07:00
2014-04-11 13:35:49 -07:00
2014-04-12 17:31:22 -07:00
2014-04-12 17:31:22 -07:00
2014-04-10 09:15:46 -07:00
2014-04-16 14:31:13 -07:00
2014-04-12 16:51:08 -07:00
2014-04-03 14:05:02 -07:00
2014-04-12 16:51:08 -07:00
2014-04-10 08:52:35 -07:00
2014-04-07 14:55:46 -07:00
2014-04-07 17:50:18 -07:00