Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2296911pxp; Mon, 21 Mar 2022 16:11:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpUJHNo0bDwGhYiwLoL/0s1zorhPOe+TyJ9tWlMPNV0STVkihtewfUT2Phpb9HDzd2vje+ X-Received: by 2002:a17:90a:8595:b0:1bb:fbfd:bfbf with SMTP id m21-20020a17090a859500b001bbfbfdbfbfmr1535809pjn.125.1647904305261; Mon, 21 Mar 2022 16:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647904305; cv=none; d=google.com; s=arc-20160816; b=F1zzzHG1wxTTDSKBfPVXeTiCxjTpu1qdRSYaiuwUaXpyW0w4R47OHKWTfr8N8uq07w lamkfDY0F0ELsLH508/E/5Yx2128yQZRn3I8GCgTTldvZdsDe4iHHwCeg0U6jKCL0K/R qbja0n0R4UVgPNJazvPTOLDGLnMgaArEZUqejvKs62seN9m4Puf5OXw9k/rFy8WBcOpj MBuyid3oWDP+8kxxuROYCzNzveLpWSgCjhIum5fQ6oI0Z5UccKuxGtj0cuePCNV6bWsA mI6SG17EJTRVdkdtAIi4Ug7tYGAKRYU++If1Xx/LHiphmaeRKJEd8Of5GTlSLRSEvgWe 3NyA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=48ytRN5fUayFleI0FF8CwX/DhyiZmLd4pBei86xK5n8=; b=atkBQwG7eCYeBwN6o45gtdKdA61YKiQEblEOrlTBux+8uKd8Lguurj3qa6AWGmZlmi LTTJoxh5mcUe0KdQw7elZsO3M/HNCefNXhAeJ0rFUTCGbCzFQBj6fYLYolTLfmCs+Uh5 6PYjezplsXXGXkg9A+e9SVl4IFmQNUVxVuNkOq5B2SgX22Oj20UjnhSMsGeBpHPk05fZ ZjSiiEjBUCJAxg1LJBEk8/57hGjXaZVuATjR/rxxwn6BS20J5o8O95dqT7CIxWYeylex UENBmFFY+kA8/xAn+E5fFl614XTC3scFEHfHkIUee8ph2VQ5tvggv0wIbwBEEAK6sgvs 6aCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nkaBK5pn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q4-20020a056a00084400b004fa701bd461si9740695pfk.203.2022.03.21.16.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:11:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nkaBK5pn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2241D3654BA; Mon, 21 Mar 2022 15:10:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348820AbiCUOD4 (ORCPT + 99 others); Mon, 21 Mar 2022 10:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348509AbiCUN55 (ORCPT ); Mon, 21 Mar 2022 09:57:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDCBF30F66; Mon, 21 Mar 2022 06:55:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DD9586126A; Mon, 21 Mar 2022 13:55:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0168C340E8; Mon, 21 Mar 2022 13:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647870932; bh=MyxEPHJ/yrzATKXwkG2a916fXqChGg9FQQ7ePpmg8v4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nkaBK5pnszL4BOJWNdzKeuL3BfXKqtQL6ru85ZgltDCtNmy6K/pCLFXxtNkLGsm5T TPfdoUwNEFVZebtOQ2Z7zxbj0XSlUreWrlpBXzdfRefMSTDDdH1FrNIM9Lhjx6Oa/f 921Tnm6u8kK+iAMHx39Zq9iFWuBkQyNy9qs7Lxfk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, liqiong Subject: [PATCH 4.19 21/57] mm: fix dereference a null pointer in migrate[_huge]_page_move_mapping() Date: Mon, 21 Mar 2022 14:52:02 +0100 Message-Id: <20220321133222.602567121@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321133221.984120927@linuxfoundation.org> References: <20220321133221.984120927@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: liqiong 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 Signed-off-by: Greg Kroah-Hartman --- mm/migrate.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/mm/migrate.c +++ b/mm/migrate.c @@ -472,6 +472,10 @@ int migrate_page_move_mapping(struct add 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(struc 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 ||