* [PATCH V2] Squashfs: sanity check symbolic link size
@ 2024-08-11 23:28 Phillip Lougher
2024-08-13 11:57 ` Christian Brauner
0 siblings, 1 reply; 2+ messages in thread
From: Phillip Lougher @ 2024-08-11 23:28 UTC (permalink / raw)
To: akpm, viro, brauner, jack, linux-fsdevel, linux-kernel
Cc: Phillip Lougher, Lizhi Xu, syzbot+24ac24ff58dc5b0d26b9
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 <phillip@squashfs.org.uk>
Reported-by: Lizhi Xu <lizhi.xu@windriver.com>
Reported-by: syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000a90e8c061e86a76b@google.com/
--
V2: fix spelling mistake.
---
fs/squashfs/inode.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c
index 16bd693d0b3a..d5918eba27e3 100644
--- a/fs/squashfs/inode.c
+++ b/fs/squashfs/inode.c
@@ -279,8 +279,13 @@ int squashfs_read_inode(struct inode *inode, long long ino)
if (err < 0)
goto failed_read;
- set_nlink(inode, le32_to_cpu(sqsh_ino->nlink));
inode->i_size = le32_to_cpu(sqsh_ino->symlink_size);
+ if (inode->i_size > PAGE_SIZE) {
+ ERROR("Corrupted symlink\n");
+ return -EINVAL;
+ }
+
+ set_nlink(inode, le32_to_cpu(sqsh_ino->nlink));
inode->i_op = &squashfs_symlink_inode_ops;
inode_nohighmem(inode);
inode->i_data.a_ops = &squashfs_symlink_aops;
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH V2] Squashfs: sanity check symbolic link size
2024-08-11 23:28 [PATCH V2] Squashfs: sanity check symbolic link size Phillip Lougher
@ 2024-08-13 11:57 ` Christian Brauner
0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2024-08-13 11:57 UTC (permalink / raw)
To: Phillip Lougher
Cc: Christian Brauner, Lizhi Xu, syzbot+24ac24ff58dc5b0d26b9, akpm,
viro, jack, linux-fsdevel, linux-kernel
On Mon, 12 Aug 2024 00:28:21 +0100, Phillip Lougher wrote:
> 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:
>
> [...]
I've grabbed this. Let me know if this needs to go through elsewhere.
---
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/1] Squashfs: sanity check symbolic link size
https://git.kernel.org/vfs/vfs/c/810ee43d9cd2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-13 11:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-11 23:28 [PATCH V2] Squashfs: sanity check symbolic link size Phillip Lougher
2024-08-13 11:57 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).