md: fix bi_status reporting in md_end_clone_io
authorSong Liu <song@kernel.org>
Fri, 17 Nov 2023 23:56:30 +0000 (15:56 -0800)
committerSong Liu <song@kernel.org>
Mon, 20 Nov 2023 04:51:25 +0000 (20:51 -0800)
md_end_clone_io() may overwrite error status in orig_bio->bi_status with
BLK_STS_OK. This could happen when orig_bio has BIO_CHAIN (split by
md_submit_bio => bio_split_to_limits, for example). As a result, upper
layer may miss error reported from md (or the device) and consider the
failed IO was successful.

Fix this by only update orig_bio->bi_status when current bio reports
error and orig_bio is BLK_STS_OK. This is the same behavior as
__bio_chain_endio().

Fixes: 10764815ff47 ("md: add io accounting for raid0 and raid5")
Cc: stable@vger.kernel.org # v5.14+
Reported-by: Bhanu Victor DiCara <00bvd0+linux@gmail.com>
Closes: https://lore.kernel.org/regressions/5727380.DvuYhMxLoT@bvd0/
Signed-off-by: Song Liu <song@kernel.org>
Tested-by: Xiao Ni <xni@redhat.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Guoqing Jiang <guoqing.jiang@linux.dev>
drivers/md/md.c

index 4ee4593c874a769b96b36696aa50cbc806cb8385..c94373d64f2cd4cbbdb8d49591d23b8f129aa46c 100644 (file)
@@ -8666,7 +8666,8 @@ static void md_end_clone_io(struct bio *bio)
        struct bio *orig_bio = md_io_clone->orig_bio;
        struct mddev *mddev = md_io_clone->mddev;
 
-       orig_bio->bi_status = bio->bi_status;
+       if (bio->bi_status && !orig_bio->bi_status)
+               orig_bio->bi_status = bio->bi_status;
 
        if (md_io_clone->start_time)
                bio_end_io_acct(orig_bio, md_io_clone->start_time);