Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp293292pxb; Thu, 17 Feb 2022 04:23:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxb51Fn+sUALKKCrJDkVY8kR3vwEiE0W18hTUXJSTclCaKSG5d5nMYruLHKjujWADruOYX1 X-Received: by 2002:a17:906:11d9:b0:6ce:674:f32 with SMTP id o25-20020a17090611d900b006ce06740f32mr2162345eja.524.1645100608361; Thu, 17 Feb 2022 04:23:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645100608; cv=none; d=google.com; s=arc-20160816; b=pBlOfJb1Oyu8y0n41a3GeomdWlR6lGXE6xg8B7gy9HP2e+SI3f2jecVU6kNeA7w8eR vTe1KLWt7G+Cg7Zpnz44FRVRzto3B5ptpuATw6hXJDfX++p3NUfAhKOUk/AlQmqvjo37 A+98UJHH6zZV834oIwmAL1I37OcdW18rTbcGg3d3eUQhJC+TgzenVciiKeHK94tucjBv BCNIGmbp1wxK26mUasTpZUCzAa3/I4tNBYhi/bhC5X5faEydV6sWzFEl+JCAmvhTWn0D +N63NK9hEdYLxkxdQVTtDsnlBj0liMwoqdvw52FYCZGGcigk637zCCI3bjqNV49U2kVF +WWw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Hxn6xyLjEEFgrdlZKIoLaTQ7baQDkj2L079s590l+9I=; b=veDq9vYiUAXTngUvfvqu3WnZylHed4JeJQqLtv4pUHhjWN0p7dcNaY4cUMoUFvOtz6 wqJivCVaBGI2ueMIL4hGx8UYtmIma4tg4HC9XDgivdLAwSFzeONoEBuorTokvssUPr+Q fncpC4CjXI+TQPW5zxjn1iis147EC9gwP7GctSO4SpZBvCPJ3WfAjmJkgbWzKi8cFv1W 7ulg7tvcGq2PzdES4OMyiW2y7uy6CFE8enrjZHUpDyEqPel9D1oO/2Fqv0WuJnEntCmQ C0z32ian1QeFJaP50SkxSCLvtQZQ4gNmhHzd3KWyssg35+N7FYAeYREq10bhCrHWjkBZ yoRQ== 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 gb3si1797908ejc.441.2022.02.17.04.22.52; Thu, 17 Feb 2022 04:23:27 -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 S240059AbiBQLyk (ORCPT + 99 others); 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: 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 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 || -- 2.25.1