From patchwork Sat Feb 8 08:35:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11371495 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6229B1398 for ; Sat, 8 Feb 2020 08:37:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 251FE21741 for ; Sat, 8 Feb 2020 08:37:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s6x2kWbj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 251FE21741 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8F6406B0007; Sat, 8 Feb 2020 03:37:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8CDF16B0008; Sat, 8 Feb 2020 03:37:39 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E2E56B000A; Sat, 8 Feb 2020 03:37:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 60EE36B0007 for ; Sat, 8 Feb 2020 03:37:39 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AF951249F for ; Sat, 8 Feb 2020 08:37:37 +0000 (UTC) X-FDA: 76466306154.17.push69_8566aca5274a X-Spam-Summary: 40,2.5,0,83b3f539ff93c244,d41d8cd98f00b204,lixinhai.lxh@gmail.com,::akpm@linux-foundation.org:riel@redhat.com:kirill.shutemov@linux.intel.com:willy@infradead.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3352:3865:3866:3868:3870:3871:3874:4321:5007:6261:6653:7514:7903:8660:9413:10011:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13069:13148:13230:13311:13357:14181:14384:14394:14687:14721:21080:21324:21444:21451:21627:21666:21740:30054:30079,0,RBL:209.85.208.196:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:1:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: push69_8566aca5274a X-Filterd-Recvd-Size: 4429 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Sat, 8 Feb 2020 08:37:37 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id q8so1746056ljj.11 for ; Sat, 08 Feb 2020 00:37:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bRKoUkWzGWG5sS+nRLMaxwUJGw4R0/AKLKdIHTJDorY=; b=s6x2kWbjyZ3+8C/AQVm8ADPAgYVvZdSl4y2QbvDc3FhRsywHxkxH7Kg97wAow3XH6F fomfBob/Pm6fnv+YBmbgF3vK++C73S65VIynP7brg7GPaWaiZYM5KEoVl/zgxsCRkkLT tDO7oZTMLAnHf+Vi7fVmjjUjhL2gABBUHY4UlU48S20Yg0l47eT7havl3vWh6RbX9c18 X+8uUuXSwVwzL82NvmBo4zDtrjqOnnShgcxWPM5xSzJT5Jioc5N/H9c/J/L2/whWL4Me qezuhlJalY0jLJwcBHA+nUqfQqkCpu0TcLAVyy3lr7WdmAGwcM/W+DIajXemEAm0vwnf pOiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bRKoUkWzGWG5sS+nRLMaxwUJGw4R0/AKLKdIHTJDorY=; b=mHNXsXTip4JB/lrVLhVwE7CElp6hLVA+F+cIgooiG4jqleD4++XVscRS7BKZcyGoFt O8NNoeXR9ugSuZSuFaP4td5NaFeWQWMjK3YAXWSRGUlgxn7z234qOuPf2l05zqt/GaRe 2PpkMvp4gZtQVm3+/CbyuOm57VC2SVFAz61nt2PusCl/hGYDga1qLDTYKkxE47yUp7yD lc7RWgXNFM5yEcWIbYFTPsEuG4AUO7JVTuoa8ifNZN4bo+DnREmSRoRbqXDTNVnjxaoF EG4rGtsj8I1r6fClGJ2HmnIB3ae/T0iEW4gt7Z3q7gqHkuuT/eTUjT4wliXptVjPeWhK 0R1g== X-Gm-Message-State: APjAAAXWewHR2SdiqBXcdZ06cvRuGGwPI1EFr0VHAKRBbXf4nkvWPDQp kK4WWEE6KhjLx5eYqN9sjhhYkqQr6gM= X-Google-Smtp-Source: APXvYqyp6uYhllh8Dihy6/ot72Nb8OuirQjGffaGvPvrPnC7fwZZA/cl1vUfQNkHfWM+g6CXuHAkyg== X-Received: by 2002:a2e:804b:: with SMTP id p11mr2075653ljg.235.1581151055645; Sat, 08 Feb 2020 00:37:35 -0800 (PST) Received: from localhost.localdomain.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id n11sm2663404ljg.15.2020.02.08.00.37.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 00:37:35 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, Rik van Riel , "Kirill A. Shutemov" , Matthew Wilcox Subject: [PATCH 1/3] mm: don't prepare anon_vma if vma has VM_WIPEONFORK Date: Sat, 8 Feb 2020 08:35:26 +0000 Message-Id: <1581150928-3214-2-git-send-email-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1581150928-3214-1-git-send-email-lixinhai.lxh@gmail.com> References: <1581150928-3214-1-git-send-email-lixinhai.lxh@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In dup_mmap(), anon_vma_prepare() is called for vma has VM_WIPEONFORK, and parameter 'tmp' (i.e., the new vma of child) has same ->vm_next and ->vm_prev as its parent vma. That allows anon_vma used by parent been mistakenly shared by child (find_mergeable_anon_vma() will do this reuse work). Besides this issue, call anon_vma_prepare() should be avoided because we don't copy page for this vma. Preparing anon_vma will be handled during fault. Fixes: d2cd9ede6e19 ("mm,fork: introduce MADV_WIPEONFORK") Signed-off-by: Li Xinhai Cc: Rik van Riel Cc: Kirill A. Shutemov Cc: Matthew Wilcox Acked-by: Kirill A. Shutemov --- kernel/fork.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 0808095..1bbd49a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -552,10 +552,12 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, if (retval) goto fail_nomem_anon_vma_fork; if (tmp->vm_flags & VM_WIPEONFORK) { - /* VM_WIPEONFORK gets a clean slate in the child. */ + /* + * VM_WIPEONFORK gets a clean slate in the child. + * Don't prepare anon_vma until fault since we don't + * copy page for current vma. + */ tmp->anon_vma = NULL; - if (anon_vma_prepare(tmp)) - goto fail_nomem_anon_vma_fork; } else if (anon_vma_fork(tmp, mpnt)) goto fail_nomem_anon_vma_fork; tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT); From patchwork Sat Feb 8 08:35:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11371497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D45611398 for ; Sat, 8 Feb 2020 08:37:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 96C3521741 for ; Sat, 8 Feb 2020 08:37:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cWjUoJQK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96C3521741 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5788C6B0008; Sat, 8 Feb 2020 03:37:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4FFD96B000A; Sat, 8 Feb 2020 03:37:40 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3038B6B000C; Sat, 8 Feb 2020 03:37:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id 193916B0008 for ; Sat, 8 Feb 2020 03:37:40 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9EC26181AEF00 for ; Sat, 8 Feb 2020 08:37:39 +0000 (UTC) X-FDA: 76466306238.27.price09_89b07d9a1f12 X-Spam-Summary: 2,0,0,998a1769d0609b0a,d41d8cd98f00b204,lixinhai.lxh@gmail.com,::akpm@linux-foundation.org:kirill.shutemov@linux.intel.com:willy@infradead.org:hannes@cmpxchg.org,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3868:3870:3871:3874:5007:6261:6653:7514:7903:9413:9592:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12986:13069:13311:13357:14096:14181:14384:14394:14687:14721:21080:21222:21365:21444:21451:21627:21666:21740:21789:30012:30054,0,RBL:209.85.208.195:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: price09_89b07d9a1f12 X-Filterd-Recvd-Size: 4829 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Sat, 8 Feb 2020 08:37:38 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id x14so1738130ljd.13 for ; Sat, 08 Feb 2020 00:37:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1DOw5CbbkNYP7FwQdD8qSzaPYEShSYioAUQqNAIQfdY=; b=cWjUoJQKmZ8C3F5DtZz0Rl/lsjnzEGM5g7rKcVy06kF3hSdednyyh59sl/SrJv7RBZ pVAUhkA8AJFeSqBc0a5jWbHq0henpKU9WX29p/IMwTRN/LwLLLCoRIeUV4oRHfss/BZz HYiWQ0UkD7i1vGGgbpWaOTmJ6H5Dxi8vDl3zOMv1QaL17ldW+1etB8cPcPlkq++WiZIU T15O41gcrAShIxVyy9oOaGKMuCJPDnWqOcYuSSx8EnAobZe4WOJWL6o0oW+Vj9L+LStL bipK6SPzoFvdP/ygg3kgo+P4rM0eRPDSDwU4wtqBavmjijqDABjb/+udHcy/NpcwbYjo GZPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1DOw5CbbkNYP7FwQdD8qSzaPYEShSYioAUQqNAIQfdY=; b=jH8Li90Sna8Z23TBAxJ/GEvWIpCjBjMwbFid3TPBROSkzaGY6QrRl1tQ0c6LuCbjku TvEbubflNExUQWVHLOOU7eexmj1KB+L5CNw7k7GQsno7xhW9nXtDuAl1byxrF+MB//+6 /gfg+GG5GhbWxmmAIBsKu0+O1DlnKRcBpOH6lvmqv4TSUlca0v424fOuMEaZnKbApas4 OkvUtpM6idfoqXiqaW3lQ09lrG4KOYXy2jglxUUiHm1KW+P8fqheUYhbENQPHEMlpXXz Int67nmSsgjOmquLY7H1aa36p8ZOoHhQiQeWl/vBhz8CVPXJIFYg9qOjfcV+Fc7RUtkk FU+A== X-Gm-Message-State: APjAAAVrD+m5qZ8sOTr06KD2G4ED0iCPLIBQmlAj5TWYol3odMW8eZq5 zPMOMqJSrG6J/6M3WhsM+mfv6kBEht8= X-Google-Smtp-Source: APXvYqzwQhZbgdaSQIB6j3niKwDhCjmx+2ZxfM6IA3uZw+QqRwaqq9YsYbv6PD61L7QsopT9Dexgrg== X-Received: by 2002:a2e:884c:: with SMTP id z12mr2162198ljj.55.1581151057670; Sat, 08 Feb 2020 00:37:37 -0800 (PST) Received: from localhost.localdomain.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id n11sm2663404ljg.15.2020.02.08.00.37.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 00:37:37 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, "Kirill A. Shutemov" , Matthew Wilcox , Johannes Weiner Subject: [PATCH 2/3] Revert "mm/rmap.c: reuse mergeable anon_vma as parent when fork" Date: Sat, 8 Feb 2020 08:35:27 +0000 Message-Id: <1581150928-3214-3-git-send-email-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1581150928-3214-1-git-send-email-lixinhai.lxh@gmail.com> References: <1581150928-3214-1-git-send-email-lixinhai.lxh@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This reverts commit 4e4a9eb921332b9d1edd99f76998f99f36b195f7 In dup_mmap(), anon_vma_fork() is called for attaching anon_vma and parameter 'tmp' (i.e., the new vma of child) has same ->vm_next and ->vm_prev as its parent vma. That causes the anon_vma used by parent been mistakenly shared by child (In anon_vma_clone(), the code added by that commit will do this reuse work). Besides this issue, the design of reusing anon_vma from vma which has gone through fork should be avoided ([1]). So, this patch reverts that commit and maintains the consistent logic of reusing anon_vma for fork/split/merge vma. [1] commit d0e9fe1758f2 ("Simplify and comment on anon_vma re-use for anon_vma_prepare()") explains the test of "list_is_singular()". Fixes: 4e4a9eb92133 ("mm/rmap.c: reuse mergeable anon_vma as parent when fork") Signed-off-by: Li Xinhai Cc: Kirill A. Shutemov Cc: Matthew Wilcox Cc: Johannes Weiner --- mm/rmap.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index b3e3819..861435b 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -269,19 +269,6 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) { struct anon_vma_chain *avc, *pavc; struct anon_vma *root = NULL; - struct vm_area_struct *prev = dst->vm_prev, *pprev = src->vm_prev; - - /* - * If parent share anon_vma with its vm_prev, keep this sharing in in - * child. - * - * 1. Parent has vm_prev, which implies we have vm_prev. - * 2. Parent and its vm_prev have the same anon_vma. - */ - if (!dst->anon_vma && src->anon_vma && - pprev && pprev->anon_vma == src->anon_vma) - dst->anon_vma = prev->anon_vma; - list_for_each_entry_reverse(pavc, &src->anon_vma_chain, same_vma) { struct anon_vma *anon_vma; From patchwork Sat Feb 8 08:35:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11371499 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FB7313A4 for ; Sat, 8 Feb 2020 08:37:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFA6C21741 for ; Sat, 8 Feb 2020 08:37:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ljxpLjut" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFA6C21741 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 01D266B000C; Sat, 8 Feb 2020 03:37:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F0FDF6B000D; Sat, 8 Feb 2020 03:37:41 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D896A6B000E; Sat, 8 Feb 2020 03:37:41 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id BE46C6B000C for ; Sat, 8 Feb 2020 03:37:41 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6CEC8249F for ; Sat, 8 Feb 2020 08:37:41 +0000 (UTC) X-FDA: 76466306322.05.flesh74_8e21174b585f X-Spam-Summary: 2,0,0,244c050d2af52a47,d41d8cd98f00b204,lixinhai.lxh@gmail.com,::akpm@linux-foundation.org:kirill.shutemov@linux.intel.com:willy@infradead.org:hannes@cmpxchg.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:3868:3870:4250:4321:5007:6261:6653:7514:9413:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13069:13153:13161:13228:13229:13311:13357:14181:14384:14394:14687:14721:21080:21444:21451:21627:21666:21990:30054,0,RBL:209.85.208.195:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: flesh74_8e21174b585f X-Filterd-Recvd-Size: 4073 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Sat, 8 Feb 2020 08:37:40 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id w1so1788949ljh.5 for ; Sat, 08 Feb 2020 00:37:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/6GyCmOdNDkGYSFzgyq/aYodLQz4kK1nBI1CPz/kIME=; b=ljxpLjutlIdHkR0uLyjd+8l6clX1XNNoR+OyWtke/XXzgQjDgqWuDKENrrJ54ZB2/0 PiD4EJHyvgWLX1/rB8OtYncR66tU4W9fhfRLgGOWtK7hKf+nFnhCDrCSajmZAwqgW12V R/kb7sJuDLvL1fRXlRV+2umBsaVAqHj50Wb44RN4CBPH4VXOSe22lC1J72Uu8oSpwRVp sPBtTkHAbkBQySGgbgZqmyq/OIeKJ+fgK8wEPAUQVY3N6WMt6XSgHr3yeVTgFun0UnGd D033O5sZBduljiDU7+ztwfgt++rtP+LUYilOtMkxLkucBzVOBKSjpMyGXwDTf9xAGV9p Hweg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/6GyCmOdNDkGYSFzgyq/aYodLQz4kK1nBI1CPz/kIME=; b=CU61PxvKS4QFzQIoR2qJdTv9MAvPpY2g7D819p/YRdFbyxUh74Mq/JbhWBRCoePzFN /Bcnt3+tQi8T0riEoZ+HBBLWu9n/DGD/1dkqC9gCpmIFm6iGiR/v/YjovGXdSI78Q0lX lspx19ZY35+MLc6ZJbP6vr7JMvfEbEtBO5GIgvqOYjqp8bR/iOI5C4IWvVB/qA5K0tvw t51rRykrf1yggzQ6ZnndNfGVS0eDJVlhkFx7pYsAgfwJF0e8wyTEMZaSLdXqo6/SYOAS 7FTQtND4GxZVs8Pd+y8qPzI1PSSBrrWSjTIuHS782d6Epq64vDn+RW82K4sSk5KN3NZB Lu9w== X-Gm-Message-State: APjAAAUl5ZCfJVpQYHkE9b9ZHDU4B3bE9OXDprPgFAiI7LyM3/GXtvyc zImjS7bdGd5YwAE5Yd0bEw1tHqRM+nY= X-Google-Smtp-Source: APXvYqzm3Qojf/tICk6Wb9E70etSbdMBJO1V+mGp/tXVn6Lm3D/u2C70IdWYpcxKPXRA7tkv/bwEVw== X-Received: by 2002:a2e:8e63:: with SMTP id t3mr2095812ljk.239.1581151059643; Sat, 08 Feb 2020 00:37:39 -0800 (PST) Received: from localhost.localdomain.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id n11sm2663404ljg.15.2020.02.08.00.37.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 00:37:39 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, "Kirill A. Shutemov" , Matthew Wilcox , Johannes Weiner Subject: [PATCH 3/3] mm: set vm_next and vm_prev to NULL in vm_area_dup() Date: Sat, 8 Feb 2020 08:35:28 +0000 Message-Id: <1581150928-3214-4-git-send-email-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1581150928-3214-1-git-send-email-lixinhai.lxh@gmail.com> References: <1581150928-3214-1-git-send-email-lixinhai.lxh@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Set ->vm_next and ->vm_prev to NULL to prevent potential misuse from the new duplicated vma. Currently, only in fork path there are misuse for handling anon_vma. No other bugs been revealed with this patch applied. Signed-off-by: Li Xinhai Cc: Kirill A. Shutemov Cc: Matthew Wilcox Cc: Johannes Weiner Acked-by: Kirill A. Shutemov --- kernel/fork.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index 1bbd49a..eb3a148 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -361,6 +361,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) if (new) { *new = *orig; INIT_LIST_HEAD(&new->anon_vma_chain); + new->vm_next = new->vm_prev = NULL; } return new; } @@ -561,7 +562,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, } else if (anon_vma_fork(tmp, mpnt)) goto fail_nomem_anon_vma_fork; tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT); - tmp->vm_next = tmp->vm_prev = NULL; file = tmp->vm_file; if (file) { struct inode *inode = file_inode(file);