From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796113217; b=OA9xAxAiJtmQXQODA1sT8Bu6fumVmt3L2/xO4QqfdNni5oVwaw5UJHDVWevlT0PrKyTM k3SMCaK7LxczMQdti/iJSzVMyD0jUkgg64LL9yLkxUL0SQC94H8+zkcg4K9Zz9W8n1Ka9 ciCa2+9a9YXpHgZJNqM2YfaPpevd0mVuPihVkCiJ+R8MIY7as+ldhThf9LD/E2LrujpqF LuL1HQaNtUUKnxCChTtY2Eb+DvLFJM0tC9f8n0cS0WsXDQGNIuIXVFKNLow41+p2tUtCp G1+lG4F2UzQifxuZXN31d1SBlsi/22JpsPka4TboPeqyCqOerxufuYNa3s60lIeu79A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796113217; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent:Cc: Subject:To:References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=Wt4mcnkVhbcCG1uDMbIQ2lcU6Z2C4CzCn8YRqZJPF1w=; b=ARwt7iXm7ZyhRNffAoi+7uETZfnXGu/6xZ5/lKFgQK2j4vRyb3/39PcYcbKzrkwuowwg qN+8gs1oNtlT+S0YHRayiTVzF0TCDp7NV+xY3eHfN7tKT2Zhrnf9kCb1k23P4bobm2Lx9 7d61FYenonttmOFZ4qyKIMYNSDoIOQfaAotSTijunkdhUpI5PYAFC0j7XyGaq0tH4UIX8 3hl0V8Gx2yvQ/gKeU/ZpGEAlBqQbyEezdDQZoOyFBZ5sWJ7FvrstTlq9nli3nqGFQswda BP/g6rdgJ4k2eokUKlxBYfHuaG4G7y0qWz7kfNohkSaFfsrq1LZyTZgYzhWu0o2iIwA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ILt+4Zuo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E787D606A33A; Tue, 1 Dec 2026 08:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ILt+4Zuo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 796CA1F00898; Tue, 1 Dec 2026 08:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796113216; bh=Wt4mcnkVhbcCG1uDMbIQ2lcU6Z2C4CzCn8YRqZJPF1w=; h=Date:Cc:Subject:To:References:From:In-Reply-To; b=ILt+4ZuoygF8UhRDNaUKNmCljUBWaW43POHhgeXFC+Chj2fjCC45dMKnii8cvDBcd Idsm60XaC+N+6YqHgUhZ6rYXZm7/j7ZXu5mJTLccPnKCFJpttWkF6TOgq3H4zVRr52 YeR/myZO8Gy8R3KzQ1YtNoLWrPCmElRkbmwzD3wDEebwyN0M+dikqRLtefdUxLtYn4 WNOjDi7W/1aSiT/YhJ+nm06lrqZG9GMFO5MtPWTLRuVUkwZXWrf1aLSFCL4BX0XO7f I/sK0GM78WCe9p4+xIeyXInbcgy2SyBQCH7Pwf0rksEKQpCVbLlmovnMqKwnW4+VqD TJuYxwjeW8Yjw== Message-ID: Date: Tue, 1 Dec 2026 16:20:14 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, Daeho Jeong , stable@vger.kernel.org Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid underflow in get_available_block_count() To: Daeho Jeong , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com References: <20261114011734.3806377-1-daeho43@gmail.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20261114011734.3806377-1-daeho43@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/14/26 09:17, Daeho Jeong wrote: > From: Daeho Jeong > > 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@vger.kernel.org > Signed-off-by: Daeho Jeong Reviewed-by: Chao Yu Thanks,