From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 A275A34A3A5; Fri, 4 Sep 2026 05:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500794; cv=none; b=sGhGkG3OZgXb0Ro6AoyvZh4n+BnXmxYZd+Jb1P908sQ4hg2uYCM2LgSapUh3RvAo2UcnUUpK9N/OTZMRZ6nh6/LWkN0xUs9VmM0Q9LtWQZEwqhLL4UlPBFHga5KjV0W73IImvHkgvMon5+etRaSAiqRbj1cF1nt4mDRvLUOvnSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500794; c=relaxed/simple; bh=0aGbC+s5PT9UYlO7N3egKAuMDmv9t3xNCgp16U1ycz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gXe0WEJDdmr/SJtwYp3mZAWo5I6BOpUTtFtr5dzMXbHSYAAK5mPt7Cu5Gf7OwMtxAPrYduQObp2zPfczejwV6LeSDMBeKbEp8UQ343JkXbVdFBKFRaNG9IE7WqLfcLh/KtKULmy19kAmGLPdIZkW9u4Tc8C5/1iS0ljlJFmY5/U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ht4wDI7q; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ht4wDI7q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A7041F00A3D; Fri, 4 Sep 2026 05:46:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788500793; bh=IH1ULuaDpIlWxhUh+4MGUYk+aUWHhYR27IIVQWzKHqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ht4wDI7q6B8zhdkjhwd9rLMA1SIiriINHxCRz6ScGRObNwOQAhQoryqytI+zRkGjJ bgZ3nw1+oT3OxnCrIjM16Gijjy2T8fPkEsP9toh7DpYYW5ss+TbhwVGW9Lfv7QQU7i DIsvdawo7iH0qMvNlip5TEefmaro0DICRN/4Escs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiangshan Yi , Jiri Kosina Subject: [PATCH 6.18 182/552] HID: mcp2221: validate report size in mcp2221_raw_event() Date: Fri, 4 Sep 2026 06:55:39 +0200 Message-ID: <20260904045753.144467236@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045747.813364717@linuxfoundation.org> References: <20260904045747.813364717@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiangshan Yi commit 2c9a6998c19503626c57a2267bf279e204113079 upstream. mcp2221_raw_event() never validates the size of incoming HID reports. In the MCP2221_I2C_GET_DATA path it trusts the device-supplied data[3] as the copy length without checking that 4 + data[3] bytes actually exist in the received report. A malicious or misbehaving USB device can send a short report with a large data[3], causing the memcpy to read past the valid report data in the HID transfer buffer and leak uninitialized kernel memory back to userspace through the I2C/SMBus read path. Add a minimum size check at entry and validate that the source range fits within the received report before the copy. Fixes: 67a95c21463d ("HID: mcp2221: add usb to i2c-smbus host bridge") Cc: stable@vger.kernel.org Signed-off-by: Jiangshan Yi Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-mcp2221.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -851,6 +851,9 @@ static int mcp2221_raw_event(struct hid_ u8 *buf; struct mcp2221 *mcp = hid_get_drvdata(hdev); + if (size < 4) + return 0; + switch (data[0]) { case MCP2221_I2C_WR_DATA: @@ -912,6 +915,10 @@ static int mcp2221_raw_event(struct hid_ mcp->status = -EINVAL; break; } + if (4 + data[3] > size) { + mcp->status = -EINVAL; + break; + } buf = mcp->rxbuf; memcpy(&buf[mcp->rxbuf_idx], &data[4], data[3]); mcp->rxbuf_idx = mcp->rxbuf_idx + data[3];