From: Kemeng Shi Date: Mon, 23 Mar 2026 09:37:35 +0000 (-0700) Subject: mm: shmem: avoid unpaired folio_unlock() in shmem_swapin_folio() X-Git-Tag: v6.12.78~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1be8e41962f1f695ebeec6eb847d314b60cb2c4b;p=thirdparty%2Fkernel%2Fstable.git mm: shmem: avoid unpaired folio_unlock() in shmem_swapin_folio() commit e08d5f515613a9860bfee7312461a19f422adb5e upstream. If we get a folio from swap_cache_get_folio() successfully but encounter a failure before the folio is locked, we will unlock the folio which was not previously locked. Put the folio and set it to NULL when a failure occurs before the folio is locked to fix the issue. Link: https://lkml.kernel.org/r/20250516170939.965736-1-shikemeng@huaweicloud.com Link: https://lkml.kernel.org/r/20250516170939.965736-2-shikemeng@huaweicloud.com Fixes: 058313515d5a ("mm: shmem: fix potential data corruption during shmem swapin") Signed-off-by: Kemeng Shi Reviewed-by: Baolin Wang Reviewed-by: Kairui Song Cc: Hugh Dickins Cc: kernel test robot Signed-off-by: Andrew Morton [ hughd: removed series cover letter comments ] Signed-off-by: Hugh Dickins Signed-off-by: Greg Kroah-Hartman --- diff --git a/mm/shmem.c b/mm/shmem.c index 9105c732f3411..9b7df8397efc0 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2198,6 +2198,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, */ split_order = shmem_split_large_entry(inode, index, swap, gfp); if (split_order < 0) { + folio_put(folio); + folio = NULL; error = split_order; goto failed; }