[2/3] ext4: bubble errors from ext4_find_inline_data_nolock() up to ext4_iget()

Message ID 20180523153714.28470-2-tytso@mit.edu
State New
Headers show
Series
  • [1/3] ext4: do not allow external inodes for inline data
Related show

Commit Message

Theodore Y. Ts'o May 23, 2018, 3:37 p.m.
If ext4_find_inline_data_nolock() returns an error it needs to get
reflected up to ext4_iget().  In order to fix this,
ext4_iget_extra_inode() needs to return an error (and not return
void).

This is related to "ext4: do not allow external inodes for inline
data" in that in the errors=continue case, it would be useful to for
userspace to receive an error indicating that file system is
corrupted.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
---
 fs/ext4/inode.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Andreas Dilger May 24, 2018, 4:52 p.m. | #1
On May 23, 2018, at 9:37 AM, Theodore Ts'o <tytso@mit.edu> wrote:
> 
> If ext4_find_inline_data_nolock() returns an error it needs to get
> reflected up to ext4_iget().  In order to fix this,
> ext4_iget_extra_inode() needs to return an error (and not return
> void).
> 
> This is related to "ext4: do not allow external inodes for inline
> data" in that in the errors=continue case, it would be useful to for
> userspace to receive an error indicating that file system is
> corrupted.
> 
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

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

> Cc: stable@kernel.org
> ---
> fs/ext4/inode.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 58301a697379..2ea07efbe016 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4701,19 +4701,21 @@ static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
> 	}
> }
> 
> -static inline void ext4_iget_extra_inode(struct inode *inode,
> +static inline int ext4_iget_extra_inode(struct inode *inode,
> 					 struct ext4_inode *raw_inode,
> 					 struct ext4_inode_info *ei)
> {
> 	__le32 *magic = (void *)raw_inode +
> 			EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize;
> +
> 	if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize + sizeof(__le32) <=
> 	    EXT4_INODE_SIZE(inode->i_sb) &&
> 	    *magic == cpu_to_le32(EXT4_XATTR_MAGIC)) {
> 		ext4_set_inode_state(inode, EXT4_STATE_XATTR);
> -		ext4_find_inline_data_nolock(inode);
> +		return ext4_find_inline_data_nolock(inode);
> 	} else
> 		EXT4_I(inode)->i_inline_off = 0;
> +	return 0;
> }
> 
> int ext4_get_projid(struct inode *inode, kprojid_t *projid)
> @@ -4913,7 +4915,9 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
> 			ei->i_extra_isize = sizeof(struct ext4_inode) -
> 					    EXT4_GOOD_OLD_INODE_SIZE;
> 		} else {
> -			ext4_iget_extra_inode(inode, raw_inode, ei);
> +			ret = ext4_iget_extra_inode(inode, raw_inode, ei);
> +			if (ret)
> +				goto bad_inode;
> 		}
> 	}
> 
> --
> 2.16.1.72.g5be1f00a9a
> 


Cheers, Andreas

Patch

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 58301a697379..2ea07efbe016 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4701,19 +4701,21 @@  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
 	}
 }
 
-static inline void ext4_iget_extra_inode(struct inode *inode,
+static inline int ext4_iget_extra_inode(struct inode *inode,
 					 struct ext4_inode *raw_inode,
 					 struct ext4_inode_info *ei)
 {
 	__le32 *magic = (void *)raw_inode +
 			EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize;
+
 	if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize + sizeof(__le32) <=
 	    EXT4_INODE_SIZE(inode->i_sb) &&
 	    *magic == cpu_to_le32(EXT4_XATTR_MAGIC)) {
 		ext4_set_inode_state(inode, EXT4_STATE_XATTR);
-		ext4_find_inline_data_nolock(inode);
+		return ext4_find_inline_data_nolock(inode);
 	} else
 		EXT4_I(inode)->i_inline_off = 0;
+	return 0;
 }
 
 int ext4_get_projid(struct inode *inode, kprojid_t *projid)
@@ -4913,7 +4915,9 @@  struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
 			ei->i_extra_isize = sizeof(struct ext4_inode) -
 					    EXT4_GOOD_OLD_INODE_SIZE;
 		} else {
-			ext4_iget_extra_inode(inode, raw_inode, ei);
+			ret = ext4_iget_extra_inode(inode, raw_inode, ei);
+			if (ret)
+				goto bad_inode;
 		}
 	}