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 E15F828725B; Mon, 9 Feb 2026 14:47:24 +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=1770648445; cv=none; b=F6VUq5ZT/MB1k2IeM6p7MraAa++IBPI5zBm0uCTh3UJ4TrBaJwm3lxfSFDBBdBgat7a0yBCAvwIxmZaT3Y5k1TIakdPy+Y5p8pBEvpyXWNoGKelUcB9F0ZLrN09uYZaZ04bP+jymetQSwiKkqBBjWj4BrrVZYY4m9uTlcJcFHa4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770648445; c=relaxed/simple; bh=fEwHkBjfMS9RDG1BDO56JyJhdJMCUBOTJ07YYe+fqtM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vAQWLayqlwUMTFOvdADw9IQLlfSchdoZGclRk6e0/4Ji3Tw/B97/qsr/7SUwSGsBcVd9yrN2siz2Y/4aHfoJW98LUUYOFrWWJqBQ70+z1X9VZq7Y94OVbUG/LKhFl8i6IaX2JA6nxnO76KvT1UewT4IWHUetnbhZ64juvS+Leyk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=XrPjciKV; 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="XrPjciKV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 541A0C116C6; Mon, 9 Feb 2026 14:47:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1770648444; bh=fEwHkBjfMS9RDG1BDO56JyJhdJMCUBOTJ07YYe+fqtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XrPjciKVggPUI7oB9wvgIX3ztygwZ/wltpIsp4qra/rAUlWnaUWI3EX86PY5MHh4t Koipomgos16yaquD9K7AvuWC7HX6DqRB7sqZ4ODrIHbA8/xRHC0epqDrmBB9Vn2ZnO PXlMQnyNqsQToTKpMiaHC+uE9YV5pEyYkkJdOvvg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kwok Kin Ming , Benjamin Tissoires , Sasha Levin Subject: [PATCH 6.6 39/86] HID: i2c-hid: fix potential buffer overflow in i2c_hid_get_report() Date: Mon, 9 Feb 2026 15:24:02 +0100 Message-ID: <20260209142306.192610616@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260209142304.770150175@linuxfoundation.org> References: <20260209142304.770150175@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kwok Kin Ming [ Upstream commit 2497ff38c530b1af0df5130ca9f5ab22c5e92f29 ] `i2c_hid_xfer` is used to read `recv_len + sizeof(__le16)` bytes of data into `ihid->rawbuf`. The former can come from the userspace in the hidraw driver and is only bounded by HID_MAX_BUFFER_SIZE(16384) by default (unless we also set `max_buffer_size` field of `struct hid_ll_driver` which we do not). The latter has size determined at runtime by the maximum size of different report types you could receive on any particular device and can be a much smaller value. Fix this by truncating `recv_len` to `ihid->bufsize - sizeof(__le16)`. The impact is low since access to hidraw devices requires root. Signed-off-by: Kwok Kin Ming Signed-off-by: Benjamin Tissoires Signed-off-by: Sasha Levin --- drivers/hid/i2c-hid/i2c-hid-core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index 172b783274201..0a350780407ec 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -254,6 +254,7 @@ static int i2c_hid_get_report(struct i2c_hid *ihid, * In addition to report data device will supply data length * in the first 2 bytes of the response, so adjust . */ + recv_len = min(recv_len, ihid->bufsize - sizeof(__le16)); error = i2c_hid_xfer(ihid, ihid->cmdbuf, length, ihid->rawbuf, recv_len + sizeof(__le16)); if (error) { -- 2.51.0