Revision 4837fe37adff1d159904f0c013471b1ecbcb455e authored by Michal Hocko on 14 December 2017, 23:33:15 UTC, committed by Linus Torvalds on 15 December 2017, 00:00:49 UTC
David Rientjes has reported the following memory corruption while the
oom reaper tries to unmap the victims address space

  BUG: Bad page map in process oom_reaper  pte:6353826300000000 pmd:00000000
  addr:00007f50cab1d000 vm_flags:08100073 anon_vma:ffff9eea335603f0 mapping:          (null) index:7f50cab1d
  file:          (null) fault:          (null) mmap:          (null) readpage:          (null)
  CPU: 2 PID: 1001 Comm: oom_reaper
  Call Trace:
     unmap_page_range+0x1068/0x1130
     __oom_reap_task_mm+0xd5/0x16b
     oom_reaper+0xff/0x14c
     kthread+0xc1/0xe0

Tetsuo Handa has noticed that the synchronization inside exit_mmap is
insufficient.  We only synchronize with the oom reaper if
tsk_is_oom_victim which is not true if the final __mmput is called from
a different context than the oom victim exit path.  This can trivially
happen from context of any task which has grabbed mm reference (e.g.  to
read /proc/<pid>/ file which requires mm etc.).

The race would look like this

  oom_reaper		oom_victim		task
						mmget_not_zero
			do_exit
			  mmput
  __oom_reap_task_mm				mmput
  						  __mmput
						    exit_mmap
						      remove_vma
    unmap_page_range

Fix this issue by providing a new mm_is_oom_victim() helper which
operates on the mm struct rather than a task.  Any context which
operates on a remote mm struct should use this helper in place of
tsk_is_oom_victim.  The flag is set in mark_oom_victim and never cleared
so it is stable in the exit_mmap path.

Debugged by Tetsuo Handa.

Link: http://lkml.kernel.org/r/20171210095130.17110-1-mhocko@kernel.org
Fixes: 212925802454 ("mm: oom: let oom_reap_task and exit_mmap run concurrently")
Signed-off-by: Michal Hocko <mhocko@suse.com>
Reported-by: David Rientjes <rientjes@google.com>
Acked-by: David Rientjes <rientjes@google.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Andrea Argangeli <andrea@kernel.org>
Cc: <stable@vger.kernel.org>	[4.14]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bdcf0a4
History
File Mode Size
Makefile -rw-r--r-- 563 bytes
README -rw-r--r-- 1.4 KB
bindec.S -rw-r--r-- 27.5 KB
binstr.S -rw-r--r-- 4.2 KB
bugfix.S -rw-r--r-- 13.7 KB
decbin.S -rw-r--r-- 15.4 KB
do_func.S -rw-r--r-- 13.5 KB
fpsp.h -rw-r--r-- 11.2 KB
gen_except.S -rw-r--r-- 12.9 KB
get_op.S -rw-r--r-- 19.9 KB
kernel_ex.S -rw-r--r-- 13.0 KB
res_func.S -rw-r--r-- 51.9 KB
round.S -rw-r--r-- 16.4 KB
sacos.S -rw-r--r-- 2.8 KB
sasin.S -rw-r--r-- 2.3 KB
satan.S -rw-r--r-- 15.6 KB
satanh.S -rw-r--r-- 2.2 KB
scale.S -rw-r--r-- 8.7 KB
scosh.S -rw-r--r-- 2.9 KB
setox.S -rw-r--r-- 27.7 KB
sgetem.S -rw-r--r-- 3.6 KB
sint.S -rw-r--r-- 5.6 KB
skeleton.S -rw-r--r-- 11.5 KB
slog2.S -rw-r--r-- 5.1 KB
slogn.S -rw-r--r-- 19.0 KB
smovecr.S -rw-r--r-- 4.2 KB
srem_mod.S -rw-r--r-- 12.0 KB
ssin.S -rw-r--r-- 18.6 KB
ssinh.S -rw-r--r-- 3.3 KB
stan.S -rw-r--r-- 13.0 KB
stanh.S -rw-r--r-- 4.0 KB
sto_res.S -rw-r--r-- 1.9 KB
stwotox.S -rw-r--r-- 12.0 KB
tbldo.S -rw-r--r-- 18.8 KB
util.S -rw-r--r-- 16.7 KB
x_bsun.S -rw-r--r-- 990 bytes
x_fline.S -rw-r--r-- 2.9 KB
x_operr.S -rw-r--r-- 9.6 KB
x_ovfl.S -rw-r--r-- 4.6 KB
x_snan.S -rw-r--r-- 6.5 KB
x_store.S -rw-r--r-- 6.8 KB
x_unfl.S -rw-r--r-- 6.8 KB
x_unimp.S -rw-r--r-- 2.0 KB
x_unsupp.S -rw-r--r-- 2.2 KB

README

back to top