CVE-2026-142820: kgdb: Fix buffer overflow in the 'm' packet handler
In the Linux kernel, the following vulnerability has been resolved:
kgdb: Fix buffer overflow in the 'm' packet handler
gdbcmdmemread() passes the length of the 'm' packet straight to kgdbmem2hex(), which hex-encodes the reply into remcomoutbuffer[BUFMAX] without checking that the reply fits. A client on the KGDB I/O console can ask for a read of any size, and the hex encoding runs off the end of the buffer. kgdbmem2hex() takes that length as an int count, so 2^31 truncates to a negative value and copyfromkernelnofault() is handed buf + count as its destination.
On x86 BUFMAX is 1024, so a read of 512 bytes overruns by the single byte that terminates the hex string:
BUG: KASAN: global-out-of-bounds in kgdbmem2hex+0x1dd/0x230 Write of size 1 at addr ffffffff87651780 by task sh/1 ... The buggy address belongs to the variable: remcomoutbuffer+0x400/0x420
Bounds check the length before the hex encoding:
if (length > (BUFMAX - 1) / 2) { errorpacket(remcomoutbuffer, -EINVAL); return; }
gdbstubmsgwrite() already bounds the count it hex-encodes against BUFMAX. Reads over the limit never returned valid data, so an error reply loses nothing.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 5.10.275 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 5.15.226 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.1.193 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.6.163 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.12.117 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.18.63 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 7.3.4 - Compensating control
In the KGDB 'm' packet handler, reject reads where length > (BUFMAX - 1) / 2 with -EINVAL before calling kgdb_mem2hex().
Event History
Frequently Asked Questions
Who can trigger this issue?
A client with access to the KGDB I/O console can send an oversized GDB remote-protocol memory-read request. The issue is in the handling of the 'm' packet.
What request sizes are unsafe?
The reply is hex-encoded into a fixed BUFMAX-sized output buffer, so a request is unsafe when its encoded output plus terminator exceeds that buffer. On x86, where BUFMAX is 1024, a 512-byte read overruns the buffer by one byte for the terminating string character.
How can I identify a likely occurrence?
On a KASAN-enabled system, the described condition can produce a global-out-of-bounds report in kgdb_mem2hex(), with remcom_out_buffer identified as the affected variable. The provided data does not identify affected kernel versions.
What happens to oversized reads after the fix?
Requests whose encoded response would not fit are rejected with an -EINVAL error reply rather than returning memory data. The change notes that reads over this limit did not return valid data previously.