All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix infinite loop in __blkdev_issue_discard
@ 2018-11-14 17:52 ` Mikulas Patocka
  0 siblings, 0 replies; 2+ messages in thread
From: Mikulas Patocka @ 2018-11-14 17:52 UTC (permalink / raw)
  To: Jens Axboe, Ming Lei, Zdenek Kabelac
  Cc: Mike Snitzer, Christoph Hellwig, Xiao Ni, Mariusz Dabrowski,
	dm-devel, linux-block

The "min_t(unsigned int" macro truncates both arguments to unsigned int. 
So, if we are running discard on a very big device with 2^32 or more 
sectors, the truncation may produce zero, resulting in infinite loop.

This patch fixes the infinite loop in the lvm test lvcreate-large-raid.sh

BTW. the patch 744889b7cbb56a64f957e65ade7cb65fe3f35714 that was committed 
between v4.19-rc8 and v4.19 also breaks discard by truncating sector_t to 
unsigned int (but it won't result in an infinite loop, it will result in 
an error instead). Should it be pulled out from the 4.19 long term branch? 
Or should we backport all the subsequent patches on the top of it?

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
Fixes: ba5d73851e71 ("block: cleanup __blkdev_issue_discard()")
Fixes: 744889b7cbb5 ("block: don't deal with discard limit in blkdev_issue_discard()")
Cc: stable@vger.kernel.org	# v4.19

---
 block/blk-lib.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6/block/blk-lib.c
===================================================================
--- linux-2.6.orig/block/blk-lib.c	2018-11-14 18:25:28.000000000 +0100
+++ linux-2.6/block/blk-lib.c	2018-11-14 18:33:04.000000000 +0100
@@ -55,7 +55,7 @@ int __blkdev_issue_discard(struct block_
 		return -EINVAL;
 
 	while (nr_sects) {
-		unsigned int req_sects = min_t(unsigned int, nr_sects,
+		unsigned int req_sects = min_t(sector_t, nr_sects,
 				bio_allowed_max_sectors(q));
 
 		bio = blk_next_bio(bio, 0, gfp_mask);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] fix infinite loop in __blkdev_issue_discard
@ 2018-11-14 17:52 ` Mikulas Patocka
  0 siblings, 0 replies; 2+ messages in thread
From: Mikulas Patocka @ 2018-11-14 17:52 UTC (permalink / raw)
  To: Jens Axboe, Ming Lei, Zdenek Kabelac
  Cc: Mike Snitzer, dm-devel, Mariusz Dabrowski, linux-block, Xiao Ni,
	Christoph Hellwig

The "min_t(unsigned int" macro truncates both arguments to unsigned int. 
So, if we are running discard on a very big device with 2^32 or more 
sectors, the truncation may produce zero, resulting in infinite loop.

This patch fixes the infinite loop in the lvm test lvcreate-large-raid.sh

BTW. the patch 744889b7cbb56a64f957e65ade7cb65fe3f35714 that was committed 
between v4.19-rc8 and v4.19 also breaks discard by truncating sector_t to 
unsigned int (but it won't result in an infinite loop, it will result in 
an error instead). Should it be pulled out from the 4.19 long term branch? 
Or should we backport all the subsequent patches on the top of it?

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
Fixes: ba5d73851e71 ("block: cleanup __blkdev_issue_discard()")
Fixes: 744889b7cbb5 ("block: don't deal with discard limit in blkdev_issue_discard()")
Cc: stable@vger.kernel.org	# v4.19

---
 block/blk-lib.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6/block/blk-lib.c
===================================================================
--- linux-2.6.orig/block/blk-lib.c	2018-11-14 18:25:28.000000000 +0100
+++ linux-2.6/block/blk-lib.c	2018-11-14 18:33:04.000000000 +0100
@@ -55,7 +55,7 @@ int __blkdev_issue_discard(struct block_
 		return -EINVAL;
 
 	while (nr_sects) {
-		unsigned int req_sects = min_t(unsigned int, nr_sects,
+		unsigned int req_sects = min_t(sector_t, nr_sects,
 				bio_allowed_max_sectors(q));
 
 		bio = blk_next_bio(bio, 0, gfp_mask);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-14 17:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 17:52 [PATCH] fix infinite loop in __blkdev_issue_discard Mikulas Patocka
2018-11-14 17:52 ` Mikulas Patocka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.