mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Phillip Lougher <phillip@squashfs.org.uk>,
	Lizhi Xu <lizhi.xu@windriver.com>,
	syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com,
	Christian Brauner <brauner@kernel.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 6.6 16/20] Squashfs: sanity check symbolic link size
Date: Sat, 12 Oct 2024 07:26:48 -0400	[thread overview]
Message-ID: <20241012112715.1763241-16-sashal@kernel.org> (raw)
In-Reply-To: <20241012112715.1763241-1-sashal@kernel.org>

From: Phillip Lougher <phillip@squashfs.org.uk>

[ Upstream commit 810ee43d9cd245d138a2733d87a24858a23f577d ]

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>
Link: https://lore.kernel.org/r/20240811232821.13903-1-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.
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 16bd693d0b3aa..d5918eba27e37 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.43.0


  parent reply	other threads:[~2024-10-12 11:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-12 11:26 [PATCH AUTOSEL 6.6 01/20] ksmbd: override fsids for share path check Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 02/20] ksmbd: override fsids for smb2_query_info() Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 03/20] usbnet: ipheth: race between ipheth_close and error handling Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 04/20] usbnet: ipheth: remove extraneous rx URB length check Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 05/20] usbnet: ipheth: drop RX URBs with no payload Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 06/20] usbnet: ipheth: do not stop RX on failing RX callback Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 07/20] usbnet: ipheth: fix carrier detection in modes 1 and 4 Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 08/20] kbuild: rust: skip -fmin-function-alignment in bindgen flags Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 09/20] rust: add intrinsics to fix `-Os` builds Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 10/20] net: ethernet: use ip_hdrlen() instead of bit shift Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 11/20] drm: panel-orientation-quirks: Add quirk for Ayn Loki Zero Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 12/20] drm: panel-orientation-quirks: Add quirk for Ayn Loki Max Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 13/20] net: phy: vitesse: repair vsc73xx autonegotiation Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 14/20] powerpc/mm: Fix boot warning with hugepages and CONFIG_DEBUG_VIRTUAL Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 15/20] wifi: mt76: mt7921: fix NULL pointer access in mt7921_ipv6_addr_change Sasha Levin
2024-10-12 11:26 ` Sasha Levin [this message]
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 17/20] of/irq: Prevent device address out-of-bounds read in interrupt map walk Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 18/20] lib/generic-radix-tree.c: Fix rare race in __genradix_ptr_alloc() Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 19/20] net: hns3: use correct release function during uninitialization Sasha Levin
2024-10-12 11:26 ` [PATCH AUTOSEL 6.6 20/20] btrfs: update target inode's ctime on unlink Sasha Levin
  -- strict thread matches above, loose matches on Subject: below --
2024-08-23 14:02 [PATCH AUTOSEL 6.6 01/20] ksmbd: override fsids for share path check Sasha Levin
2024-08-23 14:02 ` [PATCH AUTOSEL 6.6 16/20] Squashfs: sanity check symbolic link size Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241012112715.1763241-16-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=brauner@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.xu@windriver.com \
    --cc=phillip@squashfs.org.uk \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®