Commit 02475de9 authored by Chengguang Xu's avatar Chengguang Xu Committed by Jan Kara

ext2: introduce helper for xattr header validation

Introduce helper function ext2_xattr_header_valid()
for xattr header validation and clean up the header
check ralated code.
Reviewed-by: default avatarAndreas Dilger <adilger@dilger.ca>
Signed-off-by: default avatarChengguang Xu <cgxu519@zoho.com.cn>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent f44840ad
...@@ -134,6 +134,16 @@ ext2_xattr_handler(int name_index) ...@@ -134,6 +134,16 @@ ext2_xattr_handler(int name_index)
return handler; return handler;
} }
static bool
ext2_xattr_header_valid(struct ext2_xattr_header *header)
{
if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
header->h_blocks != cpu_to_le32(1))
return false;
return true;
}
/* /*
* ext2_xattr_get() * ext2_xattr_get()
* *
...@@ -176,9 +186,9 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name, ...@@ -176,9 +186,9 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
ea_bdebug(bh, "b_count=%d, refcount=%d", ea_bdebug(bh, "b_count=%d, refcount=%d",
atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount)); atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
end = bh->b_data + bh->b_size; end = bh->b_data + bh->b_size;
if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) || if (!ext2_xattr_header_valid(HDR(bh))) {
HDR(bh)->h_blocks != cpu_to_le32(1)) { bad_block:
bad_block: ext2_error(inode->i_sb, "ext2_xattr_get", ext2_error(inode->i_sb, "ext2_xattr_get",
"inode %ld: bad block %d", inode->i_ino, "inode %ld: bad block %d", inode->i_ino,
EXT2_I(inode)->i_file_acl); EXT2_I(inode)->i_file_acl);
error = -EIO; error = -EIO;
...@@ -266,9 +276,9 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size) ...@@ -266,9 +276,9 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
ea_bdebug(bh, "b_count=%d, refcount=%d", ea_bdebug(bh, "b_count=%d, refcount=%d",
atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount)); atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
end = bh->b_data + bh->b_size; end = bh->b_data + bh->b_size;
if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) || if (!ext2_xattr_header_valid(HDR(bh))) {
HDR(bh)->h_blocks != cpu_to_le32(1)) { bad_block:
bad_block: ext2_error(inode->i_sb, "ext2_xattr_list", ext2_error(inode->i_sb, "ext2_xattr_list",
"inode %ld: bad block %d", inode->i_ino, "inode %ld: bad block %d", inode->i_ino,
EXT2_I(inode)->i_file_acl); EXT2_I(inode)->i_file_acl);
error = -EIO; error = -EIO;
...@@ -406,9 +416,9 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name, ...@@ -406,9 +416,9 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
le32_to_cpu(HDR(bh)->h_refcount)); le32_to_cpu(HDR(bh)->h_refcount));
header = HDR(bh); header = HDR(bh);
end = bh->b_data + bh->b_size; end = bh->b_data + bh->b_size;
if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) || if (!ext2_xattr_header_valid(header)) {
header->h_blocks != cpu_to_le32(1)) { bad_block:
bad_block: ext2_error(sb, "ext2_xattr_set", ext2_error(sb, "ext2_xattr_set",
"inode %ld: bad block %d", inode->i_ino, "inode %ld: bad block %d", inode->i_ino,
EXT2_I(inode)->i_file_acl); EXT2_I(inode)->i_file_acl);
error = -EIO; error = -EIO;
...@@ -784,8 +794,7 @@ ext2_xattr_delete_inode(struct inode *inode) ...@@ -784,8 +794,7 @@ ext2_xattr_delete_inode(struct inode *inode)
goto cleanup; goto cleanup;
} }
ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count))); ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) || if (!ext2_xattr_header_valid(HDR(bh))) {
HDR(bh)->h_blocks != cpu_to_le32(1)) {
ext2_error(inode->i_sb, "ext2_xattr_delete_inode", ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
"inode %ld: bad block %d", inode->i_ino, "inode %ld: bad block %d", inode->i_ino,
EXT2_I(inode)->i_file_acl); EXT2_I(inode)->i_file_acl);
......
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