]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: validate fscrypt_symlink_data.len for fast symlinks too
authorEric Biggers <ebiggers@google.com>
Sat, 3 Mar 2018 00:59:18 +0000 (16:59 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 3 Mar 2018 21:39:59 +0000 (16:39 -0500)
Both fast and slow encrypted symlinks are prefixed with the ciphertext
length field (fscrypt_symlink_data.len).  But e2fsck was only checking
it for slow symlinks.  Start checking it for fast symlinks too.  This
matches the kernel handling of encrypted symlinks.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/pass1.c

index 723acf099769f4e2eb57c6a0e8823fd5242b697f..d9df28edb96025f6a16a22f69f69e669d5920fe6 100644 (file)
@@ -183,6 +183,7 @@ int e2fsck_pass1_check_device_inode(ext2_filsys fs EXT2FS_ATTR((unused)),
 int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino,
                               struct ext2_inode *inode, char *buf)
 {
+       unsigned int buflen;
        unsigned int len;
        int i;
        ext2_extent_handle_t    handle;
@@ -232,9 +233,8 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino,
                if (inode->i_size >= sizeof(inode->i_block))
                        return 0;
 
-               len = strnlen((char *)inode->i_block, sizeof(inode->i_block));
-               if (len == sizeof(inode->i_block))
-                       return 0;
+               buf = (char *)inode->i_block;
+               buflen = sizeof(inode->i_block);
        } else {
                if ((inode->i_size >= fs->blocksize) ||
                    (inode->i_block[0] < fs->super->s_first_data_block) ||
@@ -248,14 +248,17 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino,
                if (io_channel_read_blk64(fs->io, inode->i_block[0], 1, buf))
                        return 0;
 
-               if (inode->i_flags & EXT4_ENCRYPT_FL) {
-                       len = ext2fs_le16_to_cpu(*((__u16 *)buf)) + 2;
-               } else {
-                       len = strnlen(buf, fs->blocksize);
-               }
-               if (len >= fs->blocksize)
-                       return 0;
+               buflen = fs->blocksize;
        }
+
+       if (inode->i_flags & EXT4_ENCRYPT_FL)
+               len = ext2fs_le16_to_cpu(*(__u16 *)buf) + 2;
+       else
+               len = strnlen(buf, buflen);
+
+       if (len >= buflen)
+               return 0;
+
        if (len != inode->i_size)
                if ((inode->i_flags & EXT4_ENCRYPT_FL) == 0)
                        return 0;