Skip to content

Commit bd9db17

Browse files
gnehzuiltytso
authored andcommitted
ext4: handle symlink properly with inline_data
This commit tries to fix a bug that we can't read symlink properly with inline data feature when the length of symlink is greater than 60 bytes but less than extra space. The key issue is in ext4_inode_is_fast_symlink() that it doesn't check whether or not an inode has inline data. When the user creates a new symlink, an inode will be allocated with MAY_INLINE_DATA flag. Then symlink will be stored in ->i_block and extended attribute space. In the mean time, this inode is with inline data flag. After remounting it, ext4_inode_is_fast_symlink() function thinks that this inode is a fast symlink so that the data in ->i_block is copied to the user, and the data in extra space is trimmed. In fact this inode should be as a normal symlink. The following script can hit this bug. #!/bin/bash cd ${MNT} filename=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 rm -rf test mkdir test cd test echo "hello" >$filename ln -s $filename symlinkfile cd sudo umount /mnt/sda1 sudo mount -t ext4 /dev/sda1 /mnt/sda1 readlink /mnt/sda1/test/symlinkfile After applying this patch, it will break the assumption in e2fsck because the original implementation doesn't want to support symlink with inline data. Reported-by: "Darrick J. Wong" <[email protected]> Reported-by: Ian Nartowicz <[email protected]> Cc: Ian Nartowicz <[email protected]> Cc: Tao Ma <[email protected]> Cc: "Darrick J. Wong" <[email protected]> Cc: Andreas Dilger <[email protected]> Signed-off-by: Zheng Liu <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent b5b6077 commit bd9db17

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/ext4/inode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ static int ext4_inode_is_fast_symlink(struct inode *inode)
148148
int ea_blocks = EXT4_I(inode)->i_file_acl ?
149149
EXT4_CLUSTER_SIZE(inode->i_sb) >> 9 : 0;
150150

151+
if (ext4_has_inline_data(inode))
152+
return 0;
153+
151154
return (S_ISLNK(inode->i_mode) && inode->i_blocks - ea_blocks == 0);
152155
}
153156

0 commit comments

Comments
 (0)