linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path
@ 2025-09-30  9:16 Haofeng Li via Linux-f2fs-devel
  2025-09-30 10:04 ` Haofeng Li via Linux-f2fs-devel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Haofeng Li via Linux-f2fs-devel @ 2025-09-30  9:16 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu
  Cc: Haofeng Li, Haofeng Li, linux-kernel, linux-f2fs-devel

From: Haofeng Li <lihaofeng@kylinos.cn>

Fixes a memory leak issue in f2fs_move_inline_dirents() where
the ifolio is not properly released in certain error paths.

Problem Analysis:
- In f2fs_try_convert_inline_dir(), ifolio is acquired via f2fs_get_inode_folio()
- When do_convert_inline_dir() fails, the caller expects ifolio to be released
- However, in f2fs_move_inline_dirents(), two specific error paths don't release ifolio

Fixes: 201a05be9628a ("f2fs: add key function to handle inline dir")
Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn>
---
 fs/f2fs/inline.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index 58ac831ef704..2496866fc45d 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -425,7 +425,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
 	set_new_dnode(&dn, dir, ifolio, NULL, 0);
 	err = f2fs_reserve_block(&dn, 0);
 	if (err)
-		goto out;
+		goto out_put_ifolio;
 
 	if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
 		f2fs_put_dnode(&dn);
@@ -434,7 +434,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
 			  __func__, dir->i_ino, dn.data_blkaddr);
 		f2fs_handle_error(F2FS_F_SB(folio), ERROR_INVALID_BLKADDR);
 		err = -EFSCORRUPTED;
-		goto out;
+		goto out_put_ifolio;
 	}
 
 	f2fs_folio_wait_writeback(folio, DATA, true, true);
@@ -479,6 +479,10 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
 out:
 	f2fs_folio_put(folio, true);
 	return err;
+
+out_put_ifolio:
+	f2fs_folio_put(ifolio, true);
+	goto out;
 }
 
 static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path
  2025-09-30  9:16 [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path Haofeng Li via Linux-f2fs-devel
@ 2025-09-30 10:04 ` Haofeng Li via Linux-f2fs-devel
  2025-10-02 20:50 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
  2025-10-03  1:39 ` Chao Yu via Linux-f2fs-devel
  2 siblings, 0 replies; 5+ messages in thread
From: Haofeng Li via Linux-f2fs-devel @ 2025-09-30 10:04 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: linux-kernel, 13266079573, 920484857, jaegeuk, lihaofeng

>Fixes a memory leak issue in f2fs_move_inline_dirents() where
>the ifolio is not properly released in certain error paths.

>Problem Analysis:
>- In f2fs_try_convert_inline_dir(), ifolio is acquired via f2fs_get_inode_folio()
>- When do_convert_inline_dir() fails, the caller expects ifolio to be released
>- However, in f2fs_move_inline_dirents(), two specific error paths don't release ifolio

Add some additional information.

When do_convert_inline_dir() fails in f2fs_try_convert_inline_dir(),
the ifolio obtained via f2fs_get_inode_folio() is not properly released,
leading to a memory leak.

The issue occurs in the following call path:

f2fs_try_convert_inline_dir()
├── f2fs_get_inode_folio()  // acquires ifolio
├── do_convert_inline_dir()
│   ├── f2fs_move_inline_dirents() // The issue is in this function. 
│   │   └── Error paths may not release ifolio
└── Only releases ifolio on success: if (!err) f2fs_folio_put(ifolio, true)

Specifically, in f2fs_move_inline_dirents():
- If f2fs_reserve_block() fails, the function jumps to 'out' label
- The 'out' label only releases the newly allocated 'folio' but not 'ifolio'
- This leaves ifolio unreleased when f2fs_reserve_block() fails

In contrast, f2fs_move_rehashed_dirents() properly handles ifolio release
in its error recovery path, but the inconsistency creates a leak risk.



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path
  2025-09-30  9:16 [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path Haofeng Li via Linux-f2fs-devel
  2025-09-30 10:04 ` Haofeng Li via Linux-f2fs-devel
@ 2025-10-02 20:50 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
  2025-10-03  1:39 ` Chao Yu via Linux-f2fs-devel
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+f2fs--- via Linux-f2fs-devel @ 2025-10-02 20:50 UTC (permalink / raw)
  To: Haofeng Li
  Cc: 13266079573, linux-kernel, linux-f2fs-devel, jaegeuk, lihaofeng

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Tue, 30 Sep 2025 17:16:21 +0800 you wrote:
> From: Haofeng Li <lihaofeng@kylinos.cn>
> 
> Fixes a memory leak issue in f2fs_move_inline_dirents() where
> the ifolio is not properly released in certain error paths.
> 
> Problem Analysis:
> - In f2fs_try_convert_inline_dir(), ifolio is acquired via f2fs_get_inode_folio()
> - When do_convert_inline_dir() fails, the caller expects ifolio to be released
> - However, in f2fs_move_inline_dirents(), two specific error paths don't release ifolio
> 
> [...]

Here is the summary with links:
  - [f2fs-dev] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path
    https://git.kernel.org/jaegeuk/f2fs/c/9fc1840e0217

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path
  2025-09-30  9:16 [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path Haofeng Li via Linux-f2fs-devel
  2025-09-30 10:04 ` Haofeng Li via Linux-f2fs-devel
  2025-10-02 20:50 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
