aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext2
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2013-11-04 19:15:38 -0500
committerJan Kara <jack@suse.cz>2013-11-05 05:26:47 -0500
commit7ba3ec5749ddb61f79f7be17b5fd7720eebc52de (patch)
tree01b2ff745122e12632c17142ce72748336886b03 /fs/ext2
parent18da65e7d30a76ab3ca0ccd2b7ca0690f80f28e4 (diff)
ext2: Fix fs corruption in ext2_get_xip_mem()
Commit 8e3dffc651cb "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 <andiry.xu@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/ext2')
-rw-r--r--fs/ext2/inode.c2
-rw-r--r--fs/ext2/xip.c1
2 files changed, 3 insertions, 0 deletions
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index c260de6d7b6d..8a337640a46a 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -632,6 +632,8 @@ static int ext2_get_blocks(struct inode *inode,
632 int count = 0; 632 int count = 0;
633 ext2_fsblk_t first_block = 0; 633 ext2_fsblk_t first_block = 0;
634 634
635 BUG_ON(maxblocks == 0);
636
635 depth = ext2_block_to_path(inode,iblock,offsets,&blocks_to_boundary); 637 depth = ext2_block_to_path(inode,iblock,offsets,&blocks_to_boundary);
636 638
637 if (depth == 0) 639 if (depth == 0)
diff --git a/fs/ext2/xip.c b/fs/ext2/xip.c
index 1c3312858fcf..e98171a11cfe 100644
--- a/fs/ext2/xip.c
+++ b/fs/ext2/xip.c
@@ -35,6 +35,7 @@ __ext2_get_block(struct inode *inode, pgoff_t pgoff, int create,
35 int rc; 35 int rc;
36 36
37 memset(&tmp, 0, sizeof(struct buffer_head)); 37 memset(&tmp, 0, sizeof(struct buffer_head));
38 tmp.b_size = 1 << inode->i_blkbits;
38 rc = ext2_get_block(inode, pgoff, &tmp, create); 39 rc = ext2_get_block(inode, pgoff, &tmp, create);
39 *result = tmp.b_blocknr; 40 *result = tmp.b_blocknr;
40 41