From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E0A31FB3CC; Sat, 12 Oct 2024 11:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728732578; cv=none; b=Bj8+D20HpwnHArv6itRKLhCRDwKtqFGjQg4sTqqgEmYOlFTqk9uN5LWnnsIcc+oU2/wXDuSttktAeP2UxDCosIjkwVGh8SYTei6oXRpyXLb5AmKKK36ANLrnAhe28bB5BXePRD6Ylx7qxgG8IwaGm2cmqcqcM7EI+Zd1NfIzZ/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728732578; c=relaxed/simple; bh=mmhBkxJq8mzJIprwJgv8yMGf2dMntwHjpI9DcPhE5V8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IeTEMfcReB7SpVehUU8tEucCmFskrLCgt8DUKLa/hhyDMSahg0HRf3d7CNT9/9vCLC7tEiW06v4kXiMVw2a4D/+uRm4ERguTEzTfFdjXtFFx1kWF/tVft4K4relZ2D7ZvhNFJ7+3IoeA4qlbXvcIchROvFVTvRimgBdWr23Kyqo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DrmIIYNl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DrmIIYNl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 946BBC4CEC7; Sat, 12 Oct 2024 11:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728732578; bh=mmhBkxJq8mzJIprwJgv8yMGf2dMntwHjpI9DcPhE5V8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DrmIIYNlWlSUUTBjfqI7/cAA7ot8Exdiqsn2mQDikpVaXXQi66Q5P0/j6lG8nhHS0 PX991qFPmJfG6iEM2y9UR+5Rzj9i7cJA+HUwqEVIK0P9F4u5YorK4qtNPfkaulNqsz sKvltKGqVHQ/mHViQUcSBKfw+WBhJRHbtOn/eztajfJ67E+aNR8E32ifvUhp1Hh/7W drHcNdmn1QTORpmlHKP0QqhgGoQNolQbDY1aLtpANXFxrbpJCBVHChIfwHlWYLk6b0 LjWX0IAzfYHk8p5dWIUechKm+oqZNmEjZiDrjPfAJAVAah1uBO59/yI3p1L7MTPV5f herTD+7+sBy+g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Phillip Lougher , Lizhi Xu , syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com, Christian Brauner , Sasha Levin Subject: [PATCH AUTOSEL 5.10 6/9] Squashfs: sanity check symbolic link size Date: Sat, 12 Oct 2024 07:29:11 -0400 Message-ID: <20241012112922.1764240-6-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241012112922.1764240-1-sashal@kernel.org> References: <20241012112922.1764240-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.226 Content-Transfer-Encoding: 8bit From: Phillip Lougher [ 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 Link: https://lore.kernel.org/r/20240811232821.13903-1-phillip@squashfs.org.uk Reported-by: Lizhi Xu 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 Signed-off-by: Sasha Levin --- 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 24463145b3513..f31649080a881 100644 --- a/fs/squashfs/inode.c +++ b/fs/squashfs/inode.c @@ -276,8 +276,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