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 6D89E1922FA; Tue, 10 Sep 2024 10:04:47 +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=1725962687; cv=none; b=UF0sQvuMMlWzrFOp/IICZ2biKIZiEFkagQ8ZeH3JAzJ/gh4J/qgQMpeUzcYDnp02FtlfDUqZ2HTfyJ+sX93hXTUaMFpN1SpgOty8oVnRlXZcd36j+Cn+qYJUlysRAq3nb1WTNnNjAp4SCoVsgCbdT9CyrVfyIetpQrYVwbSuaYA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962687; c=relaxed/simple; bh=3XJnu+akOyl6RoNhOMO0YB8JCXNtV97f07NOcxUS+7Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SBLd5q7s7WILJWpg5fP6/NLzPMjEExdtbA6y32ZHhshistLO8Cp6p93LWdtB2JJeQHs6/HPOpb5LL5cxKYgDbFZG27Ocf32vJ458JSuG0ORvkkpxfoC18+WYwnrQu1ZtP/zapCFi/HGT7NL0BztwkUOWlRf+1UUwWGY1ENKa9K4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=EqsWj+3A; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="EqsWj+3A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA4ADC4CEC3; Tue, 10 Sep 2024 10:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725962687; bh=3XJnu+akOyl6RoNhOMO0YB8JCXNtV97f07NOcxUS+7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EqsWj+3ASmHZQzQIAJjrmayYtOE02mQOmxzboTqRTH4ds3VQe1hLHSwYxgxd68P2G u1GD6/C90s8gTh1Ms7xv6FAC8BvMQxNFFTjar338IO89Lfs51EWryiwge0/wm0o2sJ RH//u/4cGl2DBKrNY9dtBoIKW1FRdkJeW0H5taP8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Phillip Lougher , Lizhi Xu , syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com, Christian Brauner , Sasha Levin Subject: [PATCH 5.4 090/121] Squashfs: sanity check symbolic link size Date: Tue, 10 Sep 2024 11:32:45 +0200 Message-ID: <20240910092550.141222767@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092545.737864202@linuxfoundation.org> References: <20240910092545.737864202@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ 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 24463145b351..f31649080a88 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