Commit 26d75a16 authored by Luís Henriques's avatar Luís Henriques Committed by Theodore Ts'o

ext4: fix error code return to user-space in ext4_get_branch()

If a block is out of range in ext4_get_branch(), -ENOMEM will be returned
to user-space.  Obviously, this error code isn't really useful.  This
patch fixes it by making sure the right error code (-EFSCORRUPTED) is
propagated to user-space.  EUCLEAN is more informative than ENOMEM.
Signed-off-by: default avatarLuís Henriques <lhenriques@suse.de>
Link: https://lore.kernel.org/r/20221109181445.17843-1-lhenriques@suse.deSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
parent 060f7739
...@@ -148,6 +148,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, ...@@ -148,6 +148,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
Indirect *p = chain; Indirect *p = chain;
struct buffer_head *bh; struct buffer_head *bh;
unsigned int key;
int ret = -EIO; int ret = -EIO;
*err = 0; *err = 0;
...@@ -156,7 +157,13 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, ...@@ -156,7 +157,13 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
if (!p->key) if (!p->key)
goto no_block; goto no_block;
while (--depth) { while (--depth) {
bh = sb_getblk(sb, le32_to_cpu(p->key)); key = le32_to_cpu(p->key);
if (key > ext4_blocks_count(EXT4_SB(sb)->s_es)) {
/* the block was out of range */
ret = -EFSCORRUPTED;
goto failure;
}
bh = sb_getblk(sb, key);
if (unlikely(!bh)) { if (unlikely(!bh)) {
ret = -ENOMEM; ret = -ENOMEM;
goto failure; goto failure;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment