diff mbox series

block: bio: Trim bio to sensible size in bio_trim()

Message ID 20200829093733.45833-1-linmiaohe@huawei.com (mailing list archive)
State New, archived
Headers show
Series block: bio: Trim bio to sensible size in bio_trim() | expand

Commit Message

Miaohe Lin Aug. 29, 2020, 9:37 a.m. UTC
Trim bio to sensible size in bio_trim() or something bad may happen.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 block/bio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jens Axboe Aug. 29, 2020, 2:32 p.m. UTC | #1
On 8/29/20 3:37 AM, Miaohe Lin wrote:
> Trim bio to sensible size in bio_trim() or something bad may happen.

This really needs a LOT more detail. What is "something bad"? How does
this condition trigger to begin with?
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index a9931f23d933..94e4f97d3d4e 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1509,7 +1509,8 @@  void bio_trim(struct bio *bio, int offset, int size)
 		return;
 
 	bio_advance(bio, offset << 9);
-	bio->bi_iter.bi_size = size;
+	if (likely(bio->bi_iter.bi_size >= size))
+		bio->bi_iter.bi_size = size;
 
 	if (bio_integrity(bio))
 		bio_integrity_trim(bio);