All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: tongzhiwei <tongzhiwei@cmss.chinamobile.com>,
	"Jens Axboe" <axboe@kernel.dk>
Cc: dm-devel@lists.linux.dev, syzkaller-bugs@googlegroups.com,
	syzbot+1288484b13bf6af3620d@syzkaller.appspotmail.com
Subject: Re: [PATCH] block: fix divide by zero in queue_limit_discard_alignment()
Date: Fri, 20 Nov 2026 10:49:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-224959@kernel.org> (raw)
In-Reply-To: <20261120103040.610-1-tongzhiwei@cmss.chinamobile.com>

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 <tongzhiwei@cmss.chinamobile.com>

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/20261120103040.610-1-tongzhiwei@cmss.chinamobile.com?part=1

  reply	other threads:[~2026-11-20 10:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 10:30 [PATCH] block: fix divide by zero in queue_limit_discard_alignment() tongzhiwei
2026-11-20 10:49 ` sashiko-bot [this message]
2026-11-20 15:24 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-224959@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=syzbot+1288484b13bf6af3620d@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tongzhiwei@cmss.chinamobile.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.