From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07949C25B06 for ; Sun, 14 Aug 2022 15:47:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241595AbiHNPrg (ORCPT ); Sun, 14 Aug 2022 11:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241620AbiHNPpz (ORCPT ); Sun, 14 Aug 2022 11:45:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3CF8DE96; Sun, 14 Aug 2022 08:34:30 -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 ams.source.kernel.org (Postfix) with ESMTPS id 968BAB80B43; Sun, 14 Aug 2022 15:34:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90964C433C1; Sun, 14 Aug 2022 15:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660491268; bh=aD74N/hsr51I4dViwIJ6uB1M3qdYNTympSCUrh97GdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TWlwmNsenGcf6a//seJH/I5Y2yiL9Irkd03Lzc7QctWHoBfo/+Ihq9GZiOcv/8ICP ya1hcdep7SO56kpTgJ13i4LcZcaSuCD5mfwbQkDJRp4rkH+6orQ32gG+pbF8BR3Uke KVrwS9fOXCjurPW2CbA7JHsUBEoRF+oAkuM6X0ZgMuoOkvBrAbowefum3En3t1THFv oXmATLD1Bgfj/Iy7UL+7vf5ViZEc96vXAr7eFsEm42ihiaWC6sjDmDUAHN7oi4lI9M cqAKoKX04JG1zkgobA7rB6Y+zMlfEgCC8nZnQcmqCzMw2lV27PVqCj6bqiLb+TjGDc sjlqJ6xqBt1rA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wentao_Liang , Song Liu , Jens Axboe , Sasha Levin , linux-raid@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 44/46] drivers:md:fix a potential use-after-free bug Date: Sun, 14 Aug 2022 11:32:45 -0400 Message-Id: <20220814153247.2378312-44-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220814153247.2378312-1-sashal@kernel.org> References: <20220814153247.2378312-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Wentao_Liang [ Upstream commit 104212471b1c1817b311771d817fb692af983173 ] In line 2884, "raid5_release_stripe(sh);" drops the reference to sh and may cause sh to be released. However, sh is subsequently used in lines 2886 "if (sh->batch_head && sh != sh->batch_head)". This may result in an use-after-free bug. It can be fixed by moving "raid5_release_stripe(sh);" to the bottom of the function. Signed-off-by: Wentao_Liang Signed-off-by: Song Liu Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/raid5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index b58984ddca13..19e497a7e747 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2864,10 +2864,10 @@ static void raid5_end_write_request(struct bio *bi) if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) clear_bit(R5_LOCKED, &sh->dev[i].flags); set_bit(STRIPE_HANDLE, &sh->state); - raid5_release_stripe(sh); if (sh->batch_head && sh != sh->batch_head) raid5_release_stripe(sh->batch_head); + raid5_release_stripe(sh); } static void raid5_error(struct mddev *mddev, struct md_rdev *rdev) -- 2.35.1