Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1527660rwj; Sun, 18 Dec 2022 09:56:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf4IzQSe9ml8XFVkHupY7eUWaj3dN3Llwypdf3lYBZ7ep8WcSQuMfx5z1j8uilbx4ZqsrAlv X-Received: by 2002:a17:90b:3009:b0:221:6151:a65a with SMTP id hg9-20020a17090b300900b002216151a65amr27503789pjb.34.1671386171583; Sun, 18 Dec 2022 09:56:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671386171; cv=none; d=google.com; s=arc-20160816; b=T4BBr5qZRBDDNjZjLtZ6tGjQjKvdbmSBBvBDkHBAZ51+MZ64p097vXJn6B4PgbXDO4 HfcmH6Kkw198RtWcKOFnMVX2iggDgrT4An1O3SWVHRuF/DtkIqSYNplj77wrwaJoZ9EE wBUtA1k8wUfKlw3ZycBTDbG/V0ftW2JjcA/hc34F5ta38sReRkEvWbFqI69tq2/EjDO1 Ly7T8ZvrvIsIf/cSCW0q3wS8fM3DMNjG7ToxtyLvdPm2P8SIZeQm2j5oYW1CNeEwtzcd j0H1ZcqCYZ9rG3CkJVPaGjgAi/RawY3JQcXmlKmGH2m2KoJOibg80VJYpBjBMj/h0zit R8QQ== 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 :dkim-signature; bh=t2DZrz8SHKtEccD8m040dkQFqY7joUjhEWR2oQphUGM=; b=xNXxwXgaEHyPHJj3DLq5/A3rvK+oP2FcJ5XJ3PzTiViWrWchRhCkVv8EEJEVVaAFG3 MO698fBIVJVhfSXomMUg6GGa07+Hli0ouSdu4URJlB9VxVPcipp3xGmTNr2cVoiVjy09 AINVJMkyuPVjRUFN9uK9pjkx/ozqzDOXYMLtXVTdVFxRIAHEGHWdHO2sCT/DaWeUIJTR DuyBsXHsR7L+JfH9iUv9vIfLt7UprhrNTmfVj/TI1k/1rVUGsmcObONskBVXnCU7A9v3 VxZ73qE7vcWJJDzUkNMlmN1hlHA9c/oksRwMfUGbEM8mo/Ulo5aKEFYC5joJwN3BR5jV 110A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="o+/3Om9L"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j70-20020a638b49000000b00478c3840710si8733255pge.25.2022.12.18.09.56.03; Sun, 18 Dec 2022 09:56:11 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="o+/3Om9L"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232321AbiLRQme (ORCPT + 70 others); Sun, 18 Dec 2022 11:42:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232537AbiLRQks (ORCPT ); Sun, 18 Dec 2022 11:40:48 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 724E2E0A9; Sun, 18 Dec 2022 08:14:30 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 1E527B80766; Sun, 18 Dec 2022 16:14:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37053C433EF; Sun, 18 Dec 2022 16:14:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380067; bh=nXG3WuK/QywGgb0xAZGZZ6Y/nrBzkOPYXdvXg8/rwkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o+/3Om9L4xcD7tJOwsc7D8Hs5bmCCL5LH9xnA+W8cw1RIb43Grx+KARDDKL9/Q3XT u0Wt9o2iooV8Y+UXA0wwQS3CzfSY7PLA1+QOSbMF+oMoNqqPcm118THt3lBBCpHDaL INlBqnxME3WCIcF6Ci/WFGjs4lWMMhpzqRZ/4Fc42DXDsHsUs8duhxTM4744evKMWf iyLPUp3xKISbYHY22LdGTCWCT9asYFmFbe1Yj9mqe0QyFn6H1UNfdS4bdvpU08gwyp uAuOT3Qf4cfc3ig6frdpGdSjvewrcdgIhn8YTmivbljfWVmsWadz7RPKgG2hx95oYI /tv3le9TD8fWw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Li Zhong , Song Liu , Sasha Levin , linux-raid@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 25/46] drivers/md/md-bitmap: check the return value of md_bitmap_get_counter() Date: Sun, 18 Dec 2022 11:12:23 -0500 Message-Id: <20221218161244.930785-25-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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: Li Zhong [ Upstream commit 3bd548e5b819b8c0f2c9085de775c5c7bff9052f ] Check the return value of md_bitmap_get_counter() in case it returns NULL pointer, which will result in a null pointer dereference. v2: update the check to include other dereference Signed-off-by: Li Zhong Signed-off-by: Song Liu Signed-off-by: Sasha Levin --- drivers/md/md-bitmap.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 8cc11b1987ec..650bfccd066f 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -2196,20 +2196,23 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks, if (set) { bmc_new = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); - if (*bmc_new == 0) { - /* need to set on-disk bits too. */ - sector_t end = block + new_blocks; - sector_t start = block >> chunkshift; - start <<= chunkshift; - while (start < end) { - md_bitmap_file_set_bit(bitmap, block); - start += 1 << chunkshift; + if (bmc_new) { + if (*bmc_new == 0) { + /* need to set on-disk bits too. */ + sector_t end = block + new_blocks; + sector_t start = block >> chunkshift; + + start <<= chunkshift; + while (start < end) { + md_bitmap_file_set_bit(bitmap, block); + start += 1 << chunkshift; + } + *bmc_new = 2; + md_bitmap_count_page(&bitmap->counts, block, 1); + md_bitmap_set_pending(&bitmap->counts, block); } - *bmc_new = 2; - md_bitmap_count_page(&bitmap->counts, block, 1); - md_bitmap_set_pending(&bitmap->counts, block); + *bmc_new |= NEEDED_MASK; } - *bmc_new |= NEEDED_MASK; if (new_blocks < old_blocks) old_blocks = new_blocks; } -- 2.35.1