Re: [f2fs-dev] [PATCH] f2fs: avoid underflow in get_available_block_count()

From: Chao Yu

Date: Tue Dec 01 2026 - 03:20:25 EST


On 11/14/26 09:17, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@xxxxxxxxxx>
>
> get_available_block_count() subtracts current_reserved_blocks,
> alias_reserved_blocks and root_reserved_blocks from user_block_count
> without checking the result. Only unusable_block_count is handled so
> that the result does not go below 0.
>
> f2fs_ioc_reserve_dev_alias() checks the free space with the root
> reserved blocks allowed when root calls it, so alias_reserved_blocks can
> overlap with the root reserved blocks until the reservation is turned
> into valid blocks. For example, with
>
> user_block_count = 1000, root_reserved_blocks = 100, valid blocks = 30
>
> reserving an alias device of 950 blocks passes the check, since
> 30 + 950 <= 1000, and sets alias_reserved_blocks to 950. Then, for a
> user who cannot use the root reserved blocks, the available block count
> is 1000 - 950 - 100, which wraps around to a huge value, so the check in
> inc_valid_block_count() does not stop such a user until the reservation
> is done.
>
> current_reserved_blocks can make it wrap in the same way, for root as
> well, when reserved_blocks is written through sysfs in the meantime,
> since it is set without considering alias_reserved_blocks.
>
> Sum up all the reservations and return 0 if they do not fit in
> user_block_count, as was done for unusable_block_count only.
>
> Fixes: eae3faf210bd ("f2fs: support dynamic reserve/release for device aliasing")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Daeho Jeong <daehojeong@xxxxxxxxxx>
Reviewed-by: Chao Yu <chao@xxxxxxxxxx>

Thanks,