block: fix an integer overflow in logical block size

Logical block size has type unsigned short. That means that it can be at
most 32768. However, there are architectures that can run with 64k pages
(for example arm64) and on these architectures, it may be possible to
create block devices with 64k block size.

For exmaple (run this on an architecture with 64k pages):

Mount will fail with this error because it tries to read the superblock using 2-sector
access:
device-mapper: writecache: I/O is not aligned, sector 2, size 1024, block size 65536
EXT4-fs (dm-0): unable to read superblock

This patch changes the logical block size from unsigned short to unsigned
int to avoid the overflow.

Cc: stable@vger.kernel.org
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by Mikulas Patocka and committed by Jens Axboe ad6bf88a 16c731fe

+7 -7
+1 -1
block/blk-settings.c
··· 328 * storage device can address. The default of 512 covers most 329 * hardware. 330 **/ 331 - void blk_queue_logical_block_size(struct request_queue *q, unsigned short size) 332 { 333 q->limits.logical_block_size = size; 334
··· 328 * storage device can address. The default of 512 covers most 329 * hardware. 330 **/ 331 + void blk_queue_logical_block_size(struct request_queue *q, unsigned int size) 332 { 333 q->limits.logical_block_size = size; 334
+1 -1
drivers/md/dm-snap-persistent.c
··· 17 #include <linux/dm-bufio.h> 18 19 #define DM_MSG_PREFIX "persistent snapshot" 20 - #define DM_CHUNK_SIZE_DEFAULT_SECTORS 32 /* 16KB */ 21 22 #define DM_PREFETCH_CHUNKS 12 23
··· 17 #include <linux/dm-bufio.h> 18 19 #define DM_MSG_PREFIX "persistent snapshot" 20 + #define DM_CHUNK_SIZE_DEFAULT_SECTORS 32U /* 16KB */ 21 22 #define DM_PREFETCH_CHUNKS 12 23
+1 -1
drivers/md/raid0.c
··· 87 char b[BDEVNAME_SIZE]; 88 char b2[BDEVNAME_SIZE]; 89 struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL); 90 - unsigned short blksize = 512; 91 92 *private_conf = ERR_PTR(-ENOMEM); 93 if (!conf)
··· 87 char b[BDEVNAME_SIZE]; 88 char b2[BDEVNAME_SIZE]; 89 struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL); 90 + unsigned blksize = 512; 91 92 *private_conf = ERR_PTR(-ENOMEM); 93 if (!conf)
+4 -4
include/linux/blkdev.h
··· 328 unsigned int max_sectors; 329 unsigned int max_segment_size; 330 unsigned int physical_block_size; 331 unsigned int alignment_offset; 332 unsigned int io_min; 333 unsigned int io_opt; ··· 339 unsigned int discard_granularity; 340 unsigned int discard_alignment; 341 342 - unsigned short logical_block_size; 343 unsigned short max_segments; 344 unsigned short max_integrity_segments; 345 unsigned short max_discard_segments; ··· 1077 unsigned int max_write_same_sectors); 1078 extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, 1079 unsigned int max_write_same_sectors); 1080 - extern void blk_queue_logical_block_size(struct request_queue *, unsigned short); 1081 extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); 1082 extern void blk_queue_alignment_offset(struct request_queue *q, 1083 unsigned int alignment); ··· 1291 return q->limits.max_segment_size; 1292 } 1293 1294 - static inline unsigned short queue_logical_block_size(const struct request_queue *q) 1295 { 1296 int retval = 512; 1297 ··· 1301 return retval; 1302 } 1303 1304 - static inline unsigned short bdev_logical_block_size(struct block_device *bdev) 1305 { 1306 return queue_logical_block_size(bdev_get_queue(bdev)); 1307 }
··· 328 unsigned int max_sectors; 329 unsigned int max_segment_size; 330 unsigned int physical_block_size; 331 + unsigned int logical_block_size; 332 unsigned int alignment_offset; 333 unsigned int io_min; 334 unsigned int io_opt; ··· 338 unsigned int discard_granularity; 339 unsigned int discard_alignment; 340 341 unsigned short max_segments; 342 unsigned short max_integrity_segments; 343 unsigned short max_discard_segments; ··· 1077 unsigned int max_write_same_sectors); 1078 extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, 1079 unsigned int max_write_same_sectors); 1080 + extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); 1081 extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); 1082 extern void blk_queue_alignment_offset(struct request_queue *q, 1083 unsigned int alignment); ··· 1291 return q->limits.max_segment_size; 1292 } 1293 1294 + static inline unsigned queue_logical_block_size(const struct request_queue *q) 1295 { 1296 int retval = 512; 1297 ··· 1301 return retval; 1302 } 1303 1304 + static inline unsigned int bdev_logical_block_size(struct block_device *bdev) 1305 { 1306 return queue_logical_block_size(bdev_get_queue(bdev)); 1307 }