CVE-2026-142971: USB: serial: garmin_gps: validate packet data length in nat_receive()
In the Linux kernel, the following vulnerability has been resolved:
USB: serial: garmingps: validate packet data length in natreceive()
In natreceive() (called from garminwrite() when userspace writes to /dev/ttyUSBn in MODENATIVE mode), while garmindatap->insize is less than GARMINPKTHDRLENGTH (12), the loop copies up to 12 bytes into garmindatap->inbuffer. Once garmindatap->insize reaches GARMINPKTHDRLENGTH, natreceive() computes the total packet size as:
len = GARMINPKTHDRLENGTH + getDataLength(garmindatap->inbuffer);
Because getDataLength() returns a signed int from le32tocpup(), a 12-byte header with a negative 32-bit length field (such as 0xfffffff5, i.e., -11) causes len to underflow to a small positive value (12 + (-11) = 1) without any bounds check at that point. Then garmindatap->insize = len (12 >= 1) evaluates to true and natreceive() calls garminwritebulk(port, inbuffer, 1, 0), which allocates a 1-byte slab buffer via kmemdup() and immediately reads 4 bytes from it in getLayerId(buffer) (and again in garminwritebulkcallback() when the URB completes):
BUG: KASAN: slab-out-of-bounds in garminwritebulk.constprop.0+0x3eb/0x500 Read of size 4 at addr ffff888002cc0ba0 by task init/1 Call Trace: <TASK> dumpstacklvl+0x70/0xa0 printreport+0x153/0x4c6 kasanreport+0xf1/0x120 garminwritebulk.constprop.0+0x3eb/0x500 garminwrite+0x60f/0x1450 serialwrite+0x123/0x200 nttywrite+0x8ea/0xeb0 filettywrite.isra.0+0x44f/0x7a0 vfswrite+0x671/0xd20
Validate the unsigned 32-bit data length (dlen >= GPSINBUFSIZ - GARMINPKTHDRLENGTH, matching the existing len >= GPSINBUFSIZ bound) in natreceive() as soon as the 12-byte header is present, resetting insize and returning -EINVPKT on invalid lengths so garminwritebulk() is only ever called with a full valid packet header (12 <= len < GPSINBUFSIZ).
Tested in QEMU against Linux 7.3.0-rc3 by emulating a Garmin USB GPS device (091e:0003) via dummyhcd + raw-gadget, switching /dev/ttyUSB0 to MODENATIVE via PRIVPKTIDSETMODE, and writing a 12-byte native packet with data length 0xfffffff5: on the unfixed kernel this triggers KASAN slab-out-of-bounds reads in garminwritebulk() and garminwritebulkcallback(), whereas on the fixed kernel natreceive() rejects the packet with -EINVPKT and 0 KASAN faults.
[ johan: move comment and devdbg(); add comment about redundant check ]