diff mbox series

drivers:md:fix a potential use-after-free bug

Message ID 20220728113919.7985-1-Wentao_Liang_g@163.com (mailing list archive)
State New, archived
Delegated to: Song Liu
Headers show
Series drivers:md:fix a potential use-after-free bug | expand

Commit Message

Wentao_Liang July 28, 2022, 11:39 a.m. UTC
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(-)

Comments

Song Liu July 28, 2022, 5:55 a.m. UTC | #1
On Wed, Jul 27, 2022 at 8:40 PM Wentao_Liang <Wentao_Liang_g@163.com> wrote:
>
> 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.

I removed this paragraph while applying the patch, as it doesn't belong to
the commit log. In the future you can put it after a "---", so it will
be dropped
automatically by git-am. In other words, use something like:

========================================
...
Signed-off-by: Wentao_Liang <Wentao_Liang_g@163.com>
---
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. (This will be dropped.)
---
 drivers/md/raid5.c | 2 +-
...
======================================
>
> Signed-off-by: Wentao_Liang <Wentao_Liang_g@163.com>

Applied to md-next. Thanks for the fix.


> ---
>  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
>
diff mbox series

Patch

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)