]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commit
libext2fs: forbid creating symlinks using entire block
authorEric Biggers <ebiggers@google.com>
Sat, 3 Mar 2018 00:59:14 +0000 (16:59 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 3 Mar 2018 19:15:53 +0000 (14:15 -0500)
commitc88970f2258459e84f3fbed3b80653b3e8746dfb
tree87f928a5aef02e87d51a50cae1e3ee4aa10c91fa
parenteed9d845e84f6b74ce2d1a475020a17f2131e3d0
libext2fs: forbid creating symlinks using entire block

ext2fs_symlink() didn't count the NUL terminator when limiting the
symlink target length to fs->blocksize, so it could create symlinks
using the entire block.  Such symlinks are problematic because if
block_size == PAGE_SIZE (as is usually the case), then when following
such a symlink the kernel will truncate the last byte because it needs
to ensure the symlink page is NUL-terminated (see page_get_link()).
Perhaps for that reason, e2fsck considers such symlinks to be invalid
(although only if they use the traditional block list rather than an
extent tree, which seems to be another bug).

Fix this by counting the NUL terminator, thereby decreasing the maximum
accepted symlink target length by 1.  Note that this matches the
kernel's behavior in ext4_symlink().

This breaks the test 'f_create_symlinks' which was using debugfs to
create a 1024-byte symlink (not counting the NUL terminator) on a
1024-byte block filesystem.  Fix it by removing the leading '/' from the
test's symlink targets so that their lengths are decreased by 1.

Fixes: f01c1a6bce5e ("libext2fs: add the ext2fs_symlink() function")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/symlink.c
tests/f_create_symlinks/expect
tests/f_create_symlinks/script