LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Re: [PATCH] drivers:md:fix a potential use-after-free bug
[not found] <tencent_888910D6F881B3D8BD9C3DFED667A5009806@qq.com>
@ 2021-08-13 16:16 ` Song Liu
2021-08-17 7:47 ` Guoqing Jiang
0 siblings, 1 reply; 4+ messages in thread
From: Song Liu @ 2021-08-13 16:16 UTC (permalink / raw)
To: lwt105; +Cc: linux-raid, open list
On Thu, Aug 12, 2021 at 8:46 PM lwt105 <3061522931@qq.com> wrote:
>
> In line 2867, "raid5_release_stripe(sh);" drops the reference to sh and
> may cause sh to be released. However, sh is subsequently used in lines
> 2869 "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: lwt105 <3061522931@qq.com>
The fix looks reasonable. I guess lwt105 is not a real name. Please update
the diff with your real name.
Thanks,
Song
> ---
> 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 b8436e4930ed..16ed44646419 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.25.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers:md:fix a potential use-after-free bug
2021-08-13 16:16 ` [PATCH] drivers:md:fix a potential use-after-free bug Song Liu
@ 2021-08-17 7:47 ` Guoqing Jiang
0 siblings, 0 replies; 4+ messages in thread
From: Guoqing Jiang @ 2021-08-17 7:47 UTC (permalink / raw)
To: Song Liu, lwt105; +Cc: linux-raid, open list
On 8/14/21 12:16 AM, Song Liu wrote:
> On Thu, Aug 12, 2021 at 8:46 PM lwt105<3061522931@qq.com> wrote:
>> In line 2867, "raid5_release_stripe(sh);" drops the reference to sh and
>> may cause sh to be released. However, sh is subsequently used in lines
>> 2869 "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: lwt105<3061522931@qq.com>
> The fix looks reasonable.
I am not sure this is needed unless there is real calltrace to prove it.
Because raid5_release_stripe
doesn't mean it will release the sh's memory, pls see the comment
before clear_batch_ready in
handle_stripe, and the path handle_stripe -> handle_stripe_clean_event
-> break_stripe_batch_list.
Thanks,
Guoqing
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] drivers:md:fix a potential use-after-free bug
@ 2022-07-28 11:39 Wentao_Liang
2022-07-28 5:55 ` Song Liu
0 siblings, 1 reply; 4+ messages in thread
From: Wentao_Liang @ 2022-07-28 11:39 UTC (permalink / raw)
To: song; +Cc: linux-raid, linux-kernel, Wentao_Liang
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers:md:fix a potential use-after-free bug
2022-07-28 11:39 Wentao_Liang
@ 2022-07-28 5:55 ` Song Liu
0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2022-07-28 5:55 UTC (permalink / raw)
To: Wentao_Liang; +Cc: linux-raid, open list
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-28 5:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <tencent_888910D6F881B3D8BD9C3DFED667A5009806@qq.com>
2021-08-13 16:16 ` [PATCH] drivers:md:fix a potential use-after-free bug Song Liu
2021-08-17 7:47 ` Guoqing Jiang
2022-07-28 11:39 Wentao_Liang
2022-07-28 5:55 ` Song Liu
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).