From patchwork Tue Jul 9 12:04:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13727748 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 E8974C3DA47 for ; Tue, 9 Jul 2024 12:09:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 686E56B00A2; Tue, 9 Jul 2024 08:09:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6362B6B00A4; Tue, 9 Jul 2024 08:09:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 525086B00A7; Tue, 9 Jul 2024 08:09:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 352FB6B00A2 for ; Tue, 9 Jul 2024 08:09:06 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D0B1CA18A8 for ; Tue, 9 Jul 2024 12:09:05 +0000 (UTC) X-FDA: 82320093450.15.9B381F8 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf09.hostedemail.com (Postfix) with ESMTP id 7040B14001C for ; Tue, 9 Jul 2024 12:09:03 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720526903; 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: references; bh=xy8WIlaU7Q4VjK79UPRPt0vQWYNmJyliivblggbQWRc=; b=vfpJzxe9I7d9a94/kopzbZf6VZ/jkPZlSKrha+VjTRaKPHkfQjlcCrYkjEqshaofodrhhE kH1JA+GJSYF9hfDE/+RDVAaNuUsTtGGeuPi6Dnj5ZAwCaXBmBLEc+pgMU+sCBEBN2VoNVg Z6fhy2ZoAJdt4zoahgfFkpGN2mlnPdM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720526903; a=rsa-sha256; cv=none; b=SYK29KJ4WT6CfPmOUJHoSARD0XZPfre3hLSDLgbZW9TrKSa+UjD0so4vvs0e+IQ9QjY1g6 u+GwKF0+l5xPA76MWgUMSS8kDJ815eTuuol6TP19Hz4HvKOGJoFKRl4a4UaBslzBj6OIZb iZMwZbvNfYcURISDLj/MjAZj93a9p+M= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WJKRD3WB5zxVdJ; Tue, 9 Jul 2024 20:04:24 +0800 (CST) Received: from kwepemd200019.china.huawei.com (unknown [7.221.188.193]) by mail.maildlp.com (Postfix) with ESMTPS id 9F2AE180ADD; Tue, 9 Jul 2024 20:08:58 +0800 (CST) Received: from huawei.com (10.173.127.72) by kwepemd200019.china.huawei.com (7.221.188.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 9 Jul 2024 20:08:57 +0800 From: Miaohe Lin To: , , , CC: , , Subject: [PATCH RESEND] mm/hugetlb: fix kernel NULL pointer dereference when migrating hugetlb folio Date: Tue, 9 Jul 2024 20:04:33 +0800 Message-ID: <20240709120433.4136700-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.173.127.72] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd200019.china.huawei.com (7.221.188.193) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7040B14001C X-Stat-Signature: th5mqwaqc5gqmrjpbgwpqtjekt8k51q4 X-Rspam-User: X-HE-Tag: 1720526943-951247 X-HE-Meta: U2FsdGVkX1/EAYTrF0iPs5fV1I3JHQE1T15hl+BwEog5U5csXlXGzaxwOaspOHMR5z8ynjS2nIZ/kAx9xEWvR3DyfKIjzoMxDhO9vbhZ2WNmAwHfUzg92aJyFi2s8GQjJzl6VRVfkqlJJOF2vEemYXdQG7M3oLn7SWqPQ71p46PoRwDsq2IJ4JvsboXhOVwa3uZL7ykB4GEpPtLWlBOBhP41Lw5woegz01IZzNzACStYdqyMwV4qp25ZxZ12Iw86L6FV/7dKFMSd4+cG7Ez0McwdfYkoVITX/YjKI9cWnPG/CxeAXOqFcNx0acLeufyTn65glHWapWBanXiXI2DcRyH+hYb+L7ldB7TXy16FV1/jnRNoQmhAW0gg71yzmAlyQG0R4gB420r/PyorJI/QU5ZGNR9lGi7ZxDCjDkrxJ+4LzN7VQfiiXvRTxZrcTKVyu6jEuV871W0BULc+aNhBJMWVWOq4aQABLZn9SWB6yaPMeA4uQdllo5OKnLnd786xSt6455xg6/0JcAKEMdVH//JJ9CkOjiu1P/tXO0bdpj5pun3KBKbl6um/MudZDVYP2hJYZJ5J7biY3S/cLcqhWZaFRDRrp0kfG5hubELeVaDfFPlcZw7o1k9b+BxcVPjfSfB8dEHVlHzbTNyGPAmsDWWTSKqJTcMXJ8bec3h/9sR+Uwz+f/B8EN8b40FBHjL7s8OMEFhYWhY2UB1OYlnNJiBN0SDvBcTPBjG0COelsGk20h6WMzDgcN3diKPNuABvPbehuoGxK0iQe6Sh0W1SEk3bJH7WCJSc+gZWzj+lCDa0RbM41lUyf3piOu4hq4O1tFzNysz6R9KX2ULZfL65ArUb8DfBBrjx6KnWcKh++/ecjAK1PEEL6KnfwycGJQBfeuE/LZlozfYPQWaJZGPPnvWZmAa3xsfjOgSDTm1aRMWdJ3vsfea624QSNgE3ZCyUbWZKJgCTrI08oahdd+I 7wrFOGXI OZDVdYxXJgiD6DypwJsJA6nCu1JH3h+RYJbraf7EXPL1idaNGxaLnDWjp6MQ9FYMIwgS4eSxm06lJs3Lw4vmhQliQkkb+2KBymlS9LHPCRBPMEH95WA8AroadWjy6JKtC3lerKEdhgJnLrMhFtSvIH7wlkmID3SphyhBaavU19NNKqEvkPgWkUP3FY+6VRjEE/7JkbKIJx8icfqE= 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: List-Subscribe: List-Unsubscribe: A kernel crash was observed when migrating hugetlb folio: BUG: kernel NULL pointer dereference, address: 0000000000000008 PGD 0 P4D 0 Oops: Oops: 0002 [#1] PREEMPT SMP NOPTI CPU: 0 PID: 3435 Comm: bash Not tainted 6.10.0-rc6-00450-g8578ca01f21f #66 RIP: 0010:__folio_undo_large_rmappable+0x70/0xb0 RSP: 0018:ffffb165c98a7b38 EFLAGS: 00000097 RAX: fffffbbc44528090 RBX: 0000000000000000 RCX: 0000000000000000 RDX: ffffa30e000a2800 RSI: 0000000000000246 RDI: ffffa3153ffffcc0 RBP: fffffbbc44528000 R08: 0000000000002371 R09: ffffffffbe4e5868 R10: 0000000000000001 R11: 0000000000000001 R12: ffffa3153ffffcc0 R13: fffffbbc44468000 R14: 0000000000000001 R15: 0000000000000001 FS: 00007f5b3a716740(0000) GS:ffffa3151fc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000008 CR3: 000000010959a000 CR4: 00000000000006f0 Call Trace: __folio_migrate_mapping+0x59e/0x950 __migrate_folio.constprop.0+0x5f/0x120 move_to_new_folio+0xfd/0x250 migrate_pages+0x383/0xd70 soft_offline_page+0x2ab/0x7f0 soft_offline_page_store+0x52/0x90 kernfs_fop_write_iter+0x12c/0x1d0 vfs_write+0x380/0x540 ksys_write+0x64/0xe0 do_syscall_64+0xb9/0x1d0 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f5b3a514887 RSP: 002b:00007ffe138fce68 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 000000000000000c RCX: 00007f5b3a514887 RDX: 000000000000000c RSI: 0000556ab809ee10 RDI: 0000000000000001 RBP: 0000556ab809ee10 R08: 00007f5b3a5d1460 R09: 000000007fffffff R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000c R13: 00007f5b3a61b780 R14: 00007f5b3a617600 R15: 00007f5b3a616a00 It's because hugetlb folio is passed to __folio_undo_large_rmappable() unexpectedly. large_rmappable flag is imperceptibly set to hugetlb folio since commit f6a8dd98a2ce ("hugetlb: convert alloc_buddy_hugetlb_folio to use a folio"). Then commit be9581ea8c05 ("mm: fix crashes from deferred split racing folio migration") makes folio_migrate_mapping() call folio_undo_large_rmappable() triggering the bug. Fix this issue by clearing large_rmappable flag for hugetlb folios. They don't need that flag set anyway. Fixes: f6a8dd98a2ce ("hugetlb: convert alloc_buddy_hugetlb_folio to use a folio") Fixes: be9581ea8c05 ("mm: fix crashes from deferred split racing folio migration") Signed-off-by: Miaohe Lin Cc: --- mm/hugetlb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 6282dd9e37e3..45fd3bc75332 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2173,6 +2173,9 @@ static struct folio *alloc_buddy_hugetlb_folio(struct hstate *h, nid = numa_mem_id(); retry: folio = __folio_alloc(gfp_mask, order, nid, nmask); + /* Ensure hugetlb folio won't have large_rmappable flag set. */ + if (folio) + folio_clear_large_rmappable(folio); if (folio && !folio_ref_freeze(folio, 1)) { folio_put(folio);