Skip to content

Commit ad6bf88

Browse files
Mikulas Patockaaxboe
authored andcommitted
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: [email protected] Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Ming Lei <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 16c731f commit ad6bf88

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

block/blk-settings.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ EXPORT_SYMBOL(blk_queue_max_segment_size);
328328
* storage device can address. The default of 512 covers most
329329
* hardware.
330330
**/
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)
332332
{
333333
q->limits.logical_block_size = size;
334334

drivers/md/dm-snap-persistent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <linux/dm-bufio.h>
1818

1919
#define DM_MSG_PREFIX "persistent snapshot"
20-
#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32 /* 16KB */
20+
#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32U /* 16KB */
2121

2222
#define DM_PREFETCH_CHUNKS 12
2323

drivers/md/raid0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
8787
char b[BDEVNAME_SIZE];
8888
char b2[BDEVNAME_SIZE];
8989
struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
90-
unsigned short blksize = 512;
90+
unsigned blksize = 512;
9191

9292
*private_conf = ERR_PTR(-ENOMEM);
9393
if (!conf)

include/linux/blkdev.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ struct queue_limits {
328328
unsigned int max_sectors;
329329
unsigned int max_segment_size;
330330
unsigned int physical_block_size;
331+
unsigned int logical_block_size;
331332
unsigned int alignment_offset;
332333
unsigned int io_min;
333334
unsigned int io_opt;
@@ -338,7 +339,6 @@ struct queue_limits {
338339
unsigned int discard_granularity;
339340
unsigned int discard_alignment;
340341

341-
unsigned short logical_block_size;
342342
unsigned short max_segments;
343343
unsigned short max_integrity_segments;
344344
unsigned short max_discard_segments;
@@ -1077,7 +1077,7 @@ extern void blk_queue_max_write_same_sectors(struct request_queue *q,
10771077
unsigned int max_write_same_sectors);
10781078
extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q,
10791079
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);
10811081
extern void blk_queue_physical_block_size(struct request_queue *, unsigned int);
10821082
extern void blk_queue_alignment_offset(struct request_queue *q,
10831083
unsigned int alignment);
@@ -1291,7 +1291,7 @@ static inline unsigned int queue_max_segment_size(const struct request_queue *q)
12911291
return q->limits.max_segment_size;
12921292
}
12931293

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)
12951295
{
12961296
int retval = 512;
12971297

@@ -1301,7 +1301,7 @@ static inline unsigned short queue_logical_block_size(const struct request_queue
13011301
return retval;
13021302
}
13031303

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)
13051305
{
13061306
return queue_logical_block_size(bdev_get_queue(bdev));
13071307
}

0 commit comments

Comments
 (0)