Skip to content

Commit 6ba644b

Browse files
ebiggerstytso
authored andcommitted
ext4: remove ext4_xattr_check_entry()
ext4_xattr_check_entry() was redundant with validation of the full xattr entries list in ext4_xattr_check_entries(), which all callers also did. ext4_xattr_check_entry() also didn't actually do correct validation; specifically, it never checked that the value doesn't overlap the xattr names, nor did it account for padding when checking whether the xattr value overflows the available space. So remove it to eliminate any potential confusion. Signed-off-by: Eric Biggers <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 2c4f992 commit 6ba644b

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

fs/ext4/xattr.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,9 @@ __xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header,
244244
#define xattr_check_inode(inode, header, end) \
245245
__xattr_check_inode((inode), (header), (end), __func__, __LINE__)
246246

247-
static inline int
248-
ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size)
249-
{
250-
size_t value_size = le32_to_cpu(entry->e_value_size);
251-
252-
if (entry->e_value_block != 0 || value_size > size ||
253-
le16_to_cpu(entry->e_value_offs) + value_size > size)
254-
return -EFSCORRUPTED;
255-
return 0;
256-
}
257-
258247
static int
259248
ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
260-
const char *name, size_t size, int sorted)
249+
const char *name, int sorted)
261250
{
262251
struct ext4_xattr_entry *entry;
263252
size_t name_len;
@@ -277,8 +266,6 @@ ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
277266
break;
278267
}
279268
*pentry = entry;
280-
if (!cmp && ext4_xattr_check_entry(entry, size))
281-
return -EFSCORRUPTED;
282269
return cmp ? -ENODATA : 0;
283270
}
284271

@@ -306,17 +293,14 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
306293
ea_bdebug(bh, "b_count=%d, refcount=%d",
307294
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
308295
if (ext4_xattr_check_block(inode, bh)) {
309-
bad_block:
310296
EXT4_ERROR_INODE(inode, "bad block %llu",
311297
EXT4_I(inode)->i_file_acl);
312298
error = -EFSCORRUPTED;
313299
goto cleanup;
314300
}
315301
ext4_xattr_cache_insert(ext4_mb_cache, bh);
316302
entry = BFIRST(bh);
317-
error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1);
318-
if (error == -EFSCORRUPTED)
319-
goto bad_block;
303+
error = ext4_xattr_find_entry(&entry, name_index, name, 1);
320304
if (error)
321305
goto cleanup;
322306
size = le32_to_cpu(entry->e_value_size);
@@ -353,13 +337,12 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
353337
return error;
354338
raw_inode = ext4_raw_inode(&iloc);
355339
header = IHDR(inode, raw_inode);
356-
entry = IFIRST(header);
357340
end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
358341
error = xattr_check_inode(inode, header, end);
359342
if (error)
360343
goto cleanup;
361-
error = ext4_xattr_find_entry(&entry, name_index, name,
362-
end - (void *)entry, 0);
344+
entry = IFIRST(header);
345+
error = ext4_xattr_find_entry(&entry, name_index, name, 0);
363346
if (error)
364347
goto cleanup;
365348
size = le32_to_cpu(entry->e_value_size);
@@ -793,7 +776,7 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
793776
bs->s.end = bs->bh->b_data + bs->bh->b_size;
794777
bs->s.here = bs->s.first;
795778
error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
796-
i->name, bs->bh->b_size, 1);
779+
i->name, 1);
797780
if (error && error != -ENODATA)
798781
goto cleanup;
799782
bs->s.not_found = error;
@@ -1065,8 +1048,7 @@ int ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
10651048
return error;
10661049
/* Find the named attribute. */
10671050
error = ext4_xattr_find_entry(&is->s.here, i->name_index,
1068-
i->name, is->s.end -
1069-
(void *)is->s.base, 0);
1051+
i->name, 0);
10701052
if (error && error != -ENODATA)
10711053
return error;
10721054
is->s.not_found = error;

0 commit comments

Comments
 (0)