Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] block: misdiagnosed sub-sector check in
  queue_limit_discard_alignment()
--

commit 863891ebff09d5d7c6b856e9fe20f0c7b376f993
Author: tongzhiwei <[email protected]>

block: fix divide by zero in queue_limit_discard_alignment()

This commit restores the zero check for the sector-shifted discard
granularity in queue_limit_discard_alignment() to avoid a divide by zero
when discard_granularity is smaller than a sector.

> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 1f5ee2453269f..a0487226f48b5 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -643,6 +643,10 @@ static unsigned int queue_limit_discard_alignment(
>       alignment = lim->discard_alignment >> SECTOR_SHIFT;
>       granularity = lim->discard_granularity >> SECTOR_SHIFT;
>  
> +     /* sub-sector granularity: no meaningful alignment, avoid div by 0 */
> +     if (!granularity)
> +             return 0;

[Severity: Medium]
Can a validated queue ever have a non-zero discard_granularity smaller
than SECTOR_SIZE, or does this check only paper over callers passing
unvalidated sector units instead of bytes?

blk_validate_limits() enforces physical_block_size >= logical_block_size
>= SECTOR_SIZE and clamps discard_granularity to at least
physical_block_size whenever max_discard_sectors is non-zero:

block/blk-settings.c:blk_validate_limits() {
        ...
        if (lim->max_discard_sectors)
                lim->discard_granularity =
                        max(lim->discard_granularity, lim->physical_block_size);
        else
                lim->discard_granularity = 0;
        ...
}

The syzbot crash cited in the commit message happened because
dm_calculate_queue_limits() passed unvalidated target limits from
snapshot_io_hints() to blk_stack_limits(), and snapshot_io_hints()
stored chunk_size in sectors rather than bytes.  That root cause was
already fixed by d7216d7be2bb ("dm snapshot: fix discard_granularity
unit in snapshot_io_hints"), so returning 0 here is redundant and would
silently mask future callers that pass sector counts in
discard_granularity while leaving the bogus sub-sector value in the
stacked limits.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to