Skip to content

Commit 179b141

Browse files
LiBaokun96tytso
authored andcommitted
ext4: add EXT4_INODE_HAS_XATTR_SPACE macro in xattr.h
When adding an xattr to an inode, we must ensure that the inode_size is not less than EXT4_GOOD_OLD_INODE_SIZE + extra_isize + pad. Otherwise, the end position may be greater than the start position, resulting in UAF. Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Link: https://lore.kernel.org/r/20220616021358.2504451-2-libaokun1@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 7f0d8e1 commit 179b141

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fs/ext4/xattr.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ struct ext4_xattr_entry {
9595

9696
#define EXT4_ZERO_XATTR_VALUE ((void *)-1)
9797

98+
/*
99+
* If we want to add an xattr to the inode, we should make sure that
100+
* i_extra_isize is not 0 and that the inode size is not less than
101+
* EXT4_GOOD_OLD_INODE_SIZE + extra_isize + pad.
102+
* EXT4_GOOD_OLD_INODE_SIZE extra_isize header entry pad data
103+
* |--------------------------|------------|------|---------|---|-------|
104+
*/
105+
#define EXT4_INODE_HAS_XATTR_SPACE(inode) \
106+
((EXT4_I(inode)->i_extra_isize != 0) && \
107+
(EXT4_GOOD_OLD_INODE_SIZE + EXT4_I(inode)->i_extra_isize + \
108+
sizeof(struct ext4_xattr_ibody_header) + EXT4_XATTR_PAD <= \
109+
EXT4_INODE_SIZE((inode)->i_sb)))
110+
98111
struct ext4_xattr_info {
99112
const char *name;
100113
const void *value;

0 commit comments

Comments
 (0)