The patch titled Memory rlimit: fix crash on fork has been removed from the -mm tree. Its filename was memrlimit-add-memrlimit-controller-accounting-and-control-memory-rlimit-fix-crash-on-fork.patch This patch was dropped because it was folded into memrlimit-add-memrlimit-controller-accounting-and-control.patch The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/ ------------------------------------------------------ Subject: Memory rlimit: fix crash on fork From: Balbir Singh <balbir@xxxxxxxxxxxxxxxxxx> Remove changes from unmap_vmas(), don't call the remaining operations in exit_mmap() if mm->mmap is NULL. This patch fixes a crash that occurs when kernbench is set with memrlimit set to 500M on my x86_64 box. The root cause for the failure is 1. We don't set mm->mmap to NULL for the process for which fork() failed 2. mmput() dereferences vma (in unmap_vmas, vma->vm_mm). This patch fixes the problem by 1. Initializing mm->mmap to NULL prior to failing dup_mmap() 2. Check early if mm->mmap is NULL in exit_mmap() and return Signed-off-by: Balbir Singh <balbir@xxxxxxxxxxxxxxxxxx> Cc: Sudhir Kumar <skumar@xxxxxxxxxxxxxxxxxx> Cc: YAMAMOTO Takashi <yamamoto@xxxxxxxxxxxxx> Cc: Paul Menage <menage@xxxxxxxxxx> Cc: Li Zefan <lizf@xxxxxxxxxxxxxx> Cc: Pavel Emelianov <xemul@xxxxxxxxxx> Cc: Balbir Singh <balbir@xxxxxxxxxxxxxxxxxx> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Vivek Goyal <vgoyal@xxxxxxxxxx> Cc: Hugh Dickins <hugh@xxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/fork.c | 19 ++++++++++--------- mm/mmap.c | 9 +++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff -puN kernel/fork.c~memrlimit-add-memrlimit-controller-accounting-and-control-memory-rlimit-fix-crash-on-fork kernel/fork.c --- a/kernel/fork.c~memrlimit-add-memrlimit-controller-accounting-and-control-memory-rlimit-fix-crash-on-fork +++ a/kernel/fork.c @@ -274,15 +274,6 @@ static int dup_mmap(struct mm_struct *mm */ down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING); - /* - * Uncharging as a result of failure is done by mmput() - * in dup_mm() - */ - if (memrlimit_cgroup_charge_as(oldmm, oldmm->total_vm)) { - retval = -ENOMEM; - goto out; - } - mm->locked_vm = 0; mm->mmap = NULL; mm->mmap_cache = NULL; @@ -295,6 +286,16 @@ static int dup_mmap(struct mm_struct *mm rb_parent = NULL; pprev = &mm->mmap; + /* + * Called after mm->mmap is set to NULL, so that the routines + * following this function understand that fork failed (read + * mmput). + */ + if (memrlimit_cgroup_charge_as(oldmm, oldmm->total_vm)) { + retval = -ENOMEM; + goto out; + } + for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) { struct file *file; diff -puN mm/mmap.c~memrlimit-add-memrlimit-controller-accounting-and-control-memory-rlimit-fix-crash-on-fork mm/mmap.c --- a/mm/mmap.c~memrlimit-add-memrlimit-controller-accounting-and-control-memory-rlimit-fix-crash-on-fork +++ a/mm/mmap.c @@ -2101,6 +2101,15 @@ void exit_mmap(struct mm_struct *mm) } } vma = mm->mmap; + + /* + * In the case that dup_mm() failed, mm->mmap is NULL and + * we never really setup the mm. We don't have much to do, + * we might as well return early + */ + if (!vma) + return; + lru_add_drain(); flush_cache_mm(mm); tlb = tlb_gather_mmu(mm, 1); _ Patches currently in -mm which might be from balbir@xxxxxxxxxxxxxxxxxx are origin.patch linux-next.patch memrlimit-add-memrlimit-controller-documentation.patch memrlimit-setup-the-memrlimit-controller.patch memrlimit-add-memrlimit-controller-accounting-and-control.patch memrlimit-add-memrlimit-controller-accounting-and-control-memory-rlimit-fix-crash-on-fork.patch memrlimit-add-memrlimit-controller-accounting-and-control-fix-task_lock-recursive-locking-v2.patch memrlimit-improve-error-handling.patch memrlimit-improve-error-handling-update.patch memrlimit-handle-attach_task-failure-add-can_attach-callback.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html