diff mbox series

[2/4] btrfs-progs: check/original: detect invalid file extent items for symbol links

Message ID 82d4efde3f7f4cf14767629f647fb01698e31312.1725348299.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: convert: fix the invalid regular extents for symbol links | expand

Commit Message

Qu Wenruo Sept. 3, 2024, 7:29 a.m. UTC
[BUG]
There is a recent bug that btrfs/012 fails and kernel rejects to read a
symbol link which is backed by a regular extent.

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

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

But btrfs check doesn't handle symbol 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 symbol
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>
---
 check/main.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/check/main.c b/check/main.c
index 205bbb4a3c73..93da49b70fc4 100644
--- a/check/main.c
+++ b/check/main.c
@@ -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;
+		/*
+		 * Symbol link should only have inlined extent.
+		 * 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;
 	}