diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2018-05-12 10:10:08 +1000 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2018-05-12 10:10:08 +1000 |
commit | a155c331d42328275cb1754921a906bd88519c87 (patch) | |
tree | e2595e7e668cac4fa6d2489bd14d011c76976d72 /kernel | |
parent | 89fd67aaaa1a0d8e4007bd7a4893d305b992e384 (diff) | |
download | linux-next-a155c331d42328275cb1754921a906bd88519c87.tar.gz |
mm: check for SIGKILL inside dup_mmap() loop.
As a theoretical problem, dup_mmap() of an mm_struct with 60000+ vmas can
loop while potentially allocating memory, with mm->mmap_sem held for write
by current thread. This is bad if current thread was selected as an OOM
victim, for current thread will continue allocations using memory reserves
while OOM reaper is unable to reclaim memory.
As an actually observable problem, it is not difficult to make OOM reaper
unable to reclaim memory if the OOM victim is blocked at
i_mmap_lock_write() in this loop. Unfortunately, since nobody can explain
whether it is safe to use killable wait there, let's check for SIGKILL
before trying to allocate memory. Even without an OOM event, there is no
point with continuing the loop from the beginning if current thread is
killed.
I tested with debug printk(). This patch should be safe because we
already fail if security_vm_enough_memory_mm() or
kmem_cache_alloc(GFP_KERNEL) fails and exit_mmap() handles it.
[ 417.030691] ***** Aborting dup_mmap() due to SIGKILL *****
[ 417.036129] ***** Aborting dup_mmap() due to SIGKILL *****
[ 417.044544] ***** Aborting dup_mmap() due to SIGKILL *****
[ 419.116445] ***** Aborting dup_mmap() due to SIGKILL *****
[ 419.118401] ***** Aborting exit_mmap() due to NULL mmap *****
Link: http://lkml.kernel.org/r/201804071938.CDE04681.SOFVQJFtMHOOLF@I-love.SAKURA.ne.jp
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Rik van Riel <riel@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/fork.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 92ac6a1a69c2..4c021481dddc 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -440,6 +440,10 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, continue; } charge = 0; + if (fatal_signal_pending(current)) { + retval = -EINTR; + goto out; + } if (mpnt->vm_flags & VM_ACCOUNT) { unsigned long len = vma_pages(mpnt); |