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 D0F30C25B08 for ; Sun, 14 Aug 2022 15:52:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242094AbiHNPwh (ORCPT ); Sun, 14 Aug 2022 11:52:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242100AbiHNPvN (ORCPT ); Sun, 14 Aug 2022 11:51:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C2781D304; Sun, 14 Aug 2022 08:36:52 -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 D6016B80B7F; Sun, 14 Aug 2022 15:36:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E93F9C43143; Sun, 14 Aug 2022 15:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660491409; bh=9+9TAGae0fTA/X972osI2oujsoHgyW6Ylmjy3Vai+/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G5Nf8BiS9wbiiFakvaNrCSOQ1az6iZ4tf4e627yIjYXozk44pRBSaTHw9tKmdsjpa PXEnsaRQ744eNvo8+6zq8O6yp1hYF8GZKoG/nbI/nwVMoNKd5ZMAyistSDz1BzJAET 1N2q0tH9lmDt243DD30EwwDWG9qOLoW6o6sV/SuGxXAtDzl8kgHmRHPD/sMeGSDH9Y 8iDm2JFaFQ26e7a75Y7aLFyjgeskQNbCAWkovpDMe1/j2RT5cNnnfnNBoEzVJWsR+S KVlVVNb04+yXlq9kQm5viCAjP4B8JGJDz/gV3YP4u1V/l8t3dJ2kcLyTIec5uM6K5o E4uBELYhrgVlw== 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 4.14 7/9] drivers:md:fix a potential use-after-free bug Date: Sun, 14 Aug 2022 11:36:34 -0400 Message-Id: <20220814153637.2380406-7-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220814153637.2380406-1-sashal@kernel.org> References: <20220814153637.2380406-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 1e52443f3aca..866ba1743f9f 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2668,10 +2668,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