Re: RFC PATCH] null_blk: fix UBSAN shift-out-of-bounds when zone_size is 0 or overflows

Jens Axboe <[email protected]>
Newsgroups org.kernel.vger.linux-block,org.kernel.vger.linux-kernel
Message-ID <178683854966.1984298.9103781823601303342.b4-ty@b4>
On Sat, 08 Aug 2026 11:42:39 -0400, Rik van Riel wrote:
> null_zone_no() does sect >> ilog2(dev->zone_size_sects). When
> zone_size_sects is 0, ilog2(0) returns -1, producing shift exponent -1
> which UBSAN reports as shift-out-of-bounds.
> 
>   UBSAN: shift-out-of-bounds in drivers/block/null_blk/zoned.c:21:14
>   shift exponent -1 is negative
>   Call Trace:
>    null_zone_no drivers/block/null_blk/zoned.c:21 [inline]
>    null_process_zoned_cmd+0xf76/0xf80 drivers/block/null_blk/zoned.c:728
>    null_handle_cmd drivers/block/null_blk/main.c:1455 [inline]
>    null_queue_rq+0x8bc/0xe70 drivers/block/null_blk/main.c:1703
>    __blk_mq_issue_directly block/blk-mq.c:2694 [inline]
>    blk_mq_try_issue_directly+0x3f4/0x880 block/blk-mq.c:2754
>    blk_mq_submit_bio+0x20c0/0x2a40 block/blk-mq.c:3208
>    submit_bio_noacct_nocheck+0x2f4/0xa40 block/blk-core.c:790
>    block_read_full_folio+0x7a6/0x810 fs/buffer.c:2463
>    filemap_read_folio+0x12c/0x3a0 mm/filemap.c:2510
>    read_part_sector+0xb6/0x2b0 block/partitions/core.c:724
>    adfspart_check_ICS+0xb1/0x960 block/partitions/acorn.c:357
>    check_partition block/partitions/core.c:143 [inline]
>    blk_add_partitions block/partitions/core.c:591 [inline]
>    bdev_disk_changed+0x851/0x17a0 block/partitions/core.c:695
>    blkdev_get_whole+0x372/0x510 block/bdev.c:751
>    add_disk_final block/genhd.c:412 [inline]
>    add_disk_fwnode+0x24b/0x3a0 block/genhd.c:606
>    null_add_dev+0x130b/0x1d70 drivers/block/null_blk/main.c:2052
>    nullb_device_power_store+0x240/0x380 drivers/block/null_blk/main.c:501
>    configfs_write_iter+0x337/0x430 fs/configfs/file.c:229
> 
> [...]

Applied, thanks!

[1/1] RFC PATCH] null_blk: fix UBSAN shift-out-of-bounds when zone_size is 0 or overflows
      commit: 95491fb05105b61050cb623a5e0227eb26aa3525

Best regards,
-- 
Jens Axboe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.