From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Kwok Kin Ming <kenkinming2002@gmail.com>,
Benjamin Tissoires <bentiss@kernel.org>,
Sasha Levin <sashal@kernel.org>,
dianders@chromium.org, jikos@kernel.org, treapking@chromium.org,
dan.carpenter@linaro.org, superm1@kernel.org,
guanwentao@uniontech.com
Subject: [PATCH AUTOSEL 6.18-6.1] HID: i2c-hid: fix potential buffer overflow in i2c_hid_get_report()
Date: Mon, 12 Jan 2026 09:58:10 -0500 [thread overview]
Message-ID: <20260112145840.724774-9-sashal@kernel.org> (raw)
In-Reply-To: <20260112145840.724774-1-sashal@kernel.org>
From: Kwok Kin Ming <kenkinming2002@gmail.com>
[ 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 <kenkinming2002@gmail.com>
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
## Analysis of HID: i2c-hid: fix potential buffer overflow in
i2c_hid_get_report()
### 1. COMMIT MESSAGE ANALYSIS
The commit message clearly describes a **buffer overflow
vulnerability**:
- `recv_len` comes from userspace via the hidraw driver, bounded only by
HID_MAX_BUFFER_SIZE (16384)
- `ihid->rawbuf` has size `ihid->bufsize` determined at runtime by
device report sizes - can be much smaller
- The I2C transfer reads `recv_len + sizeof(__le16)` bytes into the
potentially smaller buffer
- The fix truncates `recv_len` to prevent overflow
Key phrase: "fix potential buffer overflow" - this is a security fix.
The message acknowledges "impact is low since access to hidraw devices
requires root," but buffer overflows are still serious vulnerabilities.
### 2. CODE CHANGE ANALYSIS
The fix is a single line addition:
```c
recv_len = min(recv_len, ihid->bufsize - sizeof(__le16));
```
**Technical mechanism of the bug:**
- `i2c_hid_xfer()` is called with `recv_len + sizeof(__le16)` as the
read length
- If userspace requests a large report via hidraw, `recv_len` could be
up to 16384
- The destination buffer `ihid->rawbuf` has size `ihid->bufsize`, which
is allocated based on the device's maximum report size
- If `recv_len + 2 > ihid->bufsize`, data is written past the end of
`rawbuf`
**Why the fix is correct:**
- The `min()` ensures `recv_len ≤ ihid->bufsize - sizeof(__le16)`
- Therefore `recv_len + sizeof(__le16) ≤ ihid->bufsize` - no overflow
possible
- Placement is perfect: right before the I2C transfer that performs the
write
### 3. CLASSIFICATION
This is a **security bug fix** - specifically a buffer overflow that:
- Can be triggered from userspace (via hidraw)
- Could lead to kernel memory corruption
- Requires root access (limiting practical exploitability)
Even with limited exploitability, buffer overflows in kernel drivers are
exactly what stable trees want to fix for defense-in-depth.
### 4. SCOPE AND RISK ASSESSMENT
| Metric | Assessment |
|--------|------------|
| Lines changed | 1 |
| Files touched | 1 |
| Complexity | Trivial (min() call) |
| Subsystem maturity | High (i2c-hid is mature, widely used) |
| Risk of regression | Near zero |
The fix is **surgical and contained** - it only adds a bounds check. It
cannot break correct behavior since:
- Valid requests (where recv_len fits in the buffer) are unaffected
- Invalid requests (oversized) now get safely truncated instead of
causing overflow
### 5. USER IMPACT
**Affected users:** Anyone using I2C-HID devices - common on laptops for
touchpads, touchscreens, and keyboards.
**Severity:** Buffer overflow = potentially high severity for security
(memory corruption, possible privilege escalation), though
exploitability is limited by root requirement.
**Real-world impact:** While requiring root reduces the attack surface,
compromised root processes or certain security models (containers,
sandboxes) make this relevant.
### 6. STABILITY INDICATORS
- Signed-off-by Benjamin Tissoires (HID subsystem maintainer)
- The fix is trivially verifiable as correct
- Standard defensive bounds checking pattern
### 7. DEPENDENCY CHECK
- Standalone fix, no dependencies on other commits
- `i2c_hid_get_report()` and the buffer management have existed for
years
- Will apply cleanly to stable trees
### STABLE KERNEL RULES ASSESSMENT
| Criterion | Met? |
|-----------|------|
| Obviously correct and tested | ✅ Yes - trivial min() bounds check |
| Fixes a real bug | ✅ Yes - buffer overflow |
| Important issue (security/crash/corruption) | ✅ Yes - security
vulnerability |
| Small and contained | ✅ Yes - 1 line, 1 file |
| No new features | ✅ Yes - pure bug fix |
| Applies cleanly | ✅ Yes - no dependencies |
### RISK VS BENEFIT
**Benefit:** Fixes a buffer overflow vulnerability in widely-used HID
driver code
**Risk:** Effectively zero - the fix is a trivial bounds check that
cannot cause regressions
### CONCLUSION
This commit is an ideal candidate for stable backporting:
- It fixes a genuine security vulnerability (buffer overflow)
- The fix is minimal (1 line), obviously correct, and risk-free
- The i2c-hid driver is widely used on modern laptops
- Even though root is required to exploit, defense-in-depth principles
favor fixing all buffer overflows
- Has proper maintainer sign-off
**YES**
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 63f46a2e57882..5a183af3d5c6a 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -286,6 +286,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
next prev parent reply other threads:[~2026-01-12 14:58 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-12 14:58 [PATCH AUTOSEL 6.18] HID: Elecom: Add support for ELECOM M-XT3DRBK (018C) Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18] x86/sev: Disable GCOV on noinstr object Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] wifi: mac80211: collect station statistics earlier when disconnect Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18] btrfs: do not free data reservation in fallback from inline due to -ENOSPC Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] btrfs: fix deadlock in wait_current_trans() due to ignored transaction type Sasha Levin
2026-01-19 11:46 ` Motiejus Jakštys
2026-01-20 11:03 ` Greg KH
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] HID: quirks: Add another Chicony HP 5MP Cameras to hid_ignore_list Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-6.1] HID: intel-ish-hid: Update ishtp bus match to support device ID table Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] HID: multitouch: add MT_QUIRK_STICKY_FINGERS to MT_CLS_VTL Sasha Levin
2026-01-12 14:58 ` Sasha Levin [this message]
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18] riscv: trace: fix snapshot deadlock with sbi ecall Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-6.12] drm/amd/pm: Disable MMIO access during SMU Mode 1 reset Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-6.12] riscv: Sanitize syscall table indexing under speculation Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.15] netfilter: replace -EEXIST with -EBUSY Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-6.12] PCI: qcom: Remove ASPM L0s support for MSM8996 SoC Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] ALSA: hda/realtek: add HP Laptop 15s-eq1xxx mute LED quirk Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] ring-buffer: Avoid softlockup in ring_buffer_resize() during memory free Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.15] HID: playstation: Center initial joystick axes to prevent spurious events Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] HID: intel-ish-hid: Reset enum_devices_done before enumeration Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18] drm/amd/display: Reduce number of arguments of dcn30's CalculatePrefetchSchedule() Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] HID: Apply quirk HID_QUIRK_ALWAYS_POLL to Edifier QR30 (2d99:a101) Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-6.1] btrfs: fix reservation leak in some error paths when inserting inline extent Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-6.12] ALSA: hda/realtek: Add quirk for Acer Nitro AN517-55 Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-6.12] HID: logitech: add HID++ support for Logitech MX Anywhere 3S Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18] HID: Intel-thc-hid: Intel-thc: Add safety check for reading DMA buffer Sasha Levin
2026-01-12 14:58 ` [PATCH AUTOSEL 6.18-5.10] HID: usbhid: paper over wrong bNumDescriptor field Sasha Levin
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=20260112145840.724774-9-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bentiss@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=dianders@chromium.org \
--cc=guanwentao@uniontech.com \
--cc=jikos@kernel.org \
--cc=kenkinming2002@gmail.com \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=superm1@kernel.org \
--cc=treapking@chromium.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