Linux Input/HID development
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Bryam Vargas <hexlabsecurity@proton.me>,
	Hans Verkuil <hverkuil@kernel.org>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 03/10] Input: synaptics-rmi4 - bound the F54 report size to the allocated buffer
Date: Thu, 25 Jun 2026 22:17:52 -0700	[thread overview]
Message-ID: <20260626051802.4033172-3-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20260626051802.4033172-1-dmitry.torokhov@gmail.com>

From: Bryam Vargas <hexlabsecurity@proton.me>

rmi_f54_work() reads a diagnostics report from the device into
f54->report_data, sizing the transfer with rmi_f54_get_report_size():

	report_size = rmi_f54_get_report_size(f54);
	...
	for (i = 0; i < report_size; i += F54_REPORT_DATA_SIZE) {
		int size = min(F54_REPORT_DATA_SIZE, report_size - i);
		...
		rmi_read_block(.., f54->report_data + i, size);
	}

report_data is allocated once at probe from F54's own electrode counts
(array3_size(f54->num_tx_electrodes, f54->num_rx_electrodes, sizeof(u16))),
but rmi_f54_get_report_size() computes the size from
drv_data->num_*_electrodes when those are set, i.e. from the F55
function's electrode counts. Both counts come straight from device
queries (F54 and F55 each report up to 255 electrodes) and nothing
constrains the F55 counts to the F54 ones.

A malicious or malfunctioning RMI4 device that reports larger F55
electrode counts than its F54 counts makes report_size exceed the
allocation, so the read loop writes past report_data (and the V4L2
dequeue memcpy() then reads past it). On conforming hardware the F55
configured electrodes are a subset of the F54 physical electrodes, so
report_size never exceeds the buffer and well-behaved devices are
unaffected.

Record the allocation size and reject a report that does not fit,
mirroring the existing zero-size check.

Fixes: c762cc68b6a1 ("Input: synaptics-rmi4 - propagate correct number of rx and tx electrodes to F54")
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/rmi4/rmi_f54.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/input/rmi4/rmi_f54.c b/drivers/input/rmi4/rmi_f54.c
index 8eac320c43e3..75839a54656b 100644
--- a/drivers/input/rmi4/rmi_f54.c
+++ b/drivers/input/rmi4/rmi_f54.c
@@ -104,6 +104,7 @@ struct f54_data {
 
 	enum rmi_f54_report_type report_type;
 	u8 *report_data;
+	size_t max_report_size;
 	int report_size;
 
 	bool is_busy;
@@ -548,6 +549,13 @@ static void rmi_f54_work(struct work_struct *work)
 		goto out;     /* retry won't help */
 	}
 
+	if (report_size > f54->max_report_size) {
+		dev_err(&fn->dev, "Report size %d exceeds buffer size %zu\n",
+			report_size, f54->max_report_size);
+		error = -EINVAL;
+		goto out;
+	}
+
 	/*
 	 * Need to check if command has completed.
 	 * If not try again later.
@@ -678,8 +686,8 @@ static int rmi_f54_probe(struct rmi_function *fn)
 
 	rx = f54->num_rx_electrodes;
 	tx = f54->num_tx_electrodes;
-	f54->report_data = devm_kzalloc(&fn->dev,
-					array3_size(tx, rx, sizeof(u16)),
+	f54->max_report_size = array3_size(tx, rx, sizeof(u16));
+	f54->report_data = devm_kzalloc(&fn->dev, f54->max_report_size,
 					GFP_KERNEL);
 	if (f54->report_data == NULL)
 		return -ENOMEM;
-- 
2.55.0.rc0.799.gd6f94ed593-goog


  parent reply	other threads:[~2026-06-26  5:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26  5:17 [PATCH 01/10] Input: synaptics-rmi4 - fix F55 transmitter electrode count typo Dmitry Torokhov
2026-06-26  5:17 ` [PATCH 02/10] Input: synaptics-rmi4 - zero report size on F54 work error Dmitry Torokhov
2026-06-26  5:32   ` sashiko-bot
2026-06-26  5:17 ` Dmitry Torokhov [this message]
2026-06-26  5:31   ` [PATCH 03/10] Input: synaptics-rmi4 - bound the F54 report size to the allocated buffer sashiko-bot
2026-06-26  5:17 ` [PATCH 04/10] Input: synaptics-rmi4 - cancel delayed work on F54 remove Dmitry Torokhov
2026-06-26  5:28   ` sashiko-bot
2026-06-26  5:17 ` [PATCH 05/10] Input: synaptics-rmi4 - block s_input when F54 queue is busy Dmitry Torokhov
2026-06-26  5:27   ` sashiko-bot
2026-06-26  5:17 ` [PATCH 06/10] Input: synaptics-rmi4 - propagate F54 worker errors to V4L2 queue Dmitry Torokhov
2026-06-26  7:30   ` sashiko-bot
2026-06-26  5:17 ` [PATCH 07/10] Input: synaptics-rmi4 - check V4L2 buffer size in F54 queue Dmitry Torokhov
2026-06-26  5:31   ` sashiko-bot
2026-06-26  5:17 ` [PATCH 08/10] Input: synaptics-rmi4 - F54 style and typo fixes Dmitry Torokhov
2026-06-26  5:29   ` sashiko-bot
2026-06-26  5:17 ` [PATCH 09/10] Input: synaptics-rmi4 - change report_size to size_t in F54 Dmitry Torokhov
2026-06-26  5:29   ` sashiko-bot
2026-06-26  5:17 ` [PATCH 10/10] Input: synaptics-rmi4 - use __le16 for FIFO offset " Dmitry Torokhov
2026-06-26  5:33   ` sashiko-bot
2026-06-26  5:31 ` [PATCH 01/10] Input: synaptics-rmi4 - fix F55 transmitter electrode count typo sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260626051802.4033172-3-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=hexlabsecurity@proton.me \
    --cc=hverkuil@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox