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

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