All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: fix offset/size check in bio_trim()
@ 2022-04-12 14:58 Ming Lei
  2022-04-13 16:47 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Ming Lei @ 2022-04-12 14:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Ming Lei, Chaitanya Kulkarni

Unit of bio->bi_iter.bi_size is bytes, but unit of offset/size
is sector.

Fix the above issue in checking offset/size in bio_trim().

Fixes: e83502ca5f1e ("block: fix argument type of bio_trim()")
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/bio.c b/block/bio.c
index cdd7b2915c53..7c5dcc352db6 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1598,7 +1598,7 @@ EXPORT_SYMBOL(bio_split);
 void bio_trim(struct bio *bio, sector_t offset, sector_t size)
 {
 	if (WARN_ON_ONCE(offset > BIO_MAX_SECTORS || size > BIO_MAX_SECTORS ||
-			 offset + size > bio->bi_iter.bi_size))
+			 offset + size > bio->bi_iter.bi_size >> 9))
 		return;
 
 	size <<= 9;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] block: fix offset/size check in bio_trim()
@ 2022-04-14  8:44 Ming Lei
  2022-04-14 16:16 ` Jens Axboe
  2022-04-15  5:26 ` Chaitanya Kulkarni
  0 siblings, 2 replies; 5+ messages in thread
From: Ming Lei @ 2022-04-14  8:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei, Chaitanya Kulkarni

Unit of bio->bi_iter.bi_size is bytes, but unit of offset/size
is sector.

Fix the above issue in checking offset/size in bio_trim().

Fixes: e83502ca5f1e ("block: fix argument type of bio_trim()")
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
V2:
	- use bio_sectors() as suggested by Christoph

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

diff --git a/block/bio.c b/block/bio.c
index cdd7b2915c53..4259125e16ab 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1598,7 +1598,7 @@ EXPORT_SYMBOL(bio_split);
 void bio_trim(struct bio *bio, sector_t offset, sector_t size)
 {
 	if (WARN_ON_ONCE(offset > BIO_MAX_SECTORS || size > BIO_MAX_SECTORS ||
-			 offset + size > bio->bi_iter.bi_size))
+			 offset + size > bio_sectors(bio)))
 		return;
 
 	size <<= 9;
-- 
2.31.1


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

end of thread, other threads:[~2022-04-15  5:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 14:58 [PATCH] block: fix offset/size check in bio_trim() Ming Lei
2022-04-13 16:47 ` Christoph Hellwig
2022-04-14  8:44 Ming Lei
2022-04-14 16:16 ` Jens Axboe
2022-04-15  5:26 ` Chaitanya Kulkarni

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.