The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] squashfs: free full-cache folio array on read error
@ 2026-11-28 21:19 Wesley Atwell
  0 siblings, 0 replies; only message in thread
From: Wesley Atwell @ 2026-11-28 21:19 UTC (permalink / raw)
  To: Chanho Min, Phillip Lougher, Andrew Morton; +Cc: Wesley Atwell, linux-kernel

With CONFIG_SQUASHFS_COMP_CACHE_FULL enabled, SquashFS allocates a
temporary array of folio pointers before reading a compressed block.
If the block read fails, squashfs_bio_read_cached() returns without
freeing that array. It remains allocated after the reader exits and the
filesystem is unmounted.

In an unmodified QEMU guest on the target mainline base, GNU tar made
one archive pass over a valid SquashFS image with 2,048 distinct files.
When the backing device returned EIO, tar reported all 2,048 file-read
errors and exited with status 2, but the kernel retained 4,096 temporary
arrays, occupying 2 MiB of slab objects after unmount. A healthy tar
control archived all files. This is a failed backup on a supported but
opt-in cache configuration under a complete backing-device read failure.

Free the array before returning the I/O error. The normal caching path
and errno are unchanged. With the fix, the same failed tar scan still
reported EIO, but all 4,096 arrays were freed; the healthy control still
archived every file.

OpenAI Codex identified the missing cleanup, drafted the fix and
changelog, and prepared the QEMU archive tests. With the fix, the
kernel freed all 4,096 tracked arrays during the injected read failure,
and GNU tar still reported EIO. The healthy archive contained all
2,048 files.

Fixes: 2e227ff5e272 ("squashfs: add optional full compressed block caching")
Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
---
 fs/squashfs/block.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index 2d5850168026..c1dd08aefbcf 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -145,8 +145,12 @@ static int squashfs_bio_read_cached(struct bio *fullbio,
 		bio_put(bio);
 	}
 
-	if (err)
+	if (err) {
+#ifdef CONFIG_SQUASHFS_COMP_CACHE_FULL
+		kfree(cache_folios);
+#endif
 		return err;
+	}
 
 	if (head_to_cache) {
 		int ret = filemap_add_folio(cache_mapping, head_to_cache,

base-commit: 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-28 21:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 21:19 [PATCH] squashfs: free full-cache folio array on read error Wesley Atwell

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