All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] squashfs: fix inode lookup sanity checks
@ 2021-02-26  9:29 Sean Nyekjaer
  2021-02-26 20:01 ` Phillip Lougher
  2021-02-26 20:09 ` Phillip Lougher
  0 siblings, 2 replies; 3+ messages in thread
From: Sean Nyekjaer @ 2021-02-26  9:29 UTC (permalink / raw)
  To: Phillip Lougher, Andrew Morton; +Cc: Sean Nyekjaer, stable, linux-kernel

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")
CC: stable@vger.kernel.org
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
 fs/squashfs/export.c      | 8 ++++++--
 fs/squashfs/squashfs_fs.h | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/squashfs/export.c b/fs/squashfs/export.c
index eb02072d28dd..723763746238 100644
--- a/fs/squashfs/export.c
+++ b/fs/squashfs/export.c
@@ -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);
 	}
diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
index 8d64edb80ebf..b3fdc8212c5f 100644
--- a/fs/squashfs/squashfs_fs.h
+++ b/fs/squashfs/squashfs_fs.h
@@ -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
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] squashfs: fix inode lookup sanity checks
  2021-02-26  9:29 [PATCH] squashfs: fix inode lookup sanity checks Sean Nyekjaer
@ 2021-02-26 20:01 ` Phillip Lougher
  2021-02-26 20:09 ` Phillip Lougher
  1 sibling, 0 replies; 3+ messages in thread
From: Phillip Lougher @ 2021-02-26 20:01 UTC (permalink / raw)
  To: Sean Nyekjaer, Andrew Morton; +Cc: stable, linux-kernel

On 26/02/2021 09:29, Sean Nyekjaer wrote:
> 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")
> CC: stable@vger.kernel.org
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>

Acked-by: phillip@squashfs.org.uk.

> ---
>   fs/squashfs/export.c      | 8 ++++++--
>   fs/squashfs/squashfs_fs.h | 1 +
>   2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/squashfs/export.c b/fs/squashfs/export.c
> index eb02072d28dd..723763746238 100644
> --- a/fs/squashfs/export.c
> +++ b/fs/squashfs/export.c
> @@ -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);
>   	}
> diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
> index 8d64edb80ebf..b3fdc8212c5f 100644
> --- a/fs/squashfs/squashfs_fs.h
> +++ b/fs/squashfs/squashfs_fs.h
> @@ -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
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] squashfs: fix inode lookup sanity checks
  2021-02-26  9:29 [PATCH] squashfs: fix inode lookup sanity checks Sean Nyekjaer
  2021-02-26 20:01 ` Phillip Lougher
@ 2021-02-26 20:09 ` Phillip Lougher
  1 sibling, 0 replies; 3+ messages in thread
From: Phillip Lougher @ 2021-02-26 20:09 UTC (permalink / raw)
  To: Sean Nyekjaer, Andrew Morton; +Cc: stable, linux-kernel


> On 26/02/2021 09:29 Sean Nyekjaer <sean@geanix.com> wrote:
> 
>  
> 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")
> CC: stable@vger.kernel.org
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>

Acked-by: Phillip Lougher <phillip@squashfs.org.uk>

> ---
>  fs/squashfs/export.c      | 8 ++++++--
>  fs/squashfs/squashfs_fs.h | 1 +
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/squashfs/export.c b/fs/squashfs/export.c
> index eb02072d28dd..723763746238 100644
> --- a/fs/squashfs/export.c
> +++ b/fs/squashfs/export.c
> @@ -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);
>  	}
> diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
> index 8d64edb80ebf..b3fdc8212c5f 100644
> --- a/fs/squashfs/squashfs_fs.h
> +++ b/fs/squashfs/squashfs_fs.h
> @@ -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
> -- 
> 2.29.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-05  2:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26  9:29 [PATCH] squashfs: fix inode lookup sanity checks Sean Nyekjaer
2021-02-26 20:01 ` Phillip Lougher
2021-02-26 20:09 ` Phillip Lougher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.