Balbir Singh 31a78f23ba mm owner: fix race between swapoff and exit
There's a race between mm->owner assignment and swapoff, more easily
seen when task slab poisoning is turned on.  The condition occurs when
try_to_unuse() runs in parallel with an exiting task.  A similar race
can occur with callers of get_task_mm(), such as /proc/<pid>/<mmstats>
or ptrace or page migration.

CPU0                                    CPU1
                                        try_to_unuse
                                        looks at mm = task0->mm
                                        increments mm->mm_users
task 0 exits
mm->owner needs to be updated, but no
new owner is found (mm_users > 1, but
no other task has task->mm = task0->mm)
mm_update_next_owner() leaves
                                        mmput(mm) decrements mm->mm_users
task0 freed
                                        dereferencing mm->owner fails

The fix is to notify the subsystem via mm_owner_changed callback(),
if no new owner is found, by specifying the new task as NULL.

Jiri Slaby:
mm->owner was set to NULL prior to calling cgroup_mm_owner_callbacks(), but
must be set after that, so as not to pass NULL as old owner causing oops.

Daisuke Nishimura:
mm_update_next_owner() may set mm->owner to NULL, but mem_cgroup_from_task()
and its callers need to take account of this situation to avoid oops.

Hugh Dickins:
Lockdep warning and hang below exec_mmap() when testing these patches.
exit_mm() up_reads mmap_sem before calling mm_update_next_owner(),
so exec_mmap() now needs to do the same.  And with that repositioning,
there's now no point in mm_need_new_owner() allowing for NULL mm.

Reported-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Paul Menage <menage@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-09-29 08:41:47 -07:00
..
2008-08-04 21:31:34 -07:00
2008-02-08 09:22:40 -08:00
2008-09-13 14:41:51 -07:00
2008-08-20 15:40:32 -07:00
2008-08-01 11:25:29 -04:00
2008-08-13 12:47:36 -05:00
2008-08-25 01:18:04 -04:00
2008-04-29 08:06:00 -07:00
2008-07-26 20:53:40 -04:00
2008-07-26 20:53:40 -04:00
2008-07-25 10:53:34 -07:00
2007-10-18 14:37:31 -07:00
2008-09-02 19:21:37 -07:00
2008-09-10 01:44:08 -07:00
2008-07-04 09:52:14 +02:00
2008-07-26 12:00:07 -07:00
2008-09-18 09:57:57 +03:00
2008-09-08 20:31:04 +02:00
2008-07-25 10:53:34 -07:00
2008-07-26 20:53:40 -04:00
2008-07-26 12:00:08 -07:00
2008-07-26 12:00:08 -07:00
2008-07-26 12:00:08 -07:00
2008-01-30 13:31:46 +01:00
2008-07-26 12:00:06 -07:00
2008-05-01 13:08:16 -04:00
2008-08-01 11:25:24 -04:00
2008-07-26 20:53:40 -04:00
2007-05-08 11:15:01 -07:00
2008-07-14 19:10:52 +03:00
2008-02-06 10:41:07 -08:00
2008-04-29 08:06:00 -07:00
2008-07-28 18:10:28 +09:00
2008-07-26 12:00:05 -07:00
2008-02-14 21:13:33 -08:00
2008-07-25 10:53:35 -07:00
2008-07-02 15:06:27 -06:00
2008-08-04 21:31:34 -07:00