From patchwork Thu Feb 17 11:54:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiong X-Patchwork-Id: 12749916 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 CC595C433FE for ; Thu, 17 Feb 2022 11:54:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F09C6B0074; Thu, 17 Feb 2022 06:54:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 179B06B0075; Thu, 17 Feb 2022 06:54:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 019E46B0078; Thu, 17 Feb 2022 06:54:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id E18656B0074 for ; Thu, 17 Feb 2022 06:54:27 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 968F8181AC9C6 for ; Thu, 17 Feb 2022 11:54:27 +0000 (UTC) X-FDA: 79152114174.27.B026B93 Received: from ha.nfschina.com (unknown [124.16.136.209]) by imf08.hostedemail.com (Postfix) with ESMTP id 3285E160003 for ; Thu, 17 Feb 2022 11:54:26 +0000 (UTC) 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 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3285E160003 X-Stat-Signature: i89oseeo9zc3cbjdu37t6opn1ni899pu X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=none (imf08.hostedemail.com: domain of liqiong@nfschina.com has no SPF policy when checking 124.16.136.209) smtp.mailfrom=liqiong@nfschina.com X-HE-Tag: 1645098866-932905 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: 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 *mapping, pslot = radix_tree_lookup_slot(&mapping->i_pages, page_index(page)); + if (pslot == NULL) { + xa_unlock_irq(&mapping->i_pages); + return -EAGAIN; + } expected_count += hpage_nr_pages(page) + page_has_private(page); if (page_count(page) != expected_count || @@ -590,6 +594,10 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, xa_lock_irq(&mapping->i_pages); pslot = radix_tree_lookup_slot(&mapping->i_pages, page_index(page)); + if (pslot == NULL) { + xa_unlock_irq(&mapping->i_pages); + return -EAGAIN; + } expected_count = 2 + page_has_private(page); if (page_count(page) != expected_count ||