From nobody Sun Jun 28 00:12:27 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 A9106C433EF for ; Thu, 17 Feb 2022 11:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240072AbiBQLyk (ORCPT ); Thu, 17 Feb 2022 06:54:40 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233179AbiBQLyj (ORCPT ); Thu, 17 Feb 2022 06:54:39 -0500 Received: from ha.nfschina.com (unknown [IPv6:2400:dd01:100f:2:72e2:84ff:fe10:5f45]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 547D0291FA6; Thu, 17 Feb 2022 03:54:24 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by ha.nfschina.com (Postfix) with ESMTP id 0C2121E80D5E; Thu, 17 Feb 2022 19:49:57 +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 kVcriJz6XfI6; Thu, 17 Feb 2022 19:49:54 +0800 (CST) Received: from localhost.localdomain (unknown [180.167.10.98]) (Authenticated sender: liqiong@nfschina.com) by ha.nfschina.com (Postfix) with ESMTPA id 0DE371E80CB5; Thu, 17 Feb 2022 19:49:54 +0800 (CST) From: liqiong To: david@redhat.com, gregkh@linuxfoundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, liqiong , stable@vger.kernel.org Subject: [PATCH] [PATCH 4.19 STABLE] mm: fix dereference a null pointer in migrate[_huge]_page_move_mapping() Date: Thu, 17 Feb 2022 19:54:16 +0800 Message-Id: <20220217115416.55835-1-liqiong@nfschina.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220217063808.42018-1-liqiong@nfschina.com> References: <20220217063808.42018-1-liqiong@nfschina.com> 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 doesn't use radix tree any more in migrate.c, no need this patch. 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 that causes kernel crash. "numad": crash> bt [exception RIP: migrate_page_move_mapping+337] Introduce pointer checking to avoid dereference a null pointer. Cc: # linux-4.19.y Signed-off-by: liqiong --- mm/migrate.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index a69b842f95da..76f8dedc0e02 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -472,6 +472,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 || @@ -590,6 +594,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