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: stable@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, From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A424606A31A for ; Tue, 1 Dec 2026 08:20:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=lists.sourceforge.net header.i=@lists.sourceforge.net header.a=rsa-sha256 header.s=beta header.b=d2uPdsXu; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.a=rsa-sha256 header.s=x header.b=PfSH5NZu; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.a=rsa-sha256 header.s=x header.b=OgW8kCM4; dkim=neutral header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ILt+4Zuo DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:In-Reply-To:References:To:MIME-Version:Date: Message-ID:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=0edBrczDlyL1BGUcZxEZWrpyy96XEWH8oezPI/VakNI=; b=d2uPdsXuCME3t3 Uewj+9EQ90GJV89XByi/YbBY7WdhPv9Fs9PTw41PyS1DD09Z06S41DoJo+bkz08HUthlM73MKQPzH QCR27uqQhL95b5XIqW5IWDR5nfCaonU8uoUlSfGNtXh/QKouaaALgWlEYTgHV8KEZuyThkjv8OkNk Rn8=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xYJ6B-000000004e9-37hT; Tue, 01 Dec 2026 08:20:27 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xYJ6A-000000004e3-1gsj for linux-f2fs-devel@lists.sourceforge.net; Tue, 01 Dec 2026 08:20:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: From:References:To:Subject:Cc:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Wt4mcnkVhbcCG1uDMbIQ2lcU6Z2C4CzCn8YRqZJPF1w=; b=PfSH5NZuMfGU6AUobCCyszsPwi A16jA5i99d2j63ashWEZZvgIq4oTzCbP7FxOUVuGwMOjk+1nzp4Lpp0Oe1F5U7VoIrE11BMdWmhiy bnoDbZ1fQCkr7gQfPwS46ndHN32C9asSWCT3f+yMPY6t5spwLbAK5xcm7KLe5hvkNOmo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:To: Subject:Cc:MIME-Version:Date:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Wt4mcnkVhbcCG1uDMbIQ2lcU6Z2C4CzCn8YRqZJPF1w=; b=OgW8kCM44Y7I/dOuU8xyDUrv1i Qiqh9OKG3ODzhnBGcjUY2R+LjXIJEK6u6UYpbERIc5zCAuNKCVhrWEc2QDlOJ+rfN7tv1fRJ9m0WW f7EHHmxfp8opmKCkdBNmmelPG+pvTYsZO+8fIKkM6DFMjmIQ5f8uEKX00eGIzo5qMsBA=; Received: from sea.source.kernel.org ([172.234.252.31]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xYJ66-000000008Lx-0YTF for linux-f2fs-devel@lists.sourceforge.net; Tue, 01 Dec 2026 08:20:26 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id A8F02405E5; Tue, 1 Dec 2026 08:20:16 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird 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 In-Reply-To: <20261114011734.3806377-1-daeho43@gmail.com> X-Spam-Score: 0.8 (/) X-Headers-End: 1xYJ66-000000008Lx-0YTF Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid underflow in get_available_block_count() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , From: Chao Yu via Linux-f2fs-devel Reply-To: Chao Yu Cc: Daeho Jeong , stable@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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, _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel