LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Wentao_Liang <Wentao_Liang_g@163.com>
To: song@kernel.org
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	Wentao_Liang <Wentao_Liang_g@163.com>
Subject: [PATCH] drivers:md:fix a potential use-after-free bug
Date: Thu, 28 Jul 2022 19:39:19 +0800	[thread overview]
Message-ID: <20220728113919.7985-1-Wentao_Liang_g@163.com> (raw)

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.

The bug has been confirmed by Song on 2021-08-14. Now, I resend this
patch with my real name. I hope the patch can be updated in a near
future.

Signed-off-by: Wentao_Liang <Wentao_Liang_g@163.com>
---
 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 5d09256d7f81..93fcbeac5096 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2881,10 +2881,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.25.1


             reply	other threads:[~2022-07-28  3:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-28 11:39 Wentao_Liang [this message]
2022-07-28  5:55 ` Song Liu
     [not found] <tencent_888910D6F881B3D8BD9C3DFED667A5009806@qq.com>
2021-08-13 16:16 ` Song Liu
2021-08-17  7:47   ` Guoqing Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220728113919.7985-1-Wentao_Liang_g@163.com \
    --to=wentao_liang_g@163.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    --subject='Re: [PATCH] drivers:md:fix a potential use-after-free bug' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).