Skip to contentSkip to conversation

block: fix "check bi_size overflow before merge"

PATCH Applied Andreas Gruenbacher 3 participants 3 messages Dec 9, 2019 – Dec 10, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: fix "check bi_size overflow before merge"

This partially reverts commit e3a5d8e386c3fb973fa75f2403622a8f3640ec06.

Commit e3a5d8e386c3 ("check bi_size overflow before merge") adds a bio_full check to __bio_try_merge_page. This will cause __bio_try_merge_page to fail when the last bi_io_vec has been reached. Instead, what we want here is only the bi_size overflow check.

Fixes e3a5d8e386c3 ("block: check bi_size overflow before merge")
---
 block/bio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/bio.c +3 -1
index 9d54aa37ce6c..a5d75f6bf4c7 100644
@@ -754,10 +754,12 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page,
 	if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
 		return false;
 
-	if (bio->bi_vcnt > 0 && !bio_full(bio, len)) {
+	if (bio->bi_vcnt > 0) {
 		struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
 
 		if (page_is_mergeable(bv, page, len, off, same_page)) {
+			if (bio->bi_iter.bi_size > UINT_MAX - len)
+				return false;
 			bv->bv_len += len;
 			bio->bi_iter.bi_size += len;
 			return true;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Andreas Gruenbacher

This partially reverts commit e3a5d8e386c3fb973fa75f2403622a8f3640ec06.

Commit e3a5d8e386c3 ("check bi_size overflow before merge") adds a bio_full check to __bio_try_merge_page. This will cause __bio_try_merge_page to fail when the last bi_io_vec has been reached. Instead, what we want here is only the bi_size overflow check.

Fixes e3a5d8e386c3 ("block: check bi_size overflow before merge")
---
 block/bio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/bio.c +0 -0
index 9d54aa37ce6c..a5d75f6bf4c7 100644
@@ -754,10 +754,12 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page,
 	if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
 		return false;
 

block/bio.c bool __bio_try_merge_page(struct bio *bio, struct page *page, · line 765

Quoted 10 lines
block/bio.c +3 -1
-	if (bio->bi_vcnt > 0 && !bio_full(bio, len)) {
+	if (bio->bi_vcnt > 0) {
 		struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
 
 		if (page_is_mergeable(bv, page, len, off, same_page)) {
+			if (bio->bi_iter.bi_size > UINT_MAX - len)
+				return false;
 			bv->bv_len += len;
 			bio->bi_iter.bi_size += len;
 			return true;

page merging doesn't consume new bvec, so this patch is correct:

Thanks,
Ming

maintainer Applied
#2 lore raw
In reply to Andreas Gruenbacher
Quoted 6 lines · Andreas Gruenbacher

This partially reverts commit e3a5d8e386c3fb973fa75f2403622a8f3640ec06.

Commit e3a5d8e386c3 ("check bi_size overflow before merge") adds a bio_full check to __bio_try_merge_page. This will cause __bio_try_merge_page to fail when the last bi_io_vec has been reached. Instead, what we want here is only the bi_size overflow check.

Applied, thanks.

Signature · 1 line
Jens Axboe