* [PATCH] squashfs: return directory read errors to readdir callers
@ 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: Andrew Morton, Phillip Lougher; +Cc: linux-kernel, Wesley Atwell
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
^ 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: return directory read errors to readdir callers Wesley Atwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox