Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp223093pxb; Thu, 17 Feb 2022 02:38:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNLfW+ylEHJc9xkXpG44ZLUlMJZV692/6jTl7SHfZetduFGVJggH9kf+UevLuH15tJBtwZ X-Received: by 2002:a05:6402:528e:b0:407:80ff:6eed with SMTP id en14-20020a056402528e00b0040780ff6eedmr1877997edb.165.1645094314632; Thu, 17 Feb 2022 02:38:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645094314; cv=none; d=google.com; s=arc-20160816; b=pcAoBkSZE9w9Q6jNuJkdTmot3L/61yCfAcVlB6m+A7Ex+8ktWCb7rF4rewbVYqRMqc w1/sAX1YGmuUnlovbmWqptYgjlMaQfzDhlbHvct2Jse/nx29wb46edfsjVhuWX5CDuVX bKKW/3gXfSSmnQ8qRZGuLSKBRmmVtD17SLyx4gMgtaAd21oqeMOyG+fmTjjxi81eEQuk C6ko/+JcymnAwb4RZr/PEP7R/cLMTrSFNX3RYrmRJYHe0DibXKyqLmQ0zKXKM/bWO+jk 8gEnp5ndqa3aRCJfEd3JFXZLc0Wp0JSjYuIqCwVZSpQwFgbAP4LzkjUoAF+JKgzkMnNi XNMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=mhXqGQe7IJYmdBVb8e92AEyhLMyelDbxaEzZ0gAldGs=; b=H9/ekW0P3jBvVVjiGyAU96OnY51e2lsGvsZrGDpmV1h0ZZiIVMydHJ7WbbAj2RZ4c2 5AwCKX/CNazxJ9O5hNSU6OzctFpyMniF90o3LGikQxAA2WWb1tCbS9ILrnnchyQyI2bn h2/9CJmWlo8MAcYoKyB/SkjT3KT0Pq1fNYerc0CGtIHYvyczGg6pbQ1hRP+z/ALhAW0N EOVjCOorPpPHTiXG48ftwvIUAlT6gMN7LjHuOYqULy3llpAOEvpBuIpCKdNxQCtpLWXq kT7leGUznGKEjnBNHR0ajEghM5+zgT/GIx5NxFF8ip0N0vmCxKzSkfqgkRqYCSHiw06i 0mgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js20si1804795ejc.37.2022.02.17.02.38.09; Thu, 17 Feb 2022 02:38:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235165AbiBQGnl (ORCPT + 99 others); Thu, 17 Feb 2022 01:43:41 -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: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 *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 || @@ -592,6 +596,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 || -- 2.25.1