From patchwork Tue Jul 9 11:58:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13727745 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 940C7C2BD09 for ; Tue, 9 Jul 2024 12:03:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B68E6B00A2; Tue, 9 Jul 2024 08:03:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03F216B00A4; Tue, 9 Jul 2024 08:03:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E228C6B00A5; Tue, 9 Jul 2024 08:03:15 -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 C37096B00A2 for ; Tue, 9 Jul 2024 08:03:15 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 70717A5060 for ; Tue, 9 Jul 2024 12:03:15 +0000 (UTC) X-FDA: 82320078750.21.C777FC2 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf30.hostedemail.com (Postfix) with ESMTP id 26A8980022 for ; Tue, 9 Jul 2024 12:03:10 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.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=1720526577; a=rsa-sha256; cv=none; b=cIlzhQp7EhNTJmPDpknVHhLwGmQU66vwwKcbIXg7JoCMlTn4El7B/2aP69JC4EmiZJ2k2U 0u7AUbshke6jF+U5qk0OTKObSpPDykxx1WgzEWEhPnQLZnbpsQUwFKx+QKtaFWVRHF1BHn CQAI3UFdQwLfNmfmHyUlJZ4yGLl19bo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.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=1720526577; 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=vvLjZPfLPhpp4dZE53SqBfN8Pokdgwk93JPMGez8y5I=; b=nkri4P8u9iwTYh6djj/MFDKOtd1s34ok+/wNDFombTQvpJ06fjZN6HeU5F0TVG9T/mzz6Q iF9ImARduTX6fuUd4JfERFzUV2/6EJOXi20iw35DdCoaWTI0KDZNh/y8wbyy+OD/GWAGHm gt82QcToqJ4mwM2uAb0tuQD8gBare2I= Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WJKJQ0VBgzxVnq; Tue, 9 Jul 2024 19:58:30 +0800 (CST) Received: from kwepemd200019.china.huawei.com (unknown [7.221.188.193]) by mail.maildlp.com (Postfix) with ESMTPS id 30D961402C6; Tue, 9 Jul 2024 20:03:04 +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:03:03 +0800 From: Miaohe Lin To: , , , CC: , , Subject: [PATCH] mm/hugetlb: fix kernel NULL pointer dereference when migrating hugetlb folio Date: Tue, 9 Jul 2024 19:58:41 +0800 Message-ID: <20240709115841.4098393-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-Stat-Signature: 8zxhdazt1797yrodrj6wuug6a9wmek6x X-Rspamd-Queue-Id: 26A8980022 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1720526590-482509 X-HE-Meta: U2FsdGVkX1/x+KA7F+B9q19GqYgEYV8/wwNa74VXbqaW6A4pB/6CbpE4ndJSEzZ9d1EEBRVjRrUCtVTCmyj5OvYn1NyVqWc8hfmxDWyFblv4ncBNkrt5+EmMFgjVgrmDIxQldYBDmDA+ZsfbhMSXptCXEB5nJZyXgN+BjBZnbOGFGqcJvVpPDO35nhdk/3hdAw2MYHPygwvqL6pBl/FGtBIrqgEL6Lz0sLvoI2wab+/iKN6RY4e6Oh1sQ+LtEFVudRD5UWytaN9V3llwFYiu04cgcgBrSt30u0L/H5Aqckh3PtrFcbeUznRxCAwpUZSNBBRRdlcIQOeyRBzSX7v1V3rmn9grLEX+rQhraRgJPjotGmxoMgnT1D7Kus5t5+dEFGlnyz9PI2jhMGYk5kjTvrWPebR0cRAwbYrq+14Zvyr7ucxAkBP6njnmRGHzA5qAHL1ulYx034BbkOCbCPl/5cGEdB93QMmyUuY9R9AlNViKffuh/Jx6W5L92FREUaf6pcGIbUMtVLHfZ52/85IJcwufkrvpyJ2pOC1k9LXvWfTQK1I4XpetOUVpEmy7PunzOhRxMG8MT3uI++xMNW3knrzuQeZsyycf1XrQVvkk61x5u2yp5pkW0oJSDQqrlEPA60dq1SucOtXH1T0FGh9XeHX4Zq06KUClpK7C3qhfDLAa7CIemJsyN4CHVjqoZcICS5qjk1GSb0J0tymtH7G41/0PE39VtIAxQssycPwT+M0i8MUQkZZMtSFEKlZCWCxXRHZnR4umpiWGKxNZqOUdZJB4fnsMNhbQFX7X/9rwKFXLns2db1mQENv8U8+DtKIuZmog+dTGZGRD3RymqAK+KX91aYhUtsqN0erwXx/cOm2r2aKIdqOKHcGwCLvD7VtwpNew1+sEIWqiN0j7CIneEytXIS0/5Ke5QQkmgJNTi4Fdj4gLP8CmsQJXB42ggAJXhZgomw9ZIupXTiri40/ 54CbKAXE 3CO3Zjz0ZnXJjPjBkHBz26F0nBwOvKlXuNtqRm9pORqSgLn1+ynBA4HKbVKbYJQ8zdzvPldFEkKDBs94VIF52RGeEQBaZfYrB8/Pr4LpABmwNQRIZ8qkNEHbEK/gYpuYbjHn0ueMfOheqMO02KUCJhzWEqDDltTOr/oKAlg1B+k33b/8xle1/x3NjJHNy1uM+2pOF15P2H91hND8= 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 6282dd9e37e3..4e288757da19 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2173,6 +2173,8 @@ 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. */ + folio_clear_large_rmappable(folio); if (folio && !folio_ref_freeze(folio, 1)) { folio_put(folio);