btrfs-progs: check/original: detect invalid file extent items for

symbolic links

[BUG]
There is a recent bug that btrfs/012 fails and kernel rejects to read a
symbolic link which is backed by a regular extent.

Furthremore in that case, "btrfs check" doesn't detect such problem at
all.

[CAUSE]
For symbolic links, we only allow inline file extents, and this means we
should only have a symbolic link target which is smaller than 4K.

But btrfs check doesn't handle symbolic link inodes any differently, thus
it doesn't check if the file extents are inlined or not, nor reporting
this problem as an error.

[FIX]
When processing data extents, if we find the owning inode is a symbolic
link, and the file extent is regular/preallocated, mark the inode with
I_ERR_FILE_EXTENT_TOO_LARGE error.

Signed-off-by: Qu Wenruo <wqu@suse.com>
This commit is contained in:
Qu Wenruo 2024-09-03 16:13:38 +09:30 committed by David Sterba
parent bc0995297f
commit fd9f8f085a
1 changed files with 7 additions and 0 deletions

View File

@ -1745,6 +1745,13 @@ static int process_file_extent(struct btrfs_root *root,
rec->errors |= I_ERR_BAD_FILE_EXTENT;
if (disk_bytenr > 0)
rec->found_size += num_bytes;
/*
* Symbolic links should only have inlined extents.
* A regular extent means it's already too large to
* be inlined.
*/
if (S_ISLNK(rec->imode))
rec->errors |= I_ERR_FILE_EXTENT_TOO_LARGE;
} else {
rec->errors |= I_ERR_BAD_FILE_EXTENT;
}