Skip to contentSkip to conversation

squashfs: fix inode lookup sanity checks

PATCH Applied Sean Nyekjaer 2 participants 3 messages Feb 26, 2021 – Mar 5, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 squashfs: fix inode lookup sanity checks

When mouting a squashfs image created without inode compression it fails with: "unable to read inode lookup table"

It turns out that the BLOCK_OFFSET is missing when checking the SQUASHFS_METADATA_SIZE agaist the actual size.

Fixes eabac19e40c0 ("squashfs: add more sanity checks in inode lookup")
---
 fs/squashfs/export.c      | 8 ++++++--
 fs/squashfs/squashfs_fs.h | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)
fs/squashfs/export.c +6 -2
index eb02072d28dd..723763746238 100644
@@ -152,14 +152,18 @@ __le64 *squashfs_read_inode_lookup_table(struct super_block *sb,
 		start = le64_to_cpu(table[n]);
 		end = le64_to_cpu(table[n + 1]);
 
-		if (start >= end || (end - start) > SQUASHFS_METADATA_SIZE) {
+		if (start >= end
+		    || (end - start) >
+		    (SQUASHFS_METADATA_SIZE + SQUASHFS_BLOCK_OFFSET)) {
 			kfree(table);
 			return ERR_PTR(-EINVAL);
 		}
 	}
 
 	start = le64_to_cpu(table[indexes - 1]);
-	if (start >= lookup_table_start || (lookup_table_start - start) > SQUASHFS_METADATA_SIZE) {
+	if (start >= lookup_table_start ||
+	    (lookup_table_start - start) >
+	    (SQUASHFS_METADATA_SIZE + SQUASHFS_BLOCK_OFFSET)) {
 		kfree(table);
 		return ERR_PTR(-EINVAL);
 	}
fs/squashfs/squashfs_fs.h +1 -0
index 8d64edb80ebf..b3fdc8212c5f 100644
@@ -17,6 +17,7 @@
 
 /* size of metadata (inode and directory) blocks */
 #define SQUASHFS_METADATA_SIZE		8192
+#define SQUASHFS_BLOCK_OFFSET		2
 
 /* default size of block device I/O */
 #ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE
Signature · 1 line
2.29.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · On 26/02/2021 09:29 Sean Nyekjaer <[email protected]> wrote:

When mouting a squashfs image created without inode compression it fails with: "unable to read inode lookup table"

Quoted 6 lines

It turns out that the BLOCK_OFFSET is missing when checking the SQUASHFS_METADATA_SIZE agaist the actual size.

Fixes eabac19e40c0 ("squashfs: add more sanity checks in inode lookup")
Quoted 44 lines
---
 fs/squashfs/export.c      | 8 ++++++--
 fs/squashfs/squashfs_fs.h | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)
fs/squashfs/export.c +6 -2
index eb02072d28dd..723763746238 100644
@@ -152,14 +152,18 @@ __le64 *squashfs_read_inode_lookup_table(struct super_block *sb,
 		start = le64_to_cpu(table[n]);
 		end = le64_to_cpu(table[n + 1]);
 
-		if (start >= end || (end - start) > SQUASHFS_METADATA_SIZE) {
+		if (start >= end
+		    || (end - start) >
+		    (SQUASHFS_METADATA_SIZE + SQUASHFS_BLOCK_OFFSET)) {
 			kfree(table);
 			return ERR_PTR(-EINVAL);
 		}
 	}
 
 	start = le64_to_cpu(table[indexes - 1]);
-	if (start >= lookup_table_start || (lookup_table_start - start) > SQUASHFS_METADATA_SIZE) {
+	if (start >= lookup_table_start ||
+	    (lookup_table_start - start) >
+	    (SQUASHFS_METADATA_SIZE + SQUASHFS_BLOCK_OFFSET)) {
 		kfree(table);
 		return ERR_PTR(-EINVAL);
 	}
fs/squashfs/squashfs_fs.h +1 -0
index 8d64edb80ebf..b3fdc8212c5f 100644
@@ -17,6 +17,7 @@
 
 /* size of metadata (inode and directory) blocks */
 #define SQUASHFS_METADATA_SIZE		8192
+#define SQUASHFS_BLOCK_OFFSET		2
 
 /* default size of block device I/O */
 #ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE
Signature · 1 line
2.29.2
maintainer Acked-by [email protected]. on v1 1/1
#2 lore raw
In reply to Sean Nyekjaer
Quoted 9 lines · Sean Nyekjaer

When mouting a squashfs image created without inode compression it fails with: "unable to read inode lookup table"

It turns out that the BLOCK_OFFSET is missing when checking the SQUASHFS_METADATA_SIZE agaist the actual size.

Fixes eabac19e40c0 ("squashfs: add more sanity checks in inode lookup")
Quoted 43 lines
---
  fs/squashfs/export.c      | 8 ++++++--
  fs/squashfs/squashfs_fs.h | 1 +
  2 files changed, 7 insertions(+), 2 deletions(-)
fs/squashfs/export.c +6 -2
index eb02072d28dd..723763746238 100644
@@ -152,14 +152,18 @@ __le64 *squashfs_read_inode_lookup_table(struct super_block *sb,
  		start = le64_to_cpu(table[n]);
  		end = le64_to_cpu(table[n + 1]);
 
-		if (start >= end || (end - start) > SQUASHFS_METADATA_SIZE) {
+		if (start >= end
+		    || (end - start) >
+		    (SQUASHFS_METADATA_SIZE + SQUASHFS_BLOCK_OFFSET)) {
  			kfree(table);
  			return ERR_PTR(-EINVAL);
  		}
  	}
 
  	start = le64_to_cpu(table[indexes - 1]);
-	if (start >= lookup_table_start || (lookup_table_start - start) > SQUASHFS_METADATA_SIZE) {
+	if (start >= lookup_table_start ||
+	    (lookup_table_start - start) >
+	    (SQUASHFS_METADATA_SIZE + SQUASHFS_BLOCK_OFFSET)) {
  		kfree(table);
  		return ERR_PTR(-EINVAL);
  	}
fs/squashfs/squashfs_fs.h +1 -0
index 8d64edb80ebf..b3fdc8212c5f 100644
@@ -17,6 +17,7 @@
 
  /* size of metadata (inode and directory) blocks */
  #define SQUASHFS_METADATA_SIZE		8192
+#define SQUASHFS_BLOCK_OFFSET		2
 
  /* default size of block device I/O */
  #ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE