Skip to contentSkip to conversation

ext4: Fix some error pointer dereferences

PATCH Applied Dan Carpenter 3 participants 3 messages Jan 3, 2019 – Feb 21, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Fix some error pointer dereferences

We can't pass error pointers to brelse().

Fixes fb265c9cb49e ("ext4: add ext4_sb_bread() to disambiguate ENOMEM cases")
---
 fs/ext4/xattr.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ext4/xattr.c +3 -0
index 7fddd519adae..6ddbbe21fdd8 100644
@@ -829,6 +829,7 @@ int ext4_get_inode_usage(struct inode *inode, qsize_t *usage)
 		bh = ext4_sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl, REQ_PRIO);
 		if (IS_ERR(bh)) {
 			ret = PTR_ERR(bh);
+			bh = NULL;
 			goto out;
 		}
 
@@ -2903,6 +2904,7 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
 			if (error = -EIO)
 				EXT4_ERROR_INODE(inode, "block %llu read error",
 						 EXT4_I(inode)->i_file_acl);
+			bh = NULL;
 			goto cleanup;
 		}
 		error = ext4_xattr_check_block(inode, bh);
@@ -3059,6 +3061,7 @@ ext4_xattr_block_cache_find(struct inode *inode,
 		if (IS_ERR(bh)) {
 			if (PTR_ERR(bh) = -ENOMEM)
 				return NULL;
+			bh = NULL;
 			EXT4_ERROR_INODE(inode, "block %lu read error",
 					 (unsigned long)ce->e_value);
 		} else if (ext4_xattr_cmp(header, BHDR(bh)) = 0) {
Signature · 1 line
2.17.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dan Carpenter

We can't pass error pointers to brelse().

Fixes fb265c9cb49e ("ext4: add ext4_sb_bread() to disambiguate ENOMEM cases")

Thanks for catching this. The patch looks good to me. You can add:

Honza

Quoted 35 lines
---
 fs/ext4/xattr.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ext4/xattr.c +3 -0
index 7fddd519adae..6ddbbe21fdd8 100644
@@ -829,6 +829,7 @@ int ext4_get_inode_usage(struct inode *inode, qsize_t *usage)
 		bh = ext4_sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl, REQ_PRIO);
 		if (IS_ERR(bh)) {
 			ret = PTR_ERR(bh);
+			bh = NULL;
 			goto out;
 		}
 
@@ -2903,6 +2904,7 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
 			if (error = -EIO)
 				EXT4_ERROR_INODE(inode, "block %llu read error",
 						 EXT4_I(inode)->i_file_acl);
+			bh = NULL;
 			goto cleanup;
 		}
 		error = ext4_xattr_check_block(inode, bh);
@@ -3059,6 +3061,7 @@ ext4_xattr_block_cache_find(struct inode *inode,
 		if (IS_ERR(bh)) {
 			if (PTR_ERR(bh) = -ENOMEM)
 				return NULL;
+			bh = NULL;
 			EXT4_ERROR_INODE(inode, "block %lu read error",
 					 (unsigned long)ce->e_value);
 		} else if (ext4_xattr_cmp(header, BHDR(bh)) = 0) {
Signature · 1 line
2.17.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR