* [PATCH] f2fs: fix valid block count leak on data block allocation failure
@ 2026-07-22 0:54 Chen Changcheng
2026-08-03 7:11 ` Chao Yu
0 siblings, 1 reply; 8+ messages in thread
From: Chen Changcheng @ 2026-07-22 0:54 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, ccc194101, Chen Changcheng
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.
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);
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] f2fs: fix valid block count leak on data block allocation failure
2026-07-22 0:54 [PATCH] f2fs: fix valid block count leak on data block allocation failure Chen Changcheng
@ 2026-08-03 7:11 ` Chao Yu
2026-08-03 7:38 ` Chen Changcheng
0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2026-08-03 7:11 UTC (permalink / raw)
To: Chen Changcheng, jaegeuk; +Cc: chao, linux-f2fs-devel, linux-kernel, ccc194101
On 7/22/26 08:54, 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.
>
Needs fixes and Cc stable line?
> Signed-off-by: Chen Changcheng <chenchangcheng@kylinos.cn>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
> ---
> 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);
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] f2fs: fix valid block count leak on data block allocation failure
2026-08-03 7:11 ` Chao Yu
@ 2026-08-03 7:38 ` Chen Changcheng
2026-08-03 7:43 ` [PATCH v2] " Chen Changcheng
0 siblings, 1 reply; 8+ messages in thread
From: Chen Changcheng @ 2026-08-03 7:38 UTC (permalink / raw)
To: chao; +Cc: chenchangcheng, jaegeuk, linux-f2fs-devel, linux-kernel,
ccc194101
Hi Chao,
> Needs fixes and Cc stable line?
>
> Reviewed-by: Chao Yu <chao@kernel.org>
Thank you for the review. Yes, I'll add both Fixes and Cc stable tags
and send a v2 shortly.
Thanks
Chen
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] f2fs: fix valid block count leak on data block allocation failure
2026-08-03 7:38 ` Chen Changcheng
@ 2026-08-03 7:43 ` Chen Changcheng
2026-08-04 0:08 ` Chao Yu
0 siblings, 1 reply; 8+ messages in thread
From: Chen Changcheng @ 2026-08-03 7:43 UTC (permalink / raw)
To: chao
Cc: jaegeuk, linux-f2fs-devel, linux-kernel, ccc194101,
Chen Changcheng, stable
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")
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);
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2] f2fs: fix valid block count leak on data block allocation failure
2026-08-03 7:43 ` [PATCH v2] " Chen Changcheng
@ 2026-08-04 0:08 ` Chao Yu
2026-08-04 0:54 ` [PATCH v3] " Chen Changcheng
0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2026-08-04 0:08 UTC (permalink / raw)
To: Chen Changcheng
Cc: chao, jaegeuk, linux-f2fs-devel, linux-kernel, ccc194101, stable
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);
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v3] f2fs: fix valid block count leak on data block allocation failure
2026-08-04 0:08 ` Chao Yu
@ 2026-08-04 0:54 ` Chen Changcheng
2026-08-04 1:08 ` Chao Yu
2026-08-05 21:20 ` [f2fs-dev] " patchwork-bot+f2fs
0 siblings, 2 replies; 8+ messages in thread
From: Chen Changcheng @ 2026-08-04 0:54 UTC (permalink / raw)
To: chao
Cc: ccc194101, jaegeuk, linux-f2fs-devel, linux-kernel, stable,
Chen Changcheng
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: 7d009e048d7c ("f2fs: fix to handle segment allocation failure correctly")
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);
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v3] f2fs: fix valid block count leak on data block allocation failure
2026-08-04 0:54 ` [PATCH v3] " Chen Changcheng
@ 2026-08-04 1:08 ` Chao Yu
2026-08-05 21:20 ` [f2fs-dev] " patchwork-bot+f2fs
1 sibling, 0 replies; 8+ messages in thread
From: Chao Yu @ 2026-08-04 1:08 UTC (permalink / raw)
To: Chen Changcheng
Cc: chao, ccc194101, jaegeuk, linux-f2fs-devel, linux-kernel, stable
On 8/4/26 08:54, 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: 7d009e048d7c ("f2fs: fix to handle segment allocation failure correctly")
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Chao Yu <chao@kernel.org>
> Signed-off-by: Chen Changcheng <chenchangcheng@kylinos.cn>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [f2fs-dev] [PATCH v3] f2fs: fix valid block count leak on data block allocation failure
2026-08-04 0:54 ` [PATCH v3] " Chen Changcheng
2026-08-04 1:08 ` Chao Yu
@ 2026-08-05 21:20 ` patchwork-bot+f2fs
1 sibling, 0 replies; 8+ messages in thread
From: patchwork-bot+f2fs @ 2026-08-05 21:20 UTC (permalink / raw)
To: Chen Changcheng
Cc: chao, linux-kernel, stable, linux-f2fs-devel, jaegeuk, ccc194101
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Tue, 4 Aug 2026 08:54:02 +0800 you 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.
>
> [...]
Here is the summary with links:
- [f2fs-dev,v3] f2fs: fix valid block count leak on data block allocation failure
https://git.kernel.org/jaegeuk/f2fs/c/0f9af07ecc1a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-08-05 21:21 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 0:54 [PATCH] f2fs: fix valid block count leak on data block allocation failure Chen Changcheng
2026-08-03 7:11 ` Chao Yu
2026-08-03 7:38 ` Chen Changcheng
2026-08-03 7:43 ` [PATCH v2] " Chen Changcheng
2026-08-04 0:08 ` Chao Yu
2026-08-04 0:54 ` [PATCH v3] " Chen Changcheng
2026-08-04 1:08 ` Chao Yu
2026-08-05 21:20 ` [f2fs-dev] " patchwork-bot+f2fs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox