From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: Chen Changcheng <chenchangcheng@kylinos.cn>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, jaegeuk@kernel.org,
ccc194101@163.com
Subject: Re: [f2fs-dev] [PATCH v2] f2fs: fix valid block count leak on data block allocation failure
Date: Tue, 4 Aug 2026 08:08:12 +0800 [thread overview]
Message-ID: <0b450e92-b9b0-4a55-bd16-ad106245d7e1@kernel.org> (raw)
In-Reply-To: <20260803074344.219899-1-chenchangcheng@kylinos.cn>
On 8/3/26 15:43, Chen Changcheng wrote:
> In __allocate_data_block(), when allocating a new data block
> (dn->data_blkaddr == NULL_ADDR), inc_valid_block_count() is
> called first to increment total_valid_block_count and i_blocks.
> If the subsequent f2fs_allocate_data_block() fails, the function
> returns the error directly without rolling back the
> already-incremented block counts, causing a permanent leak.
>
> Fix this by calling dec_valid_block_count() to undo the
> increment before returning the error. The condition
> old_blkaddr == NULL_ADDR precisely identifies the case where
> inc_valid_block_count() was called.
>
> Fixes: 54607494875e ("f2fs: compress: fix to avoid inconsistence bewteen i_blocks and dnode")
Should be?
Fixes: 7d009e048d7c ("f2fs: fix to handle segment allocation failure correctly")
Thanks,
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Chao Yu <chao@kernel.org>
> Signed-off-by: Chen Changcheng <chenchangcheng@kylinos.cn>
> ---
> fs/f2fs/data.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index a765fda71536..819631bb61ae 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -1532,8 +1532,11 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
> old_blkaddr = dn->data_blkaddr;
> err = f2fs_allocate_data_block(sbi, NULL, old_blkaddr,
> &dn->data_blkaddr, &sum, seg_type, NULL);
> - if (err)
> + if (err) {
> + if (old_blkaddr == NULL_ADDR)
> + dec_valid_block_count(sbi, dn->inode, count);
> return err;
> + }
>
> if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO)
> f2fs_invalidate_internal_cache(sbi, old_blkaddr, 1);
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <chao@kernel.org>
To: Chen Changcheng <chenchangcheng@kylinos.cn>
Cc: chao@kernel.org, jaegeuk@kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, ccc194101@163.com,
stable@vger.kernel.org
Subject: Re: [PATCH v2] f2fs: fix valid block count leak on data block allocation failure
Date: Tue, 4 Aug 2026 08:08:12 +0800 [thread overview]
Message-ID: <0b450e92-b9b0-4a55-bd16-ad106245d7e1@kernel.org> (raw)
In-Reply-To: <20260803074344.219899-1-chenchangcheng@kylinos.cn>
On 8/3/26 15:43, Chen Changcheng wrote:
> In __allocate_data_block(), when allocating a new data block
> (dn->data_blkaddr == NULL_ADDR), inc_valid_block_count() is
> called first to increment total_valid_block_count and i_blocks.
> If the subsequent f2fs_allocate_data_block() fails, the function
> returns the error directly without rolling back the
> already-incremented block counts, causing a permanent leak.
>
> Fix this by calling dec_valid_block_count() to undo the
> increment before returning the error. The condition
> old_blkaddr == NULL_ADDR precisely identifies the case where
> inc_valid_block_count() was called.
>
> Fixes: 54607494875e ("f2fs: compress: fix to avoid inconsistence bewteen i_blocks and dnode")
Should be?
Fixes: 7d009e048d7c ("f2fs: fix to handle segment allocation failure correctly")
Thanks,
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Chao Yu <chao@kernel.org>
> Signed-off-by: Chen Changcheng <chenchangcheng@kylinos.cn>
> ---
> fs/f2fs/data.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index a765fda71536..819631bb61ae 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -1532,8 +1532,11 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
> old_blkaddr = dn->data_blkaddr;
> err = f2fs_allocate_data_block(sbi, NULL, old_blkaddr,
> &dn->data_blkaddr, &sum, seg_type, NULL);
> - if (err)
> + if (err) {
> + if (old_blkaddr == NULL_ADDR)
> + dec_valid_block_count(sbi, dn->inode, count);
> return err;
> + }
>
> if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO)
> f2fs_invalidate_internal_cache(sbi, old_blkaddr, 1);
next prev parent reply other threads:[~2026-08-04 0:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 0:54 [PATCH] f2fs: fix valid block count leak on data block allocation failure Chen Changcheng
2026-07-22 0:54 ` [f2fs-dev] " Chen Changcheng
2026-08-03 7:11 ` Chao Yu
2026-08-03 7:11 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-08-03 7:38 ` Chen Changcheng
2026-08-03 7:38 ` [f2fs-dev] " Chen Changcheng
2026-08-03 7:43 ` [PATCH v2] " Chen Changcheng
2026-08-03 7:43 ` [f2fs-dev] " Chen Changcheng
2026-08-04 0:08 ` Chao Yu via Linux-f2fs-devel [this message]
2026-08-04 0:08 ` Chao Yu
2026-08-04 0:54 ` [PATCH v3] " Chen Changcheng
2026-08-04 0:54 ` [f2fs-dev] " Chen Changcheng
2026-08-04 1:08 ` Chao Yu via Linux-f2fs-devel
2026-08-04 1:08 ` Chao Yu
2026-08-05 21:20 ` [f2fs-dev] " patchwork-bot+f2fs--- via Linux-f2fs-devel
2026-08-05 21:20 ` patchwork-bot+f2fs
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=0b450e92-b9b0-4a55-bd16-ad106245d7e1@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=ccc194101@163.com \
--cc=chao@kernel.org \
--cc=chenchangcheng@kylinos.cn \
--cc=jaegeuk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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.