]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
md/raid5: Fix sectors_to_do bitmap overflow in raid5_make_request()
authorLogan Gunthorpe <logang@deltatee.com>
Thu, 7 Jul 2022 19:15:32 +0000 (13:15 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 2 Aug 2022 23:22:41 +0000 (17:22 -0600)
For unaligned IO that have nearly maximum sectors, the number of stripes
will end up being one greater than the size of the bitmap. When this
happens, the last stripe in the IO will not be processed as it should
be, resulting in data corruption.

However, this is not normally seen when the backing block devices have
4K physical block sizes since the block layer will split the request
before that happens.

To fix this increase the bitmap size by one bit and ensure the full
number of stripes are checked when calling find_first_bit().

Reported-by: David Sloan <David.Sloan@eideticom.com>
Fixes: 7e55c60acfbb ("md/raid5: Pivot raid5_make_request()")
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/raid5.c

index 00cab9e525f19e4e28b8d4a5a16babb3b3a73d5c..2690298bd92baef1ae8baf681e74d79172035504 100644 (file)
@@ -5873,8 +5873,11 @@ struct stripe_request_ctx {
        /* last sector in the request */
        sector_t last_sector;
 
-       /* bitmap to track stripe sectors that have been added to stripes */
-       DECLARE_BITMAP(sectors_to_do, RAID5_MAX_REQ_STRIPES);
+       /*
+        * bitmap to track stripe sectors that have been added to stripes
+        * add one to account for unaligned requests
+        */
+       DECLARE_BITMAP(sectors_to_do, RAID5_MAX_REQ_STRIPES + 1);
 
        /* the request had REQ_PREFLUSH, cleared after the first stripe_head */
        bool do_flush;
@@ -6047,7 +6050,7 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
        const int rw = bio_data_dir(bi);
        enum stripe_result res;
        DEFINE_WAIT(w);
-       int s;
+       int s, stripe_cnt;
 
        if (unlikely(bi->bi_opf & REQ_PREFLUSH)) {
                int ret = log_handle_flush_request(conf, bi);
@@ -6091,9 +6094,9 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
        ctx.last_sector = bio_end_sector(bi);
        bi->bi_next = NULL;
 
-       bitmap_set(ctx.sectors_to_do, 0,
-                  DIV_ROUND_UP_SECTOR_T(ctx.last_sector - logical_sector,
-                                        RAID5_STRIPE_SECTORS(conf)));
+       stripe_cnt = DIV_ROUND_UP_SECTOR_T(ctx.last_sector - logical_sector,
+                                          RAID5_STRIPE_SECTORS(conf));
+       bitmap_set(ctx.sectors_to_do, 0, stripe_cnt);
 
        pr_debug("raid456: %s, logical %llu to %llu\n", __func__,
                 bi->bi_iter.bi_sector, ctx.last_sector);
@@ -6138,8 +6141,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
                        continue;
                }
 
-               s = find_first_bit(ctx.sectors_to_do, RAID5_MAX_REQ_STRIPES);
-               if (s == RAID5_MAX_REQ_STRIPES)
+               s = find_first_bit(ctx.sectors_to_do, stripe_cnt);
+               if (s == stripe_cnt)
                        break;
 
                logical_sector = ctx.first_sector +