Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] ext4: fix folio reference leak in mpage_submit_partial_folio()
@ 2026-10-16 14:25 guolingxing
  2026-10-16 14:35 ` sashiko-bot
  2026-10-17  2:19 ` Zhang Yi
  0 siblings, 2 replies; 3+ messages in thread
From: guolingxing @ 2026-10-16 14:25 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger, Jan Kara
  Cc: Baokun Li, Ojaswin Mujoo, Ritesh Harjani, Zhang Yi, linux-ext4,
	linux-kernel, stable, guolingxing

mpage_submit_partial_folio() obtains a folio reference with
filemap_get_folio(). If the subsequent position check fails, it
returns -EINVAL without dropping that reference.

Call folio_put() before returning from this error path. Leave the
folio locked so that the caller can invalidate and unlock it through
mpage_release_unused_pages().

Fixes: ded2d726a304 ("ext4: fix stale data if it bail out of the extents mapping loop")
Cc: stable@vger.kernel.org
Signed-off-by: guolingxing <guolingxing@tju.edu.cn>
---
 fs/ext4/inode.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 26f0f9714f03..7afba6298fa2 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2412,8 +2412,14 @@ static int mpage_submit_partial_folio(struct mpage_da_data *mpd)
 	 */
 	pos = ((loff_t)mpd->map.m_lblk) << inode->i_blkbits;
 	if (WARN_ON_ONCE((folio_pos(folio) == pos) ||
-			 !folio_contains(folio, pos >> PAGE_SHIFT)))
+			 !folio_contains(folio, pos >> PAGE_SHIFT))) {
+		/*
+		 * Leave the folio locked so that the caller can invalidate
+		 * and unlock it through mpage_release_unused_pages().
+		 */
+		folio_put(folio);
 		return -EINVAL;
+	}
 
 	mpage_submit_folio(mpd, folio);
 	/*
-- 
2.34.1


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

* Re: [PATCH] ext4: fix folio reference leak in mpage_submit_partial_folio()
  2026-10-16 14:25 [PATCH] ext4: fix folio reference leak in mpage_submit_partial_folio() guolingxing
@ 2026-10-16 14:35 ` sashiko-bot
  2026-10-17  2:19 ` Zhang Yi
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-16 14:35 UTC (permalink / raw)
  To: guolingxing; +Cc: linux-ext4, tytso

> mpage_submit_partial_folio() obtains a folio reference with
> filemap_get_folio(). If the subsequent position check fails, it
> returns -EINVAL without dropping that reference.
> 
> Call folio_put() before returning from this error path. Leave the
> folio locked so that the caller can invalidate and unlock it through
> mpage_release_unused_pages().
> 
> Fixes: ded2d726a304 ("ext4: fix stale data if it bail out of the extents mapping loop")
> Cc: stable@vger.kernel.org
> Signed-off-by: guolingxing <guolingxing@tju.edu.cn>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261016142524.655789-1-guolingxing@tju.edu.cn?part=1


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

* Re: [PATCH] ext4: fix folio reference leak in mpage_submit_partial_folio()
  2026-10-16 14:25 [PATCH] ext4: fix folio reference leak in mpage_submit_partial_folio() guolingxing
  2026-10-16 14:35 ` sashiko-bot
@ 2026-10-17  2:19 ` Zhang Yi
  1 sibling, 0 replies; 3+ messages in thread
From: Zhang Yi @ 2026-10-17  2:19 UTC (permalink / raw)
  To: guolingxing
  Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Baokun Li,
	Ojaswin Mujoo, Ritesh Harjani, Zhang Yi, linux-ext4, linux-kernel,
	stable

On 10/16/2026 10:25 PM, guolingxing wrote:
> mpage_submit_partial_folio() obtains a folio reference with
> filemap_get_folio(). If the subsequent position check fails, it
> returns -EINVAL without dropping that reference.
> 
> Call folio_put() before returning from this error path. Leave the
> folio locked so that the caller can invalidate and unlock it through
> mpage_release_unused_pages().
> 
> Fixes: ded2d726a304 ("ext4: fix stale data if it bail out of the extents mapping loop")
> Cc: stable@vger.kernel.org
> Signed-off-by: guolingxing <guolingxing@tju.edu.cn>

Thank you for the fix, looks good to me.

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

> ---
>   fs/ext4/inode.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 26f0f9714f03..7afba6298fa2 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -2412,8 +2412,14 @@ static int mpage_submit_partial_folio(struct mpage_da_data *mpd)
>   	 */
>   	pos = ((loff_t)mpd->map.m_lblk) << inode->i_blkbits;
>   	if (WARN_ON_ONCE((folio_pos(folio) == pos) ||
> -			 !folio_contains(folio, pos >> PAGE_SHIFT)))
> +			 !folio_contains(folio, pos >> PAGE_SHIFT))) {
> +		/*
> +		 * Leave the folio locked so that the caller can invalidate
> +		 * and unlock it through mpage_release_unused_pages().
> +		 */
> +		folio_put(folio);
>   		return -EINVAL;
> +	}
>   
>   	mpage_submit_folio(mpd, folio);
>   	/*


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

end of thread, other threads:[~2026-10-17  2:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-16 14:25 [PATCH] ext4: fix folio reference leak in mpage_submit_partial_folio() guolingxing
2026-10-16 14:35 ` sashiko-bot
2026-10-17  2:19 ` Zhang Yi

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