[PATCH v2 22/22] Squashfs: check index isn't greater than S64_MAX in squashfs_read_data()

From: Phillip Lougher

Date: Wed Nov 11 2026 - 19:01:46 EST


The previous commits in this patch-set now sanity check index before
squashfs_read_data() is called. However, it is always wise to take
a belts and braces approach and sanity check at the lowest level to
trap any values that could slip through.

Fixes: e2780ab159ac6 ("Squashfs: block operations")
Signed-off-by: Phillip Lougher <phillip@xxxxxxxxxxxxxxx>
---
fs/squashfs/block.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index 20c3030b4f96..f2f03d815167 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -297,6 +297,15 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
int res;
int offset;

+ /*
+ * Reject index values greater than possible filesystem size (S64_MAX).
+ * This also ensures the index variable doesn't overflow in the function.
+ */
+ if (index > S64_MAX) {
+ res = -EIO;
+ goto out;
+ }
+
if (length) {
/*
* Datablock.
--
2.47.3