From nobody Sun Jun 28 00:59:35 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4492AC433FE for ; Thu, 17 Feb 2022 06:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235524AbiBQGnn (ORCPT ); Thu, 17 Feb 2022 01:43:43 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbiBQGnk (ORCPT ); Thu, 17 Feb 2022 01:43:40 -0500 X-Greylist: delayed 292 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 16 Feb 2022 22:43:24 PST Received: from ha.nfschina.com (unknown [IPv6:2400:dd01:100f:2:72e2:84ff:fe10:5f45]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2809714864F; Wed, 16 Feb 2022 22:43:23 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by ha.nfschina.com (Postfix) with ESMTP id 45DF81E80D5E; Thu, 17 Feb 2022 14:34:06 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from ha.nfschina.com ([127.0.0.1]) by localhost (ha.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ck-wX0osscM8; Thu, 17 Feb 2022 14:34:03 +0800 (CST) Received: from localhost.localdomain (unknown [180.167.10.98]) (Authenticated sender: liqiong@nfschina.com) by ha.nfschina.com (Postfix) with ESMTPA id 3FAA61E80CB5; Thu, 17 Feb 2022 14:34:03 +0800 (CST) From: liqiong To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, liqiong , stable@vger.kernel.org Subject: [PATCH] mm: fix dereference a null pointer in migrate[_huge]_page_move_mapping() Date: Thu, 17 Feb 2022 14:38:08 +0800 Message-Id: <20220217063808.42018-1-liqiong@nfschina.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Upstream has no this bug. The two functions look up a slot and dereference the pointer, If the pointer is null, the kernel would crash and dump. The 'numad' service calls 'migrate_pages' periodically. If some slots being replaced (Cache Eviction), the radix_tree_lookup_slot() returns a null pointer, then, kernel crash. "numad": crash> bt [exception RIP: migrate_page_move_mapping+337] Introduct a pointer checking to avoid dereference a null pointer. Cc: # v4.19-rc8 Signed-off-by: liqiong --- mm/migrate.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index 84381b55b2bd..1ff95c259511 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -474,6 +474,10 @@ int migrate_page_move_mapping(struct address_space *ma= pping, =20 pslot =3D radix_tree_lookup_slot(&mapping->i_pages, page_index(page)); + if (pslot =3D=3D NULL) { + xa_unlock_irq(&mapping->i_pages); + return -EAGAIN; + } =20 expected_count +=3D hpage_nr_pages(page) + page_has_private(page); if (page_count(page) !=3D expected_count || @@ -592,6 +596,10 @@ int migrate_huge_page_move_mapping(struct address_spac= e *mapping, xa_lock_irq(&mapping->i_pages); =20 pslot =3D radix_tree_lookup_slot(&mapping->i_pages, page_index(page)); + if (pslot =3D=3D NULL) { + xa_unlock_irq(&mapping->i_pages); + return -EAGAIN; + } =20 expected_count =3D 2 + page_has_private(page); if (page_count(page) !=3D expected_count || --=20 2.25.1