Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 01/10] HID: core: Protect hid->inputs traversal in hid_check_keys_pressed()
       [not found] <20261123155138.2907049-1-lee@kernel.org>
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback Lee Jones
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Jiri Kosina, Benjamin Tissoires, Dmitry Torokhov,
	Vojtech Pavlik, Michael Haboustak, Marcel Holtmann, linux-input,
	linux-kernel
  Cc: stable

hid_check_keys_pressed() is invoked from USB HID interrupt URB
completion in softirq context without holding hid->driver_input_lock.
During driver unbind or device removal, hid_device_remove() holds
hid->driver_input_lock and calls hid_hw_stop() -> hid_disconnect() ->
hidinput_disconnect(), which unlinks and frees hid_input entries from
hid->inputs before hid->claimed clears HID_CLAIMED_INPUT and before the
low-level transport stops interrupt URBs when another user such as
hidraw keeps the device open, leading to a use-after-free.

Guard hid_check_keys_pressed() with down_trylock() on
hid->driver_input_lock, matching __hid_input_report().

Fixes: c4c259bcc27c ("HID: consolidate connect and disconnect into core code")
Closes: https://sashiko.dev/#/bug/linux-bf47a448-239f-4b68-ac24-60b8b6baf724
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-core.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b4fd482d39d2..03511cddd44f 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -3216,18 +3216,26 @@ EXPORT_SYMBOL_GPL(hid_unregister_driver);
 int hid_check_keys_pressed(struct hid_device *hid)
 {
 	struct hid_input *hidinput;
+	int ret = 0;
 	int i;
 
+	if (down_trylock(&hid->driver_input_lock))
+		return 0;
+
 	if (!(hid->claimed & HID_CLAIMED_INPUT))
-		return 0;
+		goto out;
 
 	list_for_each_entry(hidinput, &hid->inputs, list) {
 		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
-			if (hidinput->input->key[i])
-				return 1;
+			if (hidinput->input->key[i]) {
+				ret = 1;
+				goto out;
+			}
 	}
 
-	return 0;
+out:
+	up(&hid->driver_input_lock);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
 
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback
       [not found] <20261123155138.2907049-1-lee@kernel.org>
  2026-11-23 15:50 ` [PATCH 01/10] HID: core: Protect hid->inputs traversal in hid_check_keys_pressed() Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 03/10] HID: logitech-hidpp: Synchronise send_receive_buf against raw events Lee Jones
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Rishi Gupta, Jiri Kosina, Benjamin Tissoires, Jiangshan Yi,
	linux-i2c, linux-input, linux-kernel
  Cc: stable

mcp2221_probe() enables incoming reports via hid_device_io_start(), so
mcp2221_raw_event() runs concurrently in interrupt context without
holding mcp->lock.  mcp_i2c_smbus_read() points mcp->rxbuf at caller
buffers, including stack-allocated SMBus data in mcp_smbus_xfer(), and
clears mcp->rxbuf at exit without synchronisation against
mcp2221_raw_event().  If a transfer times out while mcp2221_raw_event()
has already loaded mcp->rxbuf, memcpy() writes up to 60 bytes into the
caller's destroyed stack frame or freed buffer.  In addition,
mcp->rxbuf was published before initialising mcp->rxbuf_idx to zero.

Introduce a spinlock to serialise mcp->rxbuf, mcp->rxbuf_size, and
mcp->rxbuf_idx setup and teardown in mcp_i2c_smbus_read() against
MCP2221_I2C_GET_DATA handling in mcp2221_raw_event().

Fixes: 67a95c21463d ("HID: mcp2221: add usb to i2c-smbus host bridge")
Fixes: db2333f88729 ("HID: mcp2221: clear rxbuf after I2C/SMBus transfer completes")
Closes: https://sashiko.dev/#/bug/linux-4983b628-f605-439f-95bb-87560531ec95
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-mcp2221.c | 47 ++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
index 3f05d6e288f9..f3d14d5f11ab 100644
--- a/drivers/hid/hid-mcp2221.c
+++ b/drivers/hid/hid-mcp2221.c
@@ -20,6 +20,7 @@
 #include <linux/iio/iio.h>
 #include <linux/minmax.h>
 #include <linux/moduleparam.h>
+#include <linux/spinlock.h>
 #include "hid-ids.h"
 
 static bool gpio_mode_enforce;
@@ -125,6 +126,7 @@ struct mcp2221 {
 	struct mutex lock;
 	struct completion wait_in_report;
 	struct delayed_work init_work;
+	spinlock_t rxbuf_lock; /* protects rxbuf, rxbuf_size, and rxbuf_idx */
 	u8 *rxbuf;
 	u8 txbuf[64];
 	int rxbuf_idx;
@@ -320,6 +322,7 @@ static int mcp_i2c_smbus_read(struct mcp2221 *mcp,
 				struct i2c_msg *msg, int type, u16 smbus_addr,
 				u8 smbus_len, u8 *smbus_buf)
 {
+	unsigned long flags;
 	int ret;
 	u16 total_len;
 	int retries = 0;
@@ -330,22 +333,22 @@ static int mcp_i2c_smbus_read(struct mcp2221 *mcp,
 		mcp->txbuf[2] = msg->len >> 8;
 		mcp->txbuf[3] = (u8)(msg->addr << 1);
 		total_len = msg->len;
-		mcp->rxbuf = msg->buf;
-		mcp->rxbuf_size = msg->len;
 	} else {
 		mcp->txbuf[1] = smbus_len;
 		mcp->txbuf[2] = 0;
 		mcp->txbuf[3] = (u8)(smbus_addr << 1);
 		total_len = smbus_len;
-		mcp->rxbuf = smbus_buf;
-		mcp->rxbuf_size = smbus_len;
 	}
 
 	ret = mcp_send_data_req_status(mcp, mcp->txbuf, 4);
 	if (ret)
-		goto out;
+		return ret;
 
+	spin_lock_irqsave(&mcp->rxbuf_lock, flags);
+	mcp->rxbuf = msg ? msg->buf : smbus_buf;
+	mcp->rxbuf_size = total_len;
 	mcp->rxbuf_idx = 0;
+	spin_unlock_irqrestore(&mcp->rxbuf_lock, flags);
 
 	do {
 		/* Wait for the data to be read by the device */
@@ -370,14 +373,17 @@ static int mcp_i2c_smbus_read(struct mcp2221 *mcp,
 		} else {
 			retries = 0;
 		}
-	} while (mcp->rxbuf_idx < total_len);
+	} while (READ_ONCE(mcp->rxbuf_idx) < total_len);
 
 	usleep_range(980, 1000);
 	ret = mcp_chk_last_cmd_status_free_bus(mcp);
 
 out:
+	spin_lock_irqsave(&mcp->rxbuf_lock, flags);
 	mcp->rxbuf = NULL;
 	mcp->rxbuf_size = 0;
+	mcp->rxbuf_idx = 0;
+	spin_unlock_irqrestore(&mcp->rxbuf_lock, flags);
 
 	return ret;
 }
@@ -925,22 +931,20 @@ static int mcp2221_raw_event(struct hid_device *hdev,
 			}
 			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;
-				}
-				if (mcp->rxbuf_idx + data[3] > mcp->rxbuf_size) {
-					mcp->status = -EINVAL;
-					break;
-				}
-				if (4 + data[3] > size) {
-					mcp->status = -EINVAL;
-					break;
-				}
+				unsigned long flags;
+
+				spin_lock_irqsave(&mcp->rxbuf_lock, flags);
 				buf = mcp->rxbuf;
-				memcpy(&buf[mcp->rxbuf_idx], &data[4], data[3]);
-				mcp->rxbuf_idx = mcp->rxbuf_idx + data[3];
-				mcp->status = 0;
+				if (!buf || mcp->rxbuf_idx < 0 || data[3] > 60 ||
+				    mcp->rxbuf_idx + data[3] > mcp->rxbuf_size ||
+				    4 + data[3] > size) {
+					mcp->status = -EINVAL;
+				} else {
+					memcpy(&buf[mcp->rxbuf_idx], &data[4], data[3]);
+					WRITE_ONCE(mcp->rxbuf_idx, mcp->rxbuf_idx + data[3]);
+					mcp->status = 0;
+				}
+				spin_unlock_irqrestore(&mcp->rxbuf_lock, flags);
 				break;
 			}
 			mcp->status = -EIO;
@@ -1283,6 +1287,7 @@ static int mcp2221_probe(struct hid_device *hdev,
 	}
 
 	mutex_init(&mcp->lock);
+	spin_lock_init(&mcp->rxbuf_lock);
 	init_completion(&mcp->wait_in_report);
 	hid_set_drvdata(hdev, mcp);
 	mcp->hdev = hdev;
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 03/10] HID: logitech-hidpp: Synchronise send_receive_buf against raw events
       [not found] <20261123155138.2907049-1-lee@kernel.org>
  2026-11-23 15:50 ` [PATCH 01/10] HID: core: Protect hid->inputs traversal in hid_check_keys_pressed() Lee Jones
  2026-11-23 15:50 ` [PATCH 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 04/10] HID: sensor-hub: Serialise synchronous read teardown under data->lock Lee Jones
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Filipe Laíns, Bastien Nocera, Jiri Kosina,
	Benjamin Tissoires, Lopez Casado, Benoît Sevens, linux-input,
	linux-kernel
  Cc: stable

__do_hidpp_send_message_sync() stores a pointer to the caller's
stack-allocated response buffer in hidpp->send_receive_buf while
holding hidpp->send_mutex, whereas hidpp_raw_hidpp_event() runs in
interrupt context without holding hidpp->send_mutex.  Clearing
hidpp->send_receive_buf before releasing hidpp->send_mutex is
insufficient: if hidpp_raw_hidpp_event() loads hidpp->send_receive_buf
just before wait_event_timeout() expires and the caller returns,
writing *answer = *report corrupts up to 64 bytes of the popped kernel
stack frame.  Furthermore, hidpp->send_receive_buf was published before
initialising *response = *message, and error paths zeroed *response
while hidpp->send_receive_buf remained visible.

Protect hidpp->send_receive_buf and hidpp->answer_available with a
spinlock across setup, completion, and teardown so that
hidpp_raw_hidpp_event() cannot access the response buffer once
__do_hidpp_send_message_sync() finishes.

Fixes: 2f31c5252910 ("HID: Introduce hidpp, a module to handle Logitech hid++ devices")
Fixes: e2aaf2d3ad92 ("HID: logitech-hidpp: fix race condition when accessing stale stack pointer")
Closes: https://sashiko.dev/#/bug/linux-fed46492-e564-402a-b7b3-8a761e52e5e7
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-logitech-hidpp.c | 58 +++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 20 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 60fc6b86a085..6c95c4bcdd42 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -18,6 +18,7 @@
 #include <linux/slab.h>
 #include <linux/sched.h>
 #include <linux/sched/clock.h>
+#include <linux/spinlock.h>
 #include <linux/kfifo.h>
 #include <linux/input/mt.h>
 #include <linux/workqueue.h>
@@ -185,6 +186,8 @@ struct hidpp_device {
 	struct hid_device *hid_dev;
 	struct input_dev *input;
 	struct mutex send_mutex;
+	/* protects send_receive_buf and answer_available */
+	spinlock_t send_receive_lock;
 	void *send_receive_buf;
 	char *name;		/* will never be NULL and should not be freed */
 	wait_queue_head_t wait;
@@ -296,39 +299,44 @@ static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp,
 	struct hidpp_report *message,
 	struct hidpp_report *response)
 {
+	unsigned long flags;
 	int ret;
 
 	__must_hold(&hidpp->send_mutex);
 
-	hidpp->send_receive_buf = response;
-	hidpp->answer_available = false;
-
 	/*
 	 * So that we can later validate the answer when it arrives
 	 * in hidpp_raw_event
 	 */
 	*response = *message;
 
+	spin_lock_irqsave(&hidpp->send_receive_lock, flags);
+	hidpp->send_receive_buf = response;
+	hidpp->answer_available = false;
+	spin_unlock_irqrestore(&hidpp->send_receive_lock, flags);
+
 	ret = __hidpp_send_report(hidpp->hid_dev, message);
 	if (ret) {
 		dbg_hid("__hidpp_send_report returned err: %d\n", ret);
-		memset(response, 0, sizeof(struct hidpp_report));
-		goto out;
+		goto err_zero;
 	}
 
-	if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,
-				5*HZ)) {
+	if (!wait_event_timeout(hidpp->wait,
+				READ_ONCE(hidpp->answer_available), 5 * HZ)) {
 		dbg_hid("%s:timeout waiting for response\n", __func__);
-		memset(response, 0, sizeof(struct hidpp_report));
 		ret = -ETIMEDOUT;
-		goto out;
+		goto err_zero;
 	}
 
+	spin_lock_irqsave(&hidpp->send_receive_lock, flags);
+	hidpp->send_receive_buf = NULL;
+	spin_unlock_irqrestore(&hidpp->send_receive_lock, flags);
+
 	if (response->report_id == REPORT_ID_HIDPP_SHORT &&
 	    response->rap.sub_id == HIDPP_ERROR) {
 		ret = response->rap.params[1];
 		dbg_hid("%s:got hidpp error %02X\n", __func__, ret);
-		goto out;
+		return ret;
 	}
 
 	if ((response->report_id == REPORT_ID_HIDPP_LONG ||
@@ -336,13 +344,16 @@ static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp,
 	    response->fap.feature_index == HIDPP20_ERROR) {
 		ret = response->fap.params[1];
 		dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
-		goto out;
+		return ret;
 	}
 
-	ret = 0;
+	return 0;
 
-out:
+err_zero:
+	spin_lock_irqsave(&hidpp->send_receive_lock, flags);
 	hidpp->send_receive_buf = NULL;
+	spin_unlock_irqrestore(&hidpp->send_receive_lock, flags);
+	memset(response, 0, sizeof(struct hidpp_report));
 	return ret;
 }
 
@@ -4125,27 +4136,33 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
 	 * previously sent command.
 	 */
 	if (unlikely(mutex_is_locked(&hidpp->send_mutex))) {
+		unsigned long flags;
+		bool matched = false;
+
+		spin_lock_irqsave(&hidpp->send_receive_lock, flags);
 		question = hidpp->send_receive_buf;
 		answer = hidpp->send_receive_buf;
 
-		if (!question)
-			return 0;
-
 		/*
 		 * Check for a correct hidpp20 answer or the corresponding
 		 * error
 		 */
-		if (hidpp_match_answer(question, report) ||
-				hidpp_match_error(question, report)) {
+		if (question && (hidpp_match_answer(question, report) ||
+				 hidpp_match_error(question, report))) {
 			*answer = *report;
-			hidpp->answer_available = true;
+			hidpp->send_receive_buf = NULL;
+			WRITE_ONCE(hidpp->answer_available, true);
+			matched = true;
+		}
+		spin_unlock_irqrestore(&hidpp->send_receive_lock, flags);
+
+		if (matched) {
 			wake_up(&hidpp->wait);
 			/*
 			 * This was an answer to a command that this driver sent
 			 * We return 1 to hid-core to avoid forwarding the
 			 * command upstream as it has been treated by the driver
 			 */
-
 			return 1;
 		}
 	}
@@ -4723,6 +4740,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	INIT_WORK(&hidpp->work, hidpp_connect_event);
 	INIT_WORK(&hidpp->reset_hi_res_work, hidpp_reset_hi_res_handler);
 	mutex_init(&hidpp->send_mutex);
+	spin_lock_init(&hidpp->send_receive_lock);
 	init_waitqueue_head(&hidpp->wait);
 
 	/* indicates we are handling the battery properties in the kernel */
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 04/10] HID: sensor-hub: Serialise synchronous read teardown under data->lock
       [not found] <20261123155138.2907049-1-lee@kernel.org>
                   ` (2 preceding siblings ...)
  2026-11-23 15:50 ` [PATCH 03/10] HID: logitech-hidpp: Synchronise send_receive_buf against raw events Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 05/10] HID: roccat: pyra: Resolve USB device from parent in actual_profile Lee Jones
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Jiri Kosina, Jonathan Cameron, Srinivas Pandruvada,
	Benjamin Tissoires, Zhang Lixu, Andy Shevchenko, linux-input,
	linux-iio, linux-kernel
  Cc: stable

sensor_hub_input_attr_read_values() and
sensor_hub_input_attr_get_raw_value() set hsdev->pending.status under
data->lock, sleep in wait_for_completion_interruptible_timeout(), and
then clear hsdev->pending.status and consume or free
hsdev->pending.raw_data without acquiring data->lock.  When a wait is
interrupted by a signal or times out while sensor_hub_raw_event() holds
the same spinlock, sensor_hub_raw_event() can memcpy() into the
caller's popped stack buffer in sensor_hub_input_attr_read_values() or
race with kfree() and leak kmemdup() allocations in
sensor_hub_input_attr_get_raw_value().

Hold data->lock when clearing hsdev->pending.status and detaching
hsdev->pending.raw_data in both helpers, and free any prior
hsdev->pending.raw_data before kmemdup() in sensor_hub_raw_event().

Fixes: 401ca24fb34a ("HID: sensors: introduce sensor framework")
Fixes: f784fcea4506 ("HID: sensor-hub: Add sensor_hub_input_attr_read_values() for multi-byte reads")
Closes: https://sashiko.dev/#/bug/linux-5bd5ea7c-72f9-4f22-ae1d-00915390f085
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-sensor-hub.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 81c8e723f9ba..ea846e0bb301 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -306,6 +306,9 @@ int sensor_hub_input_attr_read_values(struct hid_sensor_hub_device *hsdev,
 	long cycles;
 	int ret;
 
+	if (flag == SENSOR_HUB_SYNC && (!buffer || !buffer_size))
+		return -EINVAL;
+
 	report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT);
 	if (!report)
 		return -EINVAL;
@@ -335,7 +338,10 @@ int sensor_hub_input_attr_read_values(struct hid_sensor_hub_device *hsdev,
 		else if (cycles < 0)
 			ret = cycles;
 
+		spin_lock_irqsave(&data->lock, flags);
 		hsdev->pending.status = false;
+		hsdev->pending.raw_data = NULL;
+		spin_unlock_irqrestore(&data->lock, flags);
 	}
 	mutex_unlock(hsdev->mutex_ptr);
 
@@ -375,29 +381,36 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
 	hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
 	mutex_unlock(&data->mutex);
 	if (flag == SENSOR_HUB_SYNC) {
+		u8 *raw_data;
+
 		wait_for_completion_interruptible_timeout(
 						&hsdev->pending.ready, HZ*5);
-		switch (hsdev->pending.raw_size) {
+		spin_lock_irqsave(&data->lock, flags);
+		raw_data = hsdev->pending.raw_data;
+		switch (raw_data ? hsdev->pending.raw_size : 0) {
 		case 1:
 			if (is_signed)
-				ret_val = *(s8 *)hsdev->pending.raw_data;
+				ret_val = *(s8 *)raw_data;
 			else
-				ret_val = *(u8 *)hsdev->pending.raw_data;
+				ret_val = *(u8 *)raw_data;
 			break;
 		case 2:
 			if (is_signed)
-				ret_val = *(s16 *)hsdev->pending.raw_data;
+				ret_val = *(s16 *)raw_data;
 			else
-				ret_val = *(u16 *)hsdev->pending.raw_data;
+				ret_val = *(u16 *)raw_data;
 			break;
 		case 4:
-			ret_val = *(u32 *)hsdev->pending.raw_data;
+			ret_val = *(u32 *)raw_data;
 			break;
 		default:
 			ret_val = 0;
 		}
-		kfree(hsdev->pending.raw_data);
+		hsdev->pending.raw_data = NULL;
+		hsdev->pending.raw_size = 0;
 		hsdev->pending.status = false;
+		spin_unlock_irqrestore(&data->lock, flags);
+		kfree(raw_data);
 	}
 	mutex_unlock(hsdev->mutex_ptr);
 
@@ -590,6 +603,7 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
 					}
 				}
 			} else {
+				kfree(hsdev->pending.raw_data);
 				hsdev->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
 				if (hsdev->pending.raw_data)
 					hsdev->pending.raw_size = sz;
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 05/10] HID: roccat: pyra: Resolve USB device from parent in actual_profile
       [not found] <20261123155138.2907049-1-lee@kernel.org>
                   ` (3 preceding siblings ...)
  2026-11-23 15:50 ` [PATCH 04/10] HID: sensor-hub: Serialise synchronous read teardown under data->lock Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 06/10] HID: hyperv: Validate VMBus packet and payload bounds on receive Lee Jones
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Stefan Achatz, Jiri Kosina, Benjamin Tissoires, linux-input,
	linux-kernel
  Cc: stable

pyra_sysfs_show_actual_profile() is a sysfs attribute callback on the
roccat pyra class device, whose parent is the HID device and
grandparent is the USB interface.  While it resolves pyra via
dev->parent->parent, it passes dev directly to to_usb_interface(),
casting the HID device to a USB device and passing the corrupted
pointer into roccat_common2_receive() and usb_control_msg().

Walk up to dev->parent->parent first, matching
pyra_sysfs_show_firmware_version().

Fixes: be34380ef818 ("HID: roccat: cleanup of pyra module")
Closes: https://sashiko.dev/#/bug/linux-070d5d7b-29ab-4451-90bf-175ada0a81e9
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-roccat-pyra.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c
index 44c2b416f2db..b3dde2998850 100644
--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -290,11 +290,14 @@ static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL);
 static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-	struct pyra_device *pyra =
-			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
+	struct pyra_device *pyra;
+	struct usb_device *usb_dev;
 	struct pyra_settings settings;
 
+	dev = dev->parent->parent;
+	pyra = hid_get_drvdata(dev_get_drvdata(dev));
+	usb_dev = interface_to_usbdev(to_usb_interface(dev));
+
 	mutex_lock(&pyra->pyra_lock);
 	roccat_common2_receive(usb_dev, PYRA_COMMAND_SETTINGS,
 			&settings, PYRA_SIZE_SETTINGS);
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 06/10] HID: hyperv: Validate VMBus packet and payload bounds on receive
       [not found] <20261123155138.2907049-1-lee@kernel.org>
                   ` (4 preceding siblings ...)
  2026-11-23 15:50 ` [PATCH 05/10] HID: roccat: pyra: Resolve USB device from parent in actual_profile Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 07/10] HID: hid-goodix-spi: Validate package sizes in goodix_hid_irq() Lee Jones
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Haiyang Zhang, Wei Liu, Dexuan Cui, Jiri Kosina,
	Benjamin Tissoires, Michael Bommarito, K. Y. Srinivasan,
	linux-hyperv, linux-input, linux-kernel
  Cc: stable

mousevsc_on_receive() dereferences pipe_msg and hid_msg_hdr without
verifying hv_pkt_datalen(packet), passes the untrusted pipe_msg->size
to mousevsc_on_receive_device_info() without checking that the VMBus
packet actually contains pipe_msg->size bytes, and copies up to
sizeof(input_dev->input_buf) (16 KiB) from input_report->buffer in
SYNTH_HID_INPUT_REPORT without checking input_report->header.size
against the received packet buffer.

Validate that hv_pkt_datalen(packet) covers the pipe and SynthHID
headers, that pipe_msg->size fits within the received VMBus packet, and
that input_report->header.size fits within pipe_msg->size.

Fixes: b95f5bcb811e ("HID: Move the hid-hyperv driver out of staging")
Fixes: 934b7778aa7b ("HID: hyperv: validate initial device info bounds")
Closes: https://sashiko.dev/#/bug/linux-03d64dd2-820e-44e2-ba9e-b4a70f1e55ec
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-hyperv.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c
index cfc061dbdd24..1de03e38f363 100644
--- a/drivers/hid/hid-hyperv.c
+++ b/drivers/hid/hid-hyperv.c
@@ -272,14 +272,22 @@ static void mousevsc_on_receive(struct hv_device *device,
 	struct synthhid_msg_hdr *hid_msg_hdr;
 	struct mousevsc_dev *input_dev = hv_get_drvdata(device);
 	struct synthhid_input_report *input_report;
+	u32 pkt_len = hv_pkt_datalen(packet);
 	size_t len;
 
+	if (pkt_len < sizeof(struct pipe_prt_msg) + sizeof(struct synthhid_msg_hdr))
+		return;
+
 	pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
 						(packet->offset8 << 3));
 
 	if (pipe_msg->type != PIPE_MESSAGE_DATA)
 		return;
 
+	if (pipe_msg->size < sizeof(struct synthhid_msg_hdr) ||
+	    pipe_msg->size > pkt_len - sizeof(struct pipe_prt_msg))
+		return;
+
 	hid_msg_hdr = (struct synthhid_msg_hdr *)pipe_msg->data;
 
 	switch (hid_msg_hdr->type) {
@@ -317,6 +325,10 @@ static void mousevsc_on_receive(struct hv_device *device,
 		if (!input_dev->init_complete)
 			break;
 
+		if (input_report->header.size >
+		    pipe_msg->size - sizeof(*input_report))
+			break;
+
 		len = min(input_report->header.size,
 			  (u32)sizeof(input_dev->input_buf));
 		memcpy(input_dev->input_buf, input_report->buffer, len);
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 07/10] HID: hid-goodix-spi: Validate package sizes in goodix_hid_irq()
       [not found] <20261123155138.2907049-1-lee@kernel.org>
                   ` (5 preceding siblings ...)
  2026-11-23 15:50 ` [PATCH 06/10] HID: hyperv: Validate VMBus packet and payload bounds on receive Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 08/10] HID: wacom: Stop HID hardware before releasing resources on mode change Lee Jones
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Jiri Kosina, Benjamin Tissoires, Tianchu Chen, Pan Chuang,
	Charles Wang, Dmitry Torokhov, linux-input, linux-kernel
  Cc: stable

goodix_hid_irq() reads incoming SPI reports into the 95-byte
ts->event_buf heap buffer.  For the coordinate package, pkg->size is
only checked against the 2-byte minimum header size with no upper bound
check against GOODIX_HID_COOR_PKG_LEN (84 bytes), allowing an
out-of-bounds read of up to 65533 bytes via hid_input_report().  For
the trailing attachment package, neither the minimum header size nor
the remaining report byte count is checked, allowing both a 32-bit
unsigned length underflow when pkg->size < 2 and an out-of-bounds read
past ts->event_buf.

Validate that the coordinate package size does not exceed
GOODIX_HID_COOR_PKG_LEN, that the remaining report bytes hold a full
package header before reading the attachment, and that the attachment
package size lies within [GOODIX_HID_PKG_LEN_SIZE, rem_size].

Fixes: 75e16c8ce283 ("HID: hid-goodix: Add Goodix HID-over-SPI driver")
Closes: https://sashiko.dev/#/bug/linux-07f163f5-b48d-4fd5-addc-ba577c30fc6e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-goodix-spi.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/drivers/hid/hid-goodix-spi.c b/drivers/hid/hid-goodix-spi.c
index a2c6b92f74ee..c8c158a74235 100644
--- a/drivers/hid/hid-goodix-spi.c
+++ b/drivers/hid/hid-goodix-spi.c
@@ -574,7 +574,7 @@ static irqreturn_t goodix_hid_irq(int irq, void *data)
 	struct goodix_ts_data *ts = data;
 	struct goodix_hid_report_event *event;
 	struct goodix_hid_report_package *pkg;
-	u16 report_size;
+	u16 report_size, pkg_size, rem_size;
 
 	if (!test_bit(GOODIX_HID_STARTED, &ts->flags))
 		return IRQ_HANDLED;
@@ -600,13 +600,15 @@ static irqreturn_t goodix_hid_irq(int irq, void *data)
 		return IRQ_HANDLED;
 
 	pkg = (struct goodix_hid_report_package *)event->data;
-	if (le16_to_cpu(pkg->size) < GOODIX_HID_PKG_LEN_SIZE) {
-		dev_err(ts->dev, "invalid coordinate event package size, %d",
-			le16_to_cpu(pkg->size));
+	pkg_size = le16_to_cpu(pkg->size);
+	if (pkg_size < GOODIX_HID_PKG_LEN_SIZE ||
+	    pkg_size > GOODIX_HID_COOR_PKG_LEN) {
+		dev_err(ts->dev, "invalid coordinate event package size, %u\n",
+			pkg_size);
 		return IRQ_HANDLED;
 	}
 	hid_input_report(ts->hid, HID_INPUT_REPORT, pkg->data,
-			 le16_to_cpu(pkg->size) - GOODIX_HID_PKG_LEN_SIZE, 1);
+			 pkg_size - GOODIX_HID_PKG_LEN_SIZE, 1);
 
 	report_size = le16_to_cpu(event->hdr.size);
 	/* Check if there are other packages */
@@ -614,22 +616,34 @@ static irqreturn_t goodix_hid_irq(int irq, void *data)
 		return IRQ_HANDLED;
 
 	if (report_size >= ts->hid_max_event_sz) {
-		dev_err(ts->dev, "package size exceed limit %d vs %d",
+		dev_err(ts->dev, "package size exceed limit %d vs %d\n",
 			report_size, ts->hid_max_event_sz);
 		return IRQ_HANDLED;
 	}
 
+	rem_size = report_size - GOODIX_HID_COOR_PKG_LEN;
+	if (rem_size < GOODIX_HID_PKG_LEN_SIZE) {
+		dev_err(ts->dev, "invalid attachment data length, %u\n", rem_size);
+		return IRQ_HANDLED;
+	}
+
 	/* Read the package behind the coordinate data */
 	pkg = goodix_get_event_report(ts, ts->hid_report_addr + sizeof(*event),
-				      ts->event_buf,
-				      report_size - GOODIX_HID_COOR_PKG_LEN);
+				      ts->event_buf, rem_size);
 	if (!pkg) {
-		dev_err(ts->dev, "failed read attachment data content");
+		dev_err(ts->dev, "failed read attachment data content\n");
+		return IRQ_HANDLED;
+	}
+
+	pkg_size = le16_to_cpu(pkg->size);
+	if (pkg_size < GOODIX_HID_PKG_LEN_SIZE || pkg_size > rem_size) {
+		dev_err(ts->dev, "invalid attachment package size, %u vs %u\n",
+			pkg_size, rem_size);
 		return IRQ_HANDLED;
 	}
 
 	hid_input_report(ts->hid, HID_INPUT_REPORT, pkg->data,
-			 le16_to_cpu(pkg->size) - GOODIX_HID_PKG_LEN_SIZE, 1);
+			 pkg_size - GOODIX_HID_PKG_LEN_SIZE, 1);
 
 	return IRQ_HANDLED;
 }
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 08/10] HID: wacom: Stop HID hardware before releasing resources on mode change
       [not found] <20261123155138.2907049-1-lee@kernel.org>
                   ` (6 preceding siblings ...)
  2026-11-23 15:50 ` [PATCH 07/10] HID: hid-goodix-spi: Validate package sizes in goodix_hid_irq() Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor Lee Jones
  2026-11-23 15:50 ` [PATCH 10/10] HID: playstation: Cancel DualSense output worker on create failure Lee Jones
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Ping Cheng, Jason Gerecke, Jiri Kosina, Benjamin Tissoires,
	linux-input, linux-kernel
  Cc: stable

wacom_mode_change_work() runs asynchronously on the system workqueue
without holding driver_input_lock and calls wacom_release_resources()
before hid_hw_stop() on both the pen and touch interfaces.  Because
wacom_release_resources() releases the devres group containing
pen_fifo, input devices, and shared tablet state while USB URBs and HID
transport remain active, a concurrent wacom_raw_event() triggers a
use-after-free.

Call hid_hw_stop() before wacom_release_resources() for both interfaces
to match the teardown order in wacom_remove().

Fixes: 4082da80f46a ("HID: wacom: generic: add mode change touch key")
Closes: https://sashiko.dev/#/bug/linux-e62a8e78-c17f-491a-849b-0690087100f2
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/wacom_sys.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 2d2a4d56a8da..121bead90147 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -2887,16 +2887,16 @@ static void wacom_mode_change_work(struct work_struct *work)
 
 	if (pen) {
 		wacom1 = hid_get_drvdata(pen);
-		wacom_release_resources(wacom1);
 		hid_hw_stop(wacom1->hdev);
+		wacom_release_resources(wacom1);
 		wacom1->wacom_wac.has_mode_change = true;
 		wacom1->wacom_wac.is_direct_mode = is_direct;
 	}
 
 	if (touch) {
 		wacom2 = hid_get_drvdata(touch);
-		wacom_release_resources(wacom2);
 		hid_hw_stop(wacom2->hdev);
+		wacom_release_resources(wacom2);
 		wacom2->wacom_wac.has_mode_change = true;
 		wacom2->wacom_wac.is_direct_mode = is_direct;
 	}
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor
       [not found] <20261123155138.2907049-1-lee@kernel.org>
                   ` (7 preceding siblings ...)
  2026-11-23 15:50 ` [PATCH 08/10] HID: wacom: Stop HID hardware before releasing resources on mode change Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  2026-11-23 15:50 ` [PATCH 10/10] HID: playstation: Cancel DualSense output worker on create failure Lee Jones
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Jiri Kosina, Benjamin Tissoires, Andreas Gal, Vojtech Pavlik,
	He, Bo, Zhang, Jun, linux-input, linux-kernel, bpf
  Cc: stable

hid_debug_rdesc_show() reads hdev->rdesc and hdev->rsize and formats
the raw report descriptor before acquiring hdev->driver_input_lock.
When a HID driver with report_fixup() unbinds or HID-BPF reprobes the
device, hid_device_remove() and __hid_device_probe() free hdev->rdesc
and hdev->bpf_rdesc under hdev->driver_input_lock while the debugfs
entry remains accessible, causing a use-after-free in
hid_debug_rdesc_show().

Acquire hdev->driver_input_lock at the start of hid_debug_rdesc_show()
before reading hdev->rdesc and hdev->rsize.

Fixes: cef0d4948cb0 ("HID: debug: fix race condition with between rdesc_show() and device removal")
Closes: https://sashiko.dev/#/bug/linux-31c0bbf2-e4e7-41e6-ab3b-0d17dfe45389
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-debug.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index f44e6e708404..56207dea4aa7 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -3654,10 +3654,15 @@ static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
 static int hid_debug_rdesc_show(struct seq_file *f, void *p)
 {
 	struct hid_device *hdev = f->private;
-	const __u8 *rdesc = hdev->rdesc;
-	unsigned rsize = hdev->rsize;
+	const __u8 *rdesc;
+	unsigned int rsize;
 	int i;
 
+	if (down_interruptible(&hdev->driver_input_lock))
+		return 0;
+
+	rdesc = hdev->rdesc;
+	rsize = hdev->rsize;
 	if (!rdesc) {
 		rdesc = hdev->dev_rdesc;
 		rsize = hdev->dev_rsize;
@@ -3669,9 +3674,6 @@ static int hid_debug_rdesc_show(struct seq_file *f, void *p)
 	seq_printf(f, "\n\n");
 
 	/* dump parsed data and input mappings */
-	if (down_interruptible(&hdev->driver_input_lock))
-		return 0;
-
 	hid_dump_device(hdev, f);
 	seq_printf(f, "\n");
 	hid_dump_input_mapping(hdev, f);
-- 
2.56.1.750.gf70dc682cf-goog


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

* [PATCH 10/10] HID: playstation: Cancel DualSense output worker on create failure
       [not found] <20261123155138.2907049-1-lee@kernel.org>
                   ` (8 preceding siblings ...)
  2026-11-23 15:50 ` [PATCH 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
  To: lee, Roderick Colenbrander, Jiri Kosina, Benjamin Tissoires,
	Barnabás Pőcze, linux-input, linux-kernel
  Cc: stable

dualsense_create() schedules ds->output_worker via
dualsense_set_lightbar() before registering player LEDs and assigning a
player ID.  If either step fails, the error path returns without
cancelling ds->output_worker, leaving queued or running work accessing
ds after devres frees it in hid_device_probe().

Call dualsense_remove() in the dualsense_create() error path to disable
further scheduling and cancel ds->output_worker synchronously.

Fixes: 949aaccda019 ("HID: playstation: add DualSense player LED support.")
Fixes: 182934a1e93b ("HID: playstation: stop DualSense output work on remove.")
Closes: https://sashiko.dev/#/bug/linux-b657d8df-afc1-429c-9bf5-b2583501dedd
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/hid/hid-playstation.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 143eb891e4a1..1113294f4add 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -1905,6 +1905,7 @@ static struct ps_device *dualsense_create(struct hid_device *hdev)
 	return &ds->base;
 
 err:
+	dualsense_remove(ps_dev);
 	ps_devices_list_remove(ps_dev);
 	return ERR_PTR(ret);
 }
-- 
2.56.1.750.gf70dc682cf-goog


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

end of thread, other threads:[~2026-11-23 15:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261123155138.2907049-1-lee@kernel.org>
2026-11-23 15:50 ` [PATCH 01/10] HID: core: Protect hid->inputs traversal in hid_check_keys_pressed() Lee Jones
2026-11-23 15:50 ` [PATCH 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback Lee Jones
2026-11-23 15:50 ` [PATCH 03/10] HID: logitech-hidpp: Synchronise send_receive_buf against raw events Lee Jones
2026-11-23 15:50 ` [PATCH 04/10] HID: sensor-hub: Serialise synchronous read teardown under data->lock Lee Jones
2026-11-23 15:50 ` [PATCH 05/10] HID: roccat: pyra: Resolve USB device from parent in actual_profile Lee Jones
2026-11-23 15:50 ` [PATCH 06/10] HID: hyperv: Validate VMBus packet and payload bounds on receive Lee Jones
2026-11-23 15:50 ` [PATCH 07/10] HID: hid-goodix-spi: Validate package sizes in goodix_hid_irq() Lee Jones
2026-11-23 15:50 ` [PATCH 08/10] HID: wacom: Stop HID hardware before releasing resources on mode change Lee Jones
2026-11-23 15:50 ` [PATCH 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor Lee Jones
2026-11-23 15:50 ` [PATCH 10/10] HID: playstation: Cancel DualSense output worker on create failure Lee Jones

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