* [PATCH 00/10] HID: Assorted bug fixes across HID core and drivers
@ 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
0 siblings, 1 reply; 2+ messages in thread
From: Lee Jones @ 2026-11-23 15:50 UTC (permalink / raw)
To: lee, bpf
Cc: linux-kernel, Barnabás Pőcze, Benoît Sevens,
Filipe Laíns, He, Bo, K. Y. Srinivasan, Zhang, Jun,
Andreas Gal, Andy Shevchenko, Bastien Nocera, Benjamin Tissoires,
Charles Wang, Dexuan Cui, Dmitry Torokhov, Haiyang Zhang,
Jason Gerecke, Jiangshan Yi, Jiri Kosina, Jonathan Cameron,
linux-hyperv, linux-i2c, linux-iio, linux-input, Lopez Casado,
Marcel Holtmann, Vojtech Pavlik, Michael Bommarito,
Michael Haboustak, Pan Chuang, Ping Cheng, Rishi Gupta,
Roderick Colenbrander, Srinivas Pandruvada, Stefan Achatz,
Tianchu Chen, Vojtech Pavlik, Wei Liu, Zhang Lixu
These issues were reported by Sashiko.
None of these changes have been tested on physical hardware.
Cc: "Barnabás Pőcze" <pobrn@protonmail.com>
Cc: "Benoît Sevens" <bsevens@google.com>
Cc: "Filipe Laíns" <lains@riseup.net>
Cc: "He, Bo" <bo.he@intel.com>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: "Zhang, Jun" <jun.zhang@intel.com>
Cc: Andreas Gal <gal@cs.uni-magdeburg.de>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Bastien Nocera <hadess@hadess.net>
Cc: Benjamin Tissoires <bentiss@kernel.org>
Cc: bpf@vger.kernel.org
Cc: Charles Wang <charles.goodix@gmail.com>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Jason Gerecke <jason.gerecke@wacom.com>
Cc: Jiangshan Yi <yijiangshan@kylinos.cn>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: linux-hyperv@vger.kernel.org
Cc: linux-i2c@vger.kernel.org
Cc: linux-iio@vger.kernel.org
Cc: linux-input@vger.kernel.org
Cc: Lopez Casado <nlopezcasad@logitech.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Vojtech Pavlik <vojtech@ucw.cz>
Cc: Michael Bommarito <michael.bommarito@gmail.com>
Cc: Michael Haboustak <mike-@cinci.rr.com>
Cc: Pan Chuang <panchuang@vivo.com>
Cc: Ping Cheng <ping.cheng@wacom.com>
Cc: Rishi Gupta <gupt21@gmail.com>
Cc: Roderick Colenbrander <roderick.colenbrander@sony.com>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Stefan Achatz <erazor_de@users.sourceforge.net>
Cc: Tianchu Chen <flynnnchen@tencent.com>
Cc: Vojtech Pavlik <vojtech@suse.cz>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Zhang Lixu <lixu.zhang@intel.com>
Lee Jones (10):
HID: core: Protect hid->inputs traversal in hid_check_keys_pressed()
HID: mcp2221: Synchronise rxbuf access against raw_event callback
HID: logitech-hidpp: Synchronise send_receive_buf against raw events
HID: sensor-hub: Serialise synchronous read teardown under data->lock
HID: roccat: pyra: Resolve USB device from parent in actual_profile
HID: hyperv: Validate VMBus packet and payload bounds on receive
HID: hid-goodix-spi: Validate package sizes in goodix_hid_irq()
HID: wacom: Stop HID hardware before releasing resources on mode
change
HID: debug: Hold driver_input_lock while dumping raw report descriptor
HID: playstation: Cancel DualSense output worker on create failure
drivers/hid/hid-core.c | 16 ++++++---
drivers/hid/hid-debug.c | 12 ++++---
drivers/hid/hid-goodix-spi.c | 34 +++++++++++++------
drivers/hid/hid-hyperv.c | 12 +++++++
drivers/hid/hid-logitech-hidpp.c | 58 +++++++++++++++++++++-----------
drivers/hid/hid-mcp2221.c | 47 ++++++++++++++------------
drivers/hid/hid-playstation.c | 1 +
drivers/hid/hid-roccat-pyra.c | 9 +++--
drivers/hid/hid-sensor-hub.c | 28 +++++++++++----
drivers/hid/wacom_sys.c | 4 +--
10 files changed, 149 insertions(+), 72 deletions(-)
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback
2026-11-23 15:50 [PATCH 00/10] HID: Assorted bug fixes across HID core and drivers Lee Jones
@ 2026-11-23 15:50 ` Lee Jones
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2026-11-23 15:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 15:50 [PATCH 00/10] HID: Assorted bug fixes across HID core and drivers Lee Jones
2026-11-23 15:50 ` [PATCH 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox