1 ext4: forbid i_extra_isize not divisible by 4
3 From: Eric Biggers <ebiggers@google.com>
5 i_extra_isize not divisible by 4 is problematic for several reasons:
7 - It causes the in-inode xattr space to be misaligned, but the xattr
8 header and entries are not declared __packed to express this
9 possibility. This may cause poor performance or incorrect code
10 generation on some platforms.
11 - When validating the xattr entries we can read past the end of the
12 inode if the size available for xattrs is not a multiple of 4.
13 - It allows the nonsensical i_extra_isize=1, which doesn't even leave
14 enough room for i_extra_isize itself.
16 Therefore, update ext4_iget() to consider i_extra_isize not divisible by
17 4 to be an error, like the case where i_extra_isize is too large.
19 This also matches the rule recently added to e2fsck for determining
20 whether an inode has valid i_extra_isize.
22 This patch shouldn't have any noticeable effect on
23 non-corrupted/non-malicious filesystems, since the size of ext4_inode
24 has always been a multiple of 4.
26 Signed-off-by: Eric Biggers <ebiggers@google.com>
27 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
28 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
30 fs/ext4/inode.c | 11 +++++++----
31 1 file changed, 7 insertions(+), 4 deletions(-)
33 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
34 index 861f848..bc99ebe 100644
37 @@ -4564,10 +4564,12 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
38 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
39 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
40 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
41 - EXT4_INODE_SIZE(inode->i_sb)) {
42 - EXT4_ERROR_INODE(inode, "bad extra_isize (%u != %u)",
43 - EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize,
44 - EXT4_INODE_SIZE(inode->i_sb));
45 + EXT4_INODE_SIZE(inode->i_sb) ||
46 + (ei->i_extra_isize & 3)) {
47 + EXT4_ERROR_INODE(inode,
48 + "bad extra_isize %u (inode size %u)",
50 + EXT4_INODE_SIZE(inode->i_sb));
54 @@ -4685,6 +4687,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
55 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
56 if (ei->i_extra_isize == 0) {
57 /* The extra space is currently unused. Use it. */
58 + BUILD_BUG_ON(sizeof(struct ext4_inode) & 3);
59 ei->i_extra_isize = sizeof(struct ext4_inode) -
60 EXT4_GOOD_OLD_INODE_SIZE;
63 2.8.0.rc3.226.g39d4020