Skip to content

Commit 810ee43

Browse files
plougherbrauner
authored andcommitted
Squashfs: sanity check symbolic link size
Syzkiller reports a "KMSAN: uninit-value in pick_link" bug. This is caused by an uninitialised page, which is ultimately caused by a corrupted symbolic link size read from disk. The reason why the corrupted symlink size causes an uninitialised page is due to the following sequence of events: 1. squashfs_read_inode() is called to read the symbolic link from disk. This assigns the corrupted value 3875536935 to inode->i_size. 2. Later squashfs_symlink_read_folio() is called, which assigns this corrupted value to the length variable, which being a signed int, overflows producing a negative number. 3. The following loop that fills in the page contents checks that the copied bytes is less than length, which being negative means the loop is skipped, producing an uninitialised page. This patch adds a sanity check which checks that the symbolic link size is not larger than expected. -- Signed-off-by: Phillip Lougher <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reported-by: Lizhi Xu <[email protected]> Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/ V2: fix spelling mistake. Signed-off-by: Christian Brauner <[email protected]>
1 parent e3786b2 commit 810ee43

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/squashfs/inode.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,13 @@ int squashfs_read_inode(struct inode *inode, long long ino)
279279
if (err < 0)
280280
goto failed_read;
281281

282-
set_nlink(inode, le32_to_cpu(sqsh_ino->nlink));
283282
inode->i_size = le32_to_cpu(sqsh_ino->symlink_size);
283+
if (inode->i_size > PAGE_SIZE) {
284+
ERROR("Corrupted symlink\n");
285+
return -EINVAL;
286+
}
287+
288+
set_nlink(inode, le32_to_cpu(sqsh_ino->nlink));
284289
inode->i_op = &squashfs_symlink_inode_ops;
285290
inode_nohighmem(inode);
286291
inode->i_data.a_ops = &squashfs_symlink_aops;

0 commit comments

Comments
 (0)