diff mbox series

e2fsck: fix endianness problem when reading htree nodes

Message ID 20180310224733.29843-1-tytso@mit.edu
State Accepted, archived
Headers show
Series e2fsck: fix endianness problem when reading htree nodes | expand

Commit Message

Theodore Ts'o March 10, 2018, 10:47 p.m. UTC
From: Lukas Czerner <lczerner@redhat.com>

Wrong directory block number can be saved in ->previous on big endian
system in parse_int_node(). Fix it by moving the mask out of the endian
conversion.

Fixes: ae9efd05a986 ("e2fsck: 3 level hash tree directory optimization")
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 e2fsck/pass2.c       | 5 +++--
 lib/ext2fs/ext2_fs.h | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Lukas Czerner March 12, 2018, 5:43 a.m. UTC | #1
On Sat, Mar 10, 2018 at 05:47:33PM -0500, Theodore Ts'o wrote:
> From: Lukas Czerner <lczerner@redhat.com>
> 
> Wrong directory block number can be saved in ->previous on big endian
> system in parse_int_node(). Fix it by moving the mask out of the endian
> conversion.

Thanks for the fix-up Ted. It looks good.

-Lukas

> 
> Fixes: ae9efd05a986 ("e2fsck: 3 level hash tree directory optimization")
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
>  e2fsck/pass2.c       | 5 +++--
>  lib/ext2fs/ext2_fs.h | 2 ++
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
> index 1b0504c85..e922876d3 100644
> --- a/e2fsck/pass2.c
> +++ b/e2fsck/pass2.c
> @@ -643,7 +643,7 @@ static void parse_int_node(ext2_filsys fs,
>  		printf("Entry #%d: Hash 0x%08x, block %u\n", i,
>  		       hash, ext2fs_le32_to_cpu(ent[i].block));
>  #endif
> -		blk = ext2fs_le32_to_cpu(ent[i].block) & 0x0ffffff;
> +		blk = ext2fs_le32_to_cpu(ent[i].block) & EXT4_DX_BLOCK_MASK;
>  		/* Check to make sure the block is valid */
>  		if (blk >= (blk_t) dx_dir->numblocks) {
>  			cd->pctx.blk = blk;
> @@ -664,7 +664,8 @@ static void parse_int_node(ext2_filsys fs,
>  		}
>  
>  		dx_db->previous =
> -			i ? ext2fs_le32_to_cpu(ent[i-1].block & 0x0ffffff) : 0;
> +			i ? (ext2fs_le32_to_cpu(ent[i-1].block) &
> +			     EXT4_DX_BLOCK_MASK) : 0;
>  
>  		if (hash < min_hash)
>  			min_hash = hash;
> diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
> index 2496d16da..7d6269413 100644
> --- a/lib/ext2fs/ext2_fs.h
> +++ b/lib/ext2fs/ext2_fs.h
> @@ -232,6 +232,8 @@ struct ext2_dx_root_info {
>  
>  #define EXT2_HASH_FLAG_INCOMPAT	0x1
>  
> +#define EXT4_DX_BLOCK_MASK 0x0fffffff
> +
>  struct ext2_dx_entry {
>  	__le32 hash;
>  	__le32 block;
> -- 
> 2.16.1.72.g5be1f00a9a
>
Andreas Dilger March 12, 2018, 6:18 p.m. UTC | #2
On Mar 10, 2018, at 3:47 PM, Theodore Ts'o <tytso@mit.edu> wrote:
> 
> From: Lukas Czerner <lczerner@redhat.com>
> 
> Wrong directory block number can be saved in ->previous on big endian
> system in parse_int_node(). Fix it by moving the mask out of the endian
> conversion.
> 
> Fixes: ae9efd05a986 ("e2fsck: 3 level hash tree directory optimization")
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Looks good.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> e2fsck/pass2.c       | 5 +++--
> lib/ext2fs/ext2_fs.h | 2 ++
> 2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
> index 1b0504c85..e922876d3 100644
> --- a/e2fsck/pass2.c
> +++ b/e2fsck/pass2.c
> @@ -643,7 +643,7 @@ static void parse_int_node(ext2_filsys fs,
> 		printf("Entry #%d: Hash 0x%08x, block %u\n", i,
> 		       hash, ext2fs_le32_to_cpu(ent[i].block));
> #endif
> -		blk = ext2fs_le32_to_cpu(ent[i].block) & 0x0ffffff;
> +		blk = ext2fs_le32_to_cpu(ent[i].block) & EXT4_DX_BLOCK_MASK;
> 		/* Check to make sure the block is valid */
> 		if (blk >= (blk_t) dx_dir->numblocks) {
> 			cd->pctx.blk = blk;
> @@ -664,7 +664,8 @@ static void parse_int_node(ext2_filsys fs,
> 		}
> 
> 		dx_db->previous =
> -			i ? ext2fs_le32_to_cpu(ent[i-1].block & 0x0ffffff) : 0;
> +			i ? (ext2fs_le32_to_cpu(ent[i-1].block) &
> +			     EXT4_DX_BLOCK_MASK) : 0;
> 
> 		if (hash < min_hash)
> 			min_hash = hash;
> diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
> index 2496d16da..7d6269413 100644
> --- a/lib/ext2fs/ext2_fs.h
> +++ b/lib/ext2fs/ext2_fs.h
> @@ -232,6 +232,8 @@ struct ext2_dx_root_info {
> 
> #define EXT2_HASH_FLAG_INCOMPAT	0x1
> 
> +#define EXT4_DX_BLOCK_MASK 0x0fffffff
> +
> struct ext2_dx_entry {
> 	__le32 hash;
> 	__le32 block;
> --
> 2.16.1.72.g5be1f00a9a
> 


Cheers, Andreas
diff mbox series

Patch

diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index 1b0504c85..e922876d3 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -643,7 +643,7 @@  static void parse_int_node(ext2_filsys fs,
 		printf("Entry #%d: Hash 0x%08x, block %u\n", i,
 		       hash, ext2fs_le32_to_cpu(ent[i].block));
 #endif
-		blk = ext2fs_le32_to_cpu(ent[i].block) & 0x0ffffff;
+		blk = ext2fs_le32_to_cpu(ent[i].block) & EXT4_DX_BLOCK_MASK;
 		/* Check to make sure the block is valid */
 		if (blk >= (blk_t) dx_dir->numblocks) {
 			cd->pctx.blk = blk;
@@ -664,7 +664,8 @@  static void parse_int_node(ext2_filsys fs,
 		}
 
 		dx_db->previous =
-			i ? ext2fs_le32_to_cpu(ent[i-1].block & 0x0ffffff) : 0;
+			i ? (ext2fs_le32_to_cpu(ent[i-1].block) &
+			     EXT4_DX_BLOCK_MASK) : 0;
 
 		if (hash < min_hash)
 			min_hash = hash;
diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
index 2496d16da..7d6269413 100644
--- a/lib/ext2fs/ext2_fs.h
+++ b/lib/ext2fs/ext2_fs.h
@@ -232,6 +232,8 @@  struct ext2_dx_root_info {
 
 #define EXT2_HASH_FLAG_INCOMPAT	0x1
 
+#define EXT4_DX_BLOCK_MASK 0x0fffffff
+
 struct ext2_dx_entry {
 	__le32 hash;
 	__le32 block;