linux/drivers/block
Xie Yongji 57a13a5b81 virtio-blk: Use blk_validate_block_size() to validate block size
The block layer can't support a block size larger than
page size yet. And a block size that's too small or
not a power of two won't work either. If a misconfigured
device presents an invalid block size in configuration space,
it will result in the kernel crash something like below:

[  506.154324] BUG: kernel NULL pointer dereference, address: 0000000000000008
[  506.160416] RIP: 0010:create_empty_buffers+0x24/0x100
[  506.174302] Call Trace:
[  506.174651]  create_page_buffers+0x4d/0x60
[  506.175207]  block_read_full_page+0x50/0x380
[  506.175798]  ? __mod_lruvec_page_state+0x60/0xa0
[  506.176412]  ? __add_to_page_cache_locked+0x1b2/0x390
[  506.177085]  ? blkdev_direct_IO+0x4a0/0x4a0
[  506.177644]  ? scan_shadow_nodes+0x30/0x30
[  506.178206]  ? lru_cache_add+0x42/0x60
[  506.178716]  do_read_cache_page+0x695/0x740
[  506.179278]  ? read_part_sector+0xe0/0xe0
[  506.179821]  read_part_sector+0x36/0xe0
[  506.180337]  adfspart_check_ICS+0x32/0x320
[  506.180890]  ? snprintf+0x45/0x70
[  506.181350]  ? read_part_sector+0xe0/0xe0
[  506.181906]  bdev_disk_changed+0x229/0x5c0
[  506.182483]  blkdev_get_whole+0x6d/0x90
[  506.183013]  blkdev_get_by_dev+0x122/0x2d0
[  506.183562]  device_add_disk+0x39e/0x3c0
[  506.184472]  virtblk_probe+0x3f8/0x79b [virtio_blk]
[  506.185461]  virtio_dev_probe+0x15e/0x1d0 [virtio]

So let's use a block layer helper to validate the block size.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://lore.kernel.org/r/20211026144015.188-5-xieyongji@bytedance.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-27 14:15:54 -06:00
..
aoe for-5.14/drivers-2021-06-29 2021-06-30 12:21:16 -07:00
drbd block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
mtip32xx mtip32xx: use blk_mq_alloc_disk and blk_cleanup_disk 2021-06-30 15:34:04 -06:00
null_blk block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
paride SCSI misc on 20210902 2021-09-02 15:09:46 -07:00
rnbd block: add a struct io_comp_batch argument to fops->iopoll() 2021-10-18 14:40:40 -06:00
rsxx block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
xen-blkback isystem: trim/fixup stdarg.h and other headers 2021-08-19 09:02:55 +09:00
zram block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
amiflop.c block: drop unused includes in <linux/genhd.h> 2021-10-18 06:17:02 -06:00
ataflop.c block: drop unused includes in <linux/genhd.h> 2021-10-18 06:17:02 -06:00
brd.c block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
cryptoloop.c cryptoloop: add a deprecation warning 2021-08-27 10:44:54 -06:00
floppy.c block: drop unused includes in <linux/genhd.h> 2021-10-18 06:17:02 -06:00
Kconfig SCSI misc on 20210902 2021-09-02 15:09:46 -07:00
loop.c loop: Use blk_validate_block_size() to validate block size 2021-10-27 14:15:54 -06:00
loop.h loop: reduce the loop_ctl_mutex scope 2021-09-03 22:14:40 -06:00
Makefile drivers/block: remove the umem driver 2021-03-24 06:57:40 -06:00
n64cart.c block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
nbd.c nbd: Use blk_validate_block_size() to validate block size 2021-10-27 14:15:53 -06:00
pktcdvd.c block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
ps3disk.c ps3disk: use memcpy_{from,to}_bvec 2021-08-02 13:37:27 -06:00
ps3vram.c block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
rbd_types.h libceph, rbd: replace zero-length array with flexible-array 2020-06-01 13:22:53 +02:00
rbd.c block: Rename BLKDEV_MAX_RQ -> BLKDEV_DEFAULT_RQ 2021-10-18 06:17:02 -06:00
sunvdc.c Char / Misc driver updates for 5.14-rc1 2021-07-05 13:42:16 -07:00
swim3.c swim3: use blk_mq_alloc_disk 2021-06-11 11:53:02 -06:00
swim_asm.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
swim.c block: drop unused includes in <linux/genhd.h> 2021-10-18 06:17:02 -06:00
sx8.c sx8: use the internal state machine to check if del_gendisk needs to be called 2021-08-12 10:29:36 -06:00
virtio_blk.c virtio-blk: Use blk_validate_block_size() to validate block size 2021-10-27 14:15:54 -06:00
xen-blkfront.c block: drop unused includes in <linux/genhd.h> 2021-10-18 06:17:02 -06:00
z2ram.c for-5.14/drivers-2021-06-29 2021-06-30 12:21:16 -07:00