public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: Fix memory leak in ext4_ext_shift_extents()
@ 2025-12-25  8:48 Zilin Guan
  2025-12-25  9:10 ` Baokun Li
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zilin Guan @ 2025-12-25  8:48 UTC (permalink / raw)
  To: tytso; +Cc: adilger.kernel, linux-ext4, linux-kernel, jianhao.xu, Zilin Guan

In ext4_ext_shift_extents(), if the extent is NULL in the while loop, the
function returns immediately without releasing the path obtained via
ext4_find_extent(), leading to a memory leak.

Fix this by jumping to the out label to ensure the path is properly
released.

Fixes: a18ed359bdddc ("ext4: always check ext4_ext_find_extent result")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 fs/ext4/extents.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 2cf5759ba689..1d21943a09b0 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5375,7 +5375,8 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
 		if (!extent) {
 			EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
 					 (unsigned long) *iterator);
-			return -EFSCORRUPTED;
+			ret = -EFSCORRUPTED;
+			goto out;
 		}
 		if (SHIFT == SHIFT_LEFT && *iterator >
 		    le32_to_cpu(extent->ee_block)) {
-- 
2.34.1


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

* Re: [PATCH] ext4: Fix memory leak in ext4_ext_shift_extents()
  2025-12-25  8:48 [PATCH] ext4: Fix memory leak in ext4_ext_shift_extents() Zilin Guan
@ 2025-12-25  9:10 ` Baokun Li
  2025-12-25 11:09 ` Zhang Yi
  2026-01-28 18:05 ` Theodore Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Baokun Li @ 2025-12-25  9:10 UTC (permalink / raw)
  To: Zilin Guan
  Cc: tytso, adilger.kernel, linux-ext4, linux-kernel, jianhao.xu,
	libaokun9

On 2025-12-25 16:48, Zilin Guan wrote:
> In ext4_ext_shift_extents(), if the extent is NULL in the while loop, the
> function returns immediately without releasing the path obtained via
> ext4_find_extent(), leading to a memory leak.
>
> Fix this by jumping to the out label to ensure the path is properly
> released.
>
> Fixes: a18ed359bdddc ("ext4: always check ext4_ext_find_extent result")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>

Nice catch! The patch looks good so feel free to add:

Reviewed-by: Baokun Li <libaokun1@huawei.com>

> ---
>  fs/ext4/extents.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 2cf5759ba689..1d21943a09b0 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -5375,7 +5375,8 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
>  		if (!extent) {
>  			EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
>  					 (unsigned long) *iterator);
> -			return -EFSCORRUPTED;
> +			ret = -EFSCORRUPTED;
> +			goto out;
>  		}
>  		if (SHIFT == SHIFT_LEFT && *iterator >
>  		    le32_to_cpu(extent->ee_block)) {



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

* Re: [PATCH] ext4: Fix memory leak in ext4_ext_shift_extents()
  2025-12-25  8:48 [PATCH] ext4: Fix memory leak in ext4_ext_shift_extents() Zilin Guan
  2025-12-25  9:10 ` Baokun Li
@ 2025-12-25 11:09 ` Zhang Yi
  2026-01-28 18:05 ` Theodore Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Zhang Yi @ 2025-12-25 11:09 UTC (permalink / raw)
  To: Zilin Guan, tytso; +Cc: adilger.kernel, linux-ext4, linux-kernel, jianhao.xu

On 12/25/2025 4:48 PM, Zilin Guan wrote:
> In ext4_ext_shift_extents(), if the extent is NULL in the while loop, the
> function returns immediately without releasing the path obtained via
> ext4_find_extent(), leading to a memory leak.
> 
> Fix this by jumping to the out label to ensure the path is properly
> released.
> 
> Fixes: a18ed359bdddc ("ext4: always check ext4_ext_find_extent result")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>

Looks good to me.

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

> ---
>  fs/ext4/extents.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 2cf5759ba689..1d21943a09b0 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -5375,7 +5375,8 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
>  		if (!extent) {
>  			EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
>  					 (unsigned long) *iterator);
> -			return -EFSCORRUPTED;
> +			ret = -EFSCORRUPTED;
> +			goto out;
>  		}
>  		if (SHIFT == SHIFT_LEFT && *iterator >
>  		    le32_to_cpu(extent->ee_block)) {


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

* Re: [PATCH] ext4: Fix memory leak in ext4_ext_shift_extents()
  2025-12-25  8:48 [PATCH] ext4: Fix memory leak in ext4_ext_shift_extents() Zilin Guan
  2025-12-25  9:10 ` Baokun Li
  2025-12-25 11:09 ` Zhang Yi
@ 2026-01-28 18:05 ` Theodore Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Theodore Ts'o @ 2026-01-28 18:05 UTC (permalink / raw)
  To: Zilin Guan
  Cc: Theodore Ts'o, adilger.kernel, linux-ext4, linux-kernel,
	jianhao.xu


On Thu, 25 Dec 2025 08:48:00 +0000, Zilin Guan wrote:
> In ext4_ext_shift_extents(), if the extent is NULL in the while loop, the
> function returns immediately without releasing the path obtained via
> ext4_find_extent(), leading to a memory leak.
> 
> Fix this by jumping to the out label to ensure the path is properly
> released.
> 
> [...]

Applied, thanks!

[1/1] ext4: Fix memory leak in ext4_ext_shift_extents()
      commit: ca81109d4a8f192dc1cbad4a1ee25246363c2833

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

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

end of thread, other threads:[~2026-01-28 18:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-25  8:48 [PATCH] ext4: Fix memory leak in ext4_ext_shift_extents() Zilin Guan
2025-12-25  9:10 ` Baokun Li
2025-12-25 11:09 ` Zhang Yi
2026-01-28 18:05 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox