From: Wentao_Liang Date: Thu, 28 Jul 2022 11:39:19 +0000 (+0800) Subject: drivers:md:fix a potential use-after-free bug X-Git-Tag: v6.0-rc1~112^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=104212471b1c1817b311771d817fb692af983173;p=thirdparty%2Fkernel%2Flinux.git drivers:md:fix a potential use-after-free bug 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 --- diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 8d10b190bdbbe..860c45c10a57d 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2952,10 +2952,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)