@ 2025-10-03  1:39 ` Chao Yu via Linux-f2fs-devel
  2025-10-03  3:15   ` Jaegeuk Kim via Linux-f2fs-devel
  2 siblings, 1 reply; 5+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-10-03  1:39 UTC (permalink / raw)
  To: Haofeng Li, Jaegeuk Kim
  Cc: Haofeng Li, Haofeng Li, linux-kernel, linux-f2fs-devel

On 2025/9/30 17:16, Haofeng Li wrote:
> From: Haofeng Li <lihaofeng@kylinos.cn>
> 
> Fixes a memory leak issue in f2fs_move_inline_dirents() where
> the ifolio is not properly released in certain error paths.
> 
> Problem Analysis:
> - In f2fs_try_convert_inline_dir(), ifolio is acquired via f2fs_get_inode_folio()
> - When do_convert_inline_dir() fails, the caller expects ifolio to be released
> - However, in f2fs_move_inline_dirents(), two specific error paths don't release ifolio
> 
> Fixes: 201a05be9628a ("f2fs: add key function to handle inline dir")
> Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn>
> ---
>   fs/f2fs/inline.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
> index 58ac831ef704..2496866fc45d 100644
> --- a/fs/f2fs/inline.c
> +++ b/fs/f2fs/inline.c
> @@ -425,7 +425,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
>   	set_new_dnode(&dn, dir, ifolio, NULL, 0);
>   	err = f2fs_reserve_block(&dn, 0);

f2fs_reserve_block() will call f2fs_put_dnode() in its error path, it has
unlocked & released inode folio?

>   	if (err)
> -		goto out;
> +		goto out_put_ifolio;
>   
>   	if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
>   		f2fs_put_dnode(&dn);

Ditto, or am I missing something?

Thanks,

> @@ -434,7 +434,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
>   			  __func__, dir->i_ino, dn.data_blkaddr);
>   		f2fs_handle_error(F2FS_F_SB(folio), ERROR_INVALID_BLKADDR);
>   		err = -EFSCORRUPTED;
> -		goto out;
> +		goto out_put_ifolio;
>   	}
>   
>   	f2fs_folio_wait_writeback(folio, DATA, true, true);
> @@ -479,6 +479,10 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
>   out:
>   	f2fs_folio_put(folio, true);
>   	return err;
> +
> +out_put_ifolio:
> +	f2fs_folio_put(ifolio, true);
> +	goto out;
>   }
>   
>   static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path
  2025-10-03  1:39 ` Chao Yu via Linux-f2fs-devel
@ 2025-10-03  3:15   ` Jaegeuk Kim via Linux-f2fs-devel
  0 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim via Linux-f2fs-devel @ 2025-10-03  3:15 UTC (permalink / raw)
  To: Chao Yu; +Cc: Haofeng Li, Haofeng Li, linux-kernel, Haofeng Li,
	linux-f2fs-devel

On 10/03, Chao Yu wrote:
> On 2025/9/30 17:16, Haofeng Li wrote:
> > From: Haofeng Li <lihaofeng@kylinos.cn>
> > 
> > Fixes a memory leak issue in f2fs_move_inline_dirents() where
> > the ifolio is not properly released in certain error paths.
> > 
> > Problem Analysis:
> > - In f2fs_try_convert_inline_dir(), ifolio is acquired via f2fs_get_inode_folio()
> > - When do_convert_inline_dir() fails, the caller expects ifolio to be released
> > - However, in f2fs_move_inline_dirents(), two specific error paths don't release ifolio
> > 
> > Fixes: 201a05be9628a ("f2fs: add key function to handle inline dir")
> > Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn>
> > ---
> >   fs/f2fs/inline.c | 8 ++++++--
> >   1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
> > index 58ac831ef704..2496866fc45d 100644
> > --- a/fs/f2fs/inline.c
> > +++ b/fs/f2fs/inline.c
> > @@ -425,7 +425,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
> >   	set_new_dnode(&dn, dir, ifolio, NULL, 0);
> >   	err = f2fs_reserve_block(&dn, 0);
> 
> f2fs_reserve_block() will call f2fs_put_dnode() in its error path, it has
> unlocked & released inode folio?
> 
> >   	if (err)
> > -		goto out;
> > +		goto out_put_ifolio;
> >   	if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
> >   		f2fs_put_dnode(&dn);
> 
> Ditto, or am I missing something?

It seems you're right. Let me drop this patch.

> 
> Thanks,
> 
> > @@ -434,7 +434,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
> >   			  __func__, dir->i_ino, dn.data_blkaddr);
> >   		f2fs_handle_error(F2FS_F_SB(folio), ERROR_INVALID_BLKADDR);
> >   		err = -EFSCORRUPTED;
> > -		goto out;
> > +		goto out_put_ifolio;
> >   	}
> >   	f2fs_folio_wait_writeback(folio, DATA, true, true);
> > @@ -479,6 +479,10 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
> >   out:
> >   	f2fs_folio_put(folio, true);
> >   	return err;
> > +
> > +out_put_ifolio:
> > +	f2fs_folio_put(ifolio, true);
> > +	goto out;
> >   }
> >   static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-03  3:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-30  9:16 [f2fs-dev] [PATCH] f2fs: fix ifolio memory leak in f2fs_move_inline_dirents error path Haofeng Li via Linux-f2fs-devel
2025-09-30 10:04 ` Haofeng Li via Linux-f2fs-devel
2025-10-02 20:50 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
2025-10-03  1:39 ` Chao Yu via Linux-f2fs-devel
2025-10-03  3:15   ` Jaegeuk Kim via Linux-f2fs-devel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).