From: Wesley Atwell <atwellwea@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Phillip Lougher <phillip@squashfs.org.uk>
Cc: linux-kernel@vger.kernel.org, Wesley Atwell <atwellwea@gmail.com>
Subject: [PATCH] squashfs: return directory read errors to readdir callers
Date: Sat, 28 Nov 2026 14:19:23 -0700 [thread overview]
Message-ID: <kernel-0242b80cf5415d89-v1.atwellwea@gmail.com> (raw)
squashfs_readdir() logs a directory metadata read failure but returns 0.
VFS then reports end of directory to userspace, so a scanner or backup
can accept an incomplete tree as complete.
On an unmodified mm-nonmm-unstable kernel, a QEMU guest mounted a valid,
default-compressed SquashFS image with 3,000 nonempty files. A 4 KiB
device-mapper error range inside the directory table made Fedora GNU
find exit successfully after only 163 files and GNU tar exit
successfully with only 164 archive entries. Healthy scans found all
3,000 files. Traced getdents64 returned a partial listing and then
EOF. The injected EIO models unreadable local storage; it is not a
claim of a physical-media incident.
Follow squashfs_lookup() by setting EIO for invalid directory metadata,
preserving negative metadata-read errors, and returning the result
through the existing cleanup path. With the same fault, getdents64 now
reports EIO after the partial listing, GNU find exits 1, and GNU tar
exits 2 with an I/O error. Healthy scans remain complete. BusyBox find
and tar still ignore the later readdir error, so this change does not
correct those applets' exit status.
OpenAI Codex identified the dropped read error, drafted the fix and
changelog, and prepared the QEMU directory scans. GNU find and tar
reported EIO with the fix under the injected metadata read fault.
Healthy scans still found all 3,000 files.
Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
---
fs/squashfs/dir.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/fs/squashfs/dir.c b/fs/squashfs/dir.c
index 54d228e06283..3555637a014a 100644
--- a/fs/squashfs/dir.c
+++ b/fs/squashfs/dir.c
@@ -180,7 +180,7 @@ static int squashfs_readdir(struct file *file, struct dir_context *ctx)
block = squashfs_dir_start(squashfs_i(inode)->start, msblk);
if (block < 0)
- goto failed_read;
+ goto data_error;
dire = kmalloc(sizeof(*dire) + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
if (dire == NULL) {
@@ -200,7 +200,7 @@ static int squashfs_readdir(struct file *file, struct dir_context *ctx)
* Read directory header
*/
if (!squashfs_dir_space(inode, length, sizeof(dirh)))
- goto failed_read;
+ goto data_error;
err = squashfs_read_metadata(inode->i_sb, &dirh, &block,
&offset, sizeof(dirh));
@@ -212,14 +212,14 @@ static int squashfs_readdir(struct file *file, struct dir_context *ctx)
dir_count = le32_to_cpu(dirh.count) + 1;
if (dir_count > SQUASHFS_DIR_COUNT)
- goto failed_read;
+ goto data_error;
while (dir_count--) {
/*
* Read directory entry.
*/
if (!squashfs_dir_space(inode, length, sizeof(*dire)))
- goto failed_read;
+ goto data_error;
err = squashfs_read_metadata(inode->i_sb, dire, &block,
&offset, sizeof(*dire));
@@ -231,10 +231,10 @@ static int squashfs_readdir(struct file *file, struct dir_context *ctx)
/* size should never be larger than SQUASHFS_DISK_NAME_LEN */
if (size > SQUASHFS_DISK_NAME_LEN)
- goto failed_read;
+ goto data_error;
if (!squashfs_dir_space(inode, length, ++ size))
- goto failed_read;
+ goto data_error;
err = squashfs_read_metadata(inode->i_sb, dire->name,
&block, &offset, size);
@@ -252,7 +252,7 @@ static int squashfs_readdir(struct file *file, struct dir_context *ctx)
type = le16_to_cpu(dire->type);
if (type > SQUASHFS_MAX_DIR_TYPE)
- goto failed_read;
+ goto data_error;
if (!dir_emit(ctx, dire->name, size,
inode_number,
@@ -267,11 +267,14 @@ static int squashfs_readdir(struct file *file, struct dir_context *ctx)
kfree(dire);
return 0;
+data_error:
+ err = -EIO;
+
failed_read:
ERROR("Unable to read directory [%llx:%x]\n", squashfs_i(inode)->start,
squashfs_i(inode)->offset);
kfree(dire);
- return 0;
+ return err;
}
base-commit: 941b98138a3df2127ebb5d187bb8f04858f9ed1b
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-0242b80cf5415d89-v1.atwellwea@gmail.com \
--to=atwellwea@gmail.com \
--cc=akpm@linux-foundation.org \
--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