bio: fix argument of __bio_add_page() for max_sectors > 0xffff
PATCH 1/1 bio: fix argument of __bio_add_page() for max_sectors > 0xffff
The data type of max_sectors and max_hw_sectors in queue settings are unsigned int. But these values are passed to __bio_add_page() as an argument whose data type is unsigned short. In the worst case such as max_sectors is 0x10000, bio_add_page() can't add a page and IOs can't proceed.
--- fs/bio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/bio.c +1 -1
@@ -601,7 +601,7 @@ EXPORT_SYMBOL(bio_get_nr_vecs);static int __bio_add_page (struct request_queue *q,struct bio *bio,struct page *page,unsigned int len,unsigned int offset, -unsigned short max_sectors) +unsigned int max_sectors) {int retried_segments =0 ;struct bio_vec *bvec;
Signature · 1 line
1.8.3.2
Quoted 5 lines · Akinobu Mita
The data type of
max_sectorsandmax_hw_sectorsin queue settings are unsigned int. But these values are passed to__bio_add_page()as an argument whose data type is unsigned short. In the worst case such asmax_sectorsis0x10000,bio_add_page()can't add a page and IOs can't proceed.
Thanks, added. Even at 512b sectors, 0xffff sectors would be a huuuuge page. So I don't think we'd ever see this bug hit, iirc huge pages are still broken down for IO. But it's better to be safe...
Signature · 1 line
Jens Axboe
2013/11/19 Jens Axboe <[email protected]>:
Quoted 10 lines · Akinobu Mita
Quoted 5 lines
The data type of
max_sectorsandmax_hw_sectorsin queue settings are unsigned int. But these values are passed to__bio_add_page()as an argument whose data type is unsigned short. In the worst case such asmax_sectorsis0x10000,bio_add_page()can't add a page and IOs can't proceed.Thanks, added. Even at 512b sectors,
0xffffsectors would be a huuuuge page. So I don't think we'd ever see this bug hit, iirc huge pages are still broken down for IO. But it's better to be safe...
I hit this when I was trying to change the data type of max_sectors in scsi host settings from 16-bit to 32-bit.
BTW, I found that BLKSECTGET only returns 16-bit of max_sectors. Should we need the change like below?
case BLKSECTGET:
- return put_ushort(arg, queue_max_sectors(bdev_get_queue(bdev)));
+ max_sectors = min(0xffff,
+ queue_max_sectors(bdev_get_queue(bdev)));
+ return put_ushort(arg, max_sectors);