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 B6BA22EF664; Fri, 10 Oct 2025 13:20:19 +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=1760102419; cv=none; b=FsnFNmDw8iO1uEiqBoN+bKCytYNRzFUP78tuAhzMl/dRVT/G3oxzSJP2sr8sgw8zwjSA1nbbSqfmOU1TY0QhwIuqJzuZIB4quLpbTvLqSKIteJPaHd8dc+N0tS5lHQ8cMCuQbA8o6YPYbqDP4oMfbjlQ8yMT50OtjYnMxZKKDOo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760102419; c=relaxed/simple; bh=rM7i4Vb1WcQYfDKRFKp5Wzkosl4D5VjxclSzMGKiags=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YnUTQU9HgavIgqwzwaKvChsy3EwckrIxKZSMkrUmPuOr3sCKibWZLsSoullWdZH1TiQRL5bLDgTq443L/ZMa1AbjL8OWbbc26leDYJ+lyHZw8ZuwR1CPasyUgCl8E6y0ob/VqwWWdok8j3Hmuf9GU4EO+eENG1rokxj9e41UWA4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ay3tYod5; 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="ay3tYod5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 434DEC4CEF1; Fri, 10 Oct 2025 13:20:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760102419; bh=rM7i4Vb1WcQYfDKRFKp5Wzkosl4D5VjxclSzMGKiags=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ay3tYod57lBw4jC0wZBkBqZbEck4VlbpqxxiihXt1kPewV8xpNin8Nn1zyL/WPJL9 dC1NJXMJwnKHWA9lIQGxM+056qEOCcz+bA7/eOi/TzAyt30EW7Cl3vG/kjIsTKMOg2 5sUpqSoN2x3oir355ck+lTJNisbUf/uGjGP9DGdw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+52c1a7d3e5b361ccd346@syzkaller.appspotmail.com, Arnaud Lecomte , Benjamin Tissoires , Romain Sioen Subject: [PATCH 6.16 28/41] hid: fix I2C read buffer overflow in raw_event() for mcp2221 Date: Fri, 10 Oct 2025 15:16:16 +0200 Message-ID: <20251010131334.436622059@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251010131333.420766773@linuxfoundation.org> References: <20251010131333.420766773@linuxfoundation.org> User-Agent: quilt/0.69 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 6.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaud Lecomte commit b56cc41a3ae7323aa3c6165f93c32e020538b6d2 upstream. As reported by syzbot, mcp2221_raw_event lacked validation of incoming I2C read data sizes, risking buffer overflows in mcp->rxbuf during multi-part transfers. As highlighted in the DS20005565B spec, p44, we have: "The number of read-back data bytes to follow in this packet: from 0 to a maximum of 60 bytes of read-back bytes." This patch enforces we don't exceed this limit. Reported-by: syzbot+52c1a7d3e5b361ccd346@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=52c1a7d3e5b361ccd346 Tested-by: syzbot+52c1a7d3e5b361ccd346@syzkaller.appspotmail.com Signed-off-by: Arnaud Lecomte Link: https://patch.msgid.link/20250726220931.7126-1-contact@arnaud-lcm.com Signed-off-by: Benjamin Tissoires Signed-off-by: Romain Sioen Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-mcp2221.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -816,6 +816,10 @@ static int mcp2221_raw_event(struct hid_ } if (data[2] == MCP2221_I2C_READ_COMPL || data[2] == MCP2221_I2C_READ_PARTIAL) { + if (!mcp->rxbuf || mcp->rxbuf_idx < 0 || data[3] > 60) { + mcp->status = -EINVAL; + break; + } buf = mcp->rxbuf; memcpy(&buf[mcp->rxbuf_idx], &data[4], data[3]); mcp->rxbuf_idx = mcp->rxbuf_idx + data[3];