Patch "bcache: avoid nr_stripes overflow in bcache_device_init()" has been added to the 5.7-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bcache: avoid nr_stripes overflow in bcache_device_init()

to the 5.7-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bcache-avoid-nr_stripes-overflow-in-bcache_device_in.patch
and it can be found in the queue-5.7 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit b8dd3dff4e5775897f0b0b61365af2bdd1466766
Author: Coly Li <colyli@xxxxxxx>
Date:   Sat Jul 25 20:00:21 2020 +0800

    bcache: avoid nr_stripes overflow in bcache_device_init()
    
    [ Upstream commit 65f0f017e7be8c70330372df23bcb2a407ecf02d ]
    
    For some block devices which large capacity (e.g. 8TB) but small io_opt
    size (e.g. 8 sectors), in bcache_device_init() the stripes number calcu-
    lated by,
            DIV_ROUND_UP_ULL(sectors, d->stripe_size);
    might be overflow to the unsigned int bcache_device->nr_stripes.
    
    This patch uses the uint64_t variable to store DIV_ROUND_UP_ULL()
    and after the value is checked to be available in unsigned int range,
    sets it to bache_device->nr_stripes. Then the overflow is avoided.
    
    Reported-and-tested-by: Ken Raeburn <raeburn@xxxxxxxxxx>
    Signed-off-by: Coly Li <colyli@xxxxxxx>
    Cc: stable@xxxxxxxxxxxxxxx
    Link: https://bugzilla.redhat.com/show_bug.cgi?id=1783075
    Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index b4d23d9f30f9b..d5477faa14edd 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -825,19 +825,19 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
 	struct request_queue *q;
 	const size_t max_stripes = min_t(size_t, INT_MAX,
 					 SIZE_MAX / sizeof(atomic_t));
-	size_t n;
+	uint64_t n;
 	int idx;
 
 	if (!d->stripe_size)
 		d->stripe_size = 1 << 31;
 
-	d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size);
-
-	if (!d->nr_stripes || d->nr_stripes > max_stripes) {
-		pr_err("nr_stripes too large or invalid: %u (start sector beyond end of disk?)",
-			(unsigned int)d->nr_stripes);
+	n = DIV_ROUND_UP_ULL(sectors, d->stripe_size);
+	if (!n || n > max_stripes) {
+		pr_err("nr_stripes too large or invalid: %llu (start sector beyond end of disk?)\n",
+			n);
 		return -ENOMEM;
 	}
+	d->nr_stripes = n;
 
 	n = d->nr_stripes * sizeof(atomic_t);
 	d->stripe_sectors_dirty = kvzalloc(n, GFP_KERNEL);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux