Re: [PATCH] block: fix BLKSECDISCARD zero-length range causing page cache invalidation

From: yu kuai

Date: Sun Jul 05 2026 - 12:00:08 EST


在 2026/7/4 15:39, Zizhi Wo 写道:

> From: Zizhi Wo<wozizhi@xxxxxxxxxx>
>
> Commit 697ba0b6ec4a ("block: fix integer overflow in BLKSECDISCARD") fixed
> the start+len overflow via check_add_overflow() but did not handle the
> start=0, len=0 case. There, start + len = 0, so end = 0 passes all checks,
> and truncate_bdev_range()->truncate_inode_pages_range() is then called with
> lend=UINT64_MAX, whitch is the "truncate to the end of file" sentinel, so
> the entire page cache is invalidated.
>
> Fix this by replacing the validation with blk_validate_byte_range(), which
> already rejects a zero-length range and is what BLKDISCARD uses. This also
> switches the alignment check from a hardcoded 512 to
> bdev_logical_block_size().
>
> Signed-off-by: Zizhi Wo<wozizhi@xxxxxxxxxx>
> ---
> block/ioctl.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)

Reviewed-by: Yu Kuai <yukuai@xxxxxxx>

--
Thanks,
Kuai