mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-19 00:47:22 +07:00
4837fe37ad
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: 2129258024
("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>
80 lines
2.6 KiB
C
80 lines
2.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_SCHED_COREDUMP_H
|
|
#define _LINUX_SCHED_COREDUMP_H
|
|
|
|
#include <linux/mm_types.h>
|
|
|
|
#define SUID_DUMP_DISABLE 0 /* No setuid dumping */
|
|
#define SUID_DUMP_USER 1 /* Dump as user of process */
|
|
#define SUID_DUMP_ROOT 2 /* Dump as root */
|
|
|
|
/* mm flags */
|
|
|
|
/* for SUID_DUMP_* above */
|
|
#define MMF_DUMPABLE_BITS 2
|
|
#define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1)
|
|
|
|
extern void set_dumpable(struct mm_struct *mm, int value);
|
|
/*
|
|
* This returns the actual value of the suid_dumpable flag. For things
|
|
* that are using this for checking for privilege transitions, it must
|
|
* test against SUID_DUMP_USER rather than treating it as a boolean
|
|
* value.
|
|
*/
|
|
static inline int __get_dumpable(unsigned long mm_flags)
|
|
{
|
|
return mm_flags & MMF_DUMPABLE_MASK;
|
|
}
|
|
|
|
static inline int get_dumpable(struct mm_struct *mm)
|
|
{
|
|
return __get_dumpable(mm->flags);
|
|
}
|
|
|
|
/* coredump filter bits */
|
|
#define MMF_DUMP_ANON_PRIVATE 2
|
|
#define MMF_DUMP_ANON_SHARED 3
|
|
#define MMF_DUMP_MAPPED_PRIVATE 4
|
|
#define MMF_DUMP_MAPPED_SHARED 5
|
|
#define MMF_DUMP_ELF_HEADERS 6
|
|
#define MMF_DUMP_HUGETLB_PRIVATE 7
|
|
#define MMF_DUMP_HUGETLB_SHARED 8
|
|
#define MMF_DUMP_DAX_PRIVATE 9
|
|
#define MMF_DUMP_DAX_SHARED 10
|
|
|
|
#define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS
|
|
#define MMF_DUMP_FILTER_BITS 9
|
|
#define MMF_DUMP_FILTER_MASK \
|
|
(((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
|
|
#define MMF_DUMP_FILTER_DEFAULT \
|
|
((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\
|
|
(1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
|
|
|
|
#ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
|
|
# define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS)
|
|
#else
|
|
# define MMF_DUMP_MASK_DEFAULT_ELF 0
|
|
#endif
|
|
/* leave room for more dump flags */
|
|
#define MMF_VM_MERGEABLE 16 /* KSM may merge identical pages */
|
|
#define MMF_VM_HUGEPAGE 17 /* set when VM_HUGEPAGE is set on vma */
|
|
/*
|
|
* This one-shot flag is dropped due to necessity of changing exe once again
|
|
* on NFS restore
|
|
*/
|
|
//#define MMF_EXE_FILE_CHANGED 18 /* see prctl_set_mm_exe_file() */
|
|
|
|
#define MMF_HAS_UPROBES 19 /* has uprobes */
|
|
#define MMF_RECALC_UPROBES 20 /* MMF_HAS_UPROBES can be wrong */
|
|
#define MMF_OOM_SKIP 21 /* mm is of no interest for the OOM killer */
|
|
#define MMF_UNSTABLE 22 /* mm is unstable for copy_from_user */
|
|
#define MMF_HUGE_ZERO_PAGE 23 /* mm has ever used the global huge zero page */
|
|
#define MMF_DISABLE_THP 24 /* disable THP for all VMAs */
|
|
#define MMF_OOM_VICTIM 25 /* mm is the oom victim */
|
|
#define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP)
|
|
|
|
#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\
|
|
MMF_DISABLE_THP_MASK)
|
|
|
|
#endif /* _LINUX_SCHED_COREDUMP_H */
|