From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1A12FA3740 for ; Mon, 31 Oct 2022 07:41:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1EF96B0071; Mon, 31 Oct 2022 03:41:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA6FE6B0073; Mon, 31 Oct 2022 03:41:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C46FE6B0074; Mon, 31 Oct 2022 03:41:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9A4D16B0071 for ; Mon, 31 Oct 2022 03:41:44 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2B763A06E1 for ; Mon, 31 Oct 2022 07:41:44 +0000 (UTC) X-FDA: 80080450128.06.3C8CC0E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id B911DA0012 for ; Mon, 31 Oct 2022 07:41:42 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7C5DC61000; Mon, 31 Oct 2022 07:41:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A973C433D7; Mon, 31 Oct 2022 07:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1667202100; bh=ypV8SXPSQKlxLPe6d4cCz9+wTTDfUGAMpDBflqs8sAw=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=wEUMh9I3QuxFGaFrIC2zHJn5nU0iJZ/dhkx1ptjwzIPy7ATDG8hA9eQzGNwXqcsTz eOFvdtKmUmOeg4cqI7wVXaOj0mJwGeVrUnmlXaFrO0nuHarBvlFASkTeJFsTlVSAd8 BzsBZrbg7TfYT6gBBgo0KcESzQHaBiBWrdQdjjrs= Subject: Patch "mm/memory: add non-anonymous page check in the copy_present_page()" has been added to the 5.10-stable tree To: akpm@linux-foundation.org,david@redhat.com,gregkh@linuxfoundation.org,hughd@google.com,linux-mm@kvack.org,peterx@redhat.com,songyuanzheng@huawei.com Cc: From: Date: Mon, 31 Oct 2022 08:39:22 +0100 In-Reply-To: <20221028030705.2840539-1-songyuanzheng@huawei.com> Message-ID: <1667201962240124@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit X-stable: commit X-Patchwork-Hint: ignore ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=wEUMh9I3; spf=pass (imf15.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667202103; a=rsa-sha256; cv=none; b=FaCR5L+iIcMrgIwTxVOzbtpzalc7V93NeSYfvdOsmEKKSjtOgnbtThZ5w9Lsq3rYzDBjaL c99ccIYyIKtn+LQ3rgE73HHIeX8JfRoyiHzQh74e7f3lrmrdruNb1c/SLIdeDHeT+P75xf voPc1N4NGAgO/lHNROmSSBf+onZ+xxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667202103; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:dkim-signature; bh=t6zdPi6jY45KSEML2To3JdjNx94RPKrZmKB8DTJEiys=; b=p5JpKy8Ntp6Q+u0KIlEsMyTg8LZnJ5YbWMSuQkAjOzfX9mDFZdlO7jtTBYgG1VSMEI+k9w KYUui5SRBWqqwq6FS3DRTQps/yfvndxOSeogS6Ohz597eBlRhovhsAaO3PBhuM++vjeudd C/bXHaL9F9T/M/pCGy5xRmTPqTOKfXk= X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=wEUMh9I3; spf=pass (imf15.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org X-Rspamd-Server: rspam07 X-Stat-Signature: bnkh9u8qw51ibhywx78e4hxriye968k6 X-Rspamd-Queue-Id: B911DA0012 X-HE-Tag: 1667202102-18599 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 is a note to let you know that I've just added the patch titled mm/memory: add non-anonymous page check in the copy_present_page() to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: mm-memory-add-non-anonymous-page-check-in-the-copy_present_page.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From songyuanzheng@huawei.com Mon Oct 31 08:38:39 2022 From: Yuanzheng Song Date: Fri, 28 Oct 2022 03:07:05 +0000 Subject: mm/memory: add non-anonymous page check in the copy_present_page() To: , , Cc: , , , , Message-ID: <20221028030705.2840539-1-songyuanzheng@huawei.com> From: Yuanzheng Song The vma->anon_vma of the child process may be NULL because the entire vma does not contain anonymous pages. In this case, a BUG will occur when the copy_present_page() passes a copy of a non-anonymous page of that vma to the page_add_new_anon_rmap() to set up new anonymous rmap. ------------[ cut here ]------------ kernel BUG at mm/rmap.c:1044! Internal error: Oops - BUG: 0 [#1] SMP Modules linked in: CPU: 2 PID: 3617 Comm: test Not tainted 5.10.149 #1 Hardware name: linux,dummy-virt (DT) pstate: 80000005 (Nzcv daif -PAN -UAO -TCO BTYPE=--) pc : __page_set_anon_rmap+0xbc/0xf8 lr : __page_set_anon_rmap+0xbc/0xf8 sp : ffff800014c1b870 x29: ffff800014c1b870 x28: 0000000000000001 x27: 0000000010100073 x26: ffff1d65c517baa8 x25: ffff1d65cab0f000 x24: ffff1d65c416d800 x23: ffff1d65cab5f248 x22: 0000000020000000 x21: 0000000000000001 x20: 0000000000000000 x19: fffffe75970023c0 x18: 0000000000000000 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 x11: 0000000000000000 x10: 0000000000000000 x9 : ffffc3096d5fb858 x8 : 0000000000000000 x7 : 0000000000000011 x6 : ffff5a5c9089c000 x5 : 0000000000020000 x4 : ffff5a5c9089c000 x3 : ffffc3096d200000 x2 : ffffc3096e8d0000 x1 : ffff1d65ca3da740 x0 : 0000000000000000 Call trace: __page_set_anon_rmap+0xbc/0xf8 page_add_new_anon_rmap+0x1e0/0x390 copy_pte_range+0xd00/0x1248 copy_page_range+0x39c/0x620 dup_mmap+0x2e0/0x5a8 dup_mm+0x78/0x140 copy_process+0x918/0x1a20 kernel_clone+0xac/0x638 __do_sys_clone+0x78/0xb0 __arm64_sys_clone+0x30/0x40 el0_svc_common.constprop.0+0xb0/0x308 do_el0_svc+0x48/0xb8 el0_svc+0x24/0x38 el0_sync_handler+0x160/0x168 el0_sync+0x180/0x1c0 Code: 97f8ff85 f9400294 17ffffeb 97f8ff82 (d4210000) ---[ end trace a972347688dc9bd4 ]--- Kernel panic - not syncing: Oops - BUG: Fatal exception SMP: stopping secondary CPUs Kernel Offset: 0x43095d200000 from 0xffff800010000000 PHYS_OFFSET: 0xffffe29a80000000 CPU features: 0x08200022,61806082 Memory Limit: none ---[ end Kernel panic - not syncing: Oops - BUG: Fatal exception ]--- This problem has been fixed by the commit ("mm/rmap: split page_dup_rmap() into page_dup_file_rmap() and page_try_dup_anon_rmap()"), but still exists in the linux-5.10.y branch. This patch is not applicable to this version because of the large version differences. Therefore, fix it by adding non-anonymous page check in the copy_present_page(). Cc: stable@vger.kernel.org Fixes: 70e806e4e645 ("mm: Do early cow for pinned pages during fork() for ptes") Signed-off-by: Yuanzheng Song Acked-by: Peter Xu Signed-off-by: Greg Kroah-Hartman --- mm/memory.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/mm/memory.c +++ b/mm/memory.c @@ -823,6 +823,17 @@ copy_present_page(struct vm_area_struct if (likely(!page_maybe_dma_pinned(page))) return 1; + /* + * The vma->anon_vma of the child process may be NULL + * because the entire vma does not contain anonymous pages. + * A BUG will occur when the copy_present_page() passes + * a copy of a non-anonymous page of that vma to the + * page_add_new_anon_rmap() to set up new anonymous rmap. + * Return 1 if the page is not an anonymous page. + */ + if (!PageAnon(page)) + return 1; + new_page = *prealloc; if (!new_page) return -EAGAIN; Patches currently in stable-queue which might be from songyuanzheng@huawei.com are queue-5.10/mm-memory-add-non-anonymous-page-check-in-the-copy_present_page.patch