The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Wesley Atwell <atwellwea@gmail.com>
To: Chanho Min <chanho.min@lge.com>,
	Phillip Lougher <phillip@squashfs.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Wesley Atwell <atwellwea@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] squashfs: free full-cache folio array on read error
Date: Sat, 28 Nov 2026 14:19:24 -0700	[thread overview]
Message-ID: <kernel-c7e112cb88bbba76-v1.atwellwea@gmail.com> (raw)

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

                 reply	other threads:[~2026-11-28 21:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=kernel-c7e112cb88bbba76-v1.atwellwea@gmail.com \
    --to=atwellwea@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chanho.min@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillip@squashfs.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox