summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChengguang Xu <cgxu519@zoho.com.cn>2019-07-23 07:21:54 -0400
committerJan Kara <jack@suse.cz>2019-07-31 06:04:42 -0400
commite5d395974e043cdcedcd84a0d41aaebb723786d8 (patch)
tree8ff04266c012c2ac4a3449149a9da23e3d489952
parent6fbacb8539a6659d446a9efabb538cfc007c1427 (diff)
ext2: fix block range in ext2_data_block_valid()
For block validity we should check the block range from start_block to start_block + count - 1, so fix the range in ext2_data_block_valid() and also modify the count argument properly in calling place. Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn> Link: https://lore.kernel.org/r/20190723112155.20329-1-cgxu519@zoho.com.cn Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--fs/ext2/balloc.c6
-rw-r--r--fs/ext2/xattr.c2
2 files changed, 4 insertions, 4 deletions
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 547c165299c0..92e9a7489174 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -1203,13 +1203,13 @@ int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
1203 unsigned int count) 1203 unsigned int count)
1204{ 1204{
1205 if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) || 1205 if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
1206 (start_blk + count < start_blk) || 1206 (start_blk + count - 1 < start_blk) ||
1207 (start_blk > le32_to_cpu(sbi->s_es->s_blocks_count))) 1207 (start_blk + count - 1 >= le32_to_cpu(sbi->s_es->s_blocks_count)))
1208 return 0; 1208 return 0;
1209 1209
1210 /* Ensure we do not step over superblock */ 1210 /* Ensure we do not step over superblock */
1211 if ((start_blk <= sbi->s_sb_block) && 1211 if ((start_blk <= sbi->s_sb_block) &&
1212 (start_blk + count >= sbi->s_sb_block)) 1212 (start_blk + count - 1 >= sbi->s_sb_block))
1213 return 0; 1213 return 0;
1214 1214
1215 return 1; 1215 return 1;
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 79369c13cc55..0456bc990b5e 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -794,7 +794,7 @@ ext2_xattr_delete_inode(struct inode *inode)
794 if (!EXT2_I(inode)->i_file_acl) 794 if (!EXT2_I(inode)->i_file_acl)
795 goto cleanup; 795 goto cleanup;
796 796
797 if (!ext2_data_block_valid(sbi, EXT2_I(inode)->i_file_acl, 0)) { 797 if (!ext2_data_block_valid(sbi, EXT2_I(inode)->i_file_acl, 1)) {
798 ext2_error(inode->i_sb, "ext2_xattr_delete_inode", 798 ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
799 "inode %ld: xattr block %d is out of data blocks range", 799 "inode %ld: xattr block %d is out of data blocks range",
800 inode->i_ino, EXT2_I(inode)->i_file_acl); 800 inode->i_ino, EXT2_I(inode)->i_file_acl);