mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] HID: Intel-thc-hid: Fix potential buffer overflow
@ 2026-09-22  2:46 Even Xu
  2026-09-22  2:46 ` [PATCH 1/2] HID: Intel-thc-hid: Intel-quicki2c: Fix " Even Xu
  2026-09-22  2:46 ` [PATCH 2/2] HID: Intel-thc-hid: Intel-quickspi: " Even Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Even Xu @ 2026-09-22  2:46 UTC (permalink / raw)
  To: bentiss, jikos; +Cc: srinivas.pandruvada, linux-input, linux-kernel, Even Xu

This patch set allocate enough space for both the payload and the
packet header for quicki2c and quickspi input and output buffers to 
prevent a buffer overflow when the payload reaches its maximum size,
as their sizes are currently calculated from the payload length only.

Even Xu (2):
  HID: Intel-thc-hid: Intel-quicki2c: Fix buffer overflow
  HID: Intel-thc-hid: Intel-quickspi: Fix buffer overflow

 drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c | 6 ++++--
 drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] HID: Intel-thc-hid: Intel-quicki2c: Fix buffer overflow
  2026-09-22  2:46 [PATCH 0/2] HID: Intel-thc-hid: Fix potential buffer overflow Even Xu
@ 2026-09-22  2:46 ` Even Xu
  2026-09-22  2:46 ` [PATCH 2/2] HID: Intel-thc-hid: Intel-quickspi: " Even Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Even Xu @ 2026-09-22  2:46 UTC (permalink / raw)
  To: bentiss, jikos; +Cc: srinivas.pandruvada, linux-input, linux-kernel, Even Xu

The input and output buffers are used to store complete HID-over-I2C
packets, including their protocol headers. However, their sizes are
currently calculated from the payload length only.

Allocate enough space for both the payload and the packet header to
prevent a buffer overflow when the payload reaches its maximum size.

Signed-off-by: Even Xu <even.xu@intel.com>
---
 drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
index 0d2ad7bc3648..2537288b5026 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
@@ -606,7 +606,8 @@ static int quicki2c_alloc_report_buf(struct quicki2c_device *qcdev)
 	 */
 	max_report_len = max(le16_to_cpu(qcdev->dev_desc.max_input_len), SZ_4K);
 
-	qcdev->input_buf = devm_kzalloc(qcdev->dev, max_report_len, GFP_KERNEL);
+	qcdev->input_buf = devm_kzalloc(qcdev->dev,
+					HIDI2C_PACKET_LEN(max_report_len), GFP_KERNEL);
 	if (!qcdev->input_buf)
 		return -ENOMEM;
 
@@ -616,7 +617,8 @@ static int quicki2c_alloc_report_buf(struct quicki2c_device *qcdev)
 	max_report_len = max(le16_to_cpu(qcdev->dev_desc.max_output_len),
 			     max_report_len);
 
-	qcdev->report_buf = devm_kzalloc(qcdev->dev, max_report_len, GFP_KERNEL);
+	qcdev->report_buf = devm_kzalloc(qcdev->dev,
+					 HIDI2C_PACKET_LEN(max_report_len), GFP_KERNEL);
 	if (!qcdev->report_buf)
 		return -ENOMEM;
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] HID: Intel-thc-hid: Intel-quickspi: Fix buffer overflow
  2026-09-22  2:46 [PATCH 0/2] HID: Intel-thc-hid: Fix potential buffer overflow Even Xu
  2026-09-22  2:46 ` [PATCH 1/2] HID: Intel-thc-hid: Intel-quicki2c: Fix " Even Xu
@ 2026-09-22  2:46 ` Even Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Even Xu @ 2026-09-22  2:46 UTC (permalink / raw)
  To: bentiss, jikos; +Cc: srinivas.pandruvada, linux-input, linux-kernel, Even Xu

The input buffers are used to store complete HID-over-SPI packets,
including their protocol headers. However, their sizes are
currently calculated from the payload length only.

Allocate enough space for both the payload and the packet header to
prevent a buffer overflow when the payload reaches its maximum size.

Signed-off-by: Even Xu <even.xu@intel.com>
---
 drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
index 89226f5ce45e..ad676fde211b 100644
--- a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
+++ b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
@@ -552,7 +552,8 @@ static int quickspi_alloc_report_buf(struct quickspi_device *qsdev)
 	max_input_len = max(le16_to_cpu(qsdev->dev_desc.rep_desc_len),
 			    le16_to_cpu(qsdev->dev_desc.max_input_len));
 
-	qsdev->input_buf = devm_kzalloc(qsdev->dev, max_input_len, GFP_KERNEL);
+	qsdev->input_buf = devm_kzalloc(qsdev->dev,
+					HIDSPI_INPUT_BODY_SIZE(max_input_len), GFP_KERNEL);
 	if (!qsdev->input_buf)
 		return -ENOMEM;
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-22  2:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-22  2:46 [PATCH 0/2] HID: Intel-thc-hid: Fix potential buffer overflow Even Xu
2026-09-22  2:46 ` [PATCH 1/2] HID: Intel-thc-hid: Intel-quicki2c: Fix " Even Xu
2026-09-22  2:46 ` [PATCH 2/2] HID: Intel-thc-hid: Intel-quickspi: " Even Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®