diff mbox series

[1/2] ocfs2: Fix possible memory leak in ocfs2_finish_quota_recovery

Message ID 20250402065628.706359-2-m.masimov@mt-integration.ru (mailing list archive)
State New
Headers show
Series ocfs2: Fix issues in ocfs2_finish_quota_recovery | expand

Commit Message

Murad Masimov April 2, 2025, 6:56 a.m. UTC
If ocfs2_finish_quota_recovery() exits due to an error before passing all
rc_list elements to ocfs2_recover_local_quota_file() then it can lead to
a memory leak as rc_list may still contain elements that have to be freed.

Release all memory allocated by ocfs2_add_recovery_chunk() using
ocfs2_free_quota_recovery() instead of kfree().

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: 2205363dce74 ("ocfs2: Implement quota recovery")
Signed-off-by: Murad Masimov <m.masimov@mt-integration.ru>
---
 fs/ocfs2/quota_local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.39.2

Comments

Jan Kara April 2, 2025, 12:36 p.m. UTC | #1
On Wed 02-04-25 09:56:27, Murad Masimov wrote:
> If ocfs2_finish_quota_recovery() exits due to an error before passing all
> rc_list elements to ocfs2_recover_local_quota_file() then it can lead to
> a memory leak as rc_list may still contain elements that have to be freed.
> 
> Release all memory allocated by ocfs2_add_recovery_chunk() using
> ocfs2_free_quota_recovery() instead of kfree().
> 
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
> 
> Fixes: 2205363dce74 ("ocfs2: Implement quota recovery")
> Signed-off-by: Murad Masimov <m.masimov@mt-integration.ru>

Looks good. Thanks for debugging this! Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ocfs2/quota_local.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
> index 2956d888c131..e60383d6ecc1 100644
> --- a/fs/ocfs2/quota_local.c
> +++ b/fs/ocfs2/quota_local.c
> @@ -678,7 +678,7 @@ int ocfs2_finish_quota_recovery(struct ocfs2_super *osb,
>  	}
>  out:
>  	up_read(&sb->s_umount);
> -	kfree(rec);
> +	ocfs2_free_quota_recovery(rec);
>  	return status;
>  }
> 
> --
> 2.39.2
>
Joseph Qi April 3, 2025, 12:56 a.m. UTC | #2
On 2025/4/2 14:56, Murad Masimov wrote:
> If ocfs2_finish_quota_recovery() exits due to an error before passing all
> rc_list elements to ocfs2_recover_local_quota_file() then it can lead to
> a memory leak as rc_list may still contain elements that have to be freed.
> 
> Release all memory allocated by ocfs2_add_recovery_chunk() using
> ocfs2_free_quota_recovery() instead of kfree().
> 
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
> 
> Fixes: 2205363dce74 ("ocfs2: Implement quota recovery")
> Signed-off-by: Murad Masimov <m.masimov@mt-integration.ru>

Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> ---
>  fs/ocfs2/quota_local.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
> index 2956d888c131..e60383d6ecc1 100644
> --- a/fs/ocfs2/quota_local.c
> +++ b/fs/ocfs2/quota_local.c
> @@ -678,7 +678,7 @@ int ocfs2_finish_quota_recovery(struct ocfs2_super *osb,
>  	}
>  out:
>  	up_read(&sb->s_umount);
> -	kfree(rec);
> +	ocfs2_free_quota_recovery(rec);
>  	return status;
>  }
> 
> --
> 2.39.2
diff mbox series

Patch

diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
index 2956d888c131..e60383d6ecc1 100644
--- a/fs/ocfs2/quota_local.c
+++ b/fs/ocfs2/quota_local.c
@@ -678,7 +678,7 @@  int ocfs2_finish_quota_recovery(struct ocfs2_super *osb,
 	}
 out:
 	up_read(&sb->s_umount);
-	kfree(rec);
+	ocfs2_free_quota_recovery(rec);
 	return status;
 }