Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
ext2: Fix fs corruption in ext2_get_xip_mem()
Browse files Browse the repository at this point in the history
commit 7ba3ec5 upstream.

Commit 8e3dffc "Ext2: mark inode dirty after the function
dquot_free_block_nodirty is called" unveiled a bug in __ext2_get_block()
called from ext2_get_xip_mem(). That function called ext2_get_block()
mistakenly asking it to map 0 blocks while 1 was intended. Before the
above mentioned commit things worked out fine by luck but after that commit
we started returning that we allocated 0 blocks while we in fact
allocated 1 block and thus allocation was looping until all blocks in
the filesystem were exhausted.

Fix the problem by properly asking for one block and also add assertion
in ext2_get_blocks() to catch similar problems.

Reported-and-tested-by: Andiry Xu <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
Cc: Wang Nan <[email protected]>
Signed-off-by: Zefan Li <[email protected]>
  • Loading branch information
jankara authored and lizf-os committed Sep 25, 2014
1 parent f79bb94 commit 3a8f613
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fs/ext2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ static int ext2_get_blocks(struct inode *inode,
int count = 0;
ext2_fsblk_t first_block = 0;

BUG_ON(maxblocks == 0);

depth = ext2_block_to_path(inode,iblock,offsets,&blocks_to_boundary);

if (depth == 0)
Expand Down
1 change: 1 addition & 0 deletions fs/ext2/xip.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ __ext2_get_block(struct inode *inode, pgoff_t pgoff, int create,
int rc;

memset(&tmp, 0, sizeof(struct buffer_head));
tmp.b_size = 1 << inode->i_blkbits;
rc = ext2_get_block(inode, pgoff, &tmp, create);
*result = tmp.b_blocknr;

Expand Down

0 comments on commit 3a8f613

Please sign in to comment.