Skip to content
This repository was archived by the owner on Sep 24, 2020. It is now read-only.

Commit 418c12d

Browse files
jankaratytso
authored andcommitted
ext4: fix xattr shifting when expanding inodes part 2
When multiple xattrs need to be moved out of inode, we did not properly recompute total size of xattr headers in the inode and the new header position. Thus when moving the second and further xattr we asked ext4_xattr_shift_entries() to move too much and from the wrong place, resulting in possible xattr value corruption or general memory corruption. CC: [email protected] # 4.4.x Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent d014119 commit 418c12d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/ext4/xattr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,7 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
15161516
error = ext4_xattr_ibody_set(handle, inode, &i, is);
15171517
if (error)
15181518
goto cleanup;
1519+
total_ino -= entry_size;
15191520

15201521
entry = IFIRST(header);
15211522
if (entry_size + EXT4_XATTR_SIZE(size) >= isize_diff)
@@ -1526,11 +1527,11 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
15261527
ext4_xattr_shift_entries(entry, -shift_bytes,
15271528
(void *)raw_inode + EXT4_GOOD_OLD_INODE_SIZE +
15281529
EXT4_I(inode)->i_extra_isize + shift_bytes,
1529-
(void *)header, total_ino - entry_size,
1530-
inode->i_sb->s_blocksize);
1530+
(void *)header, total_ino, inode->i_sb->s_blocksize);
15311531

15321532
isize_diff -= shift_bytes;
15331533
EXT4_I(inode)->i_extra_isize += shift_bytes;
1534+
header = IHDR(inode, raw_inode);
15341535

15351536
i.name = b_entry_name;
15361537
i.value = buffer;

0 commit comments

Comments
 (0)