On 2026-10-28T05:50:48, Ana Bobillo <[email protected]> wrote: > block: Refuse a device with an unsupported block size > > blk_post_probe() scans a block device for partitions with the block size > its driver set from what the device reports, and nothing checks it in > between. The USB storage, SCSI, IDE, NVMe and virtio block drivers and the > host command now check it where they read it, but other drivers do not, > such as the Xen PV block driver, and the partition and filesystem code > relies on it, as the patch adding blk_valid_blksz() describes. > > Refuse to probe a block device whose block size blk_valid_blksz() > rejects, or whose log2blksz does not match its blksz, before its > partitions are scanned. This covers every block driver in one place > when its device is probed. > > The check does not depend on PARTITIONS, since the filesystem code and > raw reads rely on the block size too. It is left out of SPL and TPL, > though: there it adds some 180 bytes, which takes the SPL of imx28_btt3 > and popmetal-rk3288 over their size limits, and its message needs a > putc() that the SPL of evb-rk3036 does not have. In SPL the USB storage, > SCSI, IDE, NVMe and virtio block drivers still check the block size > where they read it. > > A device with neither a size nor a block size, which is how the SCSI > code leaves a removable drive without a medium, is still probed, but > outside SPL and TPL its partitions are no longer scanned: part_test_dos() > could otherwise parse 512 bytes of a zero-sized buffer. > > Signed-off-by: Ana Bobillo <[email protected]> > > drivers/block/blk-uclass.c | 15 +++++++++++++++ > test/dm/blk.c | 41 +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 56 insertions(+)
Reviewed-by: Simon Glass <[email protected]>